From 31ba576f27ffd77b53897179193262416c176ffa Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 26 Dec 2023 12:24:11 +0100 Subject: [PATCH] macho: recognise -r flag and error as unimplemented --- src/MachO.zig | 8 ++++++-- src/MachO/Options.zig | 4 ++++ src/main.zig | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MachO.zig b/src/MachO.zig index ecf599bf..864f203c 100644 --- a/src/MachO.zig +++ b/src/MachO.zig @@ -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; diff --git a/src/MachO/Options.zig b/src/MachO/Options.zig index 55f72954..48e5b085 100644 --- a/src/MachO/Options.zig +++ b/src/MachO/Options.zig @@ -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| { diff --git a/src/main.zig b/src/main.zig index 46845160..161de5a7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -112,6 +112,7 @@ pub fn main() !void { error.UndefinedSymbols, error.RelocError, error.ResolveFailed, + error.Unimplemented, => { zld.reportWarnings(); zld.reportErrors();