[cfe-dev] Feedback on feature (and status of lld linker script support?)

Christopher Friedt via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 29 19:54:46 PST 2021


On Mon, Nov 29, 2021 at 7:20 PM Fangrui Song <maskray at google.com> wrote:
> (I use this subthread for the 16-byte section name length limitation.)
>
> It would be nice to fix the 16-byte section name limitation for Mach-O.
> For many instrumentations, for binary format portability, we have to restrict the section name length even
> when the length size doesn't cost that much.
> I think this probably should be fixed at the binary format level.

I agree - it really should be fixed at Mach-O spec level.

> For example, PE/COFF had a 7-char limitation and extended it with
> https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#section-table-section-headers
> ("For longer names, this field contains a slash (/) that is followed by
> an ASCII representation of a decimal number that is an offset into the
> string table.")

I thought of something similar - providing a key in the MSByte (0xff)
- could be used to indicate a binary offset to the string table and it
would work equally well for either 64 or 32-bit headers. However, that
solution really only works if Apple were to adopt it and amend the
Mach-O spec. Does something like that already exist on Macs? Is there
anyone at Apple who would be willing to do that?

> The rationale is that this is a limitation that the binary format maker
> would likely have an opinion on and needs to change many things in the
> ecosystem, e.g.
>
> * does the assembler need to do anything special?
> * how do otool/llvm-objdump/llvm-readobj render the section name?
> * how do ld64/ld64.lld render the section name, especially in diagnostics
> * whether the custom section can be stripped by binary manipulation tools
> * how section$start$__SEG$__section symbols work with the section representation
> * ...

I agree, and that's good long-term thinking to push Apple to amend
Mach-O. I can see it taking a while to get Apple on board with
something like that. Other tooling would just see hashed strings,
which isn't ideal.

However, the proposed solution works today and is quite handy for C
and C++. It's a nice, high-level source to source transform that
produces fully legal section names with Mach-O or really any other
binary format. Good to hear that others are thinking about that
problem as well.

Good chatting and I hope we can keep the conversation going.

Will the LLD conversation take place on llvm-dev?

Thanks,

C


More information about the cfe-dev mailing list