Jakub Konka
29c7f6810f
macho: fix 32bit builds
2024-12-02 22:05:21 -05:00
Jakub Konka
f78006c1bf
CMakeLists: add MachO/Dwarf.zig and remove MachO/dwarf.zig
2024-12-02 22:05:21 -05:00
Jakub Konka
0769afbb0f
macho: refactors errors from parsing DWARF
...
Currently we don't report any errors to the user due to a bug in
self-hosted x86_64-macos backend.
2024-12-02 22:05:21 -05:00
Jakub Konka
c824b35051
macho: move things around in MachO/Object.zig and refactor
2024-12-02 22:05:21 -05:00
Jakub Konka
8e81500051
macho: handle DWARFv5 when parsing debug info in objects
2024-12-02 22:05:21 -05:00
Jakub Konka
808306f49a
macho: rename dwarf.zig to Dwarf.zig
...
Separate commit since macOS is case-insensitive by default and so
I had to do it from Linux.
2024-12-02 22:05:21 -05:00
Jakub Konka
6ff267dc26
link/Elf: ensure we always sort all relocations by r_offset in -r mode
...
According to a comment in mold, this is the expected (and desired)
condition by the linkers, except for some architectures (RISCV and
Loongarch) where this condition does not have to upheld.
If you follow the changes in this patch and in particular doc comments
I have linked the comment/code in mold that explains and implements
this.
I have also modified `testEhFrameRelocatable` test to now test both
cases such that `zig ld -r a.o b.o -o c.o` and `zig ld -r b.o a.o -o
d.o`. In both cases, `c.o` and `d.o` should produce valid object
files which was not the case before this patch.
2024-10-29 17:27:42 -07:00
Jakub Konka
56996a2809
link/Coff: simplify file structure by collapsing all files into Coff.zig ( #21761 )
...
* coff: collapse Coff/lld.zig logic into Coff.zig
* coff: rename std.coff uses to coff_util
* coff: rename self to coff for *Coff references
* coff: collapse Coff/Atom.zig logic into Coff.zig
* coff: collapse Coff/Relocation.zig logic into Coff.zig
* coff: collapse Coff/ImportTable.zig logic into Coff.zig
* coff: remove unused Coff/Object.zig
* link/Coff: fix rebase gone wrong
2024-10-24 13:50:02 +00:00
Jakub Konka
7e530c13b3
macho: create dummy atom of size 0 marking end of a section
...
Some compilers such as Go reference the end of a section (addr + size)
which cannot be contained in any non-zero atom (since then this atom
would exceed section boundaries). In order to facilitate this behaviour,
we create a dummy zero-sized atom at section end (addr + size).
2024-10-12 02:53:15 -07:00
Jakub Konka
33401ff3bb
test/link/macho: test reporting undefined special symbols
2024-10-09 21:39:45 +02:00
Jakub Konka
d43b0cb31f
macho: fix a typo in InternalObject.addObjcMethnameSection
2024-10-09 21:39:45 +02:00
Jakub Konka
90aa68cbfc
macho: report special symbols if undefined
...
Special symbols include explictly force undefined symbols passed via -u
flag, missing entry point symbol, missing 'dyld_stub_binder' symbol, or
missing '_objc_msgsend' symbol.
2024-10-09 21:39:44 +02:00
Jakub Konka
73c3b9b8ab
elf: revert growing atoms in Dwarf.resize for standard alloc
2024-10-09 12:38:53 -07:00
Jakub Konka
e9d819a29e
elf: clean up how we create un-allocated sections
2024-10-09 12:38:53 -07:00
Jakub Konka
e448fb9601
elf: change how we manage debug atoms in Dwarf linker
2024-10-09 12:38:53 -07:00
Jakub Konka
c92c72d08c
elf: do not create atoms for section symbols that do not require it
2024-10-09 12:38:53 -07:00
Jakub Konka
ef7bac4aa5
elf: move setting section size back to Elf.growSection
2024-10-09 12:38:53 -07:00
Jakub Konka
3d315f45d8
elf: drastically simplify extracting section size logic
2024-10-09 12:38:53 -07:00
Jakub Konka
0e5cd112ef
elf: clear dynamic relocs before resolving relocs in atoms
...
When resolving and writing atoms to file, we may add dynamic relocs
to the output buffer so clear the buffers before that happens.
2024-10-09 12:38:53 -07:00
Jakub Konka
cf2e462d91
elf: add some extra logging for created dynamic relocs
2024-10-09 12:38:48 -07:00
Jakub Konka
133aa709b0
elf: do not panic if we already have create a PLT entry for a symbol
2024-10-09 12:38:11 -07:00
Jakub Konka
906cf48e14
elf: fix creation of synthetic sections
2024-10-09 12:38:11 -07:00
Jakub Konka
887f9a29f3
elf: combine growAllocSection and growNonAllocSection into growSection
2024-10-09 12:38:11 -07:00
Jakub Konka
0aa24ac2e3
elf: move sections in segments that need moving only
2024-10-09 12:38:11 -07:00
Jakub Konka
9a15c3e1a1
elf: mark objects as dirty/not-dirty
...
This way we can track if we need to redo the object parsing or not.
2024-10-09 12:38:09 -07:00
Jakub Konka
4604577ae1
elf: use arena for incremental cache
2024-10-09 12:31:04 -07:00
Jakub Konka
bd5fc899db
elf: do not re-allocate AtomLists unless dirtied
2024-10-09 12:27:30 -07:00
Jakub Konka
bae3dbffdf
elf: clear dynamic relocs before repopulating
2024-10-09 12:27:30 -07:00
Jakub Konka
bc7e0342b5
elf: do not re-populate synthetic sections when updating
2024-10-09 12:27:30 -07:00
Jakub Konka
7fead5d6dd
elf: track atoms within AtomList with array hash map
2024-10-09 12:27:30 -07:00
Jakub Konka
69ce7f0e08
Merge pull request #21573 from alexrp/elf-header
...
Some additions to `std.elf` addressing #19830 , plus some zld improvements
2024-10-03 15:19:58 +02:00
Jakub Konka
777e722b06
macho: increase pre-allocated vmsize for __TEXT_ZIG segment
2024-09-28 11:59:51 -07:00
Jakub Konka
1714b74edf
incr-check: actually handle end message for a compiler update
2024-09-25 17:54:50 +02:00
Jakub Konka
1c2048ebcc
incr-check: add --debug-link flag for verbose linker logging
2024-09-25 17:54:50 +02:00
Jakub Konka
50074a835a
elf: remove unused code
2024-09-25 17:54:50 +02:00
Jakub Konka
10c68d05db
elf: change how we create new program headers
...
We do not want to create additional ones per update that are duplicates
of existing ones.
2024-09-25 17:54:50 +02:00
Jakub Konka
992c6c3f68
elf: reset output symtab contexts before re-updating
2024-09-25 17:54:50 +02:00
Jakub Konka
82cf762b02
elf: reset (merge) sections sizes before updating
2024-09-25 17:54:50 +02:00
Jakub Konka
db3db1150e
elf: do not re-create special program headers if already created
2024-09-25 17:54:50 +02:00
Jakub Konka
62c282ba46
elf: do not re-create synthetic sections if already created
2024-09-25 17:54:50 +02:00
Jakub Konka
8c232922bd
Merge pull request #21493 from ziglang/elf-fixes
...
elf: misc fixes
2024-09-23 10:58:02 +02:00
Jakub Konka
e0acf43248
elf: always override existing __start/__stop symbols
2024-09-23 07:06:47 +02:00
Jakub Konka
7c2abff1e1
elf: only allocate __dso_handle symbol if not found in any object
2024-09-23 07:06:41 +02:00
Jakub Konka
6929a5f440
elf: remove dead code
2024-09-23 06:59:03 +02:00
Jakub Konka
f4c4ca4b4c
elf: fix condition for skipping symbols if atom is dead
...
Skipping the symbols too early when resolving would end up in the
linker not deduping CIEs fully.
2024-09-23 06:56:36 +02:00
Jakub Konka
7e31804870
Merge pull request #21305 from ziglang/elf-incr
...
elf: redo how we allocate atoms extracted from input relocatable object files
2024-09-04 21:56:45 +02:00
Jakub Konka
e1d5bb365b
elf: fix 32bit build
2024-09-04 15:55:38 +02:00
Jakub Konka
516955dbdb
elf: add AtomList.zig to CMakeLists.txt
2024-09-04 13:45:16 +02:00
Jakub Konka
b6caab63cb
elf: actually commit AtomList.zig
2024-09-04 13:44:06 +02:00
Jakub Konka
f3d527c082
elf: migrate thunks to the new mechanism (AtomList)
2024-09-04 13:34:26 +02:00
Jakub Konka
d302a1068e
elf: rename SectionChunk into AtomList and store as part of Section
2024-09-04 13:34:26 +02:00
Jakub Konka
64ad6eff16
elf: create back/forward links for atoms within section chunks
2024-09-04 13:34:26 +02:00
Jakub Konka
6ec8b15918
elf: fix emitting static lib when ZigObject is present
2024-09-04 13:34:26 +02:00
Jakub Konka
8c76a61ef5
test/link/elf: test --gc-sections on Zig input with LLVM too
2024-09-04 13:34:26 +02:00
Jakub Konka
801f038c2c
elf: do not pad placeholders coming from input object files
...
This is currently not entirely accurate since no padding will affect
the last-most atom of ZigObject that should be padded.
2024-09-04 13:34:26 +02:00
Jakub Konka
eeec50d251
elf: misc .eh_frame management fixes
2024-09-04 13:34:26 +02:00
Jakub Konka
fca92fd7c0
elf: copy existing data when allocating other alloc sections in relocatable mode
2024-09-04 13:34:26 +02:00
Jakub Konka
5cdad186fe
elf: do not create .eh_frame section if ZigObject already did so in relocatable mode
2024-09-04 13:34:26 +02:00
Jakub Konka
88e0d49feb
elf: init rela sections in a separate pass for ZigObject
2024-09-04 13:34:26 +02:00
Jakub Konka
2ef3e30e2d
elf: emit relocs for self-hosted generated .eh_frame section
2024-09-04 13:34:26 +02:00
Jakub Konka
5cb51c10de
elf: fix relocatable mode
2024-09-04 13:34:26 +02:00
Jakub Konka
6b53dc9461
elf: actually allocate atoms within each section chunk
2024-09-04 13:34:26 +02:00
Jakub Konka
6a50a0f0ed
elf: update osec index for section chunks in objects
2024-09-04 13:34:26 +02:00
Jakub Konka
f87a7251a3
elf: actually write allocated atoms in object files
2024-09-04 13:34:26 +02:00
Jakub Konka
874ef6308e
elf: do not create .eh_frame section if ZigObject already did so
2024-09-04 13:34:26 +02:00
Jakub Konka
45e46f0fb9
elf: allocate atom chunks using allocateChunk mechanics in objects
2024-09-04 13:34:25 +02:00
Jakub Konka
1ef96f05eb
elf: introduce SectionChunk - a container of atoms per object file
2024-09-04 13:34:25 +02:00
Jakub Konka
6ec5df3898
elf: allocate .tdata and .tbss using allocateAtom mechanics
2024-09-04 13:34:25 +02:00
Jakub Konka
3e100c5dab
dwarf: make Section.off a function
2024-09-04 13:34:25 +02:00
Jakub Konka
da60159d85
elf+dwarf: refer sections via section symbols
2024-09-04 13:34:25 +02:00
Jakub Konka
acb91f4b30
elf: fix emitting correct .rela. sections in -r mode
2024-09-04 13:34:25 +02:00
Jakub Konka
25fa092bb1
elf: fix a typo in setting ZigObject.data_relro_index
2024-09-04 13:34:25 +02:00
Jakub Konka
bc39bddd5f
elf: remove isDebugSection helper
2024-09-04 13:34:25 +02:00
Jakub Konka
ef6ee90ff8
elf: remove now unused number_of_zig_segments
2024-09-04 13:34:25 +02:00
Jakub Konka
2d0f4fc9c0
elf: allocate .text in ZigObject similarly to .eh_frame
2024-09-04 13:34:25 +02:00
Jakub Konka
848535535d
elf: allocate .data.rel.ro and .rodata in ZigObject similarly to .eh_frame
2024-09-04 13:34:25 +02:00
Jakub Konka
0b92404ddf
elf: allocate .data in ZigObject similarly to .eh_frame
2024-09-04 13:34:25 +02:00
Jakub Konka
37a1f0e7f2
elf: allocate .bss in ZigObject similarly to .eh_frame
2024-09-04 13:34:25 +02:00
Jakub Konka
8f1ce3c85b
elf: shuffle some stages to make it clear what needs what
2024-09-04 13:34:25 +02:00
Jakub Konka
d32af9ea2a
elf: move initOutputSection into Elf from Object
2024-09-04 13:34:25 +02:00
Jakub Konka
b44dd599ad
elf: split Atom.allocate into Atom-independent parts
2024-09-04 13:34:25 +02:00
Jakub Konka
aaca4ff74d
Merge pull request #21254 from jacobly0/fix-dwarf
...
Dwarf: fix issues with emitted debug info
2024-08-30 19:07:36 +02:00
Jakub Konka
1254509d78
elf: make Atom.allocate and related ZigObject-independent
2024-08-26 22:19:51 +02:00
Jakub Konka
20240e9cd5
elf: store atom refs for rela sections until we can do better
2024-08-25 10:20:15 +02:00
Jakub Konka
1af0f4cd00
elf: fix setting sh_info and sh_link for manually managed rela sections
2024-08-25 10:20:15 +02:00
Jakub Konka
7173ea1a15
elf: simplify output section symbol tracking
2024-08-25 10:20:15 +02:00
Jakub Konka
95c30fb486
elf: fix shdr-to-phdr links
2024-08-25 10:20:15 +02:00
Jakub Konka
a9d3885ac7
elf: streamline sections container
2024-08-25 10:20:14 +02:00
Jakub Konka
a6bf762a8b
elf: finally move initMetadata into ZigObject.init
2024-08-25 10:20:14 +02:00
Jakub Konka
7cd1c882c9
Merge pull request #21160 from ziglang/link-thunks-test
2024-08-22 06:59:45 +02:00
Jakub Konka
fa79f53f92
test/macho: simplify testing range extension thunks
2024-08-22 00:36:47 +02:00
Jakub Konka
cbb8093455
macho: emit local symbols for thunks
2024-08-22 00:34:58 +02:00
Jakub Konka
ca417e1e32
link/elf: simplify how we test thunks
2024-08-21 23:05:28 +02:00
Jakub Konka
8fc15f188c
Merge pull request #21145 from ziglang/elf-dwarf-relocs
...
elf+zigobject: emit relocs for debug sections
2024-08-21 14:51:10 +02:00
Jakub Konka
e79ac14ef3
elf: refactor tracking debug section sizes
2024-08-21 10:28:31 +02:00
Jakub Konka
b17bbf9e6c
elf: fixes after rebase
2024-08-21 01:43:21 -04:00
Jakub Konka
6c731be3a1
elf: allow for concatenating atoms to merge sections
2024-08-21 01:43:21 -04:00
Jakub Konka
b2fad5c58b
test/debugger: test emitting relocs by ELF linker
2024-08-21 01:43:21 -04:00
Jakub Konka
6a86a1041c
elf: remove obsolete call to Dwarf.resolveRelocs
2024-08-21 01:43:21 -04:00
Jakub Konka
fe6dfd5090
elf: fix emitting cross-section relocs for .debug* sections
2024-08-21 01:43:21 -04:00