authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-04-13 22:48:31+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-04-20 16:55:32+02:00
log3e73a3c29b597ff05e7a178106ff86056cf4494d
treef8f5bb5dee665b08a5a0c605438e3db691e2fee3
parentbe551d85b7610a7e0570023934f9b92ddf129966

zld: treat priv extern as weak symbol


2 files changed, 26 insertions(+), 6 deletions(-)

src/link/MachO.zig+1-2
......@@ -645,8 +645,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
645645 break :blk true;
646646 }
647647
648 if (self.base.options.link_libcpp or
649 self.base.options.output_mode == .Lib or
648 if (self.base.options.output_mode == .Lib or
650649 self.base.options.linker_script != null)
651650 {
652651 // Fallback to LLD in this handful of cases on x86_64 only.
src/link/MachO/Zld.zig+25-4
......@@ -1236,11 +1236,12 @@ fn resolveSymbolsInObject(self: *Zld, object_id: u16) !void {
12361236 continue;
12371237 } else if (Symbol.isGlobal(sym)) {
12381238 const sym_name = object.getString(sym.n_strx);
1239 const is_weak = Symbol.isWeakDef(sym) or Symbol.isPext(sym);
12391240 const global = self.symtab.getEntry(sym_name) orelse {
12401241 // Put new global symbol into the symbol table.
12411242 const name = try self.allocator.dupe(u8, sym_name);
12421243 try self.symtab.putNoClobber(self.allocator, name, .{
1243 .tag = if (Symbol.isWeakDef(sym)) .weak else .strong,
1244 .tag = if (is_weak) .weak else .strong,
12441245 .name = name,
12451246 .address = 0,
12461247 .section = 0,
......@@ -1251,10 +1252,15 @@ fn resolveSymbolsInObject(self: *Zld, object_id: u16) !void {
12511252 };
12521253
12531254 switch (global.value.tag) {
1254 .weak => continue, // If symbol is weak, nothing to do.
1255 .weak => {
1256 if (is_weak) continue; // Nothing to do for weak symbol.
1257 },
12551258 .strong => {
1256 log.err("symbol '{s}' defined multiple times", .{sym_name});
1257 return error.MultipleSymbolDefinitions;
1259 if (!is_weak) {
1260 log.err("symbol '{s}' defined multiple times", .{sym_name});
1261 return error.MultipleSymbolDefinitions;
1262 }
1263 continue;
12581264 },
12591265 else => {},
12601266 }
......@@ -1340,6 +1346,21 @@ fn resolveSymbols(self: *Zld) !void {
13401346 .section = 0,
13411347 .file = 0,
13421348 });
1349
1350 {
1351 log.warn("symtab", .{});
1352 for (self.symtab.items()) |sym| {
1353 switch (sym.value.tag) {
1354 .weak, .strong => {
1355 log.warn(" | {s} => {s}", .{ sym.key, self.objects.items[sym.value.file.?].name.? });
1356 },
1357 .import => {
1358 log.warn(" | {s} => libSystem.B.dylib", .{sym.key});
1359 },
1360 else => unreachable,
1361 }
1362 }
1363 }
13431364}
13441365
13451366fn resolveStubsAndGotEntries(self: *Zld) !void {