diff options
| author | H.J. Lu <hjl.tools@gmail.com> | 2024-10-29 06:01:14 +0800 |
|---|---|---|
| committer | H.J. Lu <hjl.tools@gmail.com> | 2024-11-22 06:22:13 +0800 |
| commit | e7b553272196e6175b8a15f807cb59217ba2843a (patch) | |
| tree | 61d06f2d421422ea5d8e14d93a1fa8395b541d3d /configure.ac | |
| parent | 713d6d7e781ced6d194d6c147f2db4ce9961bb0c (diff) | |
| download | glibc-e7b553272196e6175b8a15f807cb59217ba2843a.tar.xz glibc-e7b553272196e6175b8a15f807cb59217ba2843a.zip | |
elf: Handle static PIE with non-zero load address [BZ #31799]
For a static PIE with non-zero load address, its PT_DYNAMIC segment
entries contain the relocated values for the load address in static PIE.
Since static PIE usually doesn't have PT_PHDR segment, use p_vaddr of
the PT_LOAD segment with offset == 0 as the load address in static PIE
and adjust the entries of PT_DYNAMIC segment in static PIE by properly
setting the l_addr field for static PIE. This fixes BZ #31799.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
Diffstat (limited to 'configure.ac')
| -rw-r--r-- | configure.ac | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index d5a00461ff..895bd5267d 100644 --- a/configure.ac +++ b/configure.ac @@ -1763,6 +1763,42 @@ fi rm -f conftest.*]) LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default]) +# Get Position Dependent Executable (PDE) load address to be used to +# load static Position Independent Executable (PIE) at a known working +# non-zero load address. This is only used by glibc tests to verify +# that PIE and static PIE with non-zero load address work correctly. +AC_CACHE_CHECK([PDE load address], + libc_cv_pde_load_address, [dnl +cat > conftest.S <<EOF +.globl _start +_start: +.globl __start +__start: +EOF +if test $libc_cv_cc_pie_default = yes; then + pde_ld_flags="-no-pie" +fi +if ${CC-cc} $pde_ld_flags $CFLAGS $CPPFLAGS $LDFLAGS \ + -nostartfiles -nostdlib $no_ssp \ + -o conftest conftest.S 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then + # Get the load address of the first PT_LOAD segment. + libc_cv_pde_load_address=$(LC_ALL=C $READELF -Wl conftest \ + | $AWK '/LOAD/ { print $3; exit 0; }') +else + AC_MSG_ERROR([${CC-cc} can not create PDE]) +fi +rm -f conftest*]) +LIBC_CONFIG_VAR([pde-load-address], [$libc_cv_pde_load_address]) + +# Get the linker command-line option to load executable at a non-zero +# load address. This is only used by glibc tests to verify that PIE and +# static PIE with non-zero load address work correctly. +LIBC_LINKER_FEATURE([-Ttext-segment=$libc_cv_pde_load_address], + [-Wl,-Ttext-segment=$libc_cv_pde_load_address], + [libc_cv_load_address_ldflag=-Wl,-Ttext-segment], + [libc_cv_load_address_ldflag=]) +LIBC_CONFIG_VAR([load-address-ldflag], [$libc_cv_load_address_ldflag]) + AC_MSG_CHECKING(if we can build programs as PIE) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED # error PIE is not supported |
