authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-13 10:14:37+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-13 10:46:53+02:00
logc53423f8aac8de49e700ba6eb89ccac462ed2212
tree397a8403ed423cb08a70e217af9104230f1d9370
parent0961c1975a74acdc344be11ffbb4b11e033c8df0

macho: don't cache unused link options

This will change incrementally once we support more linker options.

1 files changed, 7 insertions(+), 21 deletions(-)

src/link/MachO.zig+7-21
......@@ -614,7 +614,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
614614 const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;
615615 const is_exe_or_dyn_lib = is_dyn_lib or self.base.options.output_mode == .Exe;
616616 const stack_size = self.base.options.stack_size_override orelse 0;
617 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;
618617
619618 const id_symlink_basename = "zld.id";
620619
......@@ -629,8 +628,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
629628 // We are about to obtain this lock, so here we give other processes a chance first.
630629 self.base.releaseLock();
631630
632 try man.addOptionalFile(self.base.options.linker_script);
633 try man.addOptionalFile(self.base.options.version_script);
634631 try man.addListOfFiles(self.base.options.objects);
635632 for (comp.c_object_table.keys()) |key| {
636633 _ = try man.addFile(key.status.success.object_path, null);
......@@ -639,21 +636,14 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
639636 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
640637 // installation sources because they are always a product of the compiler version + target information.
641638 man.hash.add(stack_size);
642 man.hash.add(self.base.options.rdynamic);
643 man.hash.addListOfBytes(self.base.options.extra_lld_args);
644639 man.hash.addListOfBytes(self.base.options.lib_dirs);
645640 man.hash.addListOfBytes(self.base.options.framework_dirs);
646641 man.hash.addListOfBytes(self.base.options.frameworks);
647642 man.hash.addListOfBytes(self.base.options.rpath_list);
648 man.hash.add(self.base.options.skip_linker_dependencies);
649 man.hash.add(self.base.options.z_nodelete);
650 man.hash.add(self.base.options.z_defs);
651643 if (is_dyn_lib) {
652644 man.hash.addOptional(self.base.options.version);
653645 }
654646 man.hash.addStringSet(self.base.options.system_libs);
655 man.hash.add(allow_shlib_undefined);
656 man.hash.add(self.base.options.bind_global_refs_locally);
657647 man.hash.addOptionalBytes(self.base.options.sysroot);
658648
659649 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
......@@ -909,16 +899,12 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
909899 Compilation.dump_argv(argv.items);
910900 }
911901
912 self.base.file = try fs.cwd().createFile(full_out_path, .{
902 const sub_path = self.base.options.emit.?.sub_path;
903 self.base.file = try directory.handle.createFile(sub_path, .{
913904 .truncate = true,
914905 .read = true,
915 .mode = if (std.Target.current.os.tag == .windows) 0 else 0o777,
906 .mode = link.determineMode(self.base.options),
916907 });
917 self.page_size = switch (self.base.options.target.cpu.arch) {
918 .aarch64 => 0x4000,
919 .x86_64 => 0x1000,
920 else => unreachable,
921 };
922908
923909 // TODO mimicking insertion of null symbol from incremental linker.
924910 // This will need to moved.
......@@ -932,10 +918,14 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
932918 try self.strtab.append(self.base.allocator, 0);
933919
934920 try self.populateMetadata();
921 try self.addRpathLCs(rpaths.items);
935922 try self.parseInputFiles(positionals.items, self.base.options.sysroot);
936923 try self.parseLibs(libs.items, self.base.options.sysroot);
937924 try self.resolveSymbols();
938925 try self.parseTextBlocks();
926 try self.addLoadDylibLCs();
927 try self.addDataInCodeLC();
928 try self.addCodeSignatureLC();
939929
940930 {
941931 // Add dyld_stub_binder as the final GOT entry.
......@@ -953,10 +943,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
953943 }
954944
955945 try self.sortSections();
956 try self.addRpathLCs(rpaths.items);
957 try self.addLoadDylibLCs();
958 try self.addDataInCodeLC();
959 try self.addCodeSignatureLC();
960946 try self.allocateTextSegment();
961947 try self.allocateDataConstSegment();
962948 try self.allocateDataSegment();