Hi, Me and Pekka ran into a problem with Jato on x86-64. It segfaults in trace_magic_trampoline() _only_ at the default -Os. I was able to reproduce the bug with a short snippet of C code:
#include <stdio.h> #define b(x) __builtin_return_address(x) int func(int param) { static int count = 0; if (count++ < 10) return func(param); else { printf("%p, %p, %p, %p, %p\n", b(0), b(1), b(2), b(3), b(4)); return 0xdead1234; } } int main(int argc, char **argv) { printf("RETURN: %d\n", func(0x1234)); return 0; } At -O0, everything works fine, at -Os or -O2 it crashes. Replacing b(x) with __builtin_frame_address still makes it crash. Since we've been able to reproduce this accurately outside Jato, I'm quite confident it's not an issue in my code (i.e. trampolines). Jato seems to work fine when supplied CFLAGS="-O2 -g" or CFLAGS="-O0 -g". Quoting the GCC manual: -- Built-in Function: void * __builtin_return_address (unsigned int LEVEL) This function returns the return address of the current function, or of one of its callers. The LEVEL argument is number of frames to scan up the call stack. A value of `0' yields the return address of the current function, a value of `1' yields the return address of the caller of the current function, and so forth. When inlining the expected behavior is that the function will return the address of the function that will be returned to. To work around this behavior use the `noinline' function attribute. The LEVEL argument must be a constant integer. On some machines it may be impossible to determine the return address of any function other than the current one; in such cases, or when the top of the stack has been reached, this function will return `0' or a random value. In addition, `__builtin_frame_address' may be used to determine if the top of the stack has been reached. This function should only be used with a nonzero argument for debugging purposes. Similar stuff holds for __builtin_frame_address(n) when n > 0. Pekka asked me to let you know about this. My take on this is we should attempt to walk the stack using custom, predictable code. Perhaps take a look at what GDB or valgrind do? Cheers, Eduard ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel