authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-12 13:49:24+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-12 13:53:59+01:00
log4ce62087502c2b1eca7d5721f3face5bc4fe538b
treec644b3255c21b351dad5cbad657a838762e3aa43
parent1abae064325112895de8324bf230c7cb5cdb2711

macho: if lib or framework not found, wait until syms resolved

This way, we will inform the user that there are unresolved symbols in addition to missing library/framework as requested on the linker line. If all symbols were resolved on the other hand, we still flag up that the library/framework cannot be found. Example behaviour: ``` $ zig cc hello.c -framework MyFoundation --verbose warning(link): framework not found for '-framework MyFoundation' warning(link): Framework search paths: warning(link): /Library/Frameworks warning(link): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks thread 1079397 panic: attempt to unwrap error: FrameworkNotFound ...stack trace... ``` and ``` ❯ zig cc hello.c -lWAT --verbose warning(link): library not found for '-lWAT' warning(link): Library search paths: warning(link): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib warning(link): /usr/local/lib thread 1079824 panic: attempt to unwrap error: LibraryNotFound ...stack trace... ```

1 files changed, 17 insertions(+), 8 deletions(-)

src/link/MachO.zig+17-8
...@@ -572,6 +572,9 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -572,6 +572,9 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
572 try self.populateMissingMetadata();572 try self.populateMissingMetadata();
573 }573 }
574574
575 var lib_not_found = false;
576 var framework_not_found = false;
577
575 if (needs_full_relink) {578 if (needs_full_relink) {
576 for (self.objects.items) |*object| {579 for (self.objects.items) |*object| {
577 object.free(self.base.allocator, self);580 object.free(self.base.allocator, self);
...@@ -688,7 +691,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -688,7 +691,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
688 }691 }
689692
690 var libs = std.ArrayList([]const u8).init(arena);693 var libs = std.ArrayList([]const u8).init(arena);
691 var lib_not_found = false;
692 for (search_lib_names.items) |lib_name| {694 for (search_lib_names.items) |lib_name| {
693 // Assume ld64 default: -search_paths_first695 // Assume ld64 default: -search_paths_first
694 // Look in each directory for a dylib (stub first), and then for archive696 // Look in each directory for a dylib (stub first), and then for archive
...@@ -760,13 +762,14 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -760,13 +762,14 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
760 }762 }
761 } else {763 } else {
762 log.warn("framework not found for '-framework {s}'", .{framework});764 log.warn("framework not found for '-framework {s}'", .{framework});
763 log.warn("Framework search paths:", .{});765 framework_not_found = true;
764 for (framework_dirs.items) |dir| {766 }
765 log.warn(" {s}", .{dir});767 }
766 } else {768
767 log.warn(" <empty>. Consider specifying --sysroot", .{});769 if (framework_not_found) {
768 }770 log.warn("Framework search paths:", .{});
769 return error.FrameworkNotFound;771 for (framework_dirs.items) |dir| {
772 log.warn(" {s}", .{dir});
770 }773 }
771 }774 }
772775
...@@ -926,6 +929,12 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -926,6 +929,12 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
926 if (self.unresolved.count() > 0) {929 if (self.unresolved.count() > 0) {
927 return error.UndefinedSymbolReference;930 return error.UndefinedSymbolReference;
928 }931 }
932 if (lib_not_found) {
933 return error.LibraryNotFound;
934 }
935 if (framework_not_found) {
936 return error.FrameworkNotFound;
937 }
929938
930 try self.createTentativeDefAtoms();939 try self.createTentativeDefAtoms();
931 try self.parseObjectsIntoAtoms();940 try self.parseObjectsIntoAtoms();