public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111936] New: std::stacktrace cannot be used in a shared library
@ 2023-10-23 13:09 vincenzo.innocente at cern dot ch
  2023-10-23 13:23 ` [Bug libstdc++/111936] " vincenzo.innocente at cern dot ch
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2023-10-23 13:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111936

            Bug ID: 111936
           Summary: std::stacktrace cannot be used in a shared library
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch
  Target Milestone: ---

I would like to use std::stacktrace in a shared library to be preloaded...

when I try to build the library even for this minimal example
cat getStacktrace.cc
#include <stacktrace>

  std::string get_stacktrace() {
     std::string trace;
     for (auto & entry : std::stacktrace::current() ) trace +=
entry.description() + '#';
     return trace;
  }

it fails
 c++ -O3 -Wall -pthread -fPIC -shared getStacktrace.cc -std=c++23 -lstdc++exp
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-fileline.o):
relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-posix.o):
relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-simple.o):
relocation R_X86_64_32 against `.text' can not be used when making a shared
object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-elf.o):
relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-mmap.o):
relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-mmapio.o):
relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld:
/afs/cern.ch/work/i/innocent/public/w5/bin/../lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../lib64/libstdc++exp.a(std_stacktrace-dwarf.o):
relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status


it silently compiles with
[innocent@patatrack01 ctest]$ c++ -O3 -Wall -pthread -fPIC -shared -std=c++23
-lstdc++exp getStacktrace.cc

but the symbols are undefined

[innocent@patatrack01 ctest]$ ldd ./a.out
        linux-vdso.so.1 (0x00007ffd50f73000)
        libstdc++.so.6 => /afs/cern.ch/user/i/innocent/w5/lib64/libstdc++.so.6
(0x00007fa9437f8000)
        libm.so.6 => /usr/lib64/libm.so.6 (0x00007fa943476000)
        libgcc_s.so.1 => /afs/cern.ch/user/i/innocent/w5/lib64/libgcc_s.so.1
(0x00007fa94324b000)
        libpthread.so.0 => /usr/lib64/libpthread.so.0 (0x00007fa94302b000)
        libc.so.6 => /usr/lib64/libc.so.6 (0x00007fa942c66000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa943e68000)
[innocent@patatrack01 ctest]$ nm -C ./a.out | grep stack
0000000000000db0 T get_stacktrace[abi:cxx11]()
0000000000000be0 t get_stacktrace[abi:cxx11]() [clone .cold]
0000000000000d20 t std::basic_stacktrace<std::allocator<std::stacktrace_entry>
>::current(std::allocator<std::stacktrace_entry> const&) [clone .isra.0]
                 U std::stacktrace_entry::_Info::_M_populate(unsigned long)
0000000000001430 W std::stacktrace_entry::_Info::_S_set[abi:cxx11](void*, char
const*)
                 U std::__stacktrace_impl::_S_current(int (*)(void*, unsigned
long), void*, int)
0000000000001310 W std::basic_stacktrace<std::allocator<std::stacktrace_entry>
>::_M_prepare(unsigned short)::{lambda(void*, unsigned long)#1}::_FUN(void*,
unsigned long)


and at run time (not this example, my full application that invoke the
staketrace from a malloc hook) it (obviously fail)

[innocent@patatrack01 ctest]$ c++ -O3 -Wall -pthread -fPIC -shared -std=c++23
-lstdc++exp mallocWrapper.cc
[innocent@patatrack01 ctest]$ setenv LD_PRELOAD ./a.out ; ls ; unsetenv
LD_PRELOAD
Recoding structure constructed in a thread
ls: symbol lookup error: ./a.out: undefined symbol:
_ZNSt17__stacktrace_impl10_S_currentEPFiPvmES0_i

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-10-25 14:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 13:09 [Bug libstdc++/111936] New: std::stacktrace cannot be used in a shared library vincenzo.innocente at cern dot ch
2023-10-23 13:23 ` [Bug libstdc++/111936] " vincenzo.innocente at cern dot ch
2023-10-23 14:28 ` redi at gcc dot gnu.org
2023-10-23 14:32 ` redi at gcc dot gnu.org
2023-10-23 14:32 ` redi at gcc dot gnu.org
2023-10-23 16:13 ` redi at gcc dot gnu.org
2023-10-24 10:04 ` vincenzo.innocente at cern dot ch
2023-10-24 12:27 ` redi at gcc dot gnu.org
2023-10-24 12:38 ` vincenzo.innocente at cern dot ch
2023-10-24 15:55 ` redi at gcc dot gnu.org
2023-10-24 16:27 ` vincenzo.innocente at cern dot ch
2023-10-24 16:28 ` redi at gcc dot gnu.org
2023-10-25 10:28 ` cvs-commit at gcc dot gnu.org
2023-10-25 14:21 ` cvs-commit at gcc dot gnu.org
2023-10-25 14:35 ` cvs-commit at gcc dot gnu.org
2023-10-25 14:36 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).