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,...@@ -113,6 +113,9 @@ linker_allow_shlib_undefined: ?bool = null,
113/// Allow version scripts to refer to undefined symbols.113/// Allow version scripts to refer to undefined symbols.
114linker_allow_undefined_version: ?bool = null,114linker_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
116/// Permit read-only relocations in read-only segments. Disallowed by default.119/// Permit read-only relocations in read-only segments. Disallowed by default.
117link_z_notext: bool = false,120link_z_notext: bool = false,
118121
...@@ -1490,6 +1493,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1490,6 +1493,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1490 try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version");1493 try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version");
1491 }1494 }
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
1493 if (self.kind == .@"test") {1500 if (self.kind == .@"test") {
1494 if (self.exec_cmd_args) |exec_cmd_args| {1501 if (self.exec_cmd_args) |exec_cmd_args| {
1495 for (exec_cmd_args) |cmd_arg| {1502 for (exec_cmd_args) |cmd_arg| {
src/Compilation.zig+5-2
...@@ -1034,6 +1034,7 @@ pub const CreateOptions = struct {...@@ -1034,6 +1034,7 @@ pub const CreateOptions = struct {
1034 linker_script: ?[]const u8 = null,1034 linker_script: ?[]const u8 = null,
1035 version_script: ?[]const u8 = null,1035 version_script: ?[]const u8 = null,
1036 linker_allow_undefined_version: bool = false,1036 linker_allow_undefined_version: bool = false,
1037 linker_enable_new_dtags: ?bool = null,
1037 soname: ?[]const u8 = null,1038 soname: ?[]const u8 = null,
1038 linker_gc_sections: ?bool = null,1039 linker_gc_sections: ?bool = null,
1039 linker_allow_shlib_undefined: ?bool = null,1040 linker_allow_shlib_undefined: ?bool = null,
...@@ -1581,6 +1582,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1581,6 +1582,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1581 .image_base = options.image_base,1582 .image_base = options.image_base,
1582 .version_script = options.version_script,1583 .version_script = options.version_script,
1583 .allow_undefined_version = options.linker_allow_undefined_version,1584 .allow_undefined_version = options.linker_allow_undefined_version,
1585 .enable_new_dtags = options.linker_enable_new_dtags,
1584 .gc_sections = options.linker_gc_sections,1586 .gc_sections = options.linker_gc_sections,
1585 .emit_relocs = options.link_emit_relocs,1587 .emit_relocs = options.link_emit_relocs,
1586 .soname = options.soname,1588 .soname = options.soname,
...@@ -2460,7 +2462,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo...@@ -2460,7 +2462,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo
2460/// to remind the programmer to update multiple related pieces of code that2462/// to remind the programmer to update multiple related pieces of code that
2461/// are in different locations. Bump this number when adding or deleting2463/// are in different locations. Bump this number when adding or deleting
2462/// anything from the link cache manifest.2464/// anything from the link cache manifest.
2463pub const link_hash_implementation_version = 12;2465pub const link_hash_implementation_version = 13;
24642466
2465fn addNonIncrementalStuffToCacheManifest(2467fn addNonIncrementalStuffToCacheManifest(
2466 comp: *Compilation,2468 comp: *Compilation,
...@@ -2469,7 +2471,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -2469,7 +2471,7 @@ fn addNonIncrementalStuffToCacheManifest(
2469) !void {2471) !void {
2470 const gpa = comp.gpa;2472 const gpa = comp.gpa;
24712473
2472 comptime assert(link_hash_implementation_version == 12);2474 comptime assert(link_hash_implementation_version == 13);
24732475
2474 if (comp.module) |mod| {2476 if (comp.module) |mod| {
2475 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });2477 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });
...@@ -2541,6 +2543,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -2541,6 +2543,7 @@ fn addNonIncrementalStuffToCacheManifest(
2541 try man.addOptionalFile(opts.linker_script);2543 try man.addOptionalFile(opts.linker_script);
2542 try man.addOptionalFile(opts.version_script);2544 try man.addOptionalFile(opts.version_script);
2543 man.hash.add(opts.allow_undefined_version);2545 man.hash.add(opts.allow_undefined_version);
2546 man.hash.addOptional(opts.enable_new_dtags);
25442547
2545 man.hash.addOptional(opts.stack_size);2548 man.hash.addOptional(opts.stack_size);
2546 man.hash.addOptional(opts.image_base);2549 man.hash.addOptional(opts.image_base);
src/link.zig+1
...@@ -113,6 +113,7 @@ pub const File = struct {...@@ -113,6 +113,7 @@ pub const File = struct {
113 gc_sections: ?bool,113 gc_sections: ?bool,
114 allow_shlib_undefined: ?bool,114 allow_shlib_undefined: ?bool,
115 allow_undefined_version: bool,115 allow_undefined_version: bool,
116 enable_new_dtags: ?bool,
116 subsystem: ?std.Target.SubSystem,117 subsystem: ?std.Target.SubSystem,
117 linker_script: ?[]const u8,118 linker_script: ?[]const u8,
118 version_script: ?[]const u8,119 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)...@@ -70,7 +70,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
70 man = comp.cache_parent.obtain();70 man = comp.cache_parent.obtain();
71 self.base.releaseLock();71 self.base.releaseLock();
7272
73 comptime assert(Compilation.link_hash_implementation_version == 12);73 comptime assert(Compilation.link_hash_implementation_version == 13);
7474
75 for (comp.objects) |obj| {75 for (comp.objects) |obj| {
76 _ = try man.addFile(obj.path, null);76 _ = try man.addFile(obj.path, null);
src/link/Elf.zig+11-1
...@@ -22,6 +22,7 @@ bind_global_refs_locally: bool,...@@ -22,6 +22,7 @@ bind_global_refs_locally: bool,
22linker_script: ?[]const u8,22linker_script: ?[]const u8,
23version_script: ?[]const u8,23version_script: ?[]const u8,
24allow_undefined_version: bool,24allow_undefined_version: bool,
25enable_new_dtags: ?bool,
25print_icf_sections: bool,26print_icf_sections: bool,
26print_map: bool,27print_map: bool,
27entry_name: ?[]const u8,28entry_name: ?[]const u8,
...@@ -330,6 +331,7 @@ pub fn createEmpty(...@@ -330,6 +331,7 @@ pub fn createEmpty(
330 .linker_script = options.linker_script,331 .linker_script = options.linker_script,
331 .version_script = options.version_script,332 .version_script = options.version_script,
332 .allow_undefined_version = options.allow_undefined_version,333 .allow_undefined_version = options.allow_undefined_version,
334 .enable_new_dtags = options.enable_new_dtags,
333 .print_icf_sections = options.print_icf_sections,335 .print_icf_sections = options.print_icf_sections,
334 .print_map = options.print_map,336 .print_map = options.print_map,
335 };337 };
...@@ -2170,11 +2172,12 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi...@@ -2170,11 +2172,12 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
2170 // We are about to obtain this lock, so here we give other processes a chance first.2172 // We are about to obtain this lock, so here we give other processes a chance first.
2171 self.base.releaseLock();2173 self.base.releaseLock();
21722174
2173 comptime assert(Compilation.link_hash_implementation_version == 12);2175 comptime assert(Compilation.link_hash_implementation_version == 13);
21742176
2175 try man.addOptionalFile(self.linker_script);2177 try man.addOptionalFile(self.linker_script);
2176 try man.addOptionalFile(self.version_script);2178 try man.addOptionalFile(self.version_script);
2177 man.hash.add(self.allow_undefined_version);2179 man.hash.add(self.allow_undefined_version);
2180 man.hash.addOptional(self.enable_new_dtags);
2178 for (comp.objects) |obj| {2181 for (comp.objects) |obj| {
2179 _ = try man.addFile(obj.path, null);2182 _ = try man.addFile(obj.path, null);
2180 man.hash.add(obj.must_link);2183 man.hash.add(obj.must_link);
...@@ -2529,6 +2532,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi...@@ -2529,6 +2532,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
2529 } else {2532 } else {
2530 try argv.append("--no-undefined-version");2533 try argv.append("--no-undefined-version");
2531 }2534 }
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 }
2532 }2542 }
25332543
2534 // Positional arguments to the linker such as object files.2544 // 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...@@ -3375,7 +3375,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !vo
3375 // We are about to obtain this lock, so here we give other processes a chance first.3375 // We are about to obtain this lock, so here we give other processes a chance first.
3376 wasm.base.releaseLock();3376 wasm.base.releaseLock();
33773377
3378 comptime assert(Compilation.link_hash_implementation_version == 12);3378 comptime assert(Compilation.link_hash_implementation_version == 13);
33793379
3380 for (comp.objects) |obj| {3380 for (comp.objects) |obj| {
3381 _ = try man.addFile(obj.path, null);3381 _ = try man.addFile(obj.path, null);
src/main.zig+12
...@@ -496,6 +496,8 @@ const usage_build_generic =...@@ -496,6 +496,8 @@ const usage_build_generic =
496 \\ --version-script [path] Provide a version .map file496 \\ --version-script [path] Provide a version .map file
497 \\ --undefined-version Allow version scripts to refer to undefined symbols497 \\ --undefined-version Allow version scripts to refer to undefined symbols
498 \\ --no-undefined-version (default) Disallow version scripts from referring to undefined symbols498 \\ --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)
499 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)501 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
500 \\ --sysroot [path] Set the system root directory (usually /)502 \\ --sysroot [path] Set the system root directory (usually /)
501 \\ --version [ver] Dynamic library semver503 \\ --version [ver] Dynamic library semver
...@@ -824,6 +826,7 @@ fn buildOutputType(...@@ -824,6 +826,7 @@ fn buildOutputType(
824 var linker_script: ?[]const u8 = null;826 var linker_script: ?[]const u8 = null;
825 var version_script: ?[]const u8 = null;827 var version_script: ?[]const u8 = null;
826 var linker_allow_undefined_version: bool = false;828 var linker_allow_undefined_version: bool = false;
829 var linker_enable_new_dtags: ?bool = null;
827 var disable_c_depfile = false;830 var disable_c_depfile = false;
828 var linker_sort_section: ?link.File.Elf.SortSection = null;831 var linker_sort_section: ?link.File.Elf.SortSection = null;
829 var linker_gc_sections: ?bool = null;832 var linker_gc_sections: ?bool = null;
...@@ -1191,6 +1194,10 @@ fn buildOutputType(...@@ -1191,6 +1194,10 @@ fn buildOutputType(
1191 linker_allow_undefined_version = true;1194 linker_allow_undefined_version = true;
1192 } else if (mem.eql(u8, arg, "--no-undefined-version")) {1195 } else if (mem.eql(u8, arg, "--no-undefined-version")) {
1193 linker_allow_undefined_version = false;1196 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;
1194 } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) {1201 } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) {
1195 // We don't know whether this library is part of libc1202 // We don't know whether this library is part of libc
1196 // or libc++ until we resolve the target, so we append1203 // or libc++ until we resolve the target, so we append
...@@ -2153,6 +2160,10 @@ fn buildOutputType(...@@ -2153,6 +2160,10 @@ fn buildOutputType(
2153 linker_allow_undefined_version = true;2160 linker_allow_undefined_version = true;
2154 } else if (mem.eql(u8, arg, "--no-undefined-version")) {2161 } else if (mem.eql(u8, arg, "--no-undefined-version")) {
2155 linker_allow_undefined_version = false;2162 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;
2156 } else if (mem.eql(u8, arg, "-O")) {2167 } else if (mem.eql(u8, arg, "-O")) {
2157 linker_optimization = linker_args_it.nextOrFatal();2168 linker_optimization = linker_args_it.nextOrFatal();
2158 } else if (mem.startsWith(u8, arg, "-O")) {2169 } else if (mem.startsWith(u8, arg, "-O")) {
...@@ -3181,6 +3192,7 @@ fn buildOutputType(...@@ -3181,6 +3192,7 @@ fn buildOutputType(
3181 .linker_script = linker_script,3192 .linker_script = linker_script,
3182 .version_script = version_script,3193 .version_script = version_script,
3183 .linker_allow_undefined_version = linker_allow_undefined_version,3194 .linker_allow_undefined_version = linker_allow_undefined_version,
3195 .linker_enable_new_dtags = linker_enable_new_dtags,
3184 .disable_c_depfile = disable_c_depfile,3196 .disable_c_depfile = disable_c_depfile,
3185 .soname = resolved_soname,3197 .soname = resolved_soname,
3186 .linker_sort_section = linker_sort_section,3198 .linker_sort_section = linker_sort_section,