Why can't I LD_PRELOAD __assert_fail ?
Chris Barry
cbarry@soundmetrics.com
Fri Feb 18 02:29:00 GMT 2011
Hello,
Unlike x86, on ARM if a core file is generated when a function annotated with "__attribute ((noreturn))" is on the call stack---a function such as abort or __assert_fail---then a backtrace with that core will be nearly useless: you get a message about the PC not being saved:
=====================================
Program terminated with signal 6, Aborted.
[New process 1419]
#0 0x401f62dc in raise () from /lib/libc.so.6
(gdb) bt
#0 0x401f62dc in raise () from /lib/libc.so.6
#1 0x401fa6c8 in abort () from /lib/libc.so.6
Backtrace stopped: frame did not save the PC
(gdb)
=====================================
Now in the case of abort I was able to work around this by using LD_PRELOAD to load a custom abort that is not annotated with "__attribute ((noreturn))":
=====================================
Program terminated with signal 6, Aborted.
[New process 1423]
#0 0x401f62dc in raise () from /lib/libc.so.6
(gdb) bt
#0 0x401f62dc in raise () from /lib/libc.so.6
#1 0x4002f4bc in abort () at libcustomabort.cpp:7
#2 0x0000841c in main () at abort_test.cpp:4
=====================================
But the same LD_PRELOAD trick does not work with the __assert_fail function that the assert macro expands to: this means that when an assert is triggered and a core is dumped, the core is useless.
So before I replace every single "assert" in a large project with a custom "ASSERT" macro to get around this GCC behavior on ARM, I want to ask if one of you is aware of some workaround.
Thank you!
Chris
More information about the Gcc-help
mailing list