dynamically written code problem

Bob Wilkinson bob.wilkinson@sbcglobal.net
Mon Oct 11 07:16:00 GMT 2004


I have an application that needs to dynamically write and execute a function
at run-time.  In the Redhat 9 configuration (see below), this never required
any special handling that I am aware of.  The application simply allocated
memory using standard new(), wrote the appropriate machine code to that
memory and then called it like a function.  The application also runs Ok
when built on Redhat 9 and run on Fedora.

When compiling in the Fedora configuration, though, the application seg
faults when attempting to execute at the memory location allocated by new().
I was not able to get gdb to help much in determining the exact cause, but I
assume something became more stringent in terms of the segment descriptors
or page attributes as they relate to what can be executed.  I determined
that the change appears to be introduced at compile time in one of the
related application libraries by starting with a working [RedHat 9 built]
copy and working backwards (first relink application, then recompile
application, etc.)

Now, I played around with the linker command-file and was able to come up
with a work around by declaring a static buffer and then moving sections
around so that the text portion encompassed the bss section (which contained
the buffer), thus allowing it to be executable.  This felt like a hack and
it seems like there must be a better solution.

My questions are: 1) Does anyone know where this change was introduced, and
2) what is the "portable" (at least from a GNU tool chain perspective) to
support this scenario?

Regards,
Bob

Configurations:
Redhat 9
gcc version 3.2.2
ld version 2.13.90.0.18
libc 2.3.2-5

Fedora core 2
gcc version 3.3.3
ld version 2.15.90.0.3
libc 2.3.3-27



More information about the Gcc mailing list