17 Commits

Author SHA1 Message Date
Jakub Konka
edbfd04ec1
Do not pad out text blocks
It seems MachO does not like padding between text block in __text
section. Unlike in Elf, there is no size information in symbol
struct `nlist_64`.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 22:00:31 +02:00
Jakub Konka
9306dbd619
Fix bug where __text section would get overwritten
Fixes a bug where the last written load command would accidentally
override the beginning of the __text section. Also defines missing
MachO constants and relocation structs/enums.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 20:55:06 +02:00
Alexandros Naskos
e9807418e7 Added .pe ObjectFormat
MachO linker no longer collects unused dwarf debug information
2020-09-04 05:22:26 +03:00
Jakub Konka
dac1cd7750 Write out simple Mach-O object file
This commit adds enough Mach-O linker implementation to write out simple
Mach-O object file. Be warned however, the object file is largely incomplete:
misses relocation info, debug symbols, etc. However, it seemed like a
good starting to get the basic understanding right.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-03 16:43:47 -04:00
Jakub Konka
55dc81ba2a
Hardcode runtime (libSystem) version to minimum possible
While we try to work out what the correlation between the OS and runtime
versions is, this commit hardcodes the latter to the minimum (compat)
version of 1.0.0.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-26 06:30:54 +02:00
Jakub Konka
43b6d0e4b1
Add (empty) __TEXT segment load command
Also, link against `libSystem` by default when targeting macOS.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 21:18:27 +02:00
Jakub Konka
9745e7b512 Clean up draft for merging into upstream
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Jakub Konka
1698e6d7a7 Link against libSystem when generating Mach-O exe
This is required when generating an exe on macOS.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Jakub Konka
2516db9645 Specify path to dyld in Mach-O
This is required since an exec on macOS always has to link against
libSystem.dylib.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Andrew Kelley
89b6c47e04 stage2: decouple codegen.zig from ELF
See #6113 for an alternate way of doing this that we didn't end up
following.

Closes #6079.

I also took the opportunity here to extract C.zig and Elf.zig from
link.zig.
2020-08-21 13:25:59 -07:00
Jakub Konka
ad79b80524
Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-20 09:14:37 +02:00
Jakub Konka
9164daaa39 Write page zero as first segment for Mach-O exes
According to the Mach-O file format reference, the first
load command should be a `__PAGEZERO` segment command. The
segment is located at virtual memory location 0, has no protection
rights, and causes acccesses to NULL to immediately crash.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-20 08:33:40 +02:00
Jakub Konka
ffdeb6af91
Update src-self-hosted/link/MachO.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-19 07:43:33 +02:00
Jakub Konka
34e628a0a0 Fix compile error
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Jakub Konka
e4b3da2720 Write out Mach-O header
This commit write out Mach-O header in the linker's `flush`
method. The header currently only populates the magic number,
filetype, and cpu info.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Isaac Freund
60fb50ee5a
stage2/wasm: write exports on flush, cleanup
Exports now have a dirty flag and are rewritten on flush if this flag
has been set.

A couple other minor changes have been made based on Andrew's review.
2020-08-18 01:01:13 +02:00
Jakub Konka
5cb96681d9 Move Mach-O to link/MachO.zig submodule
Remove `ptrWidth` since as of Catalina, all apps are 64bits only.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-17 18:16:29 +02:00