diff options
| author | Motiejus Jakštys <motiejus@uber.com> | 2023-05-23 10:50:15 +0300 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-05-30 08:18:10 +0200 |
| commit | ac9f72d87e8eeb4a9d0dead80b61420485279ddd (patch) | |
| tree | 63046c79edfb445d0eef7092d695ab1646655061 /src/Compilation.zig | |
| parent | 706bdf6512aec9f5d003cc2ec64ba16ac0a202dc (diff) | |
| download | zig-ac9f72d87e8eeb4a9d0dead80b61420485279ddd.tar.gz zig-ac9f72d87e8eeb4a9d0dead80b61420485279ddd.zip | |
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
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 10 |
1 files changed, 8 insertions, 2 deletions
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<lib>`, 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| { |
