authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-14 22:18:18+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-14 22:18:18+02:00
logb20b6d7da9b63783a4f481fd0a4b48a47843abc8
tree3ff0531822527aeff0cb278d7c27acfe43b66916
parent819ef521042e7e21db4ab5dd7a0dbe180bd31c57

macho: move bit adding rpaths to common codepath


1 files changed, 24 insertions(+), 27 deletions(-)

src/link/MachO.zig+24-27
......@@ -536,6 +536,27 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
536536 try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{});
537537 }
538538 } else {
539 if (use_stage1) {
540 const sub_path = self.base.options.emit.?.sub_path;
541 self.base.file = try directory.handle.createFile(sub_path, .{
542 .truncate = true,
543 .read = true,
544 .mode = link.determineMode(self.base.options),
545 });
546 try self.populateMetadata();
547
548 // TODO mimicking insertion of null symbol from incremental linker.
549 // This will need to moved.
550 try self.locals.append(self.base.allocator, .{
551 .n_strx = 0,
552 .n_type = macho.N_UNDF,
553 .n_sect = 0,
554 .n_desc = 0,
555 .n_value = 0,
556 });
557 try self.strtab.append(self.base.allocator, 0);
558 }
559
539560 // Positional arguments to the linker such as object files and static archives.
540561 var positionals = std.ArrayList([]const u8).init(arena);
541562
......@@ -673,12 +694,6 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
673694 try rpath_table.putNoClobber(rpath, {});
674695 }
675696
676 var rpaths = std.ArrayList([]const u8).init(arena);
677 try rpaths.ensureCapacity(rpath_table.count());
678 for (rpath_table.keys()) |*key| {
679 rpaths.appendAssumeCapacity(key.*);
680 }
681
682697 if (self.base.options.verbose_link) {
683698 var argv = std.ArrayList([]const u8).init(arena);
684699
......@@ -704,7 +719,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
704719 try argv.append(syslibroot);
705720 }
706721
707 for (rpaths.items) |rpath| {
722 for (rpath_table.keys()) |rpath| {
708723 try argv.append("-rpath");
709724 try argv.append(rpath);
710725 }
......@@ -736,27 +751,9 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
736751 Compilation.dump_argv(argv.items);
737752 }
738753
739 if (use_stage1) {
740 const sub_path = self.base.options.emit.?.sub_path;
741 self.base.file = try directory.handle.createFile(sub_path, .{
742 .truncate = true,
743 .read = true,
744 .mode = link.determineMode(self.base.options),
745 });
754 try self.addRpathLCs(rpath_table.keys());
746755
747 // TODO mimicking insertion of null symbol from incremental linker.
748 // This will need to moved.
749 try self.locals.append(self.base.allocator, .{
750 .n_strx = 0,
751 .n_type = macho.N_UNDF,
752 .n_sect = 0,
753 .n_desc = 0,
754 .n_value = 0,
755 });
756 try self.strtab.append(self.base.allocator, 0);
757
758 try self.populateMetadata();
759 try self.addRpathLCs(rpaths.items);
756 if (use_stage1) {
760757 try self.parseInputFiles(positionals.items, self.base.options.sysroot);
761758 try self.parseLibs(libs.items, self.base.options.sysroot);
762759 try self.resolveSymbols();