From 68c4956b1401de70173848a6bdf620cb42fa9358 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 26 Apr 2022 09:08:54 -0700 Subject: x86: Properly handle function pointer reference Update commit ebb191adac4ab45498dec0bfaac62f0a33537ba4 Author: H.J. Lu Date: Wed Feb 9 15:51:22 2022 -0800 x86: Disallow invalid relocation against protected symbol to allow function pointer reference and make sure that PLT entry isn't used for function reference due to function pointer reference. bfd/ PR ld/29087 * elf32-i386.c (elf_i386_scan_relocs): Don't set pointer_equality_needed nor check non-canonical reference for function pointer reference. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. ld/ PR ld/29087 * testsuite/ld-x86-64/x86-64.exp: Run PR ld/29087 tests. * testsuite/ld-x86-64/protected-func-3.c: New file. --- ld/testsuite/ld-x86-64/protected-func-3.c | 41 +++++++++++++++++++++++++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 18 ++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ld/testsuite/ld-x86-64/protected-func-3.c (limited to 'ld') diff --git a/ld/testsuite/ld-x86-64/protected-func-3.c b/ld/testsuite/ld-x86-64/protected-func-3.c new file mode 100644 index 0000000..bbf433b --- /dev/null +++ b/ld/testsuite/ld-x86-64/protected-func-3.c @@ -0,0 +1,41 @@ +#include + +#include "protected-func-1.h" + +protected_func_type protected_func_1a_ptr = protected_func_1a; +protected_func_type protected_func_1b_ptr = protected_func_1b; + +int +protected_func_1b (void) +{ + return 3; +} + +int +main (void) +{ + int res = 0; + + protected_func_1a (); + protected_func_1b (); + + /* Check if we get the same address for the protected function symbol. */ + if (protected_func_1a_ptr != 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_ptr == 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 1a7d1ed..5e5636b 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -1887,6 +1887,24 @@ if { [isnative] && [check_compiler_available] } { "-fPIE" \ ] \ [list \ + "Run protected-func-3a without PIE" \ + "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-func-2a.so" \ + "-Wa,-mx86-used-note=yes" \ + { protected-func-3.c } \ + "protected-func-3a" \ + "pass.out" \ + "$NOPIE_CFLAGS" \ + ] \ + [list \ + "Run protected-func-3b with PIE" \ + "-Wl,--no-as-needed -pie tmpdir/libprotected-func-2a.so" \ + "-Wa,-mx86-used-note=yes" \ + { protected-func-3.c } \ + "protected-func-2b" \ + "pass.out" \ + "-fPIE" \ + ] \ + [list \ "Run protected-data-1a without PIE" \ "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-data-1a.so" \ "-Wa,-mx86-used-note=yes" \ -- cgit v1.1