[PATCH] x86-64: Add a test for hidden undefined symbol

H.J. Lu hjl.tools@gmail.com
Fri Nov 1 21:30:53 GMT 2024


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.


-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-64-Add-a-test-for-hidden-undefined-symbol.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20241102/d2600a8c/attachment.bin>


More information about the Binutils mailing list