Skip to content

port(Macho): copy __text section from input, introduce more output commands#1810

Merged
marxin merged 12 commits intowild-linker:mainfrom
marxin:macho4
Apr 6, 2026
Merged

port(Macho): copy __text section from input, introduce more output commands#1810
marxin merged 12 commits intowild-linker:mainfrom
marxin:macho4

Conversation

@marxin
Copy link
Copy Markdown
Collaborator

@marxin marxin commented Apr 5, 2026

Another implementation step where I properly filled up the section flags (R,W,X) and the __text and __data sections are properly copied from the input. By given that, I can dump the assembly of the final binary:

❯ llvm-objdump -d ~/Programming/wild/a.out

/Users/apple/Programming/wild/a.out:    file format mach-o arm64

Disassembly of section __TEXT,__text:

0000000100000248 <__text>:
100000248: d10083ff     sub     sp, sp, #0x20
10000024c: a9017bfd     stp     x29, x30, [sp, #0x10]
100000250: 910043fd     add     x29, sp, #0x10
100000254: d4200f60     brk     #0x7b
100000258: 90000008     adrp    x8, 0x100000000
10000025c: b9400108     ldr     w8, [x8]
100000260: 910003e9     mov     x9, sp
100000264: f9000128     str     x8, [x9]
100000268: 90000000     adrp    x0, 0x100000000
10000026c: 91000000     add     x0, x0, #0x0
100000270: 94000000     bl      0x100000270 <__text+0x28>
100000274: 52800000     mov     w0, #0x0                ; =0
100000278: a9417bfd     ldp     x29, x30, [sp, #0x10]
10000027c: 910083ff     add     sp, sp, #0x20
100000280: d65f03c0     ret

Next, I will focus on the mandatory commands that will eventually allow running a binary.

Issue #757

@marxin marxin requested a review from davidlattimore April 5, 2026 08:49
lapla-cogito and others added 3 commits April 5, 2026 15:45
)

wild-linker@f704b10
stopped processing debug relocations during layout to fix GC. As a side
effect, local symbols referenced only from debug sections no longer get
merged resolutions on RISC-V/LoongArch64, causing the section resolution
fallback in `get_resolution()` to be reached for the first time on these
architectures.

This fallback only returned the section base address, which was
sufficient for x86-64/AArch64 where debug relocations reference section
symbols (value=0). On RISC-V/LoongArch64, the referenced local symbols
have non-zero values, so the missing offset caused paired relocations
like `R_RISCV_SET_ULEB128` / `R_RISCV_SUB_ULEB128` to compute incorrect
differences, producing wrong values or overflowing the ULEB128 buffer.
Include `sym.value()` adjusted for relaxation deltas in the fallback,
matching [the fix already applied in
`apply_debug_relocation()`](https://github.com/wild-linker/wild/blob/8708f550d3f57edd047709eb94cf21b552a69a6c/libwild/src/elf_writer.rs#L3020-L3038).

fix wild-linker#1796
@marxin marxin merged commit e669be5 into wild-linker:main Apr 6, 2026
24 checks passed
@marxin marxin deleted the macho4 branch April 6, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants