24 Commits

Author SHA1 Message Date
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
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
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
570c75cb74 macho: write all atoms in flush so that we can resolve relocs 2021-08-26 14:23: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
ee786e5c3c macho: add GOT entries as actual atoms 2021-08-25 17:23:30 +02:00
Jakub Konka
da57d6df32 macho: simplify symbol management and resolution
instead of globally storing unresolved and tentative defs,
store indices to actual symbols in the functions that are responsible
for symbol resolution.
2021-08-12 10:20:57 +02:00
Jakub Konka
bf25650974 macho: refactor management of section ordinals
Instead of storing a two-way relation (seg,sect) <=> ordinal
we get the latter with `getIndex((seg, sect))`.
2021-08-02 19:49:32 +02:00
Jakub Konka
c30cc4dbbf macho: don't store allocator in Object
instead, pass it in functions that require it. Also, when parsing
relocs, make Object part of the context struct where we pass in
additional goodies such as `*MachO` or `*Allocator`.
2021-08-01 09:06:56 +02:00
Jakub Konka
1beda818e1 macho: re-enable parsing sections into atoms
However, make it default only when building in release modes since
it's a prelude to advanced dead code stripping not very useful in
debug.
2021-07-23 16:55:19 +02:00
Jakub Konka
a4feb97cdf macho: assign and cache section ordinals upon creation
then, when sorting sections within segments, clear and redo the
ordinals since we re-apply them to symbols anyway. It is vital
to have the ordinals consistent with parsing and resolving relocs
however.
2021-07-22 23:13:13 +02:00
Jakub Konka
ca90efe88e macho: fix memory leaks when emptying TextBlocks
This happens on every call to `TextBlock.empty` by the `Module`.
2021-07-22 14:05:12 +02:00
Jakub Konka
5276ce8e63 macho: use adapters to directly reference strtab
Thanks to this, we no longer need to do allocs per symbol name
landing in the symbol resolver, plus we do not need to actively
track if the string was already inserted into the string table.
2021-07-20 23:37:22 +02:00
Jakub Konka
a442b165f1 macho: add stub relocs when adding extern fn
in self-hosted.
2021-07-20 20:33:07 +02:00
Jakub Konka
f6d13e9d6f zld: move contents of Zld into MachO module 2021-07-18 17:48:00 +02:00
Jakub Konka
2828cd2983 zld: migrate symbol mgmt to incremental backend 2021-07-18 15:05:52 +02:00
Jakub Konka
9f20a51555 zld: demote logging back to debug from warn 2021-07-17 18:33:47 +02:00
Jakub Konka
97914d93a9 zld: fixup flush function 2021-07-17 17:30:16 +02:00
Jakub Konka
71384a383e zld: correctly set n_sect for sections as symbols 2021-07-17 11:29:40 +02:00
Jakub Konka
db8020ac0d zld: adjust resolving relocs logic to the new approach 2021-07-17 11:01:10 +02:00
Jakub Konka
407745a5e9 zld: simplify and move Relocations into TextBlock
It makes sense to have them as a dependent type since they only ever
deal with TextBlocks. Simplify Relocations to rely on symbol indices
and symbol resolver rather than pointers.
2021-07-17 01:03:40 +02:00
Jakub Konka
54a403d4ff zld: replace parsed reloc with a simple wrapper around macho.relocation_info 2021-07-16 17:18:53 +02:00
Jakub Konka
f519e781c6 zld: move TextBlock into standalone file
which should make managing the logic of parsing and resolving relocs
that much simpler to parse.
2021-07-15 18:49:48 +02:00