authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-15 14:55:12+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-15 14:55:12+02:00
log0f4173c5d834dca2710005ffc1e040a4b307df00
treed0826553e15baa9a52c8ba4c1e89f204334401f4
parent7f9076c77124d9fdc10863e96f17b4ad36626ddb
parent82047633281252aed14b44831e8920950f8c7dd6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9122 from ziglang/zld-proxies

zld: clean up stubs resolution, error messages and use ld64 defaults for system libs resolution

2 files changed, 11 insertions(+), 16 deletions(-)

src/link/MachO.zig+4-3
...@@ -758,10 +758,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -758,10 +758,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
758 }758 }
759 }759 }
760760
761 // Search for static libraries first, then dynamic libraries.761 // Assume ld64 default: -search_paths_first
762 // TODO Respect flags such as -search_paths_first to the linker.762 // Look in each directory for a dylib (tbd), and then for archive
763 // TODO implement alternative: -search_dylibs_first
763 // TODO text-based API, or .tbd files.764 // TODO text-based API, or .tbd files.
764 const exts = &[_][]const u8{ "a", "dylib" };765 const exts = &[_][]const u8{ "dylib", "a" };
765766
766 for (search_lib_names.items) |l_name| {767 for (search_lib_names.items) |l_name| {
767 var found = false;768 var found = false;
src/link/MachO/Zld.zig+7-13
...@@ -1891,7 +1891,6 @@ fn resolveStubsAndGotEntries(self: *Zld) !void {...@@ -1891,7 +1891,6 @@ fn resolveStubsAndGotEntries(self: *Zld) !void {
1891 const relocs = sect.relocs orelse continue;1891 const relocs = sect.relocs orelse continue;
1892 for (relocs) |rel| {1892 for (relocs) |rel| {
1893 switch (rel.@"type") {1893 switch (rel.@"type") {
1894 .unsigned => continue,
1895 .got_page, .got_page_off, .got_load, .got, .pointer_to_got => {1894 .got_page, .got_page_off, .got_load, .got, .pointer_to_got => {
1896 const sym = rel.target.symbol.getTopmostAlias();1895 const sym = rel.target.symbol.getTopmostAlias();
1897 if (sym.got_index != null) continue;1896 if (sym.got_index != null) continue;
...@@ -2025,12 +2024,9 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void {...@@ -2025,12 +2024,9 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void {
2025 const got = dc_seg.sections.items[self.got_section_index.?];2024 const got = dc_seg.sections.items[self.got_section_index.?];
2026 const final = rel.target.symbol.getTopmostAlias();2025 const final = rel.target.symbol.getTopmostAlias();
2027 const got_index = final.got_index orelse {2026 const got_index = final.got_index orelse {
2028 // TODO remove this when we can link against TAPI files.2027 log.err("expected GOT index relocating symbol '{s}'", .{final.name});
2029 log.err("undefined reference to symbol '{s}'", .{final.name});2028 log.err("this is an internal linker error", .{});
2030 log.err(" | referenced in {s}", .{2029 return error.FailedToResolveRelocationTarget;
2031 rel.target.symbol.cast(Symbol.Unresolved).?.file.name.?,
2032 });
2033 return error.UndefinedSymbolReference;
2034 };2030 };
2035 args.target_addr = got.addr + got_index * @sizeOf(u64);2031 args.target_addr = got.addr + got_index * @sizeOf(u64);
2036 },2032 },
...@@ -2099,16 +2095,14 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T...@@ -2099,16 +2095,14 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T
2099 const segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;2095 const segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2100 const stubs = segment.sections.items[self.stubs_section_index.?];2096 const stubs = segment.sections.items[self.stubs_section_index.?];
2101 const stubs_index = proxy.base.stubs_index orelse {2097 const stubs_index = proxy.base.stubs_index orelse {
2102 // TODO remove this when we can link against TAPI files.2098 log.err("expected stubs index when relocating symbol '{s}'", .{final.name});
2103 log.err("undefined reference to symbol '{s}'", .{final.name});2099 log.err("this is an internal linker error", .{});
2104 log.err(" | referenced in {s}", .{2100 return error.FailedToResolveRelocationTarget;
2105 sym.cast(Symbol.Unresolved).?.file.name.?,
2106 });
2107 return error.UndefinedSymbolReference;
2108 };2101 };
2109 break :blk stubs.addr + stubs_index * stubs.reserved2;2102 break :blk stubs.addr + stubs_index * stubs.reserved2;
2110 } else {2103 } else {
2111 log.err("failed to resolve symbol '{s}' as a relocation target", .{sym.name});2104 log.err("failed to resolve symbol '{s}' as a relocation target", .{sym.name});
2105 log.err("this is an internal linker error", .{});
2112 return error.FailedToResolveRelocationTarget;2106 return error.FailedToResolveRelocationTarget;
2113 }2107 }
2114 },2108 },