[PATCH 3/5] configure: use TEST_CC to check for -Ttext-segment

Sam James sam@gentoo.org
Sat Dec 6 13:31:17 GMT 2025


Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:

> The ld.lld does not support this option; however, it does support a
> similar option (--image-base=).  If the -Ttext-segment check fails, it
> also checks for support for --image-base=.

How similar are they? Identical functionality or not? If identical,
let's just use it for bfd, as it seems to support it. If not, we need to
know why it's OK to use it.

> ---
>  configure    | 41 +++++++++++++++++++++++++++++++++++++++++
>  configure.ac | 15 +++++++++++----
>  2 files changed, 52 insertions(+), 4 deletions(-)
>
> diff --git a/configure b/configure
> index 4cfc3daf83..7bf92aab37 100755
> --- a/configure
> +++ b/configure
> @@ -9125,6 +9125,8 @@ 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
>  		  -fPIC -shared -o conftest.so conftest.c
> @@ -9149,8 +9151,47 @@ if test $libc_linker_feature = yes; then
>  else
>    libc_cv_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; }
> +if test -z $libc_cv_load_address_ldflag; then
> +  # ld.lld does not support -Ttext-segment, but supports a similar option
> +  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linker that supports --image-base=$libc_cv_pde_load_address" >&5
> +printf %s "checking for linker that supports --image-base=$libc_cv_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,--image-base=$libc_cv_pde_load_address -nostdlib -nostartfiles
> +		  -fPIC -shared -o conftest.so conftest.c
> +		  1>&5'
> +  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> +  (eval $ac_try) 2>&5
> +  ac_status=$?
> +  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,--image-base=$libc_cv_pde_load_address -nostdlib \
> +      -nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
> +      | grep "warning: --image-base=$libc_cv_pde_load_address ignored" > /dev/null 2>&1; then
> +    true
> +  else
> +    libc_linker_feature=yes
> +  fi
> +fi
> +rm -f conftest*
> +if test $libc_linker_feature = yes; then
> +  libc_cv_load_address_ldflag=-Wl,--image-base
> +else
> +  libc_cv_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; }
> +fi
>  config_vars="$config_vars
>  load-address-ldflag = $libc_cv_load_address_ldflag"
>  
> diff --git a/configure.ac b/configure.ac
> index c7907f48f8..92ad33f37a 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2043,10 +2043,17 @@ 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_TEST_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=])

I'd really prefer AS_IF for the below test wherever possible but I won't
insist on it. At some point I'll convert everything where appropriate..

> +if test -z $libc_cv_load_address_ldflag; then
> +  # ld.lld does not support -Ttext-segment, but supports a similar option
> +  LIBC_TEST_LINKER_FEATURE([--image-base=$libc_cv_pde_load_address],
> +			   [-Wl,--image-base=$libc_cv_pde_load_address],
> +			   [libc_cv_load_address_ldflag=-Wl,--image-base],
> +			   [libc_cv_load_address_ldflag=])
> +fi
>  LIBC_CONFIG_VAR([load-address-ldflag], [$libc_cv_load_address_ldflag])
>  
>  # Check if compiler supports -fno-fp-int-builtin-inexact


More information about the Libc-alpha mailing list