aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-06-17 10:19:29 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-06-17 10:26:34 -0700
commitb6b42983720c2d88f680ef7679f41c3ff95daae1 (patch)
treef005b076e24e10e3429fa3441632ce6873a2ccce /ld
parentd208bc7617e93dc7dda400b69e8bc49aeb9436f7 (diff)
downloadgdb-b6b42983720c2d88f680ef7679f41c3ff95daae1.zip
gdb-b6b42983720c2d88f680ef7679f41c3ff95daae1.tar.gz
gdb-b6b42983720c2d88f680ef7679f41c3ff95daae1.tar.bz2
x86-64: Test protected function pointers
On x86-64, function pointers in executable for external funtions may be resolved to their PLT entries in executable. If it happens, function pointers of protected funtions in shared libraries must be resolved to the PLT entries in executable, not addresses of protected funtions in shared libraries. PR ld/27973 * testsuite/ld-x86-64/x86-64.exp: Run protected function tests. * testsuite/ld-x86-64/protected-func-1.h: New file. * testsuite/ld-x86-64/protected-func-1a.s: Likewise. * testsuite/ld-x86-64/protected-func-1b.c: Likewise.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog8
-rw-r--r--ld/testsuite/ld-x86-64/protected-func-1.h6
-rw-r--r--ld/testsuite/ld-x86-64/protected-func-1a.s48
-rw-r--r--ld/testsuite/ld-x86-64/protected-func-1b.c35
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp25
5 files changed, 122 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 3d3cbed..2b46bb9 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2021-06-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/27973
+ * testsuite/ld-x86-64/x86-64.exp: Run protected function tests.
+ * testsuite/ld-x86-64/protected-func-1.h: New file.
+ * testsuite/ld-x86-64/protected-func-1a.s: Likewise.
+ * testsuite/ld-x86-64/protected-func-1b.c: Likewise.
+
2021-06-17 Fangrui Song <maskray@google.com>
* ldlex.h (enum option_values): Add OPTION_NO_PIE.
diff --git a/ld/testsuite/ld-x86-64/protected-func-1.h b/ld/testsuite/ld-x86-64/protected-func-1.h
new file mode 100644
index 0000000..b5ff4e8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/protected-func-1.h
@@ -0,0 +1,6 @@
+extern int protected_func_1a (void);
+extern int protected_func_1b (void);
+
+typedef int (*protected_func_type) (void);
+extern protected_func_type protected_func_1a_p (void);
+extern protected_func_type protected_func_1b_p (void);
diff --git a/ld/testsuite/ld-x86-64/protected-func-1a.s b/ld/testsuite/ld-x86-64/protected-func-1a.s
new file mode 100644
index 0000000..eb2ed91
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/protected-func-1a.s
@@ -0,0 +1,48 @@
+ .text
+ .p2align 4
+ .protected protected_func_1a
+ .globl protected_func_1a
+ .type protected_func_1a, @function
+protected_func_1a:
+.LFB0:
+ .cfi_startproc
+ movl $1, %eax
+ ret
+ .cfi_endproc
+.LFE0:
+ .size protected_func_1a, .-protected_func_1a
+ .p2align 4
+ .protected protected_func_1b
+ .globl protected_func_1b
+ .type protected_func_1b, @function
+protected_func_1b:
+.LFB1:
+ .cfi_startproc
+ movl $2, %eax
+ ret
+ .cfi_endproc
+.LFE1:
+ .size protected_func_1b, .-protected_func_1b
+ .p2align 4
+ .globl protected_func_1a_p
+ .type protected_func_1a_p, @function
+protected_func_1a_p:
+.LFB2:
+ .cfi_startproc
+ movq protected_func_1a@GOTPCREL(%rip), %rax
+ ret
+ .cfi_endproc
+.LFE2:
+ .size protected_func_1a_p, .-protected_func_1a_p
+ .p2align 4
+ .globl protected_func_1b_p
+ .type protected_func_1b_p, @function
+protected_func_1b_p:
+.LFB3:
+ .cfi_startproc
+ movq protected_func_1b@GOTPCREL(%rip), %rax
+ ret
+ .cfi_endproc
+.LFE3:
+ .size protected_func_1b_p, .-protected_func_1b_p
+ .section .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/protected-func-1b.c b/ld/testsuite/ld-x86-64/protected-func-1b.c
new file mode 100644
index 0000000..a9d728a
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/protected-func-1b.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+#include "protected-func-1.h"
+
+int
+protected_func_1b (void)
+{
+ return 3;
+}
+
+int
+main (void)
+{
+ int res = 0;
+
+ /* Check if we get the same address for the protected function symbol. */
+ if (protected_func_1a != protected_func_1a_p ())
+ {
+ puts ("'protected_func_1a' in main and shared library doesn't have same address");
+ res = 1;
+ }
+
+ /* Check if we get the different addresses for the protected function
+ symbol. */
+ if (protected_func_1b == protected_func_1b_p ())
+ {
+ puts ("'protected_func_1b' in main and shared library has same address");
+ res = 1;
+ }
+
+ if (!res)
+ puts ("PASS");
+
+ return res;
+}
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 8071666..5dc9a1c 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -1321,6 +1321,14 @@ if { [isnative] && [check_compiler_available] } {
{readelf -rW pr22842b.rd}} \
"pr22842" \
] \
+ [list \
+ "Build libprotected-func-1.so" \
+ "-shared" \
+ "-fPIC -Wa,-mx86-used-note=yes" \
+ { protected-func-1a.s } \
+ {} \
+ "libprotected-func-1.so" \
+ ] \
]
if {[istarget "x86_64-*-linux*-gnux32"]} {
@@ -1730,6 +1738,23 @@ if { [isnative] && [check_compiler_available] } {
"pr23997" \
"pass.out" \
] \
+ [list \
+ "Run protected-func-1 without PIE" \
+ "-Wl,--no-as-needed tmpdir/libprotected-func-1.so" \
+ "-Wa,-mx86-used-note=yes" \
+ { protected-func-1b.c } \
+ "protected-func-1a" \
+ "pass.out" \
+ ] \
+ [list \
+ "Run protected-func-1 with PIE" \
+ "-Wl,--no-as-needed -pie tmpdir/libprotected-func-1.so" \
+ "-Wa,-mx86-used-note=yes" \
+ { protected-func-1b.c } \
+ "protected-func-1b" \
+ "pass.out" \
+ "-fPIE" \
+ ] \
]
# Run-time tests which require working ifunc attribute support.