authorgravatar for dillen@brainhive.nlDillen Meijboom <dillen@brainhive.nl> 2024-02-22 23:39:16+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-06 17:52:05-08:00
log377ecc6afb14a112a07c6d2c3570e2b77b12a116
tree706ef264ff807f729e37e2aef2b83a8d8e7ab99e
parentaa7d16aba1f0b3a9e816684618d16cb1d178a6d3

feat: add support for --enable-new-dtags and --disable-new-dtags


7 files changed, 38 insertions(+), 5 deletions(-)

lib/std/Build/Step/Compile.zig+7
......@@ -113,6 +113,9 @@ linker_allow_shlib_undefined: ?bool = null,
113113/// Allow version scripts to refer to undefined symbols.
114114linker_allow_undefined_version: ?bool = null,
115115
116// Enable (or disable) the new DT_RUNPATH tag in the dynamic section.
117linker_enable_new_dtags: ?bool = null,
118
116119/// Permit read-only relocations in read-only segments. Disallowed by default.
117120link_z_notext: bool = false,
118121
......@@ -1490,6 +1493,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
14901493 try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version");
14911494 }
14921495
1496 if (self.linker_enable_new_dtags) |enabled| {
1497 try zig_args.append(if (enabled) "--enable-new-dtags" else "--disable-new-dtags");
1498 }
1499
14931500 if (self.kind == .@"test") {
14941501 if (self.exec_cmd_args) |exec_cmd_args| {
14951502 for (exec_cmd_args) |cmd_arg| {
src/Compilation.zig+5-2
......@@ -1034,6 +1034,7 @@ pub const CreateOptions = struct {
10341034 linker_script: ?[]const u8 = null,
10351035 version_script: ?[]const u8 = null,
10361036 linker_allow_undefined_version: bool = false,
1037 linker_enable_new_dtags: ?bool = null,
10371038 soname: ?[]const u8 = null,
10381039 linker_gc_sections: ?bool = null,
10391040 linker_allow_shlib_undefined: ?bool = null,
......@@ -1581,6 +1582,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
15811582 .image_base = options.image_base,
15821583 .version_script = options.version_script,
15831584 .allow_undefined_version = options.linker_allow_undefined_version,
1585 .enable_new_dtags = options.linker_enable_new_dtags,
15841586 .gc_sections = options.linker_gc_sections,
15851587 .emit_relocs = options.link_emit_relocs,
15861588 .soname = options.soname,
......@@ -2460,7 +2462,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo
24602462/// to remind the programmer to update multiple related pieces of code that
24612463/// are in different locations. Bump this number when adding or deleting
24622464/// anything from the link cache manifest.
2463pub const link_hash_implementation_version = 12;
2465pub const link_hash_implementation_version = 13;
24642466
24652467fn addNonIncrementalStuffToCacheManifest(
24662468 comp: *Compilation,
......@@ -2469,7 +2471,7 @@ fn addNonIncrementalStuffToCacheManifest(
24692471) !void {
24702472 const gpa = comp.gpa;
24712473
2472 comptime assert(link_hash_implementation_version == 12);
2474 comptime assert(link_hash_implementation_version == 13);
24732475
24742476 if (comp.module) |mod| {
24752477 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });
......@@ -2541,6 +2543,7 @@ fn addNonIncrementalStuffToCacheManifest(
25412543 try man.addOptionalFile(opts.linker_script);
25422544 try man.addOptionalFile(opts.version_script);
25432545 man.hash.add(opts.allow_undefined_version);
2546 man.hash.addOptional(opts.enable_new_dtags);
25442547
25452548 man.hash.addOptional(opts.stack_size);
25462549 man.hash.addOptional(opts.image_base);
src/link.zig+1
......@@ -113,6 +113,7 @@ pub const File = struct {
113113 gc_sections: ?bool,
114114 allow_shlib_undefined: ?bool,
115115 allow_undefined_version: bool,
116 enable_new_dtags: ?bool,
116117 subsystem: ?std.Target.SubSystem,
117118 linker_script: ?[]const u8,
118119 version_script: ?[]const u8,
src/link/Coff/lld.zig+1-1
......@@ -70,7 +70,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
7070 man = comp.cache_parent.obtain();
7171 self.base.releaseLock();
7272
73 comptime assert(Compilation.link_hash_implementation_version == 12);
73 comptime assert(Compilation.link_hash_implementation_version == 13);
7474
7575 for (comp.objects) |obj| {
7676 _ = try man.addFile(obj.path, null);
src/link/Elf.zig+11-1
......@@ -22,6 +22,7 @@ bind_global_refs_locally: bool,
2222linker_script: ?[]const u8,
2323version_script: ?[]const u8,
2424allow_undefined_version: bool,
25enable_new_dtags: ?bool,
2526print_icf_sections: bool,
2627print_map: bool,
2728entry_name: ?[]const u8,
......@@ -330,6 +331,7 @@ pub fn createEmpty(
330331 .linker_script = options.linker_script,
331332 .version_script = options.version_script,
332333 .allow_undefined_version = options.allow_undefined_version,
334 .enable_new_dtags = options.enable_new_dtags,
333335 .print_icf_sections = options.print_icf_sections,
334336 .print_map = options.print_map,
335337 };
......@@ -2170,11 +2172,12 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
21702172 // We are about to obtain this lock, so here we give other processes a chance first.
21712173 self.base.releaseLock();
21722174
2173 comptime assert(Compilation.link_hash_implementation_version == 12);
2175 comptime assert(Compilation.link_hash_implementation_version == 13);
21742176
21752177 try man.addOptionalFile(self.linker_script);
21762178 try man.addOptionalFile(self.version_script);
21772179 man.hash.add(self.allow_undefined_version);
2180 man.hash.addOptional(self.enable_new_dtags);
21782181 for (comp.objects) |obj| {
21792182 _ = try man.addFile(obj.path, null);
21802183 man.hash.add(obj.must_link);
......@@ -2529,6 +2532,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
25292532 } else {
25302533 try argv.append("--no-undefined-version");
25312534 }
2535 if (self.enable_new_dtags) |enable_new_dtags| {
2536 if (enable_new_dtags) {
2537 try argv.append("--enable-new-dtags");
2538 } else {
2539 try argv.append("--disable-new-dtags");
2540 }
2541 }
25322542 }
25332543
25342544 // Positional arguments to the linker such as object files.
src/link/Wasm.zig+1-1
......@@ -3375,7 +3375,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !vo
33753375 // We are about to obtain this lock, so here we give other processes a chance first.
33763376 wasm.base.releaseLock();
33773377
3378 comptime assert(Compilation.link_hash_implementation_version == 12);
3378 comptime assert(Compilation.link_hash_implementation_version == 13);
33793379
33803380 for (comp.objects) |obj| {
33813381 _ = try man.addFile(obj.path, null);
src/main.zig+12
......@@ -496,6 +496,8 @@ const usage_build_generic =
496496 \\ --version-script [path] Provide a version .map file
497497 \\ --undefined-version Allow version scripts to refer to undefined symbols
498498 \\ --no-undefined-version (default) Disallow version scripts from referring to undefined symbols
499 \\ --enable-new-dtags Use the new behavior for dynamic tags (RUNPATH)
500 \\ --disable-new-dtags Use the old behavior for dynamic tags (RPATH)
499501 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
500502 \\ --sysroot [path] Set the system root directory (usually /)
501503 \\ --version [ver] Dynamic library semver
......@@ -824,6 +826,7 @@ fn buildOutputType(
824826 var linker_script: ?[]const u8 = null;
825827 var version_script: ?[]const u8 = null;
826828 var linker_allow_undefined_version: bool = false;
829 var linker_enable_new_dtags: ?bool = null;
827830 var disable_c_depfile = false;
828831 var linker_sort_section: ?link.File.Elf.SortSection = null;
829832 var linker_gc_sections: ?bool = null;
......@@ -1191,6 +1194,10 @@ fn buildOutputType(
11911194 linker_allow_undefined_version = true;
11921195 } else if (mem.eql(u8, arg, "--no-undefined-version")) {
11931196 linker_allow_undefined_version = false;
1197 } else if (mem.eql(u8, arg, "--enable-new-dtags")) {
1198 linker_enable_new_dtags = true;
1199 } else if (mem.eql(u8, arg, "--disable-new-dtags")) {
1200 linker_enable_new_dtags = false;
11941201 } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) {
11951202 // We don't know whether this library is part of libc
11961203 // or libc++ until we resolve the target, so we append
......@@ -2153,6 +2160,10 @@ fn buildOutputType(
21532160 linker_allow_undefined_version = true;
21542161 } else if (mem.eql(u8, arg, "--no-undefined-version")) {
21552162 linker_allow_undefined_version = false;
2163 } else if (mem.eql(u8, arg, "--enable-new-dtags")) {
2164 linker_enable_new_dtags = true;
2165 } else if (mem.eql(u8, arg, "--disable-new-dtags")) {
2166 linker_enable_new_dtags = false;
21562167 } else if (mem.eql(u8, arg, "-O")) {
21572168 linker_optimization = linker_args_it.nextOrFatal();
21582169 } else if (mem.startsWith(u8, arg, "-O")) {
......@@ -3181,6 +3192,7 @@ fn buildOutputType(
31813192 .linker_script = linker_script,
31823193 .version_script = version_script,
31833194 .linker_allow_undefined_version = linker_allow_undefined_version,
3195 .linker_enable_new_dtags = linker_enable_new_dtags,
31843196 .disable_c_depfile = disable_c_depfile,
31853197 .soname = resolved_soname,
31863198 .linker_sort_section = linker_sort_section,