<div dir="ltr">Hey folks,<div><br></div><div>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:</div><div><br></div><div>```</div><div>% cat /tmp/main.c<br>#include <stdio.h><br><br>int main() {<br>  printf("hi\n");<br>}<br>% clang /tmp/main.c -o /tmp/main.o<br>% llvm-objcopy --prefix-symbols=bar /tmp/main.o<br>% clang /tmp/main.o<br>/usr/bin/ld: error in /tmp/main.o(.eh_frame); no .eh_frame_hdr table will be created<br>/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':<br>(.text+0x24): undefined reference to `main'<br>clang: error: linker command failed with exit code 1 (use -v to see invocation)</div><div>```</div><div><br></div><div>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:</div><div><br></div><div>```</div><div>/usr/bin/ld: prefixed.o:(.data+0x6b0): undefined reference to `barmunmap'<br>/usr/bin/ld: prefixed.o:(.data+0x6c8): undefined reference to `barmremap'<br>/usr/bin/ld: prefixed.o:(.data+0x6f8): undefined reference to `barreadlink'<br>/usr/bin/ld: prefixed.o:(.data+0x710): undefined reference to `barlstat64'<br>clang: error: linker command failed with exit code 1 (use -v to see invocation)<br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">```</div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br></div><div class="gmail_signature" data-smartmail="gmail_signature">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.</div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br></div><div class="gmail_signature" data-smartmail="gmail_signature">Thanks!</div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">--<br>Keith Smiley<br></div></div></div></div>