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 {
758758 }
759759 }
760760
761 // Search for static libraries first, then dynamic libraries.
762 // TODO Respect flags such as -search_paths_first to the linker.
761 // Assume ld64 default: -search_paths_first
762 // Look in each directory for a dylib (tbd), and then for archive
763 // TODO implement alternative: -search_dylibs_first
763764 // TODO text-based API, or .tbd files.
764 const exts = &[_][]const u8{ "a", "dylib" };
765 const exts = &[_][]const u8{ "dylib", "a" };
765766
766767 for (search_lib_names.items) |l_name| {
767768 var found = false;
src/link/MachO/Zld.zig+7-13
......@@ -1891,7 +1891,6 @@ fn resolveStubsAndGotEntries(self: *Zld) !void {
18911891 const relocs = sect.relocs orelse continue;
18921892 for (relocs) |rel| {
18931893 switch (rel.@"type") {
1894 .unsigned => continue,
18951894 .got_page, .got_page_off, .got_load, .got, .pointer_to_got => {
18961895 const sym = rel.target.symbol.getTopmostAlias();
18971896 if (sym.got_index != null) continue;
......@@ -2025,12 +2024,9 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void {
20252024 const got = dc_seg.sections.items[self.got_section_index.?];
20262025 const final = rel.target.symbol.getTopmostAlias();
20272026 const got_index = final.got_index orelse {
2028 // TODO remove this when we can link against TAPI files.
2029 log.err("undefined reference to symbol '{s}'", .{final.name});
2030 log.err(" | referenced in {s}", .{
2031 rel.target.symbol.cast(Symbol.Unresolved).?.file.name.?,
2032 });
2033 return error.UndefinedSymbolReference;
2027 log.err("expected GOT index relocating symbol '{s}'", .{final.name});
2028 log.err("this is an internal linker error", .{});
2029 return error.FailedToResolveRelocationTarget;
20342030 };
20352031 args.target_addr = got.addr + got_index * @sizeOf(u64);
20362032 },
......@@ -2099,16 +2095,14 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T
20992095 const segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
21002096 const stubs = segment.sections.items[self.stubs_section_index.?];
21012097 const stubs_index = proxy.base.stubs_index orelse {
2102 // TODO remove this when we can link against TAPI files.
2103 log.err("undefined reference to symbol '{s}'", .{final.name});
2104 log.err(" | referenced in {s}", .{
2105 sym.cast(Symbol.Unresolved).?.file.name.?,
2106 });
2107 return error.UndefinedSymbolReference;
2098 log.err("expected stubs index when relocating symbol '{s}'", .{final.name});
2099 log.err("this is an internal linker error", .{});
2100 return error.FailedToResolveRelocationTarget;
21082101 };
21092102 break :blk stubs.addr + stubs_index * stubs.reserved2;
21102103 } else {
21112104 log.err("failed to resolve symbol '{s}' as a relocation target", .{sym.name});
2105 log.err("this is an internal linker error", .{});
21122106 return error.FailedToResolveRelocationTarget;
21132107 }
21142108 },