How to execute machine code programatically in golang?
121 views
Skip to first unread message
kant kodali
unread,
Jun 22, 2024, 1:13:17 AM (11 days ago) Jun 22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-dev
Hi All,
I was trying to see how I can execute machine code programmatically in golang. Here is an example I have so far https://go.dev/play/p/5HL1ydr5IUy but this results in a segfault when I finally call the function in the end. Any idea how to fix this?
Thanks,
Kant
Mark Diener
unread,
Jun 23, 2024, 4:32:27 PM (9 days ago) Jun 23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to kant kodali, golang-dev
A func value is a pointer to a word containing the address of the
code; in other words, it's doubly indirect. (The code generated for
f() is a load from f followed by an indirect CALL.) So, you need to
introduce another level of indirection. Also, the logic for the unsafe
coercion is wrong: it lacks an & operator, so you need a second level
of indirection.