Skip to content

Commit 495dba3

Browse files
committed
ELF: Scan for dylibs-as-objects when adding rpaths
Shared libraries can be provided on the command line as if they were objects, as a path to the ".so" file. The "each-lib-rpath" functionality was ignoring these shared libraries accidentally, causing missing rpaths in the output executable.
1 parent 8c2139c commit 495dba3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/link/Elf.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,21 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
15921592
}
15931593
}
15941594
}
1595+
for (self.base.options.objects) |obj| {
1596+
// Libraries may appear as object files on the command line, so we scan
1597+
// for them here (looking for ".so", ".so.X", ".so.X.Y", etc.)
1598+
var it = std.mem.split(u8, std.fs.path.basename(obj.path), ".");
1599+
_ = it.next();
1600+
const suffix = it.next() orelse continue;
1601+
1602+
if (std.mem.startsWith(u8, suffix, target.dynamicLibSuffix()[1..])) {
1603+
const lib_dir_path = std.fs.path.dirname(obj.path).?;
1604+
if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
1605+
try argv.append("-rpath");
1606+
try argv.append(lib_dir_path);
1607+
}
1608+
}
1609+
}
15951610
}
15961611

15971612
for (self.base.options.lib_dirs) |lib_dir| {

0 commit comments

Comments
 (0)