Re: eh_globals.o in libstdc++.a not relocatable?

RVP <[email protected]>
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
> ld: /usr/lib/libstdc++.a(eh_globals.o): relocation R_X86_64_TPOFF32 against `_ZZN12_GLOBAL__N_110get_globalEvE6global' can not be used w hen making a shared object; recompile with -fPIC
>

This is telling you that _that_ object (and by extension the library itself)
hasn't been compiled with -fPIC.

Q1: Why is this linking against the system libstdc++ instead of the
     recently compiled one?

Q2: If it really needs the system library (unlikely!) why doesn't it link
     against the shared library libstdc++.so?

> On the other hand:
>
> $ ar x /usr/lib/libstdc++.a eh_globals.o
> $ file eh_globals.o
> eh_globals.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
>
> so eh_globals.o seems to be relocatable?
>

Not compiled with `-fPIC' though. This is the eh_globals.o from /usr/lib/libstdc++.a

```
$ readelf -r eh_globals.o | c++filt

Relocation section with addend (.rela.text):
r_offset     r_info       r_type              st_value         st_name + r_addend
00000000000b 000300000017 R_X86_64_TPOFF32    0000000000000000 (anonymous namespace)::get_global()::global + 0
00000000001b 000300000017 R_X86_64_TPOFF32    0000000000000000 (anonymous namespace)::get_global()::global + 0

Relocation section with addend (.rela.eh_frame):
r_offset     r_info       r_type              st_value         st_name + r_addend
000000000020 000200000002 R_X86_64_PC32       0000000000000000 .text + 0
000000000034 000200000002 R_X86_64_PC32       0000000000000000 .text + 10
$
```

This is the one from gcc-12.2.0 on Linux, where I configured GCC with
--enable-shared.

```
$ readelf -r eh_globals.o | c++filt

Relocation section with addend (.rela.text.__cxa_get_globals_fast):
r_offset     r_info       r_type              st_value         st_name + r_addend
00000000000b 000200000014 R_X86_64_TLSLD      0000000000000000 (anonymous namespace)::get_global()::global + fffffffffffffffc
000000000010 000e00000004 R_X86_64_PLT32      0000000000000000 __tls_get_addr + fffffffffffffffc
00000000001a 000200000015 R_X86_64_DTPOFF32   0000000000000000 (anonymous namespace)::get_global()::global + 0

Relocation section with addend (.rela.text.__cxa_get_globals):
r_offset     r_info       r_type              st_value         st_name + r_addend
00000000000b 000200000014 R_X86_64_TLSLD      0000000000000000 (anonymous namespace)::get_global()::global + fffffffffffffffc
000000000010 000e00000004 R_X86_64_PLT32      0000000000000000 __tls_get_addr + fffffffffffffffc
00000000001a 000200000015 R_X86_64_DTPOFF32   0000000000000000 (anonymous namespace)::get_global()::global + 0

Relocation section with addend (.rela.eh_frame):
r_offset     r_info       r_type              st_value         st_name + r_addend
000000000020 000100000002 R_X86_64_PC32       0000000000000000 .text.__cxa_get_globals_fast + 0
000000000038 000300000002 R_X86_64_PC32       0000000000000000 .text.__cxa_get_globals + 0
$
```

Note `R_X86_64_TLSLD' type and the reference to `__tls_get_addr' when `-fPIC'
is used when creating the object.

-RVP
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.