configure: Fix check for INSERT in linker script

Message ID 20210910005051.2120865-1-maskray@google.com
State Committed
Commit 5f07d47e4b3d137edfbe3ea6c4eeba1ea6cfa54d
Delegated to: Siddhesh Poyarekar
Headers
Series configure: Fix check for INSERT in linker script |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Fangrui Song Sept. 10, 2021, 12:50 a.m. UTC
  GCC/Clang use local access when referencing a const variable,
so the conftest.so may have no dynamic relocation.
LLD reports `error: unable to insert .foo after .rela.dyn` when the
destination section does not exist.

Use a non-const int to ensure that .rela.dyn exists.
---
 configure    | 2 +-
 configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Siddhesh Poyarekar Sept. 13, 2021, 1:58 p.m. UTC | #1
On 9/10/21 6:20 AM, Fangrui Song via Libc-alpha wrote:
> GCC/Clang use local access when referencing a const variable,
> so the conftest.so may have no dynamic relocation.
> LLD reports `error: unable to insert .foo after .rela.dyn` when the
> destination section does not exist.
> 
> Use a non-const int to ensure that .rela.dyn exists.
> ---
>   configure    | 2 +-
>   configure.ac | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 542802ad35..39d75eb4ed 100755
> --- a/configure
> +++ b/configure
> @@ -5793,7 +5793,7 @@ if ${libc_cv_insert+:} false; then :
>     $as_echo_n "(cached) " >&6
>   else
>     cat > conftest.c <<EOF
> -		const int __attribute__ ((section(".bar"))) bar = 0x12345678;
> +		int __attribute__ ((section(".bar"))) bar = 0x12345678;
>   		int test (void) { return bar; }
>   EOF
>   		cat > conftest.t <<EOF
> diff --git a/configure.ac b/configure.ac
> index d9232418de..00f49f09f7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1217,7 +1217,7 @@ AC_SUBST(libc_cv_protected_data)
>   AC_CACHE_CHECK(linker support for INSERT in linker script,
>   	       libc_cv_insert,
>   	       [cat > conftest.c <<EOF
> -		const int __attribute__ ((section(".bar"))) bar = 0x12345678;
> +		int __attribute__ ((section(".bar"))) bar = 0x12345678;
>   		int test (void) { return bar; }
>   EOF
>   		cat > conftest.t <<EOF
> 

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
  

Patch

diff --git a/configure b/configure
index 542802ad35..39d75eb4ed 100755
--- a/configure
+++ b/configure
@@ -5793,7 +5793,7 @@  if ${libc_cv_insert+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat > conftest.c <<EOF
-		const int __attribute__ ((section(".bar"))) bar = 0x12345678;
+		int __attribute__ ((section(".bar"))) bar = 0x12345678;
 		int test (void) { return bar; }
 EOF
 		cat > conftest.t <<EOF
diff --git a/configure.ac b/configure.ac
index d9232418de..00f49f09f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1217,7 +1217,7 @@  AC_SUBST(libc_cv_protected_data)
 AC_CACHE_CHECK(linker support for INSERT in linker script,
 	       libc_cv_insert,
 	       [cat > conftest.c <<EOF
-		const int __attribute__ ((section(".bar"))) bar = 0x12345678;
+		int __attribute__ ((section(".bar"))) bar = 0x12345678;
 		int test (void) { return bar; }
 EOF
 		cat > conftest.t <<EOF