]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Copy non_got_ref_without_indirect_extern_access
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 10 Sep 2025 01:38:49 +0000 (18:38 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Sep 2025 12:44:56 +0000 (05:44 -0700)
Copy non_got_ref_without_indirect_extern_access when copying indirect
symbol for weak alias so that _bfd_x86_elf_adjust_dynamic_symbol will
properly handle GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.

bfd/

PR ld/33409
* elfxx-x86.c (_bfd_x86_elf_copy_indirect_symbol): Copy
non_got_ref_without_indirect_extern_access.

ld/

PR ld/33409
* testsuite/config/default.exp (NO_DIRECT_EXTERN_ACCESS_CFLAGS):
New.
* testsuite/ld-elf/shared.exp: Run PR ld/33409 tests.
* testsuite/ld-elf/pr33409a.c: New file.
* testsuite/ld-elf/pr33409b.c: Likewise.
* testsuite/ld-elf/pr33409c.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elfxx-x86.c
ld/testsuite/config/default.exp
ld/testsuite/ld-elf/pr33409a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr33409b.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr33409c.c [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 58a83173827f5e0be6bda848c57bd9520adc6b92..06265ee4e15560366717d731aa987723d8816cea 100644 (file)
@@ -3155,6 +3155,12 @@ _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info *info,
      generate a R_386_COPY reloc.  */
   edir->gotoff_ref |= eind->gotoff_ref;
 
+  /* Copy non_got_ref_without_indirect_extern_access so that
+     _bfd_x86_elf_adjust_dynamic_symbol will handle
+     GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS properly.  */
+  edir->non_got_ref_without_indirect_extern_access
+    |= eind->non_got_ref_without_indirect_extern_access;
+
   edir->zero_undefweak |= eind->zero_undefweak;
 
   if (ELIMINATE_COPY_RELOCS
index 3619f523762e2ad667aeb7598cd8af1b147fe3e0..fae7d72d7e07239b23e8fd5320eb4a4a54bec4da 100644 (file)
@@ -458,10 +458,13 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
 
 if { ![info exists DIRECT_EXTERN_ACCESS_CFLAGS] } then {
     set DIRECT_EXTERN_ACCESS_CFLAGS ""
+    set NO_DIRECT_EXTERN_ACCESS_CFLAGS ""
     if [compiler_supports "-mdirect-extern-access"] {
        set DIRECT_EXTERN_ACCESS_CFLAGS "-mdirect-extern-access"
+       set NO_DIRECT_EXTERN_ACCESS_CFLAGS "-mno-direct-extern-access"
     } elseif [compiler_supports "-fdirect-access-external-data"] {
        set DIRECT_EXTERN_ACCESS_CFLAGS "-fdirect-access-external-data"
+       set NO_DIRECT_EXTERN_ACCESS_CFLAGS "-fno-direct-access-external-data"
     }
 }
 
diff --git a/ld/testsuite/ld-elf/pr33409a.c b/ld/testsuite/ld-elf/pr33409a.c
new file mode 100644 (file)
index 0000000..c37a5e6
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+extern char *array[];
+
+char **
+foo (void)
+{
+  return array;
+}
+
+extern void bar (void);
+
+int
+main()
+{
+  char **p = foo ();
+  bar ();
+  printf ("%s\n", p[0]);
+  return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr33409b.c b/ld/testsuite/ld-elf/pr33409b.c
new file mode 100644 (file)
index 0000000..db64e13
--- /dev/null
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+char *__array [] =
+{
+  "PASS",
+  NULL
+};
+
+extern __typeof (__array) array __attribute__ ((weak, alias ("__array")));
diff --git a/ld/testsuite/ld-elf/pr33409c.c b/ld/testsuite/ld-elf/pr33409c.c
new file mode 100644 (file)
index 0000000..7de81b3
--- /dev/null
@@ -0,0 +1,4 @@
+void
+bar (void)
+{
+}
index a24525a2ff82905fd2c185ddc0bb0930c722d7a2..fad38120e6ecf83e66a5a55cfdf6528d0bcc954b 100644 (file)
@@ -1016,6 +1016,20 @@ run_cc_link_tests [list \
         {nm {-u -D --with-symbol-versions} pr26302.nd}} \
        "pr26302b.so" \
     ] \
+    [list \
+       "Build pr33409a.o" \
+       "" \
+       "$DIRECT_EXTERN_ACCESS_CFLAGS" \
+       {pr33409a.c} \
+    ] \
+    [list \
+       "Build pr33409.so" \
+       "-shared" \
+       "-fPIC" \
+       {pr33409b.c} \
+       {} \
+       "pr33409.so" \
+    ] \
 ]
 
 run_ld_link_tests [list \
@@ -1206,6 +1220,17 @@ set run_tests [list \
      "tmpdir/pr31482b-no-lto.so tmpdir/pr31482c-no-lto.a \
       tmpdir/pr31482d-no-lto.a" \
     ] \
+    [list "Run pr33409" \
+     "-Wl,-z,text" \
+     "" \
+     {pr33409c.c} \
+     "pr33409" \
+     "pass.out" \
+     "$NO_DIRECT_EXTERN_ACCESS_CFLAGS" \
+     "c" \
+     "" \
+     "tmpdir/pr33409a.o tmpdir/pr33409.so" \
+    ] \
 ]
 
 # NetBSD ELF systems do not currently support the .*_array sections.