Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3e30c43
create pr with this
DhashS Sep 29, 2023
4b02438
Update src/Compilation.zig
DhashS Sep 30, 2023
e260a2a
make changes suggested by @motiejus
DhashS Sep 30, 2023
ccdb979
Merge branch 'add-no-undefined-version-linker-arg' of github.com:Dhas…
DhashS Sep 30, 2023
9bd334b
push flag thru Compilation and Elf
DhashS Sep 30, 2023
94b5bd8
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Sep 30, 2023
8ff5bb0
woops
DhashS Sep 30, 2023
d7f165c
Merge branch 'add-no-undefined-version-linker-arg' of github.com:Dhas…
DhashS Sep 30, 2023
4451275
more woops
DhashS Sep 30, 2023
3ac80ac
Update src/link.zig
DhashS Sep 30, 2023
719ddf3
Update src/link/Elf.zig
DhashS Sep 30, 2023
4a6271d
Update src/Compilation.zig
DhashS Sep 30, 2023
9672c58
Update src/Compilation.zig
DhashS Sep 30, 2023
d7d2901
remove duplicate
DhashS Sep 30, 2023
a9b7fed
Update src/link/Elf.zig
DhashS Oct 7, 2023
202d9ba
Update src/link.zig
DhashS Oct 7, 2023
b0de657
Update src/main.zig
DhashS Oct 7, 2023
8f37748
Update src/main.zig
DhashS Oct 7, 2023
c7c1382
Update src/main.zig
DhashS Oct 7, 2023
a7b6364
Update src/Compilation.zig
DhashS Oct 7, 2023
bc66160
Update src/Compilation.zig
DhashS Oct 7, 2023
82b28c7
Update src/main.zig
DhashS Oct 7, 2023
2ea0369
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Oct 7, 2023
f40fcb6
modify docstring to be LLD's
DhashS Oct 9, 2023
af85118
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Oct 9, 2023
f86ac25
bump linker implementation version
DhashS Oct 14, 2023
a49a735
Merge branch 'add-no-undefined-version-linker-arg' of github.com:Dhas…
DhashS Oct 14, 2023
c578638
add to cache
DhashS Oct 14, 2023
8aec947
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Oct 15, 2023
682bd7c
Update src/Compilation.zig
DhashS Oct 30, 2023
59ad896
Update src/link/Elf.zig
DhashS Oct 30, 2023
c0df02c
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Oct 30, 2023
84840bb
Merge branch 'master' into add-no-undefined-version-linker-arg
DhashS Nov 2, 2023
fa84a9f
Merge branch 'master' into add-no-undefined-version-linker-arg
behos Dec 11, 2023
922dfe9
Run zig fmt for updated files
behos Dec 11, 2023
2e9b3b6
Fix handling of `--(no-)undefined-version` option
castholm Dec 15, 2023
8c7a940
Expose `--(no-)undefined-version` to the build system
castholm Dec 15, 2023
092b8d0
Merge pull request #1 from castholm/add-no-undefined-version-linker-arg
behos Dec 16, 2023
729b76f
Merge branch 'master' into add-no-undefined-version-linker-arg
behos Dec 18, 2023
8287e5a
Merge branch 'master' into add-no-undefined-version-linker-arg
behos Jan 3, 2024
db21d79
Merge branch 'master' into add-no-undefined-version-linker-arg
behos Jan 4, 2024
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
6 changes: 6 additions & 0 deletions lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ linker_dynamicbase: bool = true,

linker_allow_shlib_undefined: ?bool = null,

/// Allow unused version in version script (disabled by default)
linker_allow_undefined_version: ?bool = null,

/// Permit read-only relocations in read-only segments. Disallowed by default.
link_z_notext: bool = false,

Expand Down Expand Up @@ -1323,6 +1326,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
if (self.linker_allow_shlib_undefined) |x| {
try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");
}
if (self.linker_allow_undefined_version) |x| {
try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version");
}
if (self.link_z_notext) {
try zig_args.append("-z");
try zig_args.append("notext");
Expand Down
7 changes: 5 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ pub const CreateOptions = struct {
linker_script: ?[]const u8 = null,
version_script: ?[]const u8 = null,
soname: ?[]const u8 = null,
linker_allow_undefined_version: ?bool = null,
linker_gc_sections: ?bool = null,
linker_allow_shlib_undefined: ?bool = null,
linker_bind_global_refs_locally: ?bool = null,
Expand Down Expand Up @@ -1560,6 +1561,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.max_memory = options.linker_max_memory,
.global_base = options.linker_global_base,
.export_symbol_names = options.linker_export_symbol_names,
.allow_undefined_version = options.linker_allow_undefined_version,
.print_gc_sections = options.linker_print_gc_sections,
.print_icf_sections = options.linker_print_icf_sections,
.print_map = options.linker_print_map,
Expand Down Expand Up @@ -2459,7 +2461,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,
Expand All @@ -2468,7 +2470,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);
Expand Down Expand Up @@ -2564,6 +2566,7 @@ fn addNonIncrementalStuffToCacheManifest(
man.hash.addOptionalBytes(target.dynamic_linker.get());
}
man.hash.addOptional(opts.allow_shlib_undefined);
man.hash.addOptional(opts.allow_undefined_version);
man.hash.add(opts.bind_global_refs_locally);

// ELF specific stuff
Expand Down
2 changes: 2 additions & 0 deletions src/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub const File = struct {
allow_shlib_undefined: bool,
stack_size: u64,

allow_undefined_version: bool = false,
/// Prevents other processes from clobbering files in the output directory
/// of this linking operation.
lock: ?Cache.Lock = null,
Expand Down Expand Up @@ -113,6 +114,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,
Expand Down
2 changes: 1 addition & 1 deletion src/link/Coff/lld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ 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);
Expand Down Expand Up @@ -2468,6 +2468,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
try link.hashAddSystemLibs(&man, comp.system_libs);
man.hash.addListOfBytes(comp.force_undefined_symbols.keys());
man.hash.add(self.base.allow_shlib_undefined);
man.hash.add(self.base.allow_undefined_version);
man.hash.add(self.bind_global_refs_locally);
man.hash.add(self.compress_debug_sections);
man.hash.add(comp.config.any_sanitize_thread);
Expand Down Expand Up @@ -2611,6 +2612,12 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
try argv.append(arg);
}

if (self.base.allow_undefined_version) {
try argv.append("--undefined-version");
} else {
try argv.append("--no-undefined-version");
}

if (self.base.gc_sections) {
try argv.append("--gc-sections");
}
Expand Down Expand Up @@ -2925,6 +2932,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node) !voi
try argv.append("--allow-shlib-undefined");
}

if (self.base.allow_undefined_version) {
try argv.append("--allow-undefined-version");
}

switch (self.compress_debug_sections) {
.none => {},
.zlib => try argv.append("--compress-debug-sections=zlib"),
Expand Down
2 changes: 1 addition & 1 deletion src/link/MachO/zld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/link/Wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 unused version in version script (disabled by default)
\\ --no-undefined-version Makes unused version in version script a fatal error
\\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
\\ --sysroot [path] Set the system root directory (usually /)
\\ --version [ver] Dynamic library semver
Expand Down Expand Up @@ -828,6 +830,7 @@ fn buildOutputType(
var version_script: ?[]const u8 = null;
var disable_c_depfile = false;
var linker_sort_section: ?link.File.Elf.SortSection = null;
var linker_allow_undefined_version: ?bool = null;
var linker_gc_sections: ?bool = null;
var linker_compress_debug_sections: ?link.File.Elf.CompressDebugSections = null;
var linker_allow_shlib_undefined: ?bool = null;
Expand Down Expand Up @@ -1525,6 +1528,10 @@ fn buildOutputType(
linker_allow_shlib_undefined = true;
} else if (mem.eql(u8, arg, "-fno-allow-shlib-undefined")) {
linker_allow_shlib_undefined = false;
} 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, "-z")) {
const z_arg = args_iter.nextOrFatal();
if (mem.eql(u8, z_arg, "nodelete")) {
Expand Down Expand Up @@ -2437,6 +2444,10 @@ fn buildOutputType(
fatal("unable to parse /version '{s}': {s}", .{ arg, @errorName(err) });
};
have_version = true;
} 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, "--version")) {
try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
process.exit(0);
Expand Down Expand Up @@ -3168,6 +3179,7 @@ fn buildOutputType(
.version_script = version_script,
.disable_c_depfile = disable_c_depfile,
.soname = resolved_soname,
.linker_allow_undefined_version = linker_allow_undefined_version,
.linker_sort_section = linker_sort_section,
.linker_gc_sections = linker_gc_sections,
.linker_allow_shlib_undefined = linker_allow_shlib_undefined,
Expand Down