authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-24 17:11:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-24 17:14:20-07:00
log7e23b3245a9bf6e002009e6c18c10a9995671afa
tree484a5787656936680e39f2d59c4af6fc0b955644
parentfd369bcb0b67bde0072f1549be2fd0b34014703f

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.

6 files changed, 9 insertions(+), 17 deletions(-)

src/Compilation.zig-3
......@@ -667,7 +667,6 @@ pub const InitOptions = struct {
667667 optimize_mode: std.builtin.Mode = .Debug,
668668 keep_source_files_loaded: bool = false,
669669 clang_argv: []const []const u8 = &[0][]const u8{},
670 lld_argv: []const []const u8 = &[0][]const u8{},
671670 lib_dirs: []const []const u8 = &[0][]const u8{},
672671 rpath_list: []const []const u8 = &[0][]const u8{},
673672 c_source_files: []const CSourceFile = &[0]CSourceFile{},
......@@ -946,7 +945,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
946945 link_eh_frame_hdr or
947946 options.link_emit_relocs or
948947 options.output_mode == .Lib or
949 options.lld_argv.len != 0 or
950948 options.image_base_override != null or
951949 options.linker_script != null or options.version_script != null or
952950 options.out_implib != null)
......@@ -1440,7 +1438,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14401438 .eh_frame_hdr = link_eh_frame_hdr,
14411439 .emit_relocs = options.link_emit_relocs,
14421440 .rdynamic = options.rdynamic,
1443 .extra_lld_args = options.lld_argv,
14441441 .soname = options.soname,
14451442 .version = options.version,
14461443 .compatibility_version = options.compatibility_version,
src/link.zig-2
......@@ -132,8 +132,6 @@ pub const Options = struct {
132132 version_script: ?[]const u8,
133133 soname: ?[]const u8,
134134 llvm_cpu_features: ?[*:0]const u8,
135 /// Extra args passed directly to LLD. Ignored when not linking with LLD.
136 extra_lld_args: []const []const u8,
137135
138136 objects: []const []const u8,
139137 framework_dirs: []const []const u8,
src/link/Coff.zig-3
......@@ -927,7 +927,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
927927 try man.addOptionalFile(module_obj_path);
928928 man.hash.addOptional(self.base.options.stack_size_override);
929929 man.hash.addOptional(self.base.options.image_base_override);
930 man.hash.addListOfBytes(self.base.options.extra_lld_args);
931930 man.hash.addListOfBytes(self.base.options.lib_dirs);
932931 man.hash.add(self.base.options.skip_linker_dependencies);
933932 if (self.base.options.link_libc) {
......@@ -1058,8 +1057,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
10581057 try argv.append("-dynamicbase");
10591058 }
10601059
1061 try argv.appendSlice(self.base.options.extra_lld_args);
1062
10631060 const subsystem_suffix = ss: {
10641061 if (self.base.options.major_subsystem_version) |major| {
10651062 if (self.base.options.minor_subsystem_version) |minor| {
src/link/Elf.zig-3
......@@ -1322,7 +1322,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13221322 man.hash.add(self.base.options.eh_frame_hdr);
13231323 man.hash.add(self.base.options.emit_relocs);
13241324 man.hash.add(self.base.options.rdynamic);
1325 man.hash.addListOfBytes(self.base.options.extra_lld_args);
13261325 man.hash.addListOfBytes(self.base.options.lib_dirs);
13271326 man.hash.addListOfBytes(self.base.options.rpath_list);
13281327 man.hash.add(self.base.options.each_lib_rpath);
......@@ -1461,8 +1460,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
14611460 try argv.append("--export-dynamic");
14621461 }
14631462
1464 try argv.appendSlice(self.base.options.extra_lld_args);
1465
14661463 if (self.base.options.z_nodelete) {
14671464 try argv.append("-z");
14681465 try argv.append("nodelete");
src/link/Wasm.zig-1
......@@ -714,7 +714,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
714714 try man.addOptionalFile(module_obj_path);
715715 try man.addOptionalFile(compiler_rt_path);
716716 man.hash.addOptional(self.base.options.stack_size_override);
717 man.hash.addListOfBytes(self.base.options.extra_lld_args);
718717 man.hash.add(self.base.options.import_memory);
719718 man.hash.addOptional(self.base.options.initial_memory);
720719 man.hash.addOptional(self.base.options.max_memory);
src/main.zig+9-5
......@@ -672,9 +672,6 @@ fn buildOutputType(
672672 var extra_cflags = std.ArrayList([]const u8).init(gpa);
673673 defer extra_cflags.deinit();
674674
675 var lld_argv = std.ArrayList([]const u8).init(gpa);
676 defer lld_argv.deinit();
677
678675 var lib_dirs = std.ArrayList([]const u8).init(gpa);
679676 defer lib_dirs.deinit();
680677
......@@ -1474,8 +1471,16 @@ fn buildOutputType(
14741471 fatal("expected linker arg after '{s}'", .{arg});
14751472 }
14761473 version_script = linker_args.items[i];
1474 } else if (mem.eql(u8, arg, "-O")) {
1475 i += 1;
1476 if (i >= linker_args.items.len) {
1477 fatal("expected linker arg after '{s}'", .{arg});
1478 }
1479 warn("ignoring linker arg -O{s} because it does nothing", .{
1480 linker_args.items[i],
1481 });
14771482 } else if (mem.startsWith(u8, arg, "-O")) {
1478 try lld_argv.append(arg);
1483 warn("ignoring linker arg {s} because it does nothing", .{arg});
14791484 } else if (mem.eql(u8, arg, "--gc-sections")) {
14801485 linker_gc_sections = true;
14811486 } else if (mem.eql(u8, arg, "--no-gc-sections")) {
......@@ -2200,7 +2205,6 @@ fn buildOutputType(
22002205 .optimize_mode = optimize_mode,
22012206 .keep_source_files_loaded = false,
22022207 .clang_argv = clang_argv.items,
2203 .lld_argv = lld_argv.items,
22042208 .lib_dirs = lib_dirs.items,
22052209 .rpath_list = rpath_list.items,
22062210 .c_source_files = c_source_files.items,