[Bug tree-optimization/66826] Unused result from dlsym in constructor results in a segfault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 Andrew Pinski changed: What|Removed |Added URL|https://gist.github.com/dau | |rnimator/a468e01800752d11cd | |15 | Status|UNCONFIRMED |NEW Last reconfirmed||2021-09-02 Ever confirmed|0 |1 --- Comment #7 from Andrew Pinski --- https://gist.github.com/daurnimator/a468e01800752d11cd15 Confirmed.
[Bug tree-optimization/66826] Unused result from dlsym in constructor results in a segfault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 --- Comment #6 from Yuri Gribov --- (In reply to Rich Felker from comment #5) > maybe there are workarounds glibc could do to prevent tco without needing a > new attribute... X-posted to Glibc BZ: https://sourceware.org/bugzilla/show_bug.cgi?id=21050
[Bug tree-optimization/66826] Unused result from dlsym in constructor results in a segfault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 Rich Felker changed: What|Removed |Added CC||bugdal at aerifal dot cx --- Comment #5 from Rich Felker --- I think the issue is more complicated. Even if glibc were fixed not to crash, code like the following: return dlsym(RTLD_NEXT, "whatever"); would return the wrong result under tco when the caller's caller is in a different dso. GCC probably needs a "notailcall" attribute to fix this, but maybe there are workarounds glibc could do to prevent tco without needing a new attribute...
[Bug tree-optimization/66826] Unused result from dlsym in constructor results in a segfault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 --- Comment #4 from Yuri Gribov --- As this is not a GCC bug I suggest you * close this issue (as not-a-bug?) * report to Glibc folks (perhaps they could do more checking of return address or at least document their calling convention assumptions in manpages)
[Bug tree-optimization/66826] Unused result from dlsym in constructor results in a segfault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 Yuri Gribov changed: What|Removed |Added CC||tetra2005 at gmail dot com --- Comment #3 from Yuri Gribov --- This is a very funny bug but not related to GCC per se. Firstly, let's consider a miminal repro: __attribute__((constructor)) static void some_init() { dlsym(RTLD_DEFAULT, "anything"); } (segfaults just as well). Under -O0 this produces a normal call: calldlsym@PLT ... ret but with -O2 GCC is clever enough to tail-call-optimize it to a plain jump: jmp dlsym@PLT Now dlsym (and other dl-functions) secretly take shadow parameter - return address on stack: void * __dlsym (void *handle, const char *name DL_CALLER_DECL) { ... struct dlsym_args args; args.who = DL_CALLER; args.handle = handle; args.name = name; (from dlsym.c). As in our case return address is missing, args.who argument is missing which causes segfault during symbol resolution (dynamic linker is lame on checks).