authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-17 15:11:21-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-17 15:12:01-08:00
logf7f6217df91b4de5225c0c971ca1946166026e49
tree7c08eefd448025766e2642021e11ab0fda1da491
parentacf70439551fc3f49b2d292ff93ee519901cdf42

macho linker: adjust symbol priority

strong symbols always take precedence over weak symbols.

1 files changed, 6 insertions(+), 14 deletions(-)

src/link/MachO/file.zig+6-14
......@@ -45,29 +45,21 @@ pub const File = union(enum) {
4545
4646 /// Encodes symbol rank so that the following ordering applies:
4747 /// * strong in object
48 /// * weak in object
49 /// * tentative in object
5048 /// * strong in archive/dylib
49 /// * weak in object
5150 /// * weak in archive/dylib
51 /// * tentative in object
5252 /// * tentative in archive
5353 /// * unclaimed
54 /// Ties are broken by file priority.
5455 pub fn getSymbolRank(file: File, args: struct {
5556 archive: bool = false,
5657 weak: bool = false,
5758 tentative: bool = false,
5859 }) u32 {
59 if (file != .dylib and !args.archive) {
60 const base: u32 = blk: {
61 if (args.tentative) break :blk 3;
62 break :blk if (args.weak) 2 else 1;
63 };
64 return (base << 16) + file.getIndex();
65 }
66 const base: u32 = blk: {
67 if (args.tentative) break :blk 3;
68 break :blk if (args.weak) 2 else 1;
69 };
70 return base + (file.getIndex() << 24);
60 const archive_or_dylib = @as(u32, @intFromBool(file == .dylib or args.archive)) << 29;
61 const strength: u32 = if (args.tentative) 0b10 << 30 else if (args.weak) 0b01 << 30 else 0b00 << 30;
62 return strength | archive_or_dylib | file.getIndex();
7163 }
7264
7365 pub fn getAtom(file: File, atom_index: Atom.Index) ?*Atom {