Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to detect if libgcc has been loaded

I want to use GNU libc’s backtrace() and backtrace_symbols_fd() functions in a signal handler. However, the backtrace docs page tells me to make sure that libgcc is loaded already in that case.

But how to make sure that libgcc is loaded?

I could try to call some simple functions from libgcc, but it seems that they could simply be builtin in the compiler already and not trigger loading of libgcc. I also tried to use something like dlopen("/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so", RTLD_NOW); on Debian 12, but this does not work, either (with random other shared lib it does work, though). Linking libgcc statically is apparently also not a good option. The solution should be fairly generic and not tied to, e.g., Ubuntu only.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Besides my searching effort, I haven’t found any good solution for this case. Any tips or hints would be highly appreciated.

>Solution :

If you want a function inside libgcc that you can call to ensure the library is loaded, an obvious choice is backtrace itself. Just call it once and throw away the result.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading