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 {...@@ -800,7 +800,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
800 .llvm_cpu_features = llvm_cpu_features,800 .llvm_cpu_features = llvm_cpu_features,
801 .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc,801 .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc,
802 .parent_compilation_link_libc = options.parent_compilation_link_libc,802 .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,
804 .disable_lld_caching = options.disable_lld_caching,804 .disable_lld_caching = options.disable_lld_caching,
805 .subsystem = options.subsystem,805 .subsystem = options.subsystem,
806 .is_test = options.is_test,806 .is_test = options.is_test,
src/link/Elf.zig+3-2
...@@ -1453,10 +1453,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1453,10 +1453,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1453 var test_path = std.ArrayList(u8).init(self.base.allocator);1453 var test_path = std.ArrayList(u8).init(self.base.allocator);
1454 defer test_path.deinit();1454 defer test_path.deinit();
1455 for (self.base.options.lib_dirs) |lib_dir_path| {1455 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;
1457 test_path.shrinkRetainingCapacity(0);1458 test_path.shrinkRetainingCapacity(0);
1458 const sep = fs.path.sep_str;1459 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 });
1460 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {1461 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1461 error.FileNotFound => continue,1462 error.FileNotFound => continue,
1462 else => |e| return e,1463 else => |e| return e,
src/main.zig+6-3
...@@ -268,10 +268,11 @@ const usage_build_generic =...@@ -268,10 +268,11 @@ const usage_build_generic =
268 \\ -T[script], --script [script] Use a custom linker script268 \\ -T[script], --script [script] Use a custom linker script
269 \\ --version-script [path] Provide a version .map file269 \\ --version-script [path] Provide a version .map file
270 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)270 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
271 \\ --each-lib-rpath Add rpath for each used dynamic library
272 \\ --version [ver] Dynamic library semver271 \\ --version [ver] Dynamic library semver
273 \\ -rdynamic Add all symbols to the dynamic symbol table272 \\ -rdynamic Add all symbols to the dynamic symbol table
274 \\ -rpath [path] Add directory to the runtime library search path273 \\ -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
275 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker276 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
276 \\ --emit-relocs Enable output of relocation sections for post build tools277 \\ --emit-relocs Enable output of relocation sections for post build tools
277 \\ -dynamic Force output to be dynamically linked278 \\ -dynamic Force output to be dynamically linked
...@@ -442,7 +443,7 @@ fn buildOutputType(...@@ -442,7 +443,7 @@ fn buildOutputType(
442 var use_clang: ?bool = null;443 var use_clang: ?bool = null;
443 var link_eh_frame_hdr = false;444 var link_eh_frame_hdr = false;
444 var link_emit_relocs = false;445 var link_emit_relocs = false;
445 var each_lib_rpath = false;446 var each_lib_rpath: ?bool = null;
446 var libc_paths_file: ?[]const u8 = null;447 var libc_paths_file: ?[]const u8 = null;
447 var machine_code_model: std.builtin.CodeModel = .default;448 var machine_code_model: std.builtin.CodeModel = .default;
448 var runtime_args_start: ?usize = null;449 var runtime_args_start: ?usize = null;
...@@ -739,8 +740,10 @@ fn buildOutputType(...@@ -739,8 +740,10 @@ fn buildOutputType(
739 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});740 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
740 i += 1;741 i += 1;
741 override_lib_dir = args[i];742 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")) {
743 each_lib_rpath = true;744 each_lib_rpath = true;
745 } else if (mem.eql(u8, arg, "-fno-each-lib-rpath")) {
746 each_lib_rpath = false;
744 } else if (mem.eql(u8, arg, "--enable-cache")) {747 } else if (mem.eql(u8, arg, "--enable-cache")) {
745 enable_cache = true;748 enable_cache = true;
746 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {749 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {