1

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.

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

1
  • 1
    I believe the backtrace doc is in error. backtrace* are part of libc. And, malloc et. al. are part of libc. So, it's self contained. No need to check for libgcc.* It will already be linked/loaded (if needed, and I don't think these functions directly depend on it). Neither malloc nor backtrace can be in libgcc because they are system-dependent and that's the province of libc and not libgcc. Commented Apr 20, 2024 at 0:00

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.