mirror of git://sourceware.org/git/glibc.git
In some cases, an IFUNC resolver may need to access the gp pointer to access global variables. Such an object may have l_relocated == 0 at this time. In this case, an IFUNC resolver will fail to access a global variable and cause a SIGSEGV. This patch fixes this issue by relaxing the check of l_relocated in elf_machine_runtime_setup, but added a check for SHARED case to avoid using this code in static-linked executables. Such object have already set up the gp pointer in load_gp function and l->l_scope will be NULL if it is a pie object. So if we use these code to set up the gp pointer again for static-pie, it will causing a SIGSEGV in glibc as original bug on BZ #31317. I have also reproduced and checked BZ #31317 using the mold commit bed5b1731b ("illumos: Treat absolute symbols specially"), this patch can fix the issue. Also, we used the wrong gp pointer previously because ref->st_value is not the relocated address but just the offset from the base address of ELF. An edge case may happen if we reference gp pointer in a IFUNC resolver in a PIE object, but it will not happen in compiler-generated codes since -pie will disable relax to gp. In this case, the GP will be initialized incorrectly since the ref->st_value is not the address after relocation. This patch fixes this issue by adding the l->l_addr to ref->st_value to get the relocated address for the gp pointer. We don't use SYMBOL_ADDRESS macro here because __global_pointer$ is a special symbol that has SHN_ABS type, but it will use PC-relative addressing in the load_gp function using lla. Closes: BZ #32269 Fixes: |
||
|---|---|---|
| .. | ||
| bits | ||
| multiarch | ||
| nofpu | ||
| nptl | ||
| rv32 | ||
| rv64 | ||
| rvd | ||
| rvf | ||
| sys | ||
| Implies | ||
| Makefile | ||
| __longjmp.S | ||
| bsd-_setjmp.c | ||
| bsd-setjmp.c | ||
| configure | ||
| configure.ac | ||
| dl-irel.h | ||
| dl-link.sym | ||
| dl-machine.h | ||
| dl-relocate-ld.h | ||
| dl-tls.h | ||
| dl-trampoline.S | ||
| e_sqrtl.c | ||
| fpu_control.h | ||
| gccframe.h | ||
| jmpbuf-offsets.h | ||
| jmpbuf-unwind.h | ||
| ldsodefs.h | ||
| libc-tls.c | ||
| linkmap.h | ||
| machine-gmon.h | ||
| math-tests-snan-payload.h | ||
| math-tests-trap.h | ||
| preconfigure | ||
| preconfigure.ac | ||
| riscv-ifunc.h | ||
| setjmp.S | ||
| sfp-machine.h | ||
| sotruss-lib.c | ||
| start.S | ||
| string-fza.h | ||
| string-fzi.h | ||
| thread_pointer.h | ||
| tininess.h | ||
| tst-audit.h | ||
| utmp-size.h | ||