summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-07-18 11:44:32 -0700
committerH.J. Lu <hjl.tools@gmail.com>2022-07-19 09:08:41 -0700
commit19892fedb7b7e9129d76a0c48b26721d4973fb20 (patch)
tree85e9748a8e26d54645e57a230ff041f0f1936c85
parent730a2af40f3e17bb168e29817b40f00a2c90bd56 (diff)
x86: Properly check invalid relocation against protected symbollinaro-local/ci/tcwg_bmk_llvm_apm/llvm-release-aarch64-spec2k6-Os
Only check invalid relocation against protected symbol defined in shared object. bfd/ PR ld/29377 * elf32-i386.c (elf_i386_scan_relocs): Only check invalid relocation against protected symbol defined in shared object. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. ld/ PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Run PR ld/29377 tests. * testsuite/ld-elf/pr29377a.c: New file. * testsuite/ld-elf/pr29377b.c: Likewise. (cherry picked from commit bd0736124c20950ac353f01e5029b7cb5d8a7010) ld: Pass -nostdlib to compiler with -r Pass -nostdlib to compiler with -r to avoid unnecessary .o file and libraries. PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Pass -nostdlib with -r. (cherry picked from commit 76e4fa70e79ee959c0e11eaacd4cf863291b1ddb)
-rw-r--r--bfd/elf32-i386.c2
-rw-r--r--bfd/elf64-x86-64.c2
-rw-r--r--ld/testsuite/ld-elf/linux-x86.exp16
-rw-r--r--ld/testsuite/ld-elf/pr29377a.c5
-rw-r--r--ld/testsuite/ld-elf/pr29377b.c10
5 files changed, 35 insertions, 0 deletions
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 3bc710096a..94a23bf30a 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1811,6 +1811,8 @@ elf_i386_scan_relocs (bfd *abfd,
if (h->pointer_equality_needed
&& h->type == STT_FUNC
&& eh->def_protected
+ && !SYMBOL_DEFINED_NON_SHARED_P (h)
+ && h->def_dynamic
&& elf_has_indirect_extern_access (h->root.u.def.section->owner))
{
/* Disallow non-canonical reference to canonical
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 16229b39dc..970379dea3 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2254,6 +2254,8 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
if (h->pointer_equality_needed
&& h->type == STT_FUNC
&& eh->def_protected
+ && !SYMBOL_DEFINED_NON_SHARED_P (h)
+ && h->def_dynamic
&& elf_has_indirect_extern_access (h->root.u.def.section->owner))
{
/* Disallow non-canonical reference to canonical
diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
index 2e0cbd37f1..a3eb56809b 100644
--- a/ld/testsuite/ld-elf/linux-x86.exp
+++ b/ld/testsuite/ld-elf/linux-x86.exp
@@ -134,6 +134,22 @@ run_cc_link_tests [list \
{{readelf {--dyn-syms -W} pr28158.rd} {nm -D pr28158.nd}} \
"pr28158" \
] \
+ [list \
+ "Build pr29377.o" \
+ "-r -nostdlib -Wl,-z,noexecstack" \
+ "" \
+ {pr29377a.c indirect-extern-access.S} \
+ {} \
+ "pr29377.o" \
+ ] \
+ [list \
+ "Build pr29377" \
+ "$NOPIE_LDFLAGS tmpdir/pr29377.o" \
+ "-fPIC" \
+ {pr29377b.c} \
+ {} \
+ "pr29377" \
+ ] \
]
run_ld_link_exec_tests [list \
diff --git a/ld/testsuite/ld-elf/pr29377a.c b/ld/testsuite/ld-elf/pr29377a.c
new file mode 100644
index 0000000000..41d9545e3b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr29377a.c
@@ -0,0 +1,5 @@
+__attribute__ ((visibility ("protected")))
+void
+foo (void)
+{
+}
diff --git a/ld/testsuite/ld-elf/pr29377b.c b/ld/testsuite/ld-elf/pr29377b.c
new file mode 100644
index 0000000000..3cf163b25b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr29377b.c
@@ -0,0 +1,10 @@
+extern void foo (void);
+
+void (*foo_p) (void);
+
+int
+main ()
+{
+ foo_p = foo;
+ return 0;
+}