<div dir="ltr"><div>I discussed this with Seiya off the mailing list yesterday, and this was the suggestion we came up with, on the basis that GNU objcopy has support for the renaming for GDB support, but it might be confusing to people who are new to the system, so we provide a more expected output option. I'm not experienced with MachO at all, though, so we'd appreciate any feedback from any MachO users.</div><div><br></div><div>Thanks,</div><div><br></div><div>James<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 23 May 2019 at 05:43, Seiya Nuta <<a href="mailto:nuta@seiya.me">nuta@seiya.me</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">Hi,<br>
<br>
I'm going to implement Mach-O support in llvm-objcopy. Before working<br>
on this, I'd like to hear your thoughts how llvm-objcopy should handle<br>
Mach-O section names.<br>
<br>
By convention, Mach-O section names are denoted by "<segment<br>
name>,<section name>". However, GNU objcopy renames them in the<br>
following rule [1]:<br>
<br>
- If the section name is well-known, rename it to an "canonical" name [2].<br>
- Otherwise:<br>
    - Rename to "<segment name>.<section name>" (the separator is `.' not `,')<br>
    - If the segment name does not start with `_', prefix it with `LC_SEGMENT.'<br>
<br>
For example, __TEXT,__text is renamed to .text and<br>
__TEXT,__unwind_info is renamed to __TEXT.__unwind_info. For that<br>
reason, specifying a section in command line options is rather<br>
nonintuitive:<br>
<br>
WRONG: objcopy --only-secton=__TEXT,__text a.out<br>
WRONG: objcopy --only-secton=__TEXT.__text a.out<br>
OK: objcopy --only-secton=.text a.out<br>
<br>
WRONG: objcopy --only-secton=__TEXT,__unwind_info a.out<br>
WRONG: objcopy --only-secton=.unwind_info a.out<br>
OK: objcopy --only-secton=__TEXT.__unwind_info a.out<br>
<br>
For the compatibility with GNU binutils, I propose to make this<br>
section renaming rule as default in llvm-objcopy and implement a flag<br>
named —macho-names to use conventional section names:<br>
<br>
WRONG: llvm-objcopy --only-secton=__TEXT,__text a.out<br>
WRONG: llvm-objcopy --only-secton=__TEXT.__text a.out<br>
OK: llvm-objcopy --only-secton=.text a.out a.out2<br>
<br>
WRONG: llvm-objcopy --macho-names --only-secton=.text a.out<br>
WRONG: llvm-objcopy --macho-names --only-secton=__TEXT.__text a.out<br>
OK: llvm-objcopy --macho-names --only-secton=__TEXT,__text a.out<br>
<br>
What do you think about this behavior?<br>
<br>
Thanks,<br>
Seiya<br>
<br>
[1]: <a href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l364" rel="noreferrer" target="_blank">https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l364</a><br>
[2]: <a href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l90" rel="noreferrer" target="_blank">https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l90</a><br>
</blockquote></div>