diff mbox series

Properly check linker option in LIBC_LINKER_FEATURE [BZ #28738]

Message ID 20220102141623.589517-1-hjl.tools@gmail.com
State Committed
Commit bd1616c6bee625a2726d0f8b477881b4b25697d8
Headers show
Series Properly check linker option in LIBC_LINKER_FEATURE [BZ #28738] | expand

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

H.J. Lu Jan. 2, 2022, 2:16 p.m. UTC
Update LIBC_LINKER_FEATURE to also check linker warning message since
unknown linker -z option may be ignored by linker:

$ touch x.c
$ gcc -shared -Wl,-z,foobar x.c
/usr/bin/ld: warning: -z foobar ignored
$ echo $?
0
$

This fixes BZ #28738.
---
 aclocal.m4 |  8 +++++++-
 configure  | 32 ++++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 5 deletions(-)

Comments

Florian Weimer Jan. 3, 2022, 11:20 a.m. UTC | #1
* H. J. Lu via Libc-alpha:

> Update LIBC_LINKER_FEATURE to also check linker warning message since
> unknown linker -z option may be ignored by linker:
>
> $ touch x.c
> $ gcc -shared -Wl,-z,foobar x.c
> /usr/bin/ld: warning: -z foobar ignored
> $ echo $?
> 0
> $
>
> This fixes BZ #28738.

Looks okay to me.

Thanks,
Florian
Joseph Myers Jan. 4, 2022, 6:37 p.m. UTC | #2
On Sun, 2 Jan 2022, H.J. Lu via Libc-alpha wrote:

> +    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp $2 -nostdlib \
> +	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
> +	| grep "warning: $1 ignored" > /dev/null 2>&1; then

If you check for specific English language text like that (which may not 
be a good idea, since binutils maintainers may expect to be able to 
rephrase messages without breaking glibc), you need to run the linker (and 
thus the compiler) with LC_ALL=C to avoid getting a translated message.
Florian Weimer Jan. 4, 2022, 9:47 p.m. UTC | #3
* Joseph Myers:

> On Sun, 2 Jan 2022, H.J. Lu via Libc-alpha wrote:
>
>> +    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp $2 -nostdlib \
>> +	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
>> +	| grep "warning: $1 ignored" > /dev/null 2>&1; then
>
> If you check for specific English language text like that (which may not 
> be a good idea, since binutils maintainers may expect to be able to 
> rephrase messages without breaking glibc), you need to run the linker (and 
> thus the compiler) with LC_ALL=C to avoid getting a translated message.

That was my thought as well, but I think the generated configure script
already takes care of that:

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

That's fairly early in the script.

Thanks,
Florian
diff mbox series

Patch

diff --git a/aclocal.m4 b/aclocal.m4
index 3a90d4f679..3e0bcdd12b 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -236,7 +236,13 @@  EOF
 		    -fPIC -shared -o conftest.so conftest.c
 		    1>&AS_MESSAGE_LOG_FD])
   then
-    libc_linker_feature=yes
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp $2 -nostdlib \
+	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+	| grep "warning: $1 ignored" > /dev/null 2>&1; then
+      true
+    else
+      libc_linker_feature=yes
+    fi
   fi
   rm -f conftest*
 fi
diff --git a/configure b/configure
index 954bae803e..3f956cf777 100755
--- a/configure
+++ b/configure
@@ -6009,7 +6009,13 @@  EOF
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
   then
-    libc_linker_feature=yes
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,-z,execstack -nostdlib \
+	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+	| grep "warning: -z execstack ignored" > /dev/null 2>&1; then
+      true
+    else
+      libc_linker_feature=yes
+    fi
   fi
   rm -f conftest*
 fi
@@ -6039,7 +6045,13 @@  EOF
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
   then
-    libc_linker_feature=yes
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,-z,start-stop-gc -nostdlib \
+	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+	| grep "warning: -z start-stop-gc ignored" > /dev/null 2>&1; then
+      true
+    else
+      libc_linker_feature=yes
+    fi
   fi
   rm -f conftest*
 fi
@@ -6070,7 +6082,13 @@  EOF
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
   then
-    libc_linker_feature=yes
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,--depaudit,x -nostdlib \
+	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+	| grep "warning: --depaudit ignored" > /dev/null 2>&1; then
+      true
+    else
+      libc_linker_feature=yes
+    fi
   fi
   rm -f conftest*
 fi
@@ -6101,7 +6119,13 @@  EOF
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
   then
-    libc_linker_feature=yes
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,--no-dynamic-linker -nostdlib \
+	-nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+	| grep "warning: --no-dynamic-linker ignored" > /dev/null 2>&1; then
+      true
+    else
+      libc_linker_feature=yes
+    fi
   fi
   rm -f conftest*
 fi