From ac9f72d87e8eeb4a9d0dead80b61420485279ddd Mon Sep 17 00:00:00 2001 From: Motiejus Jakštys Date: Tue, 23 May 2023 10:50:15 +0300 Subject: zig ld: handle `--library :path/to/lib.so` `-l :path/to/lib.so` behavior on gcc/clang is: - the path is recorded as-is: no paths, exact filename (`libX.so.Y`). - no rpaths. The previous version removed the `:` and pretended it's a positional argument to the linker. That works in almost all cases, except in how rules_go[1] does things (the Bazel wrapper for Go). Test case in #15743, output: gcc rpath: 0x0000000000000001 (NEEDED) Shared library: [libversioned.so.2] 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/x] gcc plain: 0x0000000000000001 (NEEDED) Shared library: [libversioned.so.2] zig cc rpath: 0x0000000000000001 (NEEDED) Shared library: [libversioned.so.2] 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/x] zig cc plain: 0x0000000000000001 (NEEDED) Shared library: [libversioned.so.2] Fixes #15743 [1]: https://github.com/bazelbuild/rules_go --- src/Compilation.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index cc2e2a916b..2ab9dde35c 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -451,6 +451,11 @@ pub const CacheMode = link.CacheMode; pub const LinkObject = struct { path: []const u8, must_link: bool = false, + // When the library is passed via a positional argument, it will be + // added as a full path. If it's `-l`, then just the basename. + // + // Consistent with `withLOption` variable name in lld ELF driver. + loption: bool = false, }; pub const InitOptions = struct { @@ -2196,7 +2201,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo /// to remind the programmer to update multiple related pieces of code that /// are in different locations. Bump this number when adding or deleting /// anything from the link cache manifest. -pub const link_hash_implementation_version = 8; +pub const link_hash_implementation_version = 9; fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void { const gpa = comp.gpa; @@ -2206,7 +2211,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes defer arena_allocator.deinit(); const arena = arena_allocator.allocator(); - comptime assert(link_hash_implementation_version == 8); + comptime assert(link_hash_implementation_version == 9); if (comp.bin_file.options.module) |mod| { const main_zig_file = try mod.main_pkg.root_src_directory.join(arena, &[_][]const u8{ @@ -2244,6 +2249,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes for (comp.bin_file.options.objects) |obj| { _ = try man.addFile(obj.path, null); man.hash.add(obj.must_link); + man.hash.add(obj.loption); } for (comp.c_object_table.keys()) |key| { -- cgit v1.2.3