Skip to content

Commit

Permalink
macho: handle -arch_multiple flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 25, 2024
1 parent cbfacc6 commit 3ebdefc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
'';
};

devShells.default = pkgs.mkShell {
devShells.default = pkgs.stdenvNoCC.mkDerivation {
name = "emerald";
buildInputs = commonInputs ++ (with pkgs; [
zlspkgs.default
tracy
Expand Down
14 changes: 13 additions & 1 deletion src/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,19 @@ fn reportUndefs(self: *MachO) !void {

const err = try addFn(&self.base, nnotes);
defer err.unlock();
try err.addMsg("undefined symbol: {s}", .{undef_sym.getName(self)});

if (self.options.arch_multiple) {
// When clang is invoked with two -arch flags, it will pass -arch_multiple and -final_output to the linker.
// According to LLD implementation [1], -arch_multiple is only used to signal to the linker that it should
// suffix undefined symbols errors/warnings with current architecture.
// [1]: https://reviews.llvm.org/D105450
try err.addMsg("undefined symbol for architecture {s}: {s}", .{
@tagName(self.options.cpu_arch.?),
undef_sym.getName(self),
});
} else {
try err.addMsg("undefined symbol: {s}", .{undef_sym.getName(self)});
}

switch (notes) {
.force_undefined => try err.addNote("referenced with linker flag -u", .{}),
Expand Down
5 changes: 5 additions & 0 deletions src/MachO/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const usage =
\\-no_adhoc_codesign Does not generate adhoc code signature
\\-all_load Loads all members of all static archive libraries
\\-arch [name] Specifies which architecture the output file should be
\\-arch_multiple Specifies that the linker should augment error and warning
\\ messages with the architecture name.
\\-current_version [value] Specifies the current version number of the library
\\-compatibility_version [value] Specifies the compatibility version number of the library
\\-dead_strip Remove functions and data that are unreachable by the entry point or
Expand Down Expand Up @@ -105,6 +107,7 @@ dylib: bool = false,
relocatable: bool = false,
dynamic: bool = false,
cpu_arch: ?std.Target.Cpu.Arch = null,
arch_multiple: bool = false,
platform: ?Platform = null,
sdk_version: ?Version = null,
inferred_platform_versions: [supported_platforms.len]Platform = undefined,
Expand Down Expand Up @@ -282,6 +285,8 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options
} else {
ctx.fatal("Could not parse CPU architecture from '{s}'\n", .{value});
}
} else if (p.flag1("arch_multiple")) {
opts.arch_multiple = true;
} else if (p.arg1("macos_version_min")) |ver| {
const min_ver = Version.parse(ver) orelse
ctx.fatal("Unable to parse version from '{s}'\n", .{version});
Expand Down

0 comments on commit 3ebdefc

Please sign in to comment.