This change implements --icf=safe for MachO based on addrsig section that is implemented in D123751.
Details
- Reviewers
int3 - Group Reviewers
Restricted Project - Commits
- rGe29dc0c6fde2: [lld] Implement safe icf for MachO
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Re testing: you can look at https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/icf.s for inspiration. I would probably create a new test file that has some address-significant functions, and check that we don't dedup them with --icf=safe while continuing to do so with --icf=all.
lld/test/MachO/icf-safe.s | ||
---|---|---|
9–13 ↗ | (On Diff #423491) | if you add --macho to the objdump command (i.e. llvm-objdump --macho -d) these will be rendered as bl _func0<N> instead, then it's easy to check that those values are the same / different |
lld/MachO/Driver.cpp | ||
---|---|---|
1510–1512 | nit: can omit if braces | |
lld/MachO/ICF.cpp | ||
361–365 | can omit braces | |
370–371 | hmm if I understand correctly, the failure case we are trying to avoid here is that a DSO may export two symbols a and b, and whatever loads that DSO may end up comparing the addresses of a and b for equality? If that's the case I think any exported symbol in a DSO should be marked as address-significant. But... that seems like we would end up marking a lot of symbols :/ referencedDynamically is only used to mark symbols that shouldn't be stripped (and currently only applies to __mh_execute_header, as per its block comment); but stripped symbols can still have their addresses taken if they are in the export trie. What does LLD-ELF do here? | |
373 | I think the _or_null isn't necessary, this should always be nonnull | |
380 | ||
389–390 | codebase convention is to avoid auto for simple types | |
427 | ||
lld/MachO/ICF.h | ||
24 | symtab and config are globals in LLD; no need to pass them explicitly | |
lld/MachO/InputSection.h | ||
74 | would be nice to have a comment here | |
lld/test/MachO/icf-options.s | ||
12 ↗ | (On Diff #423660) | can just reuse DIAG-EMPTY here, no need for DIAG-SAFE |
lld/test/MachO/icf-safe.s | ||
16–18 ↗ | (On Diff #423660) | nit: align |
34–39 ↗ | (On Diff #423660) | we usually try to create test cases that are as minimal as possible. can this just be a ret void? |
104–106 ↗ | (On Diff #423660) | ditto, I suppose we need noinline but can we omit the others? |
lld/MachO/ICF.cpp | ||
---|---|---|
370–371 | we should cover this with a test too |
lgtm!
lld/MachO/ICF.h | ||
---|---|---|
12 | could forward-declare InputFile and move this include to the .cpp | |
21 | oops, I belatedly realized that inputFiles is a global as well, doesn't need to be passed either :D (we could do away with the SetVector.h include in that case) | |
lld/test/MachO/icf-safe.s | ||
9–11 ↗ | (On Diff #423966) | FileCheck operates via substring matching by default, so there's no need for the regex nit: also align the lines with the _callAllFunctions line above |
23 ↗ | (On Diff #423966) | should remove the other attributes we deleted below (or just remove the entire comment altogether) |
lld/MachO/InputSection.h | ||
---|---|---|
74 | Nit: "symbol" is a bit confusing, since the flag is on a section. Perhaps something like this instead? |
lld/test/MachO/icf-safe.s | ||
---|---|---|
24 ↗ | (On Diff #423966) | Nit: you can inline the attributes instead of declaring them out of line (same for everything below) |
nit: can omit if braces