[ELF] Place x86-64 large sections after .bss by default (#245107)
The default layout places .ltext and .lrodata before .rodata. When they
are large, R_X86_64_PC32 references from .text to `__ehdr_start` (e.g.
from compiler-rt) and absolute relocations to small symbols in -fno-pic
code are out of range. -z lrodata-after-bss moves .lrodata after .bss
but leaves .ltext in place.
Make -z lrodata-after-bss the default and change its layout to
```
.rodata .text .data .bss .ltext .lrodata .ldata .lbss
```
.ltext is the first large section, as small code may reference it with
32-bit relocations, e.g. a prebuilt object calling a -mcmodel=large
function. .lbss, which is free in the file and therefore the section
most likely to span several GiB, is the last one.
[8 lines not shown]
Regenerate inlineasm-sched-bug.ll's checks
Main now schedules @folded's load of p after its other argument loads. The
store to *p still comes before the asm, which is what the test checks.
Assisted-by: Claude Opus 5.5
[RegAllocFast] Don't apply the hint bonus to a register that can't be spilled
allocVirtReg() takes spillPrefBonus off a hinted register's spill cost even
when the cost is spillImpossible, which makes the register look cheaper than
impossible. When no other register was free, a value then got a register
that it can't have, e.g. one that the instruction clobbers. An inline asm
"r" input copied from a register that the asm clobbers silently got that
register, instead of the "inline assembly requires more registers than
available" error that an input with no hint gets. Only apply the bonus to a
register that can be spilled.
Assisted-by: Claude Opus 5.5
Test an "rm" input next to two byte inputs with the fast allocator
With only EDX left, the fast register allocator's estimate counted DL and DH
as two 32-bit registers and found no fit for an "rm" input next to two byte
"r" inputs, which ran out of registers where choosing 'm' for the input had
compiled. Now that it folds the input anyway, test the case end to end,
where "rm" prefers a register.
Assisted-by: Claude Opus 5.5
Update S3 protocol tests for bucket policies and NoSuchBucket
Two truenas_s3 changes moved answers test_s3_buckets.py pinned.
A bucket's policy is now its grant rows, so ?policy and ?policyStatus
answer a document on every bucket a row names. Take both out of the
absent-configuration matrix and the modeled probe loop, assert the
document the session's row renders, and cover both states in
test_s3_grants.py.
A name no row holds now answers 404 NoSuchBucket to any signed caller
where it answered 403. Replace the case that held three such names to
one 403 with two: the 404, and the bare 403 wherever a row stands.
Trim the docstrings and comments in the five files touched to a line
or two each.
Needs truenas_s3 with bucket policies and the NoSuchBucket answer.
Require NTS for S3 Object Lock only when require_nts is set
s3d refused every time source without NTS, so on the default NTP
servers every object-locked bucket was read-only. Render require_nts
into its [server] section, and when the setting changes, restart S3
once chronyd has selected a source again (up to 60 s).
Needs truenas_s3 with the [server] require_nts key.
Fold the "rm" inputs when the estimate finds no fit
The estimate counts DL and DH as two registers of GR32, although they share
EDX. So on i686 an "rm" input next to two byte "r" inputs found no fit even
folded, and nothing was folded, which ran out of registers where choosing
'm' for the "rm" input had compiled. Fold every foldable register that the
asm only reads then, as choosing 'm' did.
Assisted-by: Claude Opus 5.5
Don't fold a copy's source that the asm also uses
The asm could have an undef use of the source of an input's copy, which
readsVirtualRegister() ignores, so the source was folded in the copy's
place. But the folder folds every operand of a register or none, and
refused the source, which asserts. Don't use the source if the asm refers
to it at all.
Assisted-by: Claude Opus 5.5
Spill a folded input whose def block comes later
Folding an "rm" input that lives into the asm's block makes the asm read
the register's stack slot, which a block that defines the register spills
it to only if the register may live out of that block. The fold removed the
asm's use, so a defining block allocated after the asm's saw no use outside
it, and the asm read a slot that nothing wrote. Record that the register
lives across blocks when it's folded.
Assisted-by: Claude Opus 5.5
Don't fold inline asm operands that are all undef uses
The peephole optimizer can fold a load into operands that are all undef
uses. The asm doesn't access the slot then, and the memory operand got
neither the load nor the store flag, which asserts. Return null, since
there's nothing to fold.
Assisted-by: Claude Opus 5.5
[lld][MachO] Pool relocation storage per input section
Compilers split input sections into many subsections, and each subsection currently grows its own relocation vector. In a Chromium link, that means 3.41 million small allocations for 51.3 million relocations. Allocation dominates parallel relocation parsing: glibc grows worker arenas with `mprotect`, and the workers contend on the process's `mmap_lock`.
## Design
I allocate one relocation array per input Section and let its subsections borrow slices of it. Chromium then needs 82,210 arrays. The arrays come from a thread-local bump allocator, which this PR adds to `lld/Common`: the existing thread-local allocators are typed and construct and destroy their elements, which a buffer filled by placement does not want.
Compilers emit relocations by descending address, so each subsection's relocations arrive one after another. `ld -r` output may not be sorted: the parser checks the order as it goes, and on the first out-of-order relocation it sorts the section's relocations and parses them again, holding back diagnostics until it can no longer start over. A slice that later passes append to moves to a buffer of its own.
The parser fills each array from the back, so relocations end up in ascending address order, both across subsections and within each one. A SUBTRACTOR still precedes its paired UNSIGNED. Upstream stores each subsection's relocations in descending order, and the thunk pass walks them in reverse to visit branches by ascending address. With ascending storage, the relocation scan and the thunk pass both read a section's relocations front to back, and the thunk pass becomes a forward loop.
Passes that act on relocations in storage order now do so in ascending address order within a subsection. GOT, stub and binding entries are therefore created in source order, as are undefined-symbol diagnostics and `-why_live` output. The affected tests are updated; only the order of entries changes.
## Measurements
Both tables compare this PR, merged into `main` at 950baabb7fdf, against that commit. They give means and cbdr 95% confidence intervals over 30 interleaved paired rounds at the default thread count.
Linux (AMD Ryzen 7 7700):
[38 lines not shown]