This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Disallow input section description without a filename
ClosedPublic

Authored by MaskRay on May 12 2022, 11:39 PM.

Details

Summary

GNU ld does not allow .foo : { (*foo) }, but we may recognize it as three
input section descriptions: file "(" with any section name, file "*foo" with
any section name, file ")" with any section name. Disallow the error-prone usage.

Diff Detail

Event Timeline

MaskRay created this revision.May 12 2022, 11:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 11:40 PM
MaskRay requested review of this revision.May 12 2022, 11:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 11:40 PM
peter.smith accepted this revision.May 13 2022, 1:52 AM

LGTM. GNU ld documentation for InputSection https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html states that An input section description consists of a file name optionally followed by a list of section names in parentheses. I couldn't find anything about which characters in filenames were not permitted. It looks like both lld and gnu ld can handle these when quoted. For example for a file "file(o)" we can write { "file(o)"(.text) } I do hope parentheses in filenames are not common though. Maybe worth a test case if we've not got one already.

This revision is now accepted and ready to land.May 13 2022, 1:52 AM

LGTM. GNU ld documentation for InputSection https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html states that An input section description consists of a file name optionally followed by a list of section names in parentheses. I couldn't find anything about which characters in filenames were not permitted. It looks like both lld and gnu ld can handle these when quoted. For example for a file "file(o)" we can write { "file(o)"(.text) } I do hope parentheses in filenames are not common though. Maybe worth a test case if we've not got one already.

Most printable characters are accepted in the filename pattern, with exception to ()#%. Seems that disallowing ( and )` is sufficient for us to disambiguate the grammar.
Parentheses in filenames are accepted if quoted. Let me check whether there is an existing test...