aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorMotiejus Jakštys <motiejus@uber.com>2023-05-23 10:50:15 +0300
committerJakub Konka <kubkon@jakubkonka.com>2023-05-30 08:18:10 +0200
commitac9f72d87e8eeb4a9d0dead80b61420485279ddd (patch)
tree63046c79edfb445d0eef7092d695ab1646655061 /src/main.zig
parent706bdf6512aec9f5d003cc2ec64ba16ac0a202dc (diff)
downloadzig-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/main.zig')
-rw-r--r--src/main.zig43
1 files changed, 6 insertions, 37 deletions
diff --git a/src/main.zig b/src/main.zig
index f7afbe767b..b4778c1b00 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -889,14 +889,6 @@ fn buildOutputType(
var link_objects = std.ArrayList(Compilation.LinkObject).init(gpa);
defer link_objects.deinit();
- // This map is a flag per link_objects item, used to represent the
- // `-l :file.so` syntax from gcc/clang.
- // This is only exposed from the `zig cc` interface. It means that the `path`
- // field from the corresponding `link_objects` element is a suffix, and is
- // to be tried against each library path as a prefix until an existing file is found.
- // This map remains empty for the main CLI.
- var link_objects_lib_search_paths: std.AutoHashMapUnmanaged(u32, void) = .{};
-
var framework_dirs = std.ArrayList([]const u8).init(gpa);
defer framework_dirs.deinit();
@@ -1627,14 +1619,15 @@ fn buildOutputType(
// We don't know whether this library is part of libc or libc++ until
// we resolve the target, so we simply append to the list for now.
if (mem.startsWith(u8, it.only_arg, ":")) {
- // This "feature" of gcc/clang means to treat this as a positional
- // link object, but using the library search directories as a prefix.
+ // -l :path/to/filename is used when callers need
+ // more control over what's in the resulting
+ // binary: no extra rpaths and DSO filename exactly
+ // as provided. Hello, Go.
try link_objects.append(.{
- .path = it.only_arg[1..],
+ .path = it.only_arg,
.must_link = must_link,
+ .loption = true,
});
- const index = @intCast(u32, link_objects.items.len - 1);
- try link_objects_lib_search_paths.put(arena, index, {});
} else if (force_static_libs) {
try static_libs.append(it.only_arg);
} else {
@@ -2640,30 +2633,6 @@ fn buildOutputType(
}
}
- // Resolve `-l :file.so` syntax from `zig cc`. We use a separate map for this data
- // since this is an uncommon case.
- {
- var it = link_objects_lib_search_paths.iterator();
- while (it.next()) |item| {
- const link_object_i = item.key_ptr.*;
- const suffix = link_objects.items[link_object_i].path;
-
- for (lib_dirs.items) |lib_dir_path| {
- const test_path = try fs.path.join(arena, &.{ lib_dir_path, suffix });
- fs.cwd().access(test_path, .{}) catch |err| switch (err) {
- error.FileNotFound => continue,
- else => |e| fatal("unable to search for library '{s}': {s}", .{
- test_path, @errorName(e),
- }),
- };
- link_objects.items[link_object_i].path = test_path;
- break;
- } else {
- fatal("library '{s}' not found", .{suffix});
- }
- }
- }
-
const object_format = target_info.target.ofmt;
if (output_mode == .Obj and (object_format == .coff or object_format == .macho)) {