authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-17 19:49:17+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-17 19:49:17+02:00
log8b795fe2ac17466d0bc9de7b494f0cf076d7c46d
tree598299ec55d738deebab605e00f91ec942507181
parent69f42817745a13fc3cc69896cb628a7028696a88

macho: parse input files and libs in incremental

This converges parsing of linker line in incremental; however, still doesn't save the parsing state between updates.

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

src/link/MachO.zig+8-31
...@@ -93,9 +93,6 @@ source_version_cmd_index: ?u16 = null,...@@ -93,9 +93,6 @@ source_version_cmd_index: ?u16 = null,
93build_version_cmd_index: ?u16 = null,93build_version_cmd_index: ?u16 = null,
94uuid_cmd_index: ?u16 = null,94uuid_cmd_index: ?u16 = null,
95code_signature_cmd_index: ?u16 = null,95code_signature_cmd_index: ?u16 = null,
96/// Path to libSystem
97/// TODO this is obsolete, remove it.
98libsystem_cmd_index: ?u16 = null,
9996
100// __TEXT segment sections97// __TEXT segment sections
101text_section_index: ?u16 = null,98text_section_index: ?u16 = null,
...@@ -281,15 +278,6 @@ const ideal_factor = 2;...@@ -281,15 +278,6 @@ const ideal_factor = 2;
281/// instead but this will do for now.278/// instead but this will do for now.
282const DEFAULT_DYLD_PATH: [*:0]const u8 = "/usr/lib/dyld";279const DEFAULT_DYLD_PATH: [*:0]const u8 = "/usr/lib/dyld";
283280
284/// Default lib search path
285/// TODO instead of hardcoding it, we should probably look through some env vars and search paths
286/// instead but this will do for now.
287const DEFAULT_LIB_SEARCH_PATH: []const u8 = "/usr/lib";
288
289const LIB_SYSTEM_NAME: [*:0]const u8 = "System";
290/// TODO we should search for libSystem and fail if it doesn't exist, instead of hardcoding it
291const LIB_SYSTEM_PATH: [*:0]const u8 = DEFAULT_LIB_SEARCH_PATH ++ "/libSystem.B.dylib";
292
293/// In order for a slice of bytes to be considered eligible to keep metadata pointing at281/// In order for a slice of bytes to be considered eligible to keep metadata pointing at
294/// it as a possible place to put new symbols, it must have enough room for this many bytes282/// it as a possible place to put new symbols, it must have enough room for this many bytes
295/// (plus extra for reserved capacity).283/// (plus extra for reserved capacity).
...@@ -793,17 +781,17 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {...@@ -793,17 +781,17 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
793 Compilation.dump_argv(argv.items);781 Compilation.dump_argv(argv.items);
794 }782 }
795783
784 try self.parseInputFiles(positionals.items, self.base.options.sysroot);
785 try self.parseLibs(libs.items, self.base.options.sysroot);
786 try self.resolveSymbols();
787 try self.resolveDyldStubBinder();
788 try self.parseTextBlocks();
796 try self.addRpathLCs(rpath_table.keys());789 try self.addRpathLCs(rpath_table.keys());
790 try self.addLoadDylibLCs();
791 try self.addDataInCodeLC();
792 try self.addCodeSignatureLC();
797793
798 if (use_stage1) {794 if (use_stage1) {
799 try self.parseInputFiles(positionals.items, self.base.options.sysroot);
800 try self.parseLibs(libs.items, self.base.options.sysroot);
801 try self.resolveSymbols();
802 try self.resolveDyldStubBinder();
803 try self.parseTextBlocks();
804 try self.addLoadDylibLCs();
805 try self.addDataInCodeLC();
806 try self.addCodeSignatureLC();
807 try self.sortSections();795 try self.sortSections();
808 try self.allocateTextSegment();796 try self.allocateTextSegment();
809 try self.allocateDataConstSegment();797 try self.allocateDataConstSegment();
...@@ -812,17 +800,6 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {...@@ -812,17 +800,6 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
812 try self.allocateTextBlocks();800 try self.allocateTextBlocks();
813 try self.flushZld();801 try self.flushZld();
814 } else {802 } else {
815 // TODO this is just a temp; libsystem load command will be autoresolved when parsing libSystem from
816 // the linker line and actually referencing symbols.
817 if (self.libsystem_cmd_index == null) {
818 self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len);
819 var dylib_cmd = try commands.createLoadDylibCommand(self.base.allocator, mem.spanZ(LIB_SYSTEM_PATH), 2, 0, 0);
820 errdefer dylib_cmd.deinit(self.base.allocator);
821 try self.load_commands.append(self.base.allocator, .{ .Dylib = dylib_cmd });
822 self.load_commands_dirty = true;
823 }
824 try self.addDataInCodeLC();
825 try self.addCodeSignatureLC();
826 try self.flushModule(comp);803 try self.flushModule(comp);
827 }804 }
828 }805 }