[PATCH] libstdc++: use a link test to test for -Wl,-z,relro

JonY 10walls@gmail.com
Tue Sep 22 09:40:05 GMT 2020


On 9/22/20 8:50 AM, Jonathan Wakely wrote:
> 
> I don't see a patch, or any previous email to the libstdc++ list.
> 
> Please resend with the patch, CCing libstdc++@
> 
> Thanks.
> 
> 
> 

Resent for the record. I've been told it might not be appropriate
because some targets cannot link yet and therefore will fail incorrectly.

Currently, the linker support is misdetected since binutils can support
multiple targets. MinGW/Cygwin PE formats don't support such a flag.
-------------- next part --------------
From: Jonathan Yong <10walls@gmail.com>
Date: Sun, 22 Mar 2020 01:59:37 +0000 (+0800)
Subject: libstdc++: use a link test to test for -Wl,-z,relro
X-Git-Url: https://repo.or.cz/gcc/cygwin-gcc.git/commitdiff_plain/1b20e03e7468760828bfc70fc5e811b5b3738adf

libstdc++: use a link test to test for -Wl,-z,relro

Do a link test instead of just a grep. The linker can
support multiple targets, but not all targets can use it.

Signed-off-by: Jonathan Yong <10walls@gmail.com>
---

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index bc7d137dc74..209aa3a91f3 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -274,7 +274,16 @@ AC_DEFUN([GLIBCXX_CHECK_LINKER_FEATURES], [
   ac_ld_relro=no
   if test x"$with_gnu_ld" = x"yes"; then
     AC_MSG_CHECKING([for ld that supports -Wl,-z,relro])
-    cxx_z_relo=`$LD -v --help 2>/dev/null | grep "z relro"`
+    ac_save_ldflags="$LDFLAGS"
+    LDFLAGS="$LDFLAGS -Wl,-z,relro"
+    AC_LINK_IFELSE([
+      AC_LANG_SOURCE(
+        [[int main() { return 0; }]]
+      )],
+      [cxx_z_relo="1"],
+      [cxx_z_relo=""])
+   LDFLAGS="$ac_save_ldflags"
+
     if test -n "$cxx_z_relo"; then
       OPT_LDFLAGS="-Wl,-z,relro"
       ac_ld_relro=yes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200922/6aa368b5/attachment.sig>


More information about the Gcc-patches mailing list