authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-04 23:16:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-04 23:16:46-07:00
log55ac973953da88c3a108398849ee29f797c4ae52
treeb01c6bf6a399774ec39a057b1af93f03f82453f0
parentd5d48c6f4ea8a16c2fa9dc9b083c1917a3accee0

fix each-lib-rpath functionality

It was regressed in 2 ways from the merge of #6250: * it was not being enabled by default when the target OS is native. * we were testing the libfoo.so file path existence with bogus format string ('{}' instead of '{s}') and so it ended up being something like "libstd.HashMap(K,V,...).Entry.so" instead of "libfoo.so". Using {} rather than {s} is a footgun, be careful! Previous functionality is now restored. closes #6523

3 files changed, 10 insertions(+), 6 deletions(-)

src/Compilation.zig+1-1
......@@ -800,7 +800,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
800800 .llvm_cpu_features = llvm_cpu_features,
801801 .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc,
802802 .parent_compilation_link_libc = options.parent_compilation_link_libc,
803 .each_lib_rpath = options.each_lib_rpath orelse false,
803 .each_lib_rpath = options.each_lib_rpath orelse options.is_native_os,
804804 .disable_lld_caching = options.disable_lld_caching,
805805 .subsystem = options.subsystem,
806806 .is_test = options.is_test,
src/link/Elf.zig+3-2
......@@ -1453,10 +1453,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
14531453 var test_path = std.ArrayList(u8).init(self.base.allocator);
14541454 defer test_path.deinit();
14551455 for (self.base.options.lib_dirs) |lib_dir_path| {
1456 for (self.base.options.system_libs.items()) |link_lib| {
1456 for (self.base.options.system_libs.items()) |entry| {
1457 const link_lib = entry.key;
14571458 test_path.shrinkRetainingCapacity(0);
14581459 const sep = fs.path.sep_str;
1459 try test_path.writer().print("{}" ++ sep ++ "lib{}.so", .{ lib_dir_path, link_lib });
1460 try test_path.writer().print("{s}" ++ sep ++ "lib{s}.so", .{ lib_dir_path, link_lib });
14601461 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
14611462 error.FileNotFound => continue,
14621463 else => |e| return e,
src/main.zig+6-3
......@@ -268,10 +268,11 @@ const usage_build_generic =
268268 \\ -T[script], --script [script] Use a custom linker script
269269 \\ --version-script [path] Provide a version .map file
270270 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
271 \\ --each-lib-rpath Add rpath for each used dynamic library
272271 \\ --version [ver] Dynamic library semver
273272 \\ -rdynamic Add all symbols to the dynamic symbol table
274273 \\ -rpath [path] Add directory to the runtime library search path
274 \\ -feach-lib-rpath Ensure adding rpath for each used dynamic library
275 \\ -fno-each-lib-rpath Prevent adding rpath for each used dynamic library
275276 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
276277 \\ --emit-relocs Enable output of relocation sections for post build tools
277278 \\ -dynamic Force output to be dynamically linked
......@@ -442,7 +443,7 @@ fn buildOutputType(
442443 var use_clang: ?bool = null;
443444 var link_eh_frame_hdr = false;
444445 var link_emit_relocs = false;
445 var each_lib_rpath = false;
446 var each_lib_rpath: ?bool = null;
446447 var libc_paths_file: ?[]const u8 = null;
447448 var machine_code_model: std.builtin.CodeModel = .default;
448449 var runtime_args_start: ?usize = null;
......@@ -739,8 +740,10 @@ fn buildOutputType(
739740 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
740741 i += 1;
741742 override_lib_dir = args[i];
742 } else if (mem.eql(u8, arg, "--each-lib-rpath")) {
743 } else if (mem.eql(u8, arg, "-feach-lib-rpath")) {
743744 each_lib_rpath = true;
745 } else if (mem.eql(u8, arg, "-fno-each-lib-rpath")) {
746 each_lib_rpath = false;
744747 } else if (mem.eql(u8, arg, "--enable-cache")) {
745748 enable_cache = true;
746749 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {