[llvm-dev] objcopy --prefix-symbols and undefined symbols
Keith Smiley via llvm-dev
llvm-dev at lists.llvm.org
Fri Nov 12 17:01:06 PST 2021
Hey folks,
I went to implement objcopy's --prefix-symbol support for MachO binaries
and was a bit surprised by the behavior of it with elf binaries (which
matches binutils' objcopy as well). Prefixing applies to all symbols,
including undefined symbols, meaning something as simple as this example,
will not work:
```
% cat /tmp/main.c
#include <stdio.h>
int main() {
printf("hi\n");
}
% clang /tmp/main.c -o /tmp/main.o
% llvm-objcopy --prefix-symbols=bar /tmp/main.o
% clang /tmp/main.o
/usr/bin/ld: error in /tmp/main.o(.eh_frame); no .eh_frame_hdr table will
be created
/usr/bin/ld:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o:
in function `_start':
(.text+0x24): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
```
While prefixing `main` specifically might not be a common use case, my
expected use case for this would be to prefix symbols in a static library,
which has a similar issue for undefined symbols:
```
/usr/bin/ld: prefixed.o:(.data+0x6b0): undefined reference to `barmunmap'
/usr/bin/ld: prefixed.o:(.data+0x6c8): undefined reference to `barmremap'
/usr/bin/ld: prefixed.o:(.data+0x6f8): undefined reference to `barreadlink'
/usr/bin/ld: prefixed.o:(.data+0x710): undefined reference to `barlstat64'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
```
I must be understanding the purpose of this flag in general so I'm curious
if someone could clarify this use case to see if it's worth following
through on MachO support for.
Thanks!
--
Keith Smiley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211112/3c206196/attachment.html>
More information about the llvm-dev
mailing list