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
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 | ||
---|---|---|
10–14 | 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 | ||
---|---|---|
1546–1548 | nit: can omit if braces | |
lld/MachO/ICF.cpp | ||
370–374 | can omit braces | |
379–380 | 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? | |
382 | I think the _or_null isn't necessary, this should always be nonnull | |
389 | ||
398–399 | codebase convention is to avoid auto for simple types | |
424 | ||
lld/MachO/ICF.h | ||
21 | 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 | can just reuse DIAG-EMPTY here, no need for DIAG-SAFE | |
lld/test/MachO/icf-safe.s | ||
17–19 | nit: align | |
35–40 | we usually try to create test cases that are as minimal as possible. can this just be a ret void? | |
105–107 | ditto, I suppose we need noinline but can we omit the others? |
lld/MachO/ICF.cpp | ||
---|---|---|
379–380 | 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 | |
20 | 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 | ||
10–12 | 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 | |
24 | 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 | ||
---|---|---|
25 | Nit: you can inline the attributes instead of declaring them out of line (same for everything below) |
nit: can omit if braces