Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move rpath to frontend and remove native paths from it #17917

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/std/zig/system/NativePaths.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
} else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
const lib_path = word[2..];
try self.addLibDir(lib_path);
try self.addRPath(lib_path);
} else {
try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
break;
Expand Down
6 changes: 0 additions & 6 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ pub const CreateOptions = struct {
linker_print_icf_sections: bool = false,
linker_print_map: bool = false,
llvm_opt_bisect_limit: i32 = -1,
each_lib_rpath: ?bool = null,
build_id: ?std.zig.BuildId = null,
disable_c_depfile: bool = false,
linker_z_nodelete: bool = false,
Expand Down Expand Up @@ -1341,9 +1340,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil

const error_limit = options.error_limit orelse (std.math.maxInt(u16) - 1);

const each_lib_rpath = options.each_lib_rpath orelse
options.root_mod.resolved_target.is_native_os;

// We put everything into the cache hash that *cannot be modified
// during an incremental update*. For example, one cannot change the
// target between updates, but one can change source files, so the
Expand Down Expand Up @@ -1578,7 +1574,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.emit_relocs = options.link_emit_relocs,
.soname = options.soname,
.compatibility_version = options.compatibility_version,
.each_lib_rpath = each_lib_rpath,
.build_id = build_id,
.disable_lld_caching = options.disable_lld_caching or options.cache_mode == .whole,
.subsystem = options.subsystem,
Expand Down Expand Up @@ -2552,7 +2547,6 @@ fn addNonIncrementalStuffToCacheManifest(
man.hash.addListOfBytes(opts.lib_dirs);
man.hash.addListOfBytes(opts.rpath_list);
man.hash.addListOfBytes(opts.symbol_wrap_set.keys());
man.hash.add(opts.each_lib_rpath);
if (comp.config.link_libc) {
man.hash.add(comp.libc_installation != null);
const target = comp.root_mod.resolved_target.result;
Expand Down
1 change: 0 additions & 1 deletion src/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub const File = struct {
max_memory: ?u64,
export_symbol_names: []const []const u8,
global_base: ?u64,
each_lib_rpath: bool,
build_id: std.zig.BuildId,
disable_lld_caching: bool,
hash_style: Elf.HashStyle,
Expand Down
63 changes: 0 additions & 63 deletions src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ lib_dirs: []const []const u8,
hash_style: HashStyle,
compress_debug_sections: CompressDebugSections,
symbol_wrap_set: std.StringArrayHashMapUnmanaged(void),
each_lib_rpath: bool,
sort_section: ?SortSection,
soname: ?[]const u8,
bind_global_refs_locally: bool,
Expand Down Expand Up @@ -320,7 +319,6 @@ pub fn createEmpty(
.hash_style = options.hash_style,
.compress_debug_sections = options.compress_debug_sections,
.symbol_wrap_set = options.symbol_wrap_set,
.each_lib_rpath = options.each_lib_rpath,
.sort_section = options.sort_section,
.soname = options.soname,
.bind_global_refs_locally = options.bind_global_refs_locally,
Expand Down Expand Up @@ -1108,25 +1106,6 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
_ = try rpath_table.put(rpath, {});
}

if (self.each_lib_rpath) {
var test_path = std.ArrayList(u8).init(gpa);
defer test_path.deinit();
for (self.lib_dirs) |lib_dir_path| {
for (comp.system_libs.keys()) |link_lib| {
if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
continue;
_ = try rpath_table.put(lib_dir_path, {});
}
}
for (comp.objects) |obj| {
if (Compilation.classifyFileExt(obj.path) == .shared_library) {
const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
if (obj.loption) continue;
_ = try rpath_table.put(lib_dir_path, {});
}
}
}

// TSAN
if (comp.config.any_sanitize_thread) {
try positionals.append(.{ .path = comp.tsan_static_lib.?.full_object_path });
Expand Down Expand Up @@ -1693,22 +1672,6 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
try argv.append(rpath);
}

if (self.each_lib_rpath) {
for (self.lib_dirs) |lib_dir_path| {
try argv.append("-rpath");
try argv.append(lib_dir_path);
}
for (comp.objects) |obj| {
if (Compilation.classifyFileExt(obj.path) == .shared_library) {
const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
if (obj.loption) continue;

try argv.append("-rpath");
try argv.append(lib_dir_path);
}
}
}

try argv.appendSlice(&.{
"-z",
try std.fmt.allocPrint(arena, "stack-size={d}", .{self.base.stack_size}),
Expand Down Expand Up @@ -2439,7 +2402,6 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
man.hash.add(comp.config.rdynamic);
man.hash.addListOfBytes(self.lib_dirs);
man.hash.addListOfBytes(self.base.rpath_list);
man.hash.add(self.each_lib_rpath);
if (output_mode == .Exe) {
man.hash.add(self.base.stack_size);
man.hash.add(self.base.build_id);
Expand Down Expand Up @@ -2739,31 +2701,6 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
try argv.appendSlice(&.{ "-wrap", symbol_name });
}

if (self.each_lib_rpath) {
var test_path = std.ArrayList(u8).init(arena);
for (self.lib_dirs) |lib_dir_path| {
for (comp.system_libs.keys()) |link_lib| {
if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
continue;
if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
try argv.append("-rpath");
try argv.append(lib_dir_path);
}
}
}
for (comp.objects) |obj| {
if (Compilation.classifyFileExt(obj.path) == .shared_library) {
const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
if (obj.loption) continue;

if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
try argv.append("-rpath");
try argv.append(lib_dir_path);
}
}
}
}

for (self.lib_dirs) |lib_dir| {
try argv.append("-L");
try argv.append(lib_dir);
Expand Down
12 changes: 8 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ fn buildOutputType(
var image_base: ?u64 = null;
var link_eh_frame_hdr = false;
var link_emit_relocs = false;
var each_lib_rpath: ?bool = null;
var build_id: ?std.zig.BuildId = null;
var runtime_args_start: ?usize = null;
var test_filter: ?[]const u8 = null;
Expand Down Expand Up @@ -964,6 +963,7 @@ fn buildOutputType(
.frameworks = .{},
.framework_dirs = .{},
.rpath_list = .{},
.each_lib_rpath = null,
.libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
.link_objects = .{},
.native_system_include_paths = &.{},
Expand Down Expand Up @@ -1334,9 +1334,9 @@ fn buildOutputType(
} else if (mem.eql(u8, arg, "-fno-compiler-rt")) {
want_compiler_rt = false;
} else if (mem.eql(u8, arg, "-feach-lib-rpath")) {
each_lib_rpath = true;
create_module.each_lib_rpath = true;
} else if (mem.eql(u8, arg, "-fno-each-lib-rpath")) {
each_lib_rpath = false;
create_module.each_lib_rpath = false;
} else if (mem.eql(u8, arg, "--test-cmd-bin")) {
try test_exec_args.append(null);
} else if (mem.eql(u8, arg, "--test-evented-io")) {
Expand Down Expand Up @@ -3236,7 +3236,6 @@ fn buildOutputType(
.verbose_llvm_cpu_features = verbose_llvm_cpu_features,
.time_report = time_report,
.stack_report = stack_report,
.each_lib_rpath = each_lib_rpath,
.build_id = build_id,
.test_filter = test_filter,
.test_name_prefix = test_name_prefix,
Expand Down Expand Up @@ -3450,6 +3449,7 @@ const CreateModule = struct {
native_system_include_paths: []const []const u8,
framework_dirs: std.ArrayListUnmanaged([]const u8),
rpath_list: std.ArrayListUnmanaged([]const u8),
each_lib_rpath: ?bool,
libc_paths_file: ?[]const u8,
link_objects: std.ArrayListUnmanaged(Compilation.LinkObject),
};
Expand Down Expand Up @@ -3644,6 +3644,10 @@ fn createModule(
create_module.want_native_include_dirs = true;
}

if (create_module.each_lib_rpath orelse resolved_target.is_native_os) {
try create_module.rpath_list.appendSlice(arena, create_module.lib_dirs.items);
}

// Trigger native system library path detection if necessary.
if (create_module.sysroot == null and
resolved_target.is_native_os and resolved_target.is_native_abi and
Expand Down