authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-23 23:16:11+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-23 23:16:11+02:00
log2bb713ca1cc66b7c56b2d7a4187095da91be8738
tree95a398c5a7d98b9fd65d2ccb2b80055032d15f3a
parent9b6f39c3a020ab2a917bc32ec9164c95b3a8a3b5

elf: reuse accessLibPath when checking rpaths


1 files changed, 9 insertions(+), 22 deletions(-)

src/link/Elf.zig+9-22
......@@ -1318,15 +1318,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
13181318 defer test_path.deinit();
13191319 for (self.base.options.lib_dirs) |lib_dir_path| {
13201320 for (self.base.options.system_libs.keys()) |link_lib| {
1321 test_path.clearRetainingCapacity();
1322 const sep = fs.path.sep_str;
1323 try test_path.writer().print("{s}" ++ sep ++ "lib{s}.so", .{
1324 lib_dir_path, link_lib,
1325 });
1326 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1327 error.FileNotFound => continue,
1328 else => |e| return e,
1329 };
1321 if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
1322 continue;
13301323 _ = try rpath_table.put(lib_dir_path, {});
13311324 }
13321325 }
......@@ -1892,7 +1885,7 @@ fn parseLdScript(self: *Elf, in_file: std.fs.File, lib: SystemLib, ctx: *ParseEr
18921885fn accessLibPath(
18931886 self: *Elf,
18941887 test_path: *std.ArrayList(u8),
1895 checked_paths: *std.ArrayList([]const u8),
1888 checked_paths: ?*std.ArrayList([]const u8),
18961889 lib_dir_path: []const u8,
18971890 lib_name: []const u8,
18981891 link_mode: ?std.builtin.LinkMode,
......@@ -1909,7 +1902,9 @@ fn accessLibPath(
19091902 .Dynamic => target.dynamicLibSuffix(),
19101903 } else "",
19111904 });
1912 try checked_paths.append(try self.base.allocator.dupe(u8, test_path.items));
1905 if (checked_paths) |cpaths| {
1906 try cpaths.append(try self.base.allocator.dupe(u8, test_path.items));
1907 }
19131908 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
19141909 error.FileNotFound => return false,
19151910 else => |e| return e,
......@@ -2543,19 +2538,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
25432538 }
25442539
25452540 if (self.base.options.each_lib_rpath) {
2546 var test_path = std.ArrayList(u8).init(self.base.allocator);
2547 defer test_path.deinit();
2541 var test_path = std.ArrayList(u8).init(arena);
25482542 for (self.base.options.lib_dirs) |lib_dir_path| {
25492543 for (self.base.options.system_libs.keys()) |link_lib| {
2550 test_path.clearRetainingCapacity();
2551 const sep = fs.path.sep_str;
2552 try test_path.writer().print("{s}" ++ sep ++ "lib{s}.so", .{
2553 lib_dir_path, link_lib,
2554 });
2555 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
2556 error.FileNotFound => continue,
2557 else => |e| return e,
2558 };
2544 if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
2545 continue;
25592546 if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
25602547 try argv.append("-rpath");
25612548 try argv.append(lib_dir_path);