diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-11-02 05:19:35 +0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-11-02 05:27:48 +0800 |
commit | 360f74a101937d1c26e5e0b341043bac6e2d299d (patch) | |
tree | 6e50e5df604886e123ec0c55d9be1e3259ce3c25 | |
parent | 086a2beb152c95ac43ac6b73859eb9e9081fc2df (diff) | |
download | binutils-360f74a101937d1c26e5e0b341043bac6e2d299d.zip binutils-360f74a101937d1c26e5e0b341043bac6e2d299d.tar.gz binutils-360f74a101937d1c26e5e0b341043bac6e2d299d.tar.bz2 |
x86-64: Add a test for hidden undefined symbol
Linker should report an error for hidden undefined symbol when building
a shared library without the "recompile with -fPIC" message:
$ cat x.c
extern int foo __attribute__ ((visibility ("hidden")));
int
func (void)
{
return foo;
}
$ gcc -c -fPIC -O2 x.c
$ objdump -dwr x.o
x.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <func>:
0: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 6 <func+0x6> 2: R_X86_64_PC32 foo-0x4
6: c3 ret
$ ld -shared -o x.so x.o
ld: x.o: in function `func':
x.c:(.text+0x2): undefined reference to `foo'
ld: x.o: relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object
ld: final link failed: bad value
$
since -fPIC has been used.
* testsuite/ld-x86-64/hidden6.d: New file.
* testsuite/ld-x86-64/hidden6.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run hidden6.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
-rw-r--r-- | ld/testsuite/ld-x86-64/hidden6.d | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/hidden6.s | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 1 |
3 files changed, 11 insertions, 0 deletions
diff --git a/ld/testsuite/ld-x86-64/hidden6.d b/ld/testsuite/ld-x86-64/hidden6.d new file mode 100644 index 0000000..c4c843b --- /dev/null +++ b/ld/testsuite/ld-x86-64/hidden6.d @@ -0,0 +1,3 @@ +#as: --64 +#ld: -shared -melf_x86_64 +#error: .*relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object diff --git a/ld/testsuite/ld-x86-64/hidden6.s b/ld/testsuite/ld-x86-64/hidden6.s new file mode 100644 index 0000000..807422b --- /dev/null +++ b/ld/testsuite/ld-x86-64/hidden6.s @@ -0,0 +1,7 @@ + .text +.globl bar + .type bar, @function +bar: + mov foo(%rip), %eax + .size bar, .-bar + .hidden foo diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index bd7574d..2a1657d 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -321,6 +321,7 @@ run_dump_test "hidden2" run_dump_test "hidden3" run_dump_test "hidden4" run_dump_test "hidden5" +run_dump_test "hidden6" run_dump_test "protected1" run_dump_test "protected2" run_dump_test "protected3" |