From 7e23b3245a9bf6e002009e6c18c10a9995671afa Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 24 Nov 2021 17:11:37 -0700 Subject: [PATCH] stage2: remove extra_lld_args This mechanism for sending arbitrary linker args to LLD has no place in the Zig frontend, because our goal is for the frontend to understand all the arguments and not treat linker args like a black box. For example we have self-hosted linking in addition to LLD, so we want to have the options make sense to both linking codepaths, not just the LLD one. Passing -O linker args will now result in a warning that the arg does nothing. --- src/Compilation.zig | 3 --- src/link.zig | 2 -- src/link/Coff.zig | 3 --- src/link/Elf.zig | 3 --- src/link/Wasm.zig | 1 - src/main.zig | 14 +++++++++----- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 61533eebb0f4b4e6234c0dd54a2a3e80ed142601..c84fd2c96d4a365c2035a1dda34e1b4da06d2211 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -667,7 +667,6 @@ pub const InitOptions = struct { optimize_mode: std.builtin.Mode = .Debug, keep_source_files_loaded: bool = false, clang_argv: []const []const u8 = &[0][]const u8{}, - lld_argv: []const []const u8 = &[0][]const u8{}, lib_dirs: []const []const u8 = &[0][]const u8{}, rpath_list: []const []const u8 = &[0][]const u8{}, c_source_files: []const CSourceFile = &[0]CSourceFile{}, @@ -946,7 +945,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { link_eh_frame_hdr or options.link_emit_relocs or options.output_mode == .Lib or - options.lld_argv.len != 0 or options.image_base_override != null or options.linker_script != null or options.version_script != null or options.out_implib != null) @@ -1440,7 +1438,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .eh_frame_hdr = link_eh_frame_hdr, .emit_relocs = options.link_emit_relocs, .rdynamic = options.rdynamic, - .extra_lld_args = options.lld_argv, .soname = options.soname, .version = options.version, .compatibility_version = options.compatibility_version, diff --git a/src/link.zig b/src/link.zig index 76f50a78fe352279b552faff45ec447db1586cf3..f00d7809f4e13198fa1677049ba50e775c30d0ba 100644 --- a/src/link.zig +++ b/src/link.zig @@ -132,8 +132,6 @@ pub const Options = struct { version_script: ?[]const u8, soname: ?[]const u8, llvm_cpu_features: ?[*:0]const u8, - /// Extra args passed directly to LLD. Ignored when not linking with LLD. - extra_lld_args: []const []const u8, objects: []const []const u8, framework_dirs: []const []const u8, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index c9feebe7a21358002b44d16813f31d158a19b563..19a99a2e329e6f1a0e85ee18803fbd9aa18bf92d 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -927,7 +927,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { try man.addOptionalFile(module_obj_path); man.hash.addOptional(self.base.options.stack_size_override); man.hash.addOptional(self.base.options.image_base_override); - man.hash.addListOfBytes(self.base.options.extra_lld_args); man.hash.addListOfBytes(self.base.options.lib_dirs); man.hash.add(self.base.options.skip_linker_dependencies); if (self.base.options.link_libc) { @@ -1058,8 +1057,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { try argv.append("-dynamicbase"); } - try argv.appendSlice(self.base.options.extra_lld_args); - const subsystem_suffix = ss: { if (self.base.options.major_subsystem_version) |major| { if (self.base.options.minor_subsystem_version) |minor| { diff --git a/src/link/Elf.zig b/src/link/Elf.zig index cc7d5ba0e5f0665de74aabacaaa4e1face1630de..43447e0ec4ff95cdc105e802c18b3725fbee6765 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1322,7 +1322,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { man.hash.add(self.base.options.eh_frame_hdr); man.hash.add(self.base.options.emit_relocs); man.hash.add(self.base.options.rdynamic); - man.hash.addListOfBytes(self.base.options.extra_lld_args); man.hash.addListOfBytes(self.base.options.lib_dirs); man.hash.addListOfBytes(self.base.options.rpath_list); man.hash.add(self.base.options.each_lib_rpath); @@ -1461,8 +1460,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { try argv.append("--export-dynamic"); } - try argv.appendSlice(self.base.options.extra_lld_args); - if (self.base.options.z_nodelete) { try argv.append("-z"); try argv.append("nodelete"); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index cf05fcd94a68c3b39cdc419f58e417e05b7685a7..fd6e042f9a30b59421852f1dfbf778068996b3fb 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -714,7 +714,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { try man.addOptionalFile(module_obj_path); try man.addOptionalFile(compiler_rt_path); man.hash.addOptional(self.base.options.stack_size_override); - man.hash.addListOfBytes(self.base.options.extra_lld_args); man.hash.add(self.base.options.import_memory); man.hash.addOptional(self.base.options.initial_memory); man.hash.addOptional(self.base.options.max_memory); diff --git a/src/main.zig b/src/main.zig index 4900743677b53be4913a111e5364f1fe39237d15..7d8b9b1265c0069360267d4bfd22efc51b7944a2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -672,9 +672,6 @@ fn buildOutputType( var extra_cflags = std.ArrayList([]const u8).init(gpa); defer extra_cflags.deinit(); - var lld_argv = std.ArrayList([]const u8).init(gpa); - defer lld_argv.deinit(); - var lib_dirs = std.ArrayList([]const u8).init(gpa); defer lib_dirs.deinit(); @@ -1474,8 +1471,16 @@ fn buildOutputType( fatal("expected linker arg after '{s}'", .{arg}); } version_script = linker_args.items[i]; + } else if (mem.eql(u8, arg, "-O")) { + i += 1; + if (i >= linker_args.items.len) { + fatal("expected linker arg after '{s}'", .{arg}); + } + warn("ignoring linker arg -O{s} because it does nothing", .{ + linker_args.items[i], + }); } else if (mem.startsWith(u8, arg, "-O")) { - try lld_argv.append(arg); + warn("ignoring linker arg {s} because it does nothing", .{arg}); } else if (mem.eql(u8, arg, "--gc-sections")) { linker_gc_sections = true; } else if (mem.eql(u8, arg, "--no-gc-sections")) { @@ -2200,7 +2205,6 @@ fn buildOutputType( .optimize_mode = optimize_mode, .keep_source_files_loaded = false, .clang_argv = clang_argv.items, - .lld_argv = lld_argv.items, .lib_dirs = lib_dirs.items, .rpath_list = rpath_list.items, .c_source_files = c_source_files.items, -- 2.54.0