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) {...@@ -45,29 +45,21 @@ pub const File = union(enum) {
4545
46 /// Encodes symbol rank so that the following ordering applies:46 /// Encodes symbol rank so that the following ordering applies:
47 /// * strong in object47 /// * strong in object
48 /// * weak in object
49 /// * tentative in object
50 /// * strong in archive/dylib48 /// * strong in archive/dylib
49 /// * weak in object
51 /// * weak in archive/dylib50 /// * weak in archive/dylib
51 /// * tentative in object
52 /// * tentative in archive52 /// * tentative in archive
53 /// * unclaimed53 /// * unclaimed
54 /// Ties are broken by file priority.
54 pub fn getSymbolRank(file: File, args: struct {55 pub fn getSymbolRank(file: File, args: struct {
55 archive: bool = false,56 archive: bool = false,
56 weak: bool = false,57 weak: bool = false,
57 tentative: bool = false,58 tentative: bool = false,
58 }) u32 {59 }) u32 {
59 if (file != .dylib and !args.archive) {60 const archive_or_dylib = @as(u32, @intFromBool(file == .dylib or args.archive)) << 29;
60 const base: u32 = blk: {61 const strength: u32 = if (args.tentative) 0b10 << 30 else if (args.weak) 0b01 << 30 else 0b00 << 30;
61 if (args.tentative) break :blk 3;62 return strength | archive_or_dylib | file.getIndex();
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);
71 }63 }
7264
73 pub fn getAtom(file: File, atom_index: Atom.Index) ?*Atom {65 pub fn getAtom(file: File, atom_index: Atom.Index) ?*Atom {