[PATCH v2 3/3] configure: replace -Ttext-segment -with --imgage-base

H.J. Lu hjl.tools@gmail.com
Wed Dec 17 23:20:58 GMT 2025


On Tue, Dec 9, 2025 at 10:59 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
> Although they are not strictly identical, the -Ttext-segment does not
> consider the ELF header when setting the base virtual address; both
> are sufficient to trigger the issue for the tests that use it [1]
> (a non-zero load address).
>
> Also, lld does not support -Ttext-segment.  The patch also changes the
> onfigure test to use LIBC_TEST_LINKER_FEATURE, since it is used only
> for testing.
>
> [1] https://sourceware.org/bugzilla/show_bug.cgi?id=31799
> ---
>  configure    | 29 ++++++++++++++++-------------
>  configure.ac | 16 ++++++++--------
>  2 files changed, 24 insertions(+), 21 deletions(-)
>
> diff --git a/configure b/configure
> index aa92a122b1..f49bcda0b7 100755
> --- a/configure
> +++ b/configure
> @@ -9056,7 +9056,7 @@ cc-pie-default = $libc_cv_cc_pie_default"
>  # that PIE and static PIE with non-zero load address work correctly.
>  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking PDE load address" >&5
>  printf %s "checking PDE load address... " >&6; }
> -if test ${libc_cv_pde_load_address+y}
> +if test ${libc_cv_test_pde_load_address+y}
>  then :
>    printf %s "(cached) " >&6
>  else case e in #(
> @@ -9074,7 +9074,7 @@ if ${CC-cc} $pde_ld_flags $CFLAGS $CPPFLAGS $LDFLAGS \
>             -nostartfiles -nostdlib $no_ssp \
>             -o conftest conftest.S 1>&5 2>&5; then
>    # Get the load address of the first PT_LOAD segment.
> -  libc_cv_pde_load_address=$(LC_ALL=C $READELF -Wl conftest \
> +  libc_cv_test_pde_load_address=$(LC_ALL=C $READELF -Wl conftest \
>                              | $AWK '/LOAD/ { print $3; exit 0; }')
>  else
>    as_fn_error $? "${CC-cc} can not create PDE" "$LINENO" 5
> @@ -9082,22 +9082,24 @@ fi
>  rm -f conftest* ;;
>  esac
>  fi
> -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pde_load_address" >&5
> -printf "%s\n" "$libc_cv_pde_load_address" >&6; }
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_pde_load_address" >&5
> +printf "%s\n" "$libc_cv_test_pde_load_address" >&6; }
>  config_vars="$config_vars
> -pde-load-address = $libc_cv_pde_load_address"
> +pde-load-address = $libc_cv_test_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.
> -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linker that supports -Ttext-segment=$libc_cv_pde_load_address" >&5
> -printf %s "checking for linker that supports -Ttext-segment=$libc_cv_pde_load_address... " >&6; }
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linker that supports --image-base=$libc_cv_test_pde_load_address" >&5
> +printf %s "checking for linker that supports --image-base=$libc_cv_test_pde_load_address... " >&6; }
>  libc_linker_feature=no
>  cat > conftest.c <<EOF
>  int _start (void) { return 42; }
>  EOF
> +saved_CC="$CC"
> +CC="$TEST_CC"
>  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
> -                 -Wl,-Ttext-segment=$libc_cv_pde_load_address -nostdlib -nostartfiles
> +                 -Wl,--image-base=$libc_cv_test_pde_load_address -nostdlib -nostartfiles
>                   -fPIC -shared -o conftest.so conftest.c
>                   1>&5'
>    { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> @@ -9106,9 +9108,9 @@ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
>    printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>    test $ac_status = 0; }; }
>  then
> -  if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,-Ttext-segment=$libc_cv_pde_load_address -nostdlib \
> +  if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,--image-base=$libc_cv_test_pde_load_address -nostdlib \
>        -nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
> -      | grep "warning: -Ttext-segment=$libc_cv_pde_load_address ignored" > /dev/null 2>&1; then
> +      | grep "warning: --image-base=$libc_cv_test_pde_load_address ignored" > /dev/null 2>&1; then
>      true
>    else
>      libc_linker_feature=yes
> @@ -9116,14 +9118,15 @@ then
>  fi
>  rm -f conftest*
>  if test $libc_linker_feature = yes; then
> -  libc_cv_load_address_ldflag=-Wl,-Ttext-segment
> +  libc_cv_test_load_address_ldflag=-Wl,--image-base
>  else
> -  libc_cv_load_address_ldflag=
> +  libc_cv_test_load_address_ldflag=
>  fi
> +CC="$saved_CC"
>  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
>  printf "%s\n" "$libc_linker_feature" >&6; }
>  config_vars="$config_vars
> -load-address-ldflag = $libc_cv_load_address_ldflag"
> +load-address-ldflag = $libc_cv_test_load_address_ldflag"
>
>  # Check if compiler supports -fno-fp-int-builtin-inexact
>
> diff --git a/configure.ac b/configure.ac
> index ab355fa266..24826fb71e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2009,7 +2009,7 @@ LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
>  # 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
> +              libc_cv_test_pde_load_address, [dnl
>  cat > conftest.S <<EOF
>  .globl _start
>  _start:
> @@ -2024,22 +2024,22 @@ 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 \
> +  libc_cv_test_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])
> +LIBC_CONFIG_VAR([pde-load-address], [$libc_cv_test_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])
> +LIBC_TEST_LINKER_FEATURE([--image-base=$libc_cv_test_pde_load_address],
> +                        [-Wl,--image-base=$libc_cv_test_pde_load_address],
> +                        [libc_cv_test_load_address_ldflag=-Wl,--image-base],
> +                        [libc_cv_test_load_address_ldflag=])
> +LIBC_CONFIG_VAR([load-address-ldflag], [$libc_cv_test_load_address_ldflag])

Do all supported binutils have --image-base? If not, please try
-Ttext-segment if
--image-base isn't available.

>  # Check if compiler supports -fno-fp-int-builtin-inexact
>  LIBC_TRY_CC_AND_TEST_CC_OPTION([if compiler supports -fno-fp-int-builtin-inexact],
> --
> 2.43.0
>


-- 
H.J.


More information about the Libc-alpha mailing list