This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Implement options -rename_section -rename_segment
ClosedPublic

Authored by gkm on Feb 26 2021, 5:42 PM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rG6f9dd843db40: [lld-macho] Implement options -rename_section -rename_segment
Summary

Implement command-line options to rename output sections & segments.

Diff Detail

Event Timeline

gkm created this revision.Feb 26 2021, 5:42 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: dang. · View Herald Transcript
gkm requested review of this revision.Feb 26 2021, 5:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2021, 5:42 PM
gkm added inline comments.Feb 26 2021, 5:54 PM
lld/MachO/InputFiles.cpp
109 ↗(On Diff #326855)

FYI: This turned-up in my option-parsing test: when I omitted a sub-arg, then it swallowed -o, leaving /dev/null without a prefix, so it was interpreted as an input filename. Since its size was zero, ASAN caught the attempted read of the non-existent header.

int3 added inline comments.Feb 26 2021, 8:32 PM
lld/MachO/Config.h
28–29

try to avoid std::map in general (as per the LLVM programmer's manual). In this case we could use a DenseMap of NamePair and a DenseMap of CachedHashStringRef respectively

86–93

Config should be just a plain bag of values. I think this can be a standalone function in Writer.cpp

lld/MachO/Driver.cpp
822
lld/MachO/InputFiles.cpp
109 ↗(On Diff #326855)

Ah, nice catch. This should probably be in a separate diff with its own test. Also, I think we should make it an error if the file is shorter than sizeof(hdr->magic)... one issue though is that we currently use readFile to read non-binary files like the symbol order file, but I think we can just create a separate function for that

gkm marked 4 inline comments as done.Feb 26 2021, 9:44 PM
gkm added inline comments.
lld/MachO/Config.h
28–29

Why CachedHashStringRef ? Is that supposed to give us some code sharing, at the expense of clarity?

gkm updated this revision to Diff 326877.Feb 26 2021, 9:44 PM
gkm marked an inline comment as done.
  • revise according to review feedback
int3 added inline comments.Feb 27 2021, 9:08 AM
lld/MachO/Config.h
28–29

It saves on recomputation of the hash. Not that it matters here since this map shouldn't part of a hot loop, but I just use it everywhere we need a map of string keys, so I don't have to think about whether performance is important in a particular case.

There's also StringMap, but that allocates and owns its own strings, which for LLD isn't really optimal since our strings are mostly interned / not deallocated till the end of the process.

lld/test/MachO/rename.s
34
int3 accepted this revision.Feb 27 2021, 9:08 AM
This revision is now accepted and ready to land.Feb 27 2021, 9:08 AM
gkm marked an inline comment as done.Feb 27 2021, 11:21 AM
gkm updated this revision to Diff 326917.Feb 27 2021, 11:25 AM
  • amend according to review feedback
  • migrate some changes to lld/test/MachO/rename.s from a successor diff that really belong here
This revision was landed with ongoing or failed builds.Feb 27 2021, 11:55 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Feb 27 2021, 2:21 PM

Looks like this breaks tests on windows: http://45.33.8.238/win/34054/step_10.txt

Please take a look, and revert for now if it takes a while to fix.

int3 added a comment.Feb 27 2021, 2:50 PM

D97610 which just landed will likely fix it