]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Always treat protected symbols as local
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 11 Aug 2025 19:40:15 +0000 (12:40 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 12 Aug 2025 13:34:40 +0000 (06:34 -0700)
Since linker never generates dynamic relocation for protected symbol in:

__attribute__((visibility("protected"))) int my_data;

int *
func (void)
{
  return &my_data;
}

we should always treat protected symbols as local.

bfd/

PR ld/33260
* elfxx-x86.h (COPY_INPUT_RELOC_P): Always treat protected symbols
as local.

ld/

PR ld/33260
* testsuite/ld-i386/i386-export-class.rd: Updated.
* testsuite/ld-i386/i386-export-class.xd: Likewise.
* testsuite/ld-i386/i386.exp: Run pr33260-2.
* testsuite/ld-i386/pr33260-2.d: New file.
* testsuite/ld-i386/pr33260-2.s: Likewise.
* testsuite/ld-i386/pr33260.d: Remove "-z indirect-extern-access".
* testsuite/ld-x86-64/pr33260-x32.d: Likewise.
* testsuite/ld-x86-64/pr33260.d: Likewise.
* testsuite/ld-x86-64/pr33260-2-x32.d: New file.
* testsuite/ld-x86-64/pr33260-2.d: Likewise.
* testsuite/ld-x86-64/pr33260-2.s: Likewise.
* testsuite/ld-x86-64/x86-64-64-export-class.rd: Updated.
* testsuite/ld-x86-64/x86-64-x32-export-class.rd: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr33260-2 and
pr33260-2-x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
15 files changed:
bfd/elfxx-x86.h
ld/testsuite/ld-i386/i386-export-class.rd
ld/testsuite/ld-i386/i386-export-class.xd
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr33260-2.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr33260-2.s [new file with mode: 0644]
ld/testsuite/ld-i386/pr33260.d
ld/testsuite/ld-x86-64/pr33260-2-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr33260-2.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr33260-2.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr33260-x32.d
ld/testsuite/ld-x86-64/pr33260.d
ld/testsuite/ld-x86-64/x86-64-64-export-class.rd
ld/testsuite/ld-x86-64/x86-64-x32-export-class.rd
ld/testsuite/ld-x86-64/x86-64.exp

index 05c416fdf26cf104525e3d313f1c60fac6f80c51..f6ee6a6535674df64eadbd4799ff5f47025b4c53 100644 (file)
 
 /* TRUE if this input relocation should be copied to output.  H->dynindx
    may be -1 if this symbol was marked to become local.  STV_PROTECTED
-   symbols with indirect external access are local. */
+   symbols are local. */
 #define COPY_INPUT_RELOC_P(IS_X86_64, INFO, H, R_TYPE) \
   ((H) != NULL \
    && (H)->dynindx != -1 \
    && (X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
        || !(bfd_link_executable (INFO) \
            || SYMBOLIC_BIND ((INFO), (H)) \
-           || ((INFO)->indirect_extern_access > 0 \
-               && ELF_ST_VISIBILITY ((H)->other) == STV_PROTECTED)) \
+           || ELF_ST_VISIBILITY ((H)->other) == STV_PROTECTED) \
        || !(H)->def_regular))
 
 /* TRUE if this is actually a static link, or it is a -Bsymbolic link
index d7beadef2c438a287380f551e9d452288576e2aa..7ec0825ee5b942cd31067cf1f6b75ec193cb3e47 100644 (file)
@@ -1,11 +1,11 @@
 Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
  * Offset * Info * Type * Sym\. *Value * Sym\. * Name
+12340000  00000008 R_386_RELATIVE *
 12340010  00000008 R_386_RELATIVE *
 12340020  00000008 R_386_RELATIVE *
+12340040  00000008 R_386_RELATIVE *
+12340050  00000008 R_386_RELATIVE *
 12340060  00000008 R_386_RELATIVE *
 12340070  00000008 R_386_RELATIVE *
 12340080  00000008 R_386_RELATIVE *
 12340090  00000008 R_386_RELATIVE *
-12340000  [0-9a-f]+01 R_386_32          123400a0   protected_baz
-12340040  [0-9a-f]+01 R_386_32          123400a0   protected_foo
-12340050  [0-9a-f]+01 R_386_32          123400a0   protected_bar
index a797f2069402e914b798b697772a0eafcc6963f4..31f011f8136907db7c094efa03175f860571efb4 100644 (file)
@@ -1,10 +1,10 @@
 Hex dump of section '\.data':
-  0x12340000 00000000 00000000 00000000 00000000 .*
+  0x12340000 a0003412 00000000 00000000 00000000 .*
   0x12340010 a0003412 00000000 00000000 00000000 .*
   0x12340020 a0003412 00000000 00000000 00000000 .*
   0x12340030 00000000 00000000 00000000 00000000 .*
-  0x12340040 00000000 00000000 00000000 00000000 .*
-  0x12340050 00000000 00000000 00000000 00000000 .*
+  0x12340040 a0003412 00000000 00000000 00000000 .*
+  0x12340050 a0003412 00000000 00000000 00000000 .*
   0x12340060 a0003412 00000000 00000000 00000000 .*
   0x12340070 a0003412 00000000 00000000 00000000 .*
   0x12340080 a0003412 00000000 00000000 00000000 .*
index 0d653e90627444ce1164a3f92c34ea00135fede1..86748b1a49419e7ccd36c6fdb33b2d2f2e7a9243 100644 (file)
@@ -521,6 +521,7 @@ run_dump_test "pr30787"
 run_dump_test "pr31047"
 run_dump_test "pr32191"
 run_dump_test "pr33260"
+run_dump_test "pr33260-2"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr33260-2.d b/ld/testsuite/ld-i386/pr33260-2.d
new file mode 100644 (file)
index 0000000..d84442b
--- /dev/null
@@ -0,0 +1,6 @@
+#source: pr33260-2.s
+#as: -mrelax-relocations=yes --32
+#ld: -melf_i386 -shared
+#readelf: -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-i386/pr33260-2.s b/ld/testsuite/ld-i386/pr33260-2.s
new file mode 100644 (file)
index 0000000..0fcd388
--- /dev/null
@@ -0,0 +1,30 @@
+       .text
+       .p2align 4
+       .globl  my_func
+       .type   my_func, @function
+my_func:
+       .cfi_startproc
+       call    __x86.get_pc_thunk.ax
+       addl    $_GLOBAL_OFFSET_TABLE_, %eax
+       movl    my_data@GOT(%eax), %eax
+       ret
+       .cfi_endproc
+       .size   my_func, .-my_func
+       .protected      my_data
+       .globl  my_data
+       .bss
+       .align 4
+       .type   my_data, @object
+       .size   my_data, 4
+my_data:
+       .zero   4
+       .section        .text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
+       .globl  __x86.get_pc_thunk.ax
+       .hidden __x86.get_pc_thunk.ax
+       .type   __x86.get_pc_thunk.ax, @function
+__x86.get_pc_thunk.ax:
+       .cfi_startproc
+       movl    (%esp), %eax
+       ret
+       .cfi_endproc
+       .section        .note.GNU-stack,"",@progbits
index 4b1755d993803dc55c7a3ba24a0e4275a2b401a0..fc05e4ca596c5b3c3a35e9c541ebe85e79d9ec07 100644 (file)
@@ -1,6 +1,6 @@
 #source: pr33260.s
 #as: -mrelax-relocations=yes --32
-#ld: -melf_i386 -shared -z indirect-extern-access
+#ld: -melf_i386 -shared
 #readelf: -r --wide
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
diff --git a/ld/testsuite/ld-x86-64/pr33260-2-x32.d b/ld/testsuite/ld-x86-64/pr33260-2-x32.d
new file mode 100644 (file)
index 0000000..383129a
--- /dev/null
@@ -0,0 +1,6 @@
+#source: pr33260-2.s
+#as: -mrelax-relocations=yes --x32
+#ld: -melf32_x86_64 -shared
+#readelf: -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr33260-2.d b/ld/testsuite/ld-x86-64/pr33260-2.d
new file mode 100644 (file)
index 0000000..7f237c8
--- /dev/null
@@ -0,0 +1,6 @@
+#source: pr33260-2.s
+#as: -mrelax-relocations=yes --64
+#ld: -melf_x86_64 -shared
+#readelf: -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr33260-2.s b/ld/testsuite/ld-x86-64/pr33260-2.s
new file mode 100644 (file)
index 0000000..061137d
--- /dev/null
@@ -0,0 +1,19 @@
+       .text
+       .p2align 4
+       .globl  my_func
+       .type   my_func, @function
+my_func:
+       .cfi_startproc
+       movq    my_data@GOTPCREL(%rip), %rax
+       ret
+       .cfi_endproc
+       .size   my_func, .-my_func
+       .protected      my_data
+       .globl  my_data
+       .bss
+       .align 4
+       .type   my_data, @object
+       .size   my_data, 4
+my_data:
+       .zero   4
+       .section        .note.GNU-stack,"",@progbits
index d45e42dca3d192ae4d900933fd15fe128bd2b955..42088fbc4e16070e5f9f00a01342605ee3c4eae9 100644 (file)
@@ -1,6 +1,6 @@
 #source: pr33260.s
 #as: -mrelax-relocations=yes --x32
-#ld: -melf32_x86_64 -shared -z indirect-extern-access
+#ld: -melf32_x86_64 -shared
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
index d98c1658fa13615f6785f9602bc1c2408185e5a3..18b5472a03f1e6223705a834d801f267ba4874e0 100644 (file)
@@ -1,6 +1,6 @@
 #source: pr33260.s
 #as: -mrelax-relocations=yes --64 -defsym __x86_64__=1
-#ld: -melf_x86_64 -shared -z indirect-extern-access
+#ld: -melf_x86_64 -shared
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
index 308e307c94b2207bfcac4458f32a776a42e9f561..4a0bfa1cc10065259eb4ab510d0f02900ef3872b 100644 (file)
@@ -1,11 +1,11 @@
 Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
  * Offset * Info * Type * Sym\. *Value * Sym\. * Name * \+ * Addend
+000012340000  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340010  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340020  000000000008 R_X86_64_RELATIVE                    123400a0
+000012340040  000000000008 R_X86_64_RELATIVE                    123400a0
+000012340050  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340060  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340070  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340080  000000000008 R_X86_64_RELATIVE                    123400a0
 000012340090  000000000008 R_X86_64_RELATIVE                    123400a0
-000012340000  [0-9a-f]+00000001 R_X86_64_64       00000000123400a0 protected_baz \+ 0
-000012340040  [0-9a-f]+00000001 R_X86_64_64       00000000123400a0 protected_foo \+ 0
-000012340050  [0-9a-f]+00000001 R_X86_64_64       00000000123400a0 protected_bar \+ 0
index 4ea93bacfccc6cbda934d929c95287e4d9456029..5018229f2b5b156c67b0cd71af77fd61957dc6d2 100644 (file)
@@ -1,11 +1,11 @@
 Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
  * Offset * Info * Type * Sym\. *Value * Sym\. * Name * \+ * Addend
+12340000  00000008 R_X86_64_RELATIVE            123400a0
 12340010  00000008 R_X86_64_RELATIVE            123400a0
 12340020  00000008 R_X86_64_RELATIVE            123400a0
+12340040  00000008 R_X86_64_RELATIVE            123400a0
+12340050  00000008 R_X86_64_RELATIVE            123400a0
 12340060  00000008 R_X86_64_RELATIVE            123400a0
 12340070  00000008 R_X86_64_RELATIVE            123400a0
 12340080  00000008 R_X86_64_RELATIVE            123400a0
 12340090  00000008 R_X86_64_RELATIVE            123400a0
-12340000  [0-9a-f]+0a R_X86_64_32       123400a0   protected_baz \+ 0
-12340040  [0-9a-f]+0a R_X86_64_32       123400a0   protected_foo \+ 0
-12340050  [0-9a-f]+0a R_X86_64_32       123400a0   protected_bar \+ 0
index f3fdf023cb2ec3b20e7edfa779206c90f5b9c72b..6b86bc3d018a28a683de22b73e6d9815cf3ec125 100644 (file)
@@ -566,6 +566,8 @@ run_dump_test "pr32591-4-x32"
 run_dump_test "pr32809"
 run_dump_test "pr33260"
 run_dump_test "pr33260-x32"
+run_dump_test "pr33260-2"
+run_dump_test "pr33260-2-x32"
 
 if { ![skip_sframe_tests] } {
     run_dump_test "sframe-simple-1"