diff options
| author | dhash <me@dha.sh> | 2023-09-29 13:38:54 -0400 |
|---|---|---|
| committer | Carl Åstholm <carl@astholm.se> | 2024-01-09 17:24:11 +0100 |
| commit | 9bb643031864c8c3c2d4ac52aecb175283e335e3 (patch) | |
| tree | 20e8fa8787aa7e29e9771edff9d20f8a404ea70b /src | |
| parent | 60094cc3fc979df0928c412c9fded457172f2060 (diff) | |
| download | zig-9bb643031864c8c3c2d4ac52aecb175283e335e3.tar.gz zig-9bb643031864c8c3c2d4ac52aecb175283e335e3.zip | |
Add support for `--(no-)undefined-version`
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Samuel Cantero <scanterog@gmail.com>
Co-authored-by: Giorgos Georgiou <giorgos.georgiou@datadoghq.com>
Co-authored-by: Carl Åstholm <carl@astholm.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 7 | ||||
| -rw-r--r-- | src/link.zig | 1 | ||||
| -rw-r--r-- | src/link/Coff/lld.zig | 2 | ||||
| -rw-r--r-- | src/link/Elf.zig | 10 | ||||
| -rw-r--r-- | src/link/MachO/zld.zig | 2 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 4 | ||||
| -rw-r--r-- | src/main.zig | 12 |
7 files changed, 31 insertions, 7 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index ccd64ca9b3..9dd45d8ced 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1033,6 +1033,7 @@ pub const CreateOptions = struct { link_emit_relocs: bool = false, linker_script: ?[]const u8 = null, version_script: ?[]const u8 = null, + linker_allow_undefined_version: bool = false, soname: ?[]const u8 = null, linker_gc_sections: ?bool = null, linker_allow_shlib_undefined: ?bool = null, @@ -1572,6 +1573,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .stack_size = options.stack_size, .image_base = options.image_base, .version_script = options.version_script, + .allow_undefined_version = options.linker_allow_undefined_version, .gc_sections = options.linker_gc_sections, .emit_relocs = options.link_emit_relocs, .soname = options.soname, @@ -2458,7 +2460,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo /// to remind the programmer to update multiple related pieces of code that /// are in different locations. Bump this number when adding or deleting /// anything from the link cache manifest. -pub const link_hash_implementation_version = 10; +pub const link_hash_implementation_version = 11; fn addNonIncrementalStuffToCacheManifest( comp: *Compilation, @@ -2467,7 +2469,7 @@ fn addNonIncrementalStuffToCacheManifest( ) !void { const gpa = comp.gpa; - comptime assert(link_hash_implementation_version == 10); + comptime assert(link_hash_implementation_version == 11); if (comp.module) |mod| { const main_zig_file = try mod.main_mod.root.joinString(arena, mod.main_mod.root_src_path); @@ -2541,6 +2543,7 @@ fn addNonIncrementalStuffToCacheManifest( try man.addOptionalFile(opts.linker_script); try man.addOptionalFile(opts.version_script); + man.hash.add(opts.allow_undefined_version); man.hash.addOptional(opts.stack_size); man.hash.addOptional(opts.image_base); diff --git a/src/link.zig b/src/link.zig index 5c296b49ab..e4c46a8af9 100644 --- a/src/link.zig +++ b/src/link.zig @@ -113,6 +113,7 @@ pub const File = struct { minor_subsystem_version: ?u16, gc_sections: ?bool, allow_shlib_undefined: ?bool, + allow_undefined_version: bool, subsystem: ?std.Target.SubSystem, linker_script: ?[]const u8, version_script: ?[]const u8, diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig index 1115b91a57..6b9054b2b4 100644 --- a/src/link/Coff/lld.zig +++ b/src/link/Coff/lld.zig @@ -70,7 +70,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) man = comp.cache_parent.obtain(); self.base.releaseLock(); - comptime assert(Compilation.link_hash_implementation_version == 10); + comptime assert(Compilation.link_hash_implementation_version == 11); for (comp.objects) |obj| { _ = try man.addFile(obj.path, null); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 2f1d5703f9..ef06c8e1dd 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -22,6 +22,7 @@ soname: ?[]const u8, bind_global_refs_locally: bool, linker_script: ?[]const u8, version_script: ?[]const u8, +allow_undefined_version: bool, print_icf_sections: bool, print_map: bool, entry_name: ?[]const u8, @@ -325,6 +326,7 @@ pub fn createEmpty( .bind_global_refs_locally = options.bind_global_refs_locally, .linker_script = options.linker_script, .version_script = options.version_script, + .allow_undefined_version = options.allow_undefined_version, .print_icf_sections = options.print_icf_sections, .print_map = options.print_map, }; @@ -2410,10 +2412,11 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi // We are about to obtain this lock, so here we give other processes a chance first. self.base.releaseLock(); - comptime assert(Compilation.link_hash_implementation_version == 10); + comptime assert(Compilation.link_hash_implementation_version == 11); try man.addOptionalFile(self.linker_script); try man.addOptionalFile(self.version_script); + man.hash.add(self.allow_undefined_version); for (comp.objects) |obj| { _ = try man.addFile(obj.path, null); man.hash.add(obj.must_link); @@ -2789,6 +2792,11 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi try argv.append("-version-script"); try argv.append(version_script); } + if (self.allow_undefined_version) { + try argv.append("--undefined-version"); + } else { + try argv.append("--no-undefined-version"); + } } // Positional arguments to the linker such as object files. diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index b266bfeb47..57681dd935 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -55,7 +55,7 @@ pub fn linkWithZld( // We are about to obtain this lock, so here we give other processes a chance first. macho_file.base.releaseLock(); - comptime assert(Compilation.link_hash_implementation_version == 10); + comptime assert(Compilation.link_hash_implementation_version == 11); for (objects) |obj| { _ = try man.addFile(obj.path, null); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 185d802588..9dbef32648 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -3547,7 +3547,7 @@ fn linkWithZld(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) lin // We are about to obtain this lock, so here we give other processes a chance first. wasm.base.releaseLock(); - comptime assert(Compilation.link_hash_implementation_version == 10); + comptime assert(Compilation.link_hash_implementation_version == 11); for (objects) |obj| { _ = try man.addFile(obj.path, null); @@ -4633,7 +4633,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, prog_node: *std.Progress.Node) !vo // We are about to obtain this lock, so here we give other processes a chance first. wasm.base.releaseLock(); - comptime assert(Compilation.link_hash_implementation_version == 10); + comptime assert(Compilation.link_hash_implementation_version == 11); for (comp.objects) |obj| { _ = try man.addFile(obj.path, null); diff --git a/src/main.zig b/src/main.zig index 4442234bd2..5dbb4a0cf7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -500,6 +500,8 @@ const usage_build_generic = \\Global Link Options: \\ -T[script], --script [script] Use a custom linker script \\ --version-script [path] Provide a version .map file + \\ --undefined-version Allow version scripts to refer to undefined symbols + \\ --no-undefined-version (default) Disallow version scripts from referring to undefined symbols \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so) \\ --sysroot [path] Set the system root directory (usually /) \\ --version [ver] Dynamic library semver @@ -826,6 +828,7 @@ fn buildOutputType( var want_compiler_rt: ?bool = null; var linker_script: ?[]const u8 = null; var version_script: ?[]const u8 = null; + var linker_allow_undefined_version: bool = false; var disable_c_depfile = false; var linker_sort_section: ?link.File.Elf.SortSection = null; var linker_gc_sections: ?bool = null; @@ -1200,6 +1203,10 @@ fn buildOutputType( linker_script = args_iter.nextOrFatal(); } else if (mem.eql(u8, arg, "-version-script") or mem.eql(u8, arg, "--version-script")) { version_script = args_iter.nextOrFatal(); + } else if (mem.eql(u8, arg, "--undefined-version")) { + linker_allow_undefined_version = true; + } else if (mem.eql(u8, arg, "--no-undefined-version")) { + linker_allow_undefined_version = false; } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) { // We don't know whether this library is part of libc // or libc++ until we resolve the target, so we append @@ -2153,6 +2160,10 @@ fn buildOutputType( create_module.opts.rdynamic = true; } else if (mem.eql(u8, arg, "-version-script") or mem.eql(u8, arg, "--version-script")) { version_script = linker_args_it.nextOrFatal(); + } else if (mem.eql(u8, arg, "--undefined-version")) { + linker_allow_undefined_version = true; + } else if (mem.eql(u8, arg, "--no-undefined-version")) { + linker_allow_undefined_version = false; } else if (mem.eql(u8, arg, "-O")) { linker_optimization = linker_args_it.nextOrFatal(); } else if (mem.startsWith(u8, arg, "-O")) { @@ -3166,6 +3177,7 @@ fn buildOutputType( .hash_style = hash_style, .linker_script = linker_script, .version_script = version_script, + .linker_allow_undefined_version = linker_allow_undefined_version, .disable_c_depfile = disable_c_depfile, .soname = resolved_soname, .linker_sort_section = linker_sort_section, |
