<div dir="ltr"><div>Hi Keith,</div><div><br></div><div>llvm-objcopy's ELF behaviour is closely modelled on GNU objcopy's behaviour, with the intent that it is a drop-in replacement for that tool. There are a limited number of exceptions to this, but --prefix-symbols is not one of them. When using GNU objcopy v2.30, I get the following behaviour:</div><div><br></div><div>$ cat test.cpp</div><div>void foo();<br>int main(){<br>   foo();<br>}</div><div>$ gcc -c test.cpp</div><div>$ nm test.o</div><div>                 U _GLOBAL_OFFSET_TABLE_<br>0000000000000000 T main<br>                 U _Z3foov</div><div>$ objcopy test.o test.prefix.o --prefix-symbols=bar</div><div>$ nm test.prefix.o<br>                 U bar_GLOBAL_OFFSET_TABLE_<br>0000000000000000 T barmain<br>                 U bar_Z3foov</div><div><br></div><div>I agree with you that I don't know under what situations this behaviour can be useful, apart from some pretty niche cases. Perhaps worth raising on the GNU mailing list?</div><div><br></div><div>James<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 13 Nov 2021 at 01:02, Keith Smiley via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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">```</div><div dir="ltr"><br></div><div>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"><br></div><div>Thanks!</div><div dir="ltr">--<br>Keith Smiley<br></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>