From 30aeb41a19d3ac15c89190cd546cbe7c05c60ac8 Mon Sep 17 00:00:00 2001 From: Ganesan Rajagopal Date: Mon, 5 Dec 2022 16:17:19 +0530 Subject: [PATCH] Fix linker segfault adding rpath to sharedlib If the shared library is a relative path, dirname will return null causing a segfault. In the case I debugged, the current directory was already in RPATH so just ignoring this case seems a reasonable fix. After this fix "make" and "make test" pass for mimalloc. Closes #13766 --- src/link/Elf.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/link/Elf.zig b/src/link/Elf.zig index f1ab98372e..fcab34bf5e 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1636,7 +1636,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v } for (self.base.options.objects) |obj| { if (Compilation.classifyFileExt(obj.path) == .shared_library) { - const lib_dir_path = std.fs.path.dirname(obj.path).?; + const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue; if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) { try argv.append("-rpath"); try argv.append(lib_dir_path);