Jakub Konka
1965465ced
macho: split resolveSymbols into standalone functions
2021-09-13 13:19:08 +02:00
Jakub Konka
7aa6064638
macho: insert rpaths upon parsing
...
Also, insert empty data-in-code lc in populateMissingMetadata fn.
2021-09-11 14:18:09 +02:00
Jakub Konka
054fe96bcd
macho: enable tracy in more places within the linker
2021-09-11 12:25:00 +02:00
Jakub Konka
31dcb0dde7
macho: change all occurrences of TextBlock into Atom
...
and unify allocateAtom with allocateTextBlock.
2021-09-11 02:03:25 +02:00
Jakub Konka
6e0c3950b8
macho: rename blocks to atoms in Object.zig
2021-09-10 22:42:39 +02:00
Jakub Konka
8e5f7f5fe8
macho: write adjacent atoms to in-memory buffer
...
and then commit the large buffer into file.
2021-09-10 15:37:51 +02:00
Jakub Konka
aaacfc0d0a
macho: init process of renaming TextBlock to Atom
...
Initially, internally within the linker.
2021-09-09 18:32:03 +02:00
Jakub Konka
56fdada577
macho: properly adjust section sizes
2021-09-09 16:55:56 +02:00
Jakub Konka
1efdb137d1
macho: don't allocate atoms when parsing objects
2021-09-09 14:18:28 +02:00
Jakub Konka
23be9cae34
macho: padToIdeal each parsed section size before storing
...
This way, we should not need to grow at all when allocating atoms
representing objects' sections as atoms.
2021-09-09 01:13:07 +02:00
Jakub Konka
9fb44e8e1f
macho: precompute total required size when parsing objects
...
This way, we can preallocate the necessary sizes for segments and
sections upfront rather than doing it per parsed atom.
2021-09-09 00:25:55 +02:00
Jakub Konka
e00b9d6192
macho: use smaller padding until we have branch islands on arm64
...
Without branch islands, it is impossible to link self-hosted using
the common linker path.
2021-09-08 13:17:43 +02:00
Jakub Konka
e229202cb8
macho: store source section address of relocs in context
...
This is particularly relevant for x86_64 and C++ when relocating
StaticInit sections containing static initializers machine code.
Then, in case of SIGNED_X relocations, it is necessary to have the
full image of the VM address layout of the sections in the object
file as this is how the addend needs to be adjusted for non-extern
relocations.
2021-09-07 23:21:08 +02:00
Jakub Konka
159e55dfd9
macho: fix alignment of atoms which begin the section
2021-09-07 20:37:58 +02:00
Jakub Konka
a2279e7e20
macho: fix commands.zig tests
2021-09-07 12:23:26 +02:00
Jakub Konka
c35f668932
macho: update max section alignment when inserting atoms
2021-09-07 10:07:09 +02:00
Jakub Konka
6836cc473c
macho: make sure that parsed bss atoms are zero-filled
2021-09-06 18:30:40 +02:00
Jakub Konka
81e5320973
macho: set and reset file offset to zerofill sections in flush
...
This way, there's no need to special the set/reset behaviour at
every stage of updating sections/atoms.
2021-09-06 17:43:24 +02:00
Jakub Konka
29d2e19c3e
macho: allocate sections one after the other and grow if needed
2021-09-06 17:31:20 +02:00
Jakub Konka
2914ea9e33
macho: require atom padding for machine code only
2021-09-06 11:17:20 +02:00
Jakub Konka
5e64d9745b
macho: fix noninclusion of data-in-code
...
Also, calculate non-extern, section offset based addends for SIGNED
and UNSIGNED relocations on x86_64 upfront as an offset wrt to the
target symbol representing position of the section/atom within the
final artifact.
2021-09-06 10:38:51 +02:00
Jakub Konka
61dca19107
macho: encaps logic for extract sect offset into fn
2021-09-05 23:30:06 +02:00
Jakub Konka
ea8808f87b
macho: add logic for segment expansion
2021-09-05 11:15:48 +02:00
Jakub Konka
d92b5416e8
macho: add a small routine to update section ordinals at the end
...
The actual ordinals may change when adding new sections to the segments.
2021-09-05 00:19:45 +02:00
Jakub Konka
7e87f93e06
macho: unfortunately, LINKEDIT commands NEED to be in order
...
Otherwise, Apple's tooling goes mental and reports that the executable
is malformed/fails strict validation. We absolutely have to get it
right to support tools such `codesign` which are required to
successfully launch an app on an iOS device for instance. When Zig
matures enough so that we can ditch any Apple tooling and still be
able to successfully codesign for iOS and other, we can revisit this
area. Until then however, we are stuck in having to rewrite the LINKEDIT
segment at every update run of the self-hosted.
FYI, the strict layout for the MachO binary apparently is (please,
read this with a pinch of salt as this is inferred by me):
* __TEXT segment
* __DATA_CONST segment
* __DATA segment
* __LINKEDIT segment
* dyld info (rebase, bind, weak bind, lazy bind, export)
* symbol table
* dynamic symbol table
* string table
* code signature (if expected)
2021-09-04 22:59:16 +02:00
Jakub Konka
80e1c244b6
macho: dyld info subsections need to follow in strict order
...
MachO, why are doing this to me?
2021-09-03 17:12:39 +02:00
Jakub Konka
1d2199b71c
macho: dirty export trie when adding globals
...
Similarly, dirty rebase info when adding a GOT atom.
2021-09-03 13:41:28 +02:00
Jakub Konka
7536a2f8cf
macho: minor fixes to allow the linker to output malformed stage1
2021-09-03 11:47:58 +02:00
Jakub Konka
a783f3a369
macho: remove obsolete mentions of stage1
2021-09-03 00:25:47 +02:00
Jakub Konka
4b07da7090
macho: remove all Zld codepaths
2021-09-03 00:21:45 +02:00
Jakub Konka
5af13f35f9
macho: implement basic section movement and reallocation
2021-09-02 18:19:07 +02:00
Jakub Konka
4741c04254
macho: better spec for sections which don't require padding
2021-09-02 00:44:33 +02:00
Jakub Konka
9dbad2d188
macho: fix calculating file offset for atom when allocating
2021-09-01 23:44:01 +02:00
Jakub Konka
17066cc12e
macho: minor refactor of const namings
2021-09-01 23:26:24 +02:00
Jakub Konka
4eff0f4ea1
macho: fix condition for checking available size for an atom
2021-09-01 16:49:16 +02:00
Jakub Konka
7a99cd069a
macho: clean up allocating atom logic
...
Instead of checking for stage1 at every callsite, move the logic
inside `allocateAtom`. This is fine since this logic will disappear
anyhow once I add expanding and shifting segments and sections.
2021-09-01 12:14:29 +02:00
Jakub Konka
d0dc622638
macho: do not reset section's size after allocating atom
2021-09-01 00:06:43 +02:00
Jakub Konka
50db993119
macho: fix allocating sections within segment when parsing objects
2021-08-31 23:05:01 +02:00
Jakub Konka
2831d6e9b8
macho: add first pass at allocating parsed atoms in objects
...
This commit makes it possible to combine self-hosted with a pre-compiled
C object file, e.g.:
```
zig-out/bin/zig build-exe hello.zig add.o
```
where `add.o` is a pre-compiled C object file.
2021-08-30 15:43:20 +02:00
Jakub Konka
a14e98fcac
macho: remove sorting sections and refactor atom parsing in objects
2021-08-27 20:32:11 +02:00
Jakub Konka
ad4a8e7665
macho: keep actual file offset for zerofill sections separately
...
This way, we will conform to the standard practice of setting the
offset within the section header to the beginning of the file and
we will be able to track the location of the section in the file
for incremental updates.
2021-08-27 13:47:43 +02:00
Jakub Konka
1e65d41a65
macho: merge __common with __bss section
2021-08-27 11:30:02 +02:00
Jakub Konka
705cd64080
macho: preactively add zerofill sections in correct order
...
The required order on macOS nowadays is:
* __data
* __thread_vars
* __thread_data
* __thread_bss
* __bss
2021-08-27 10:45:56 +02:00
Jakub Konka
8bd0687713
macho: port mechanism for allocating symbols within atoms
...
such as entire sections represented as a single atom.
2021-08-26 16:16:34 +02:00
Jakub Konka
29df0ca39d
Merge remote-tracking branch 'origin/master' into zld-incr
2021-08-26 14:35:34 +02:00
Jakub Konka
570c75cb74
macho: write all atoms in flush so that we can resolve relocs
2021-08-26 14:23:28 +02:00
Jakub Konka
432fb7054d
macho: fix stub writing in self-hosted setting
2021-08-26 13:45:28 +02:00
Jakub Konka
d19d3342c2
macho: save lazy binding info as part of the atom
2021-08-26 11:43:11 +02:00
Jakub Konka
c12183b608
macho: fix text atom allocation
2021-08-25 23:00:58 +02:00
Jakub Konka
ee786e5c3c
macho: add GOT entries as actual atoms
2021-08-25 17:23:30 +02:00