authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-20 10:14:18+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-24 14:45:45+02:00
log09b46198ff8d64c9884a0cf13788855b4d4bbe2d
treeda0ac067ec33e1cb5e3a1bdcd3438c1cb6514621
parenta600d4188025ae6ffc3fc5d6fa7572ef34438215

zld: move logic unpacking path to libc stub to Compilation


4 files changed, 21 insertions(+), 5 deletions(-)

src/Compilation.zig+15
......@@ -919,6 +919,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
919919 }
920920 };
921921
922 const libc_stub_path: ?[]const u8 = if (options.target.isDarwin()) libc_stub: {
923 // TODO consider other platforms than Darwin which require linking against libc here.
924 const needs_libc_stub: bool = switch (options.output_mode) {
925 .Obj => false,
926 .Lib => if (options.link_mode) |mode| mode == .Dynamic else false,
927 .Exe => true,
928 };
929 if (needs_libc_stub) {
930 break :libc_stub try options.zig_lib_directory.join(arena, &[_][]const u8{
931 "libc", "darwin", "libSystem.B.tbd",
932 });
933 } else break :libc_stub null;
934 } else null;
935
922936 const must_dynamic_link = dl: {
923937 if (target_util.cannotDynamicLink(options.target))
924938 break :dl false;
......@@ -1288,6 +1302,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
12881302 .use_lld = use_lld,
12891303 .use_llvm = use_llvm,
12901304 .system_linker_hack = darwin_options.system_linker_hack,
1305 .libc_stub_path = libc_stub_path,
12911306 .link_libc = link_libc,
12921307 .link_libcpp = link_libcpp,
12931308 .link_libunwind = link_libunwind,
src/link.zig+3
......@@ -62,6 +62,9 @@ pub const Options = struct {
6262 /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will
6363 /// use system linker `ld` instead of the LLD.
6464 system_linker_hack: bool,
65 /// Path to Zig-hosted libc stub file.
66 /// On Darwin, this is a path to libSystem.B.tbd stub file.
67 libc_stub_path: ?[]const u8,
6568 link_libc: bool,
6669 link_libcpp: bool,
6770 link_libunwind: bool,
src/link/MachO.zig+1-3
......@@ -848,9 +848,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
848848 try zld.link(positionals.items, full_out_path, .{
849849 .libs = libs.items,
850850 .rpaths = rpaths.items,
851 .lib_system_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
852 "libc", "darwin", "libSystem.B.tbd",
853 }),
851 .libc_stub_path = self.base.options.libc_stub_path.?,
854852 });
855853
856854 break :outer;
src/link/MachO/Zld.zig+2-2
......@@ -181,7 +181,7 @@ pub fn closeFiles(self: Zld) void {
181181const LinkArgs = struct {
182182 libs: []const []const u8,
183183 rpaths: []const []const u8,
184 lib_system_path: []const u8,
184 libc_stub_path: []const u8,
185185};
186186
187187pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: LinkArgs) !void {
......@@ -223,7 +223,7 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L
223223 try self.addRpaths(args.rpaths);
224224 try self.parseInputFiles(files);
225225 try self.parseLibs(args.libs);
226 try self.parseLibSystem(args.lib_system_path);
226 try self.parseLibSystem(args.libc_stub_path);
227227 try self.resolveSymbols();
228228 try self.resolveStubsAndGotEntries();
229229 try self.updateMetadata();