summaryrefslogtreecommitdiff
path: root/lld/MachO/InputSection.cpp
AgeCommit message (Collapse)Author
2025-11-01[lld][macho] Error out gracefully when offset is outside literal section ↵Jez Ng
(#164660) We typically shouldn't get this, but when we do (e.g. in #139439) we should error out gracefully instead of crashing. Note that we are stricter than ld64 here; ld64 appears to be able to handle section offsets that point outside literal sections if the end result is a valid pointer to another section in the input object file. Supporting this would probably be a pain given our current design, and it seems like enough of an edge case that it's onot worth it.
2025-09-22[LLD][MachO] Option to emit separate cstring sections (#158720)Ellis Hoag
Add the `--{no-}separate-cstring-literal-sections` option to emit cstring literals into sections defined by their section name. This allows for changes like https://github.com/swiftlang/swift/pull/84300 and https://github.com/swiftlang/swift/pull/84236 to actually have an affect. The default behavior has not changed. The reason this is useful is because strings in different sections might have different access patterns at runtime. By splitting these strings into separate sections, we may reduce the number of page faults during startup. For example, the ObjC runtime accesses all strings in `__objc_classname` before main.
2025-05-25[lld] Remove unused includes (NFC) (#141421)Kazu Hirata
2024-12-14[lld] Migrate away from PointerUnion::{is,get} (NFC) (#119993)Kazu Hirata
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-09-22[lld] Use StringRef idioms (NFC) (#109584)Kazu Hirata
2024-09-05[lld-macho][arm64] Enhance safe ICF with thunk-based deduplication (#106573)alx32
Currently, our `safe` ICF mode only merges non-address-significant code, leaving duplicate address-significant functions in the output. This patch introduces `safe_thunks` ICF mode, which keeps a single master copy of each function and replaces address-significant duplicates with thunks that branch to the master copy. Currently `--icf=safe_thunks` is only supported for `arm64` architectures. **Perf stats for a large binary:** | ICF Option | Total Size | __text Size | __unwind_info | % total | |-------------------|------------|-------------|---------------------|---------------------------| | `--icf=none` | 91.738 MB | 55.220 MB | 1.424 MB | 0% | | `--icf=safe` | 85.042 MB | 49.572 MB | 1.168 MB | 7.30% | | `--icf=safe_thunks` | 84.650 MB | 49.219 MB | 1.143 MB | 7.72% | | `--icf=all` | 82.060 MB | 48.726 MB | 1.111 MB | 10.55% | So overall we can expect a `~0.45%` binary size reduction for a typical large binary compared to the `--icf=safe` option. **Runtime:** Linking the above binary took ~10 seconds. Comparing the link performance of --icf=safe_thunks vs --icf=safe, a ~2% slowdown was observed.
2024-07-23[lld-macho] Fix thunks for non-__text TEXT sections (#99052)Leonard Grey
This supersedes https://github.com/llvm/llvm-project/pull/87818 and fixes https://github.com/llvm/llvm-project/issues/52767 When calculating arm64 thunks, we make a few assumptions that may not hold when considering code sections outside of `__text`: 1. That a section needs thunks only if its size is larger than the branch range. 2. That any calls into `__stubs` are necessarily forward jumps (that is, the section with the jump is ordered before `__stubs`) Sections like this exist in the wild, most prominently the `__lcxx_overrides` section introduced in https://github.com/llvm/llvm-project/pull/69498 This change: - Ensures that if one section in `__TEXT` gets thunks, all of them do. - Makes all code sections in `__TEXT` contiguous (and guaranteed to be placed before `__stubs`)
2024-04-18[lld-macho][NFC] Preserve original symbol isec, unwindEntry and size (#88357)alx32
Currently, when moving symbols from one `InputSection` to another (like in ICF) we directly update the symbol's `isec`, `unwindEntry` and `size`. By doing this we lose the original information. This information will be needed in a future change. Since when moving symbols we always set the symbol's `wasCoalesced` and `isec-> replacement`, we can just use this info to conditionally get the information we need at access time.
2024-03-27[lld-macho] Fix bug in makeSyntheticInputSection when -dead_strip flag is ↵alx32
specified (#86878) Previously, `makeSyntheticInputSection` would create a new `ConcatInputSection` without setting `live` explicitly for it. Without `-dead_strip` this would be OK since `live` would default to `true`. However, with `-dead_strip`, `live` would default to false, and it would remain set to `false`. This hasn't resulted in any issues so far since no code paths that exposed this issue were present. However a recent change - ObjC relative method lists (https://github.com/llvm/llvm-project/pull/86231) exposes this issue by creating relocations to the `SyntheticInputSection`. When these relocations are attempted to be written, this ends up with a crash(assert), since the `SyntheticInputSection` they refer to is marked as dead (`live` = `false`). With this change, we set the correct behavior - `live` will always be `true`. We add a test case that before this change would trigger an assert in the linker.
2024-03-27[lld-macho] Implement support for ObjC relative method lists (#86231)alx32
The MachO format supports relative offsets for ObjC method lists. This support is present already in ld64. With this change we implement this support in lld also. Relative method lists can be identified by a specific flag (0x80000000) in the method list header. When this flag is present, the method list will contain 32-bit relative offsets to the current Program Counter (PC), instead of absolute pointers. Additionally, when relative method lists are used, the offset to the selector name will now be relative and point to the selector reference (selref) instead of the name itself.
2024-03-22Revert "[BOLT] Add BB index to BAT (#86044)"Amir Ayupov
This reverts commit 3b3de48fd84b8269d5f45ee0a9dc6b7448368424.
2024-03-22[BOLT] Add BB index to BAT (#86044)Amir Ayupov
2024-03-21[lld-macho][NFC] Refactor insertions into inputSections (#85692)alx32
Before this change, after `InputSection` objects are created, they need to be added to the appropriate container for tracking. The logic for selecting the appropriate container lives in `Driver.cpp` / `gatherInputSections`, where the `InputSection` is added to the matching container depending on the input config and the type of `InputSection`. Also, multiple other locations also insert directly into `inputSections` array - assuming that that is the appropriate container for the `InputSection`'s they create. Currently this is the correct assumption, however an upcoming feature will change this. For an upcoming feature (relative method lists), we need to route `InputSection`'s either to `inputSections` array or to a synthetic section, depending on weather the relative method list optimization is enabled or not. We can achieve the above either by duplicating some of the logic or refactoring the routing and `InputSection`'s and reusing that. The refactoring & code sharing approach seems the correct way to go - as such this diff performs the refactoring while not introducing any functional changes. Later on we can just call `addInputSection` and not have to worry about routing logic. ---------
2023-07-19[lld-macho] Switch to xxh3_64bitsFangrui Song
xxh3 is substantially faster than xxh64. For lld/ELF, there is substantial speedup in `.debug_str` duplicate elimination (D154813). Use xxh3 for lld-macho as well. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D155677
2023-06-05[lld] StringRef::{starts,ends}with => {starts,ends}_with. NFCFangrui Song
The latter form is now preferred to be similar to C++20 starts_with. This replacement also removes one function call when startswith is not inlined.
2023-03-30[lld-macho][re-land] Warn on method name collisions from category definitionsJez Ng
This implements ld64's checks for duplicate method names in categories & classes. In addition, this sets us up for implementing Obj-C category merging. This diff handles the most of the parsing work; what's left is rewriting those category / class structures. Numbers for chromium_framework: base diff difference (95% CI) sys_time 2.182 ± 0.027 2.200 ± 0.047 [ -0.2% .. +1.8%] user_time 6.451 ± 0.034 6.479 ± 0.062 [ -0.0% .. +0.9%] wall_time 6.841 ± 0.048 6.885 ± 0.105 [ -0.1% .. +1.4%] samples 33 22 Fixes https://github.com/llvm/llvm-project/issues/54912. Issues seen with the previous land will be fixed in the next commit. Reviewed By: #lld-macho, thevinster, oontvoo Differential Revision: https://reviews.llvm.org/D142916
2023-03-08Revert "[lld-macho] Warn on method name collisions from category definitions"Jez Ng
This reverts commit ef122753db7fe8e9a0b7bedd46d2f3668a780fcb. Apparently it is causing some crashes: https://reviews.llvm.org/D142916#4178869
2023-03-07[lld-macho] Warn on method name collisions from category definitionsJez Ng
This implements ld64's checks for duplicate method names in categories & classes. In addition, this sets us up for implementing Obj-C category merging. This diff handles the most of the parsing work; what's left is rewriting those category / class structures. Numbers for chromium_framework: base diff difference (95% CI) sys_time 2.182 ± 0.027 2.200 ± 0.047 [ -0.2% .. +1.8%] user_time 6.451 ± 0.034 6.479 ± 0.062 [ -0.0% .. +0.9%] wall_time 6.841 ± 0.048 6.885 ± 0.105 [ -0.1% .. +1.4%] samples 33 22 Fixes https://github.com/llvm/llvm-project/issues/54912. Reviewed By: #lld-macho, thevinster, oontvoo Differential Revision: https://reviews.llvm.org/D142916
2022-11-27[lld] Change Optional to std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-19[lld-macho][nfc] Clean up includesVy Nguyen
- remove unused/duplicate includes - reformatting/whitespaces Differential Revision: https://reviews.llvm.org/D136266
2022-10-18[lld-macho] Folded symbols should have size zero in linker mapJez Ng
This matches ld64's behavior. I also extended the icf-stabs.s test to demonstrate that even though folded symbols have size zero, we cannot use the size-zero property in lieu of `wasIdenticalCodeFolded`, because size zero symbols should still get STABS entries. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D136001
2022-10-18[lld-macho] Don't fold subsections with symbols at nonzero offsetsJez Ng
Symbols occur at non-zero offsets in a subsection if they are `.alt_entry` symbols, or if `.subsections_via_symbols` is omitted. It doesn't seem like ld64 supports folding those subsections either. Moreover, supporting this it makes `foldIdentical` a lot more complicated to implement. The existing implementation has some questionable behavior around STABS omission -- if a section with an non-zero offset symbol was folded into one without, we would omit the STABS entry for the non-zero offset symbol. I will be following up with a diff that makes `foldIdentical` zero out the symbol sizes for folded symbols. Again, this is much easier to implement if we don't have to worry about non-zero offsets. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D136000
2022-10-04[lld-macho] Add support for emitting chained fixupsDaniel Bertalan
This commit adds support for chained fixups, which were introduced in Apple's late 2020 OS releases. This format replaces the dyld opcodes used for supplying rebase and binding information, and encodes most of that data directly in the memory location that will have the fixup applied. This reduces binary size and is a requirement for page-in linking, which will be available starting with macOS 13. A high-level overview of the format and my implementation can be found in SyntheticSections.h. This feature is currently gated behind the `-fixup_chains` flag, and will be enabled by default for supported targets in a later commit. Like in ld64, lazy binding is disabled when chained fixups are in use, and the `-init_offsets` transformation is performed by default. Differential Revision: https://reviews.llvm.org/D132560
2022-09-16[lld-macho] Parallelize linker optimization hint processingDaniel Bertalan
This commit moves the parsing of linker optimization hints into `ARM64::applyOptimizationHints`. This lets us avoid allocating memory for holding the parsed information, and moves work out of `ObjFile::parse`, which is not parallelized at the moment. This change reduces the overhead of processing LOHs to 25-30 ms when linking Chromium Framework on my M1 machine; previously it took close to 100 ms. There's no statistically significant change in runtime for a --threads=1 link. Performance figures with all 8 cores utilized: N Min Max Median Avg Stddev x 20 3.8027232 3.8760762 3.8505335 3.8454145 0.026352574 + 20 3.7019017 3.8660538 3.7546209 3.7620371 0.032680043 Difference at 95.0% confidence -0.0833775 +/- 0.019 -2.16823% +/- 0.494094% (Student's t, pooled s = 0.0296854) Differential Revision: https://reviews.llvm.org/D133439
2022-09-14[lld-macho] Have ICF dedup explicitly-defined selrefsJez Ng
This is what ld64 does (though it doesn't use ICF to do this; instead it always dedups selrefs by default). We'll want to dedup implicitly-defined selrefs as well, but I will leave that for future work. Additionally, I'm not *super* happy with the current LLD implementation because I think it is rather janky and inefficient. But at least it moves us toward the goal of closing the size gap with ld64. I've described ideas for cleaning up our implementation here: https://github.com/llvm/llvm-project/issues/57714 Differential Revision: https://reviews.llvm.org/D133780
2022-09-13[lld-macho][nfci] Don't include null terminator in StringRefsJez Ng
So @keith observed [here](https://reviews.llvm.org/D128108#inline-1263900) that the StringRefs we were returning from `CStringInputSection::getStringRef()` included the null terminator in their total length, but regular StringRefs do not. Let's fix that so these StringRefs are less confusing to use. Reviewed By: #lld-macho, keith, Roger Differential Revision: https://reviews.llvm.org/D133728
2022-09-06[lld-macho] Simplify linker optimization hint processingDaniel Bertalan
This commit removes the `relocTargets` vector, and instead makes the code reconstruct the referent addresses from the relocated instructions. This will allow us to move `applyOptimizationHints` from `ConcatInputSection::writeTo` to a separate pass that parses and applies LOHs in one step, on a per-file basis. This will improve performance, as parsing is currently done serially in `ObjFile::parse`. I opted to remove the sanity check that ensures that all relocations within a LOH point to the same symbol. This completely eliminates the need to search through relocations. It is my understanding that mismatched relocation targets should not be present in valid object files, so it's unlikely that the removal will lead to mislinks. Differential Revision: https://reviews.llvm.org/D133274
2022-08-10[lld-macho] Add support for objc_msgSend stubsKeith Smiley
Apple Clang in Xcode 14 introduced a new feature for reducing the overhead of objc_msgSend calls by deduplicating the setup calls for each individual selector. This works by clang adding undefined symbols for each selector called in a translation unit, such as `_objc_msgSend$foo` for calling the `foo` method on any `NSObject`. There are 2 different modes for this behavior, the default directly does the setup for `_objc_msgSend` and calls it, and the smaller option does the selector setup, and then calls the standard `_objc_msgSend` stub function. The general overview of how this works is: - Undefined symbols with the given prefix are collected - The suffix of each matching undefined symbol is added as a string to `__objc_methname` - A pointer is added for every method name in the `__objc_selrefs` section - A `got` entry is emitted for `_objc_msgSend` - Stubs are emitting pointing to the synthesized locations Notes: - Both `__objc_methname` and `__objc_selrefs` can also exist from object files, so their contents are merged with our synthesized contents - The compiler emits method names for defined methods, but not for undefined symbols you call, but stubs are used for both - This only implements the default "fast" mode currently just to reduce the diff, I also doubt many folks will care to swap modes - This only implements this for arm64 and x86_64, we don't need to implement this for 32 bit iOS archs, but we should implement it for watchOS archs in a later diff Differential Revision: https://reviews.llvm.org/D128108
2022-07-25[lld-macho] Demangle location name in undefined symbol diagnosticsDaniel Bertalan
If the `-demangle` flag is passed to lld, symbol names will now be demangled in the "referenced by:" message in addition to the referenced symbol's name, which was already demangled before this change. Differential Revision: https://reviews.llvm.org/D130490
2022-07-19[lld-macho] Support folding of functions with identical LSDAsJez Ng
To do this, we need to slice away the LSDA pointer, just like we are slicing away the functionAddress pointer. No observable difference in perf on chromium_framework: base diff difference (95% CI) sys_time 1.769 ± 0.068 1.761 ± 0.065 [ -2.7% .. +1.8%] user_time 9.517 ± 0.110 9.528 ± 0.116 [ -0.6% .. +0.8%] wall_time 8.291 ± 0.174 8.307 ± 0.183 [ -1.1% .. +1.5%] samples 21 25 Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D129830
2022-07-11[lld-macho] Handle user-provided dtrace symbols to avoid linking failureKaining Zhong
This fixes https://github.com/llvm/llvm-project/issues/56238. ld64.lld currently does not generate __dof section in Mach-O, and -no_dtrace_dof option is on by default. However when there are user-defined dtrace symbols, ld64.lld will treat them as undefined symbols, which causes the linking to fail because lld cannot find their definitions. This patch allows ld64.lld to rewrite the instructions calling dtrace symbols to instructions like nop as what ld64 does; therefore, when encountered with user-provided dtrace probes, the linking can still succeed. I'm not sure whether support for dtrace is expected in lld, so for now I didn't add codes to make lld emit __dof section like ld64, and only made it possible to link with dtrace symbols provided. If this feature is needed, I can add that part in Dtrace.cpp & Dtrace.h. Reviewed By: int3, #lld-macho Differential Revision: https://reviews.llvm.org/D129062
2022-06-30[lld-macho] Initial support for Linker Optimization HintsDaniel Bertalan
Linker optimization hints mark a sequence of instructions used for synthesizing an address, like ADRP+ADD. If the referenced symbol ends up close enough, it can be replaced by a faster sequence of instructions like ADR+NOP. This commit adds support for 2 of the 7 defined ARM64 optimization hints: - LOH_ARM64_ADRP_ADD, which transforms a pair of ADRP+ADD into ADR+NOP if the referenced address is within +/- 1 MiB - LOH_ARM64_ADRP_ADRP, which transforms two ADRP instructions into ADR+NOP if they reference the same page These two kinds already cover more than 50% of all LOHs in chromium_framework. Differential Review: https://reviews.llvm.org/D128093
2022-06-23[lld-macho] Use source information in duplicate symbol errorsDaniel Bertalan
Similarly to how undefined symbol diagnostics were changed in D128184, we now show where in the source file duplicate symbols are defined at: ld64.lld: error: duplicate symbol: _foo >> defined in bar.c:42 >> /path/to/bar.o >> defined in baz.c:1 >> /path/to/libbaz.a(baz.o) For objects that don't contain DWARF data, the format is unchanged. A slight difference to undefined symbol diagnostics is that we don't print the name of the symbol on the third line, as it's already contained on the first line. Differential Revision: https://reviews.llvm.org/D128425
2022-06-21Reland "[lld-macho] Show source information for undefined references"Daniel Bertalan
The error used to look like this: ld64.lld: error: undefined symbol: _foo >>> referenced by /path/to/bar.o:(symbol _baz+0x4) If DWARF line information is available, we now show where in the source the references are coming from: ld64.lld: error: unreferenced symbol: _foo >>> referenced by: bar.cpp:42 (/path/to/bar.cpp:42) >>> /path/to/bar.o:(symbol _baz+0x4) The reland is identical to the first time this landed. The fix was in D128294. This reverts commit 0cc7ad417585b3185c32e395cc5e6cf082a347af. Differential Revision: https://reviews.llvm.org/D128184
2022-06-20Revert "[lld-macho] Show source information for undefined references"Nico Weber
This reverts commit cd7624f15369f0d395c1edee1a0b9592083d2fe0. See https://reviews.llvm.org/D128184#3597534
2022-06-20[lld-macho] Show source information for undefined referencesDaniel Bertalan
The error used to look like this: ld64.lld: error: undefined symbol: _foo >>> referenced by /path/to/bar.o:(symbol _baz+0x4) If DWARF line information is available, we now show where in the source the references are coming from: ld64.lld: error: unreferenced symbol: _foo >>> referenced by: bar.cpp:42 (/path/to/bar.cpp:42) >>> /path/to/bar.o:(symbol _baz+0x4) Differential Revision: https://reviews.llvm.org/D128184
2022-06-13[lld-macho] Fix symbol name returned from InputSection::getLocationDaniel Bertalan
This commit fixes the issue that getLocation always printed the name of the first symbol in the section. For clarity, upper_bound is used instead of a linear search for finding the closest symbol name. Note that this change does not affect performance: this function is only called when printing errors and `symbols` typically contains a single symbol because of .subsections_via_symbols. Differential Revision: https://reviews.llvm.org/D127670
2022-06-13[lld-macho][reland] Initial support for EH FramesJez Ng
This reverts commit 942f4e3a7cc9a9f8b2654817cff12907d1276031. The additional change required to avoid the assertion errors seen previously is: --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -443,7 +443,9 @@ void macho::foldIdenticalSections() { /*relocVA=*/0); isec->data = copy; } - } else { + } else if (!isEhFrameSection(isec)) { + // EH frames are gathered as hashables from unwindEntry above; give a + // unique ID to everything else. isec->icfEqClass[0] = ++icfUniqueID; } } Differential Revision: https://reviews.llvm.org/D123435
2022-06-09Revert "[lld-macho] Initial support for EH Frames"Douglas Yung
This reverts commit 826be330af9c0a8553a5b32718ecd2d97e10438e. This was causing a test failure on build bots: - https://lab.llvm.org/buildbot/#/builders/36/builds/21770 - https://lab.llvm.org/buildbot/#/builders/58/builds/23913
2022-06-08[lld-macho] Initial support for EH FramesJez Ng
== Background == `llvm-mc` generates unwind info in both compact unwind and DWARF formats. LLD already handles the compact unwind format; this diff gets us close to handling the DWARF format properly. == Caveats == It's not quite done yet, but I figure it's worth getting this reviewed and landed first as it's shaping up to be a fairly large code change. **Known limitations of the current code:** * Only works for x86_64, for which `llvm-mc` emits "abs-ified" relocations as described in https://github.com/llvm/llvm-project/commit/618def651b59bd42c05bbd91d825af2fb2145683. `llvm-mc` emits regular relocations for ARM EH frames, which we do not yet handle correctly. Since the feature is not ready for real use yet, I've gated it behind a flag that only gets toggled on during test suite runs. With most of the new code disabled, we see just a hint of perf regression, so I don't think it'd be remiss to land this as-is: base diff difference (95% CI) sys_time 1.926 ± 0.168 1.979 ± 0.117 [ -1.2% .. +6.6%] user_time 3.590 ± 0.033 3.606 ± 0.028 [ +0.0% .. +0.9%] wall_time 7.104 ± 0.184 7.179 ± 0.151 [ -0.2% .. +2.3%] samples 30 31 == Design == Like compact unwind entries, EH frames are also represented as regular ConcatInputSections that get pointed to via `Defined::unwindEntry`. This allows them to be handled generically by e.g. the MarkLive and ICF code. (But note that unlike compact unwind subsections, EH frame subsections do end up in the final binary.) In order to make EH frames "look like" a regular ConcatInputSection, some processing is required. First, we need to split the `__eh_frame` section along EH frame boundaries rather than along symbol boundaries. We do this by decoding the length field of each EH frame. Second, the abs-ified relocations need to be turned into regular Relocs. == Next Steps == In order to support EH frames on ARM targets, we will either have to teach LLD how to handle EH frames with explicit relocs, or we can try to make `llvm-mc` emit abs-ified relocs for ARM as well. I'm hoping to do the latter as I think it will make the LLD implementation both simpler and faster to execute. == Misc == The `obj-file-with-stabs.s` test had to be updated as the previous version would trip assertion errors in the code. It appears that in our attempt to produce a minimal YAML test input, we created a file with invalid EH frame data. I've fixed this by re-generating the YAML and not doing any hand-pruning of it. Reviewed By: #lld-macho, Roger Differential Revision: https://reviews.llvm.org/D123435
2022-04-07[lld/mac] Don't emit stabs entries for functions folded during ICFNico Weber
This matches ld64, and makes dsymutil work better with lld's output. Fixes PR54783, see there for details. Reduces time needed to run dsymutil on Chromium Framework from 8m30s (which is already down from 26 min with D123218) to 6m30s and removes many lines of "could not find object file symbol for symbol" from dsymutil output (previously: several MB of those messages, now dsymutil is completely silent). Differential Revision: https://reviews.llvm.org/D123252
2022-03-08[lld-macho] Deduplicate the `__objc_classrefs` section contentsJez Ng
ld64 breaks down `__objc_classrefs` on a per-word level and deduplicates them. This greatly reduces the number of bind entries emitted (and therefore the amount of work `dyld` has to do at runtime). For chromium_framework, this change to LLD cuts the number of (non-lazy) binds from 912 to 190, getting us to parity with ld64 in this aspect. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D121053
2022-03-07[lld-macho][nfc] Reduce size of icfEqClass hashJez Ng
... from a `uint64_t` to a `uint32_t`. (LLD-ELF uses a `uint32_t` too.) About a 1.7% reduction in peak RSS when linking chromium_framework on my 3.2 GHz 16-Core Intel Xeon W Mac Pro, and no stat sig change in wall time. </Users/jezng/test2.sh ["before"]> </Users/jezng/test2.sh ["after"]> difference (95% CI) RSS 1003036672.000 ± 9891065.259 985539505.231 ± 10272748.749 [ -2.3% .. -1.2%] samples 27 26 base diff difference (95% CI) sys_time 1.277 ± 0.023 1.277 ± 0.024 [ -0.9% .. +0.9%] user_time 6.682 ± 0.046 6.598 ± 0.043 [ -1.6% .. -0.9%] wall_time 5.904 ± 0.062 5.895 ± 0.063 [ -0.7% .. +0.4%] samples 46 28 No appreciable change (~0.01%) in number of `equals` comparisons either: Before: ld64.lld: ICF needed 8 iterations ld64.lld: equalsConstant() called 701643 times ld64.lld: equalsVariable() called 3438526 times After: ld64.lld: ICF needed 8 iterations ld64.lld: equalsConstant() called 701729 times ld64.lld: equalsVariable() called 3438526 times Reviewed By: #lld-macho, MaskRay, thakis Differential Revision: https://reviews.llvm.org/D121052
2022-02-23[lld-macho][nfc] Move ICF-specific logic into ICF.cppJez Ng
This mirrors the code organization in `lld/ELF`. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D120378
2022-02-07[lld-macho] Include address offsets in error messagesJez Ng
This makes it easier to pinpoint the source of the problem. TODO: Have more relocation error messages make use of this functionality. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D118798
2022-02-03[lld-macho][nfc] Eliminate InputSection::SharedJez Ng
Earlier in LLD's evolution, I tried to create the illusion that subsections were indistinguishable from "top-level" sections. Thus, even though the subsections shared many common field values, I hid those common values away in a private Shared struct (see D105305). More recently, however, @gkm added a public `Section` struct in D113241 that served as an explicit way to store values that are common to an entire set of subsections (aka InputSections). Now that we have another "common value" struct, `Shared` has been rendered redundant. All its fields can be moved into `Section` instead, and the pointer to `Shared` can be replaced with a pointer to `Section`. This `Section` pointer also has the advantage of letting us inspect other subsections easily, simplifying the implementation of {D118798}. P.S. I do think that having both `Section` and `InputSection` makes for a slightly confusing naming scheme. I considered renaming `InputSection` to `Subsection`, but that would break the symmetry with `OutputSection`. It would also make us deviate from LLD-ELF's naming scheme. This change is perf-neutral on my 3.2 GHz 16-Core Intel Xeon W machine: base diff difference (95% CI) sys_time 1.258 ± 0.031 1.248 ± 0.023 [ -1.6% .. +0.1%] user_time 3.659 ± 0.047 3.658 ± 0.041 [ -0.5% .. +0.4%] wall_time 4.640 ± 0.085 4.625 ± 0.063 [ -1.0% .. +0.3%] samples 49 61 There's also no stat sig change in RSS (as measured by `time -l`): base diff difference (95% CI) time 998038627.097 ± 13567305.958 1003327715.556 ± 15210451.236 [ -0.2% .. +1.2%] samples 31 36 Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D118797
2021-11-22[MachO] Fix struct size assertionShoaib Meenai
std::vector can have different sizes depending on the STL's debug level, so account for its size separately. (You could argue that we should be accounting for all the other members separately as well, but that would be very unergonomic, and std::vector is the only one that's caused problems so far.)
2021-11-17[lld-macho][nfc] Factor-out NFC changes from main __eh_frame diffGreg McGary
In order to keep signal:noise high for the `__eh_frame` diff, I have teased-out the NFC changes and put them here. Differential Revision: https://reviews.llvm.org/D114017
2021-11-16[MachO] Move type size asserts to source files. NFCShoaib Meenai
As discussed in https://reviews.llvm.org/D113809#3128636. It's a bit unfortunate to move the asserts away from the structs whose sizes they're checking, but it's a far better developer experience when one of the asserts is violated, because you get a single error instead of every single source file including the header erroring out.
2021-11-02[lld-macho][nfc][cleanup] Fix a few code style lints and clang-tidy findingsVy Nguyen
- Use .empty() instead of `size() == 0` when possible. - Use const-ref to avoid copying Differential Revision: https://reviews.llvm.org/D112978