glibc/sysdeps
Xi Ruoyao 589eda82bb LoongArch: Fix the condition to use PC-relative addressing in start.S
A start.o compiled from start.S with -DPIC and no -DSHARED is used by
both crt1.o and rcrt1.o.  So the LoongArch static PIE patch
unintentionally introduced PC-relative addressing for main and
__libc_start_main into crt1.o.

While the latest Binutils (trunk, which will be released as 2.40)
supports the PC-relative relocs against an external function by creating
a PLT entry, the 2.39 release branch doesn't (and won't) support this.
An error is raised:

    "PLT stub does not represent and symbol not defined."

So, we need the following changes:

1. Check if ld supports the PC-relative relocs against an external
   function.  If it's not supported, we deem static PIE unsupported.
2. Change start.S.  If static PIE is supported, use PC-relative
   addressing for main and __libc_start_main and rely on the linker to
   create PLT entries.  Otherwise, restore the old behavior (using GOT
   to address these functions).

An alternative would be adding a new "static-pie-start.S", and some
custom logic into Makefile to build rcrt1.o with it.  And, restore
start.S to the state before static PIE change so crt1.o won't contain
PC-relative relocs against external symbols.  But I can't see any
benefit of this alternative, so I'd just keep it simple.

Tested by building glibc with the following configurations:

1. Binutils trunk + GCC trunk.  Static PIE enabled.  All tests
   passed.
2. Binutils 2.39 branch + GCC trunk.  Static PIE disabled.  Tests
   related to ifunc failed (it's a known issue).  All other tests
   passed.
3. Binutils 2.39 branch + GCC 12 branch, cross compilation with
   build-many-glibcs.py from x86_64-linux-gnu.  Static PIE disabled.
   Build succeeded.
2022-10-08 16:34:45 +08:00
..
aarch64 Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
alpha elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
arc Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
arm arm: Enable USE_ATOMIC_COMPILER_BUILTINS (BZ #24774) 2022-10-07 16:19:20 -03:00
csky elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
generic elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
gnu errlist: add missing entry for EDEADLOCK (bug 29545) 2022-09-08 11:40:24 +02:00
hppa hppa: Fix initialization of dp register [BZ 29635] 2022-10-01 19:49:25 +00:00
htl htl: Make pthread*_cond_timedwait register wref before releasing mutex 2022-08-22 22:27:24 +02:00
hurd hurd: Fix pthread_kill on exiting/ted thread 2022-01-15 15:11:54 +01:00
i386 x86: Remove .tfloat usage 2022-10-03 14:03:21 -03:00
ia64 Update _FloatN header support for C++ in GCC 13 2022-09-28 20:10:08 +00:00
ieee754 Update _FloatN header support for C++ in GCC 13 2022-09-28 20:10:08 +00:00
loongarch LoongArch: Fix the condition to use PC-relative addressing in start.S 2022-10-08 16:34:45 +08:00
m68k Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
mach Regenerate sysdeps/mach/hurd/bits/errno.h 2022-10-05 19:21:25 +00:00
microblaze Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
mips elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
nios2 Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
nptl Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
or1k Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
posix get_nscd_addresses: Fix subscript typos [BZ #29605] 2022-09-28 12:47:10 -04:00
powerpc elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
pthread Do not define static_assert or thread_local in headers for C2x 2022-09-07 18:39:28 +00:00
riscv Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
s390 elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
sh Use atomic_exchange_release/acquire 2022-09-26 16:58:08 +01:00
sparc elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
unix elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
x86 elf: Remove _dl_string_hwcap 2022-10-06 07:59:48 -03:00
x86_64 x86_64: Remove platform directory library loading test 2022-10-06 07:59:48 -03:00