authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-15 07:35:12+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-15 07:35:12+01:00
log852e7e24b5f15b489463bdabb0039e2a424e5ee6
treed64e0e2c20afa448be6a0b7e29617c6f603966f5
parent9097bcc06e8d9c4691fac18f7a6b4d7f2d63eefe
parent8707555c0b1fd071fc87be8b74b06ad7bd71098f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17917 from Jan200101/PR/each_lib_rpath_frontend

move rpath to frontend and remove native paths from it

5 files changed, 9 insertions(+), 74 deletions(-)

lib/std/zig/system/NativePaths.zig+1
......@@ -59,6 +59,7 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
5959 } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
6060 const lib_path = word[2..];
6161 try self.addLibDir(lib_path);
62 try self.addRPath(lib_path);
6263 } else {
6364 try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
6465 break;
src/Compilation.zig-6
......@@ -1049,7 +1049,6 @@ pub const CreateOptions = struct {
10491049 linker_print_icf_sections: bool = false,
10501050 linker_print_map: bool = false,
10511051 llvm_opt_bisect_limit: i32 = -1,
1052 each_lib_rpath: ?bool = null,
10531052 build_id: ?std.zig.BuildId = null,
10541053 disable_c_depfile: bool = false,
10551054 linker_z_nodelete: bool = false,
......@@ -1341,9 +1340,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
13411340
13421341 const error_limit = options.error_limit orelse (std.math.maxInt(u16) - 1);
13431342
1344 const each_lib_rpath = options.each_lib_rpath orelse
1345 options.root_mod.resolved_target.is_native_os;
1346
13471343 // We put everything into the cache hash that *cannot be modified
13481344 // during an incremental update*. For example, one cannot change the
13491345 // target between updates, but one can change source files, so the
......@@ -1578,7 +1574,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
15781574 .emit_relocs = options.link_emit_relocs,
15791575 .soname = options.soname,
15801576 .compatibility_version = options.compatibility_version,
1581 .each_lib_rpath = each_lib_rpath,
15821577 .build_id = build_id,
15831578 .disable_lld_caching = options.disable_lld_caching or options.cache_mode == .whole,
15841579 .subsystem = options.subsystem,
......@@ -2552,7 +2547,6 @@ fn addNonIncrementalStuffToCacheManifest(
25522547 man.hash.addListOfBytes(opts.lib_dirs);
25532548 man.hash.addListOfBytes(opts.rpath_list);
25542549 man.hash.addListOfBytes(opts.symbol_wrap_set.keys());
2555 man.hash.add(opts.each_lib_rpath);
25562550 if (comp.config.link_libc) {
25572551 man.hash.add(comp.libc_installation != null);
25582552 const target = comp.root_mod.resolved_target.result;
src/link.zig-1
......@@ -104,7 +104,6 @@ pub const File = struct {
104104 max_memory: ?u64,
105105 export_symbol_names: []const []const u8,
106106 global_base: ?u64,
107 each_lib_rpath: bool,
108107 build_id: std.zig.BuildId,
109108 disable_lld_caching: bool,
110109 hash_style: Elf.HashStyle,
src/link/Elf.zig-63
......@@ -16,7 +16,6 @@ lib_dirs: []const []const u8,
1616hash_style: HashStyle,
1717compress_debug_sections: CompressDebugSections,
1818symbol_wrap_set: std.StringArrayHashMapUnmanaged(void),
19each_lib_rpath: bool,
2019sort_section: ?SortSection,
2120soname: ?[]const u8,
2221bind_global_refs_locally: bool,
......@@ -320,7 +319,6 @@ pub fn createEmpty(
320319 .hash_style = options.hash_style,
321320 .compress_debug_sections = options.compress_debug_sections,
322321 .symbol_wrap_set = options.symbol_wrap_set,
323 .each_lib_rpath = options.each_lib_rpath,
324322 .sort_section = options.sort_section,
325323 .soname = options.soname,
326324 .bind_global_refs_locally = options.bind_global_refs_locally,
......@@ -1108,25 +1106,6 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
11081106 _ = try rpath_table.put(rpath, {});
11091107 }
11101108
1111 if (self.each_lib_rpath) {
1112 var test_path = std.ArrayList(u8).init(gpa);
1113 defer test_path.deinit();
1114 for (self.lib_dirs) |lib_dir_path| {
1115 for (comp.system_libs.keys()) |link_lib| {
1116 if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
1117 continue;
1118 _ = try rpath_table.put(lib_dir_path, {});
1119 }
1120 }
1121 for (comp.objects) |obj| {
1122 if (Compilation.classifyFileExt(obj.path) == .shared_library) {
1123 const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
1124 if (obj.loption) continue;
1125 _ = try rpath_table.put(lib_dir_path, {});
1126 }
1127 }
1128 }
1129
11301109 // TSAN
11311110 if (comp.config.any_sanitize_thread) {
11321111 try positionals.append(.{ .path = comp.tsan_static_lib.?.full_object_path });
......@@ -1693,22 +1672,6 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
16931672 try argv.append(rpath);
16941673 }
16951674
1696 if (self.each_lib_rpath) {
1697 for (self.lib_dirs) |lib_dir_path| {
1698 try argv.append("-rpath");
1699 try argv.append(lib_dir_path);
1700 }
1701 for (comp.objects) |obj| {
1702 if (Compilation.classifyFileExt(obj.path) == .shared_library) {
1703 const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
1704 if (obj.loption) continue;
1705
1706 try argv.append("-rpath");
1707 try argv.append(lib_dir_path);
1708 }
1709 }
1710 }
1711
17121675 try argv.appendSlice(&.{
17131676 "-z",
17141677 try std.fmt.allocPrint(arena, "stack-size={d}", .{self.base.stack_size}),
......@@ -2439,7 +2402,6 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
24392402 man.hash.add(comp.config.rdynamic);
24402403 man.hash.addListOfBytes(self.lib_dirs);
24412404 man.hash.addListOfBytes(self.base.rpath_list);
2442 man.hash.add(self.each_lib_rpath);
24432405 if (output_mode == .Exe) {
24442406 man.hash.add(self.base.stack_size);
24452407 man.hash.add(self.base.build_id);
......@@ -2739,31 +2701,6 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
27392701 try argv.appendSlice(&.{ "-wrap", symbol_name });
27402702 }
27412703
2742 if (self.each_lib_rpath) {
2743 var test_path = std.ArrayList(u8).init(arena);
2744 for (self.lib_dirs) |lib_dir_path| {
2745 for (comp.system_libs.keys()) |link_lib| {
2746 if (!(try self.accessLibPath(&test_path, null, lib_dir_path, link_lib, .Dynamic)))
2747 continue;
2748 if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
2749 try argv.append("-rpath");
2750 try argv.append(lib_dir_path);
2751 }
2752 }
2753 }
2754 for (comp.objects) |obj| {
2755 if (Compilation.classifyFileExt(obj.path) == .shared_library) {
2756 const lib_dir_path = std.fs.path.dirname(obj.path) orelse continue;
2757 if (obj.loption) continue;
2758
2759 if ((try rpath_table.fetchPut(lib_dir_path, {})) == null) {
2760 try argv.append("-rpath");
2761 try argv.append(lib_dir_path);
2762 }
2763 }
2764 }
2765 }
2766
27672704 for (self.lib_dirs) |lib_dir| {
27682705 try argv.append("-L");
27692706 try argv.append(lib_dir);
src/main.zig+8-4
......@@ -866,7 +866,6 @@ fn buildOutputType(
866866 var image_base: ?u64 = null;
867867 var link_eh_frame_hdr = false;
868868 var link_emit_relocs = false;
869 var each_lib_rpath: ?bool = null;
870869 var build_id: ?std.zig.BuildId = null;
871870 var runtime_args_start: ?usize = null;
872871 var test_filter: ?[]const u8 = null;
......@@ -964,6 +963,7 @@ fn buildOutputType(
964963 .frameworks = .{},
965964 .framework_dirs = .{},
966965 .rpath_list = .{},
966 .each_lib_rpath = null,
967967 .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
968968 .link_objects = .{},
969969 .native_system_include_paths = &.{},
......@@ -1334,9 +1334,9 @@ fn buildOutputType(
13341334 } else if (mem.eql(u8, arg, "-fno-compiler-rt")) {
13351335 want_compiler_rt = false;
13361336 } else if (mem.eql(u8, arg, "-feach-lib-rpath")) {
1337 each_lib_rpath = true;
1337 create_module.each_lib_rpath = true;
13381338 } else if (mem.eql(u8, arg, "-fno-each-lib-rpath")) {
1339 each_lib_rpath = false;
1339 create_module.each_lib_rpath = false;
13401340 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {
13411341 try test_exec_args.append(null);
13421342 } else if (mem.eql(u8, arg, "--test-evented-io")) {
......@@ -3236,7 +3236,6 @@ fn buildOutputType(
32363236 .verbose_llvm_cpu_features = verbose_llvm_cpu_features,
32373237 .time_report = time_report,
32383238 .stack_report = stack_report,
3239 .each_lib_rpath = each_lib_rpath,
32403239 .build_id = build_id,
32413240 .test_filter = test_filter,
32423241 .test_name_prefix = test_name_prefix,
......@@ -3450,6 +3449,7 @@ const CreateModule = struct {
34503449 native_system_include_paths: []const []const u8,
34513450 framework_dirs: std.ArrayListUnmanaged([]const u8),
34523451 rpath_list: std.ArrayListUnmanaged([]const u8),
3452 each_lib_rpath: ?bool,
34533453 libc_paths_file: ?[]const u8,
34543454 link_objects: std.ArrayListUnmanaged(Compilation.LinkObject),
34553455};
......@@ -3644,6 +3644,10 @@ fn createModule(
36443644 create_module.want_native_include_dirs = true;
36453645 }
36463646
3647 if (create_module.each_lib_rpath orelse resolved_target.is_native_os) {
3648 try create_module.rpath_list.appendSlice(arena, create_module.lib_dirs.items);
3649 }
3650
36473651 // Trigger native system library path detection if necessary.
36483652 if (create_module.sysroot == null and
36493653 resolved_target.is_native_os and resolved_target.is_native_abi and