[LLVMdev] "Bound Methods" in LLVM Bytecode

Karl Magdsick kmagnum at gmail.com
Sat Oct 29 09:48:53 PDT 2005


On 10/28/05, Evan Jones <ejones at uwaterloo.ca> wrote:
[snip]
>  Will it work if I just
> create a char array and copy in the appropriate native code for the
> current platform? I would rather let LLVM do the hard work, but if that
> isn't possible, I'm looking for some acceptable hack.

(1) The memory page/segment must be marked executable by the
OS.  Under POSIX systems, this is typically done by mmap()ing
an anonymous file and then mprotect()ing the memory.  As I remember,
POSIX doesn't guarantee that mprotect will work on memory directly
allocated with malloc or calloc.  I believe some systems allow it, but
it's my understanding that this practice is non-portable.  The Win32 API
has a function similar in name and function to mprotect
("MemProtect"?? "ProtectMem"??), but I'm not a Win32 guy.

Note: prior to OSes setting the x86 NX/DX bit, x86 code
was able to get away with the assumption that all readable pages are
executable.  This doesn't make such code correct.

(2) As already mentioned by others, you need relocatable code for this
to work properly.


-Karl




More information about the llvm-dev mailing list