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.
This commit is contained in:
Andrew Kelley 2021-11-24 17:11:37 -07:00
parent fd369bcb0b
commit 7e23b3245a
6 changed files with 9 additions and 17 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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| {

View File

@ -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");

View File

@ -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);

View File

@ -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,