Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macho: implement -r mode #95

Merged
merged 42 commits into from
Jan 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6ca25c7
macho: recognise -r flag and error as unimplemented
kubkon Dec 26, 2023
1473324
macho: forgot to commit relocatable.zig
kubkon Dec 28, 2023
6b4f895
macho: init output sections in relocatable mode
kubkon Dec 28, 2023
33d20d0
macho: calculate alloc section sizes
kubkon Dec 28, 2023
6a9208b
macho: calculate __compact_unwind and __eh_frame sizes
kubkon Dec 31, 2023
987a478
macho: allocate sections for object file
kubkon Dec 31, 2023
e9f632b
macho: allocate segment in relocatable mode
kubkon Dec 31, 2023
edaacf8
macho: allocate atoms in relocatable mode
kubkon Jan 1, 2024
35d5f02
macho: write __compact_unwind and __eh_frame
kubkon Jan 1, 2024
55473fd
macho: move calc of next __LINKEDIT offset outside of each func
kubkon Jan 1, 2024
97eaf22
macho: write well-formed relocatable object file
kubkon Jan 1, 2024
9f2ad6e
macho: preserve exports in relocatable mode
kubkon Jan 1, 2024
5c4a931
macho: unconditionally emit ALL local symbols in -r mode
kubkon Jan 1, 2024
5299045
macho: actually emit __compact_unwind section
kubkon Jan 1, 2024
606772d
macho: set data-in-code cmd to next available file offset
kubkon Jan 2, 2024
9bf929f
macho: calc number of relocations for each section
kubkon Jan 2, 2024
72b570a
macho: allocate reloffs when allocating sections
kubkon Jan 3, 2024
a8691e7
macho: emit relocs for atoms
kubkon Jan 3, 2024
406f4c1
macho: addend for unsigned needs to be written to code buffer
kubkon Jan 3, 2024
cb1f179
macho: emit __compact_unwind relocs
kubkon Jan 3, 2024
27f1aa2
macho: create atoms for __DWARF, input __compact_unwind and __eh_fram…
kubkon Jan 3, 2024
5161cff
macho: skip null unwind recs synthesis in -r; fix relocs in -r; test
kubkon Jan 3, 2024
535f932
macho: write atom relocs for x86_64 arch
kubkon Jan 3, 2024
16e5ccc
macho: write relocated __eh_frame records; fix writing into invalid L…
kubkon Jan 3, 2024
4a2fb86
macho: fix writing local relocs (non-externs)
kubkon Jan 3, 2024
e1337f1
macho: do not emit stabs in -r mode
kubkon Jan 4, 2024
a22df16
macho: error out on unhandled input stab symbols
kubkon Jan 4, 2024
7681146
macho: fix file mode in -r mode
kubkon Jan 4, 2024
9037d58
macho: emit __DWARF in -r mode (incomplete)
kubkon Jan 4, 2024
63454c1
macho: partially revert: emit __DWARF in -r mode (incomplete)
kubkon Jan 4, 2024
811e3f3
macho: write out stabs in -r mode; skip them when linking image
kubkon Jan 4, 2024
ab50dcb
macho: copy over symbol stabs from input object files
kubkon Jan 4, 2024
cf35be7
macho: fix applying __eh_frame records after -r
kubkon Jan 4, 2024
d9410be
macho: fix generating valid debug info in -r mode
kubkon Jan 5, 2024
fe08a6b
macho: flag an error when parsing __DWARF fails
kubkon Jan 5, 2024
d917206
macho: almost update to latest zig changes
kubkon Jan 6, 2024
197c4bb
macho: fix dylib test
kubkon Jan 6, 2024
a2a719c
macho: fix entry in dylib test
kubkon Jan 6, 2024
9dd651d
macho: fix fat dylib test
kubkon Jan 6, 2024
e3dacf8
macho: fix link order test
kubkon Jan 6, 2024
004a609
macho: fix tls test
kubkon Jan 6, 2024
832770e
elf: update to latest Zig build api
kubkon Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
macho: recognise -r flag and error as unimplemented
kubkon committed Jan 6, 2024
commit 6ca25c74b77c348441986f59257bb581e5a9ad05
8 changes: 6 additions & 2 deletions src/MachO.zig
Original file line number Diff line number Diff line change
@@ -348,6 +348,9 @@ pub fn flush(self: *MachO) !void {

try self.addUndefinedGlobals();
try self.resolveSymbols();

if (self.options.relocatable) return relocatable.flush(self);

try self.resolveSyntheticSymbols();

try self.convertTentativeDefinitions();
@@ -3156,11 +3159,12 @@ const macho = std.macho;
const math = std.math;
const mem = std.mem;
const meta = std.meta;
const thunks = @import("MachO/thunks.zig");
const trace = @import("tracy.zig").trace;
const relocatable = @import("MachO/relocatable.zig");
const synthetic = @import("MachO/synthetic.zig");
const state_log = std.log.scoped(.state);
const std = @import("std");
const thunks = @import("MachO/thunks.zig");
const trace = @import("tracy.zig").trace;

const Allocator = mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
4 changes: 4 additions & 0 deletions src/MachO/Options.zig
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ const usage =
\\-platform_version [platform] [min_version] [sdk_version]
\\ Sets the platform, oldest supported version of that platform and
\\ the SDK it was built against
\\-r Create a relocatable object file
\\-reexport-l[name] Link against library and re-export it for the clients
\\ -reexport_library [name]
\\-rpath [path] Specify runtime path
@@ -91,6 +92,7 @@ const cmd = "ld64.zld";

emit: Zld.Emit,
dylib: bool = false,
relocatable: bool = false,
dynamic: bool = false,
cpu_arch: ?std.Target.Cpu.Arch = null,
platform: ?Platform = null,
@@ -238,6 +240,8 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options
try force_undefined_symbols.put(name, {});
} else if (p.flag1("S")) {
opts.strip = true;
} else if (p.flag1("r")) {
opts.relocatable = true;
} else if (p.flag1("all_load")) {
opts.all_load = true;
} else if (p.arg1("force_load")) |path| {
1 change: 1 addition & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ pub fn main() !void {
error.UndefinedSymbols,
error.RelocError,
error.ResolveFailed,
error.Unimplemented,
=> {
zld.reportWarnings();
zld.reportErrors();