<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 23, 2019, at 2:05 AM, James Henderson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">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></div></blockquote><div><br class=""></div><div>Generally, Mach-O tools separate the segment name and the section name as different entries on the command line. The “<Segment Name>,<Section Name>” string is almost always an output format. Some examples include:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">    </span>otool -s __TEXT __text /bin/ls</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>ld -sectcreate __EXAMPLE __example /dev/zero ...</div><div><br class=""></div><div>In my opinion, that would be ideal from a "Mach-O users" point of view. </div><div><br class=""></div><div>That said, the “two arguments” pattern isn’t very common in llvm, although it does appear in places such as llvm-nm. llvm-objdump has a -section option that takes a single string in the  “<Segment Name>,<Section Name>” format. This option only applies when a Mach-O specific flag, “-macho” or “-m", appears on the command line. And that’s basically the proposal here. So while not ideal, it’s certainly familiar.</div><div><br class=""></div><div>How will people use llvm-objcopy when the segment and section names legitimately contain “.” or “,” characters? Will these be escapable?</div><div><br class=""></div><div>The rest of the behavior, especially around “__TEXT.__text is bad but __TEXT.__unwind_info is good”, is pretty confusing. Can we define our own “canonical names” for canonical sections such as __unwind_info? </div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">James<br class=""></div></div><br class=""><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" class="">nuta@seiya.me</a>> wrote:<br class=""></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 class="">
<br class="">
I'm going to implement Mach-O support in llvm-objcopy. Before working<br class="">
on this, I'd like to hear your thoughts how llvm-objcopy should handle<br class="">
Mach-O section names.<br class="">
<br class="">
By convention, Mach-O section names are denoted by "<segment<br class="">
name>,<section name>". However, GNU objcopy renames them in the<br class="">
following rule [1]:<br class="">
<br class="">
- If the section name is well-known, rename it to an "canonical" name [2].<br class="">
- Otherwise:<br class="">
    - Rename to "<segment name>.<section name>" (the separator is `.' not `,')<br class="">
    - If the segment name does not start with `_', prefix it with `LC_SEGMENT.’</blockquote></div></div></blockquote><div><br class=""></div><div>Can you explain what LC_SEGMENT means here? What happens if the segment name (in the file) does not begin with a “_”?</div><div><br class=""></div><div>Thanks!</div><div><br class=""></div><div>MDT</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br class="">
For example, __TEXT,__text is renamed to .text and<br class="">
__TEXT,__unwind_info is renamed to __TEXT.__unwind_info. For that<br class="">
reason, specifying a section in command line options is rather<br class="">
nonintuitive:<br class="">
<br class="">
WRONG: objcopy --only-secton=__TEXT,__text a.out<br class="">
WRONG: objcopy --only-secton=__TEXT.__text a.out<br class="">
OK: objcopy --only-secton=.text a.out<br class="">
<br class="">
WRONG: objcopy --only-secton=__TEXT,__unwind_info a.out<br class="">
WRONG: objcopy --only-secton=.unwind_info a.out<br class="">
OK: objcopy --only-secton=__TEXT.__unwind_info a.out<br class="">
<br class="">
For the compatibility with GNU binutils, I propose to make this<br class="">
section renaming rule as default in llvm-objcopy and implement a flag<br class="">
named —macho-names to use conventional section names:<br class="">
<br class="">
WRONG: llvm-objcopy --only-secton=__TEXT,__text a.out<br class="">
WRONG: llvm-objcopy --only-secton=__TEXT.__text a.out<br class="">
OK: llvm-objcopy --only-secton=.text a.out a.out2<br class="">
<br class="">
WRONG: llvm-objcopy --macho-names --only-secton=.text a.out<br class="">
WRONG: llvm-objcopy --macho-names --only-secton=__TEXT.__text a.out<br class="">
OK: llvm-objcopy --macho-names --only-secton=__TEXT,__text a.out<br class="">
<br class="">
What do you think about this behavior?<br class="">
<br class="">
Thanks,<br class="">
Seiya<br class="">
<br class="">
[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" class="">https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l364</a><br class="">
[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" class="">https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/mach-o.c;h=d9edef2871d83b53280b613935c068e4327f3270;hb=HEAD#l90</a><br class="">
</blockquote></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>