Align x86-64 stubs by whether the lazy-binding helper exists

ld-prime byte-aligns x86-64 __stubs only when they go through
__stub_helper; with chained fixups, -bind_at_load or weak-lookup
stubs alone they are 2-byte aligned. The classic-vs-chained rule we
had was the common case of that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Chris AllenandClaude Opus 5.5 committed 2026-09-23 11:54:53 -05:00
1 parent 057b20ad44
commit 5038821005
2 files changed
+12 -4

No files matched your search

+7 -4
View File
@@ -3964,11 +3964,14 @@ pub fn create_output_sections<E: Target>(ctx: &mut Context<E>) {
if !ctx.stubs.symbols.is_empty() {
ctx.stubs.hdr.reserved2 = E::STUB_SIZE as u32;
ctx.stubs.hdr.size = ctx.stubs.symbols.len() as u64 * E::STUB_SIZE;
// ld-prime's x86-64 stubs are 2-byte aligned with chained
// fixups and byte-aligned with classic dyld info; arm64's are
// instruction-aligned.
// ld-prime's x86-64 stubs are byte-aligned when they go
// through the lazy-binding helper and 2-byte aligned otherwise
// (chained fixups, -bind_at_load, weak-lookup stubs); arm64's
// are instruction-aligned.
if E::CPUTYPE == crate::macho::CPU_TYPE_X86_64 {
ctx.stubs.hdr.p2align = if ctx.use_chained_fixups() { 1 } else { 0 };
let lazy = ctx.lazy_binding()
&& ctx.stubs.symbols.iter().any(|&id| !ctx.binds_weak_lookup(id));
ctx.stubs.hdr.p2align = if lazy { 0 } else { 1 };
}
ctx.chunks.push(ChunkId::Stubs);
}
+5
View File
@@ -17,3 +17,8 @@ otool -l $t/exe > $t/lc
not grep -q '__la_symbol_ptr' $t/lc
dyld_info -fixups $t/exe | grep '__got .* bind .*_printf'
$t/exe | grep hi
# Without the lazy-binding helper, x86-64 stubs are 2-byte aligned as
# with chained fixups.
if [ $ARCH = x86_64 ]; then
grep -A8 'sectname __stubs' $t/lc | grep 'align 2^1'
fi