| author | |
| committer | |
| log | 7e23b3245a9bf6e002009e6c18c10a9995671afa |
| tree | 484a5787656936680e39f2d59c4af6fc0b955644 |
| parent | fd369bcb0b67bde0072f1549be2fd0b34014703f |
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 { | ... | @@ -667,7 +667,6 @@ pub const InitOptions = struct { |
| 667 | optimize_mode: std.builtin.Mode = .Debug, | 667 | optimize_mode: std.builtin.Mode = .Debug, |
| 668 | keep_source_files_loaded: bool = false, | 668 | keep_source_files_loaded: bool = false, |
| 669 | clang_argv: []const []const u8 = &[0][]const u8{}, | 669 | clang_argv: []const []const u8 = &[0][]const u8{}, |
| 670 | lld_argv: []const []const u8 = &[0][]const u8{}, | ||
| 671 | lib_dirs: []const []const u8 = &[0][]const u8{}, | 670 | lib_dirs: []const []const u8 = &[0][]const u8{}, |
| 672 | rpath_list: []const []const u8 = &[0][]const u8{}, | 671 | rpath_list: []const []const u8 = &[0][]const u8{}, |
| 673 | c_source_files: []const CSourceFile = &[0]CSourceFile{}, | 672 | c_source_files: []const CSourceFile = &[0]CSourceFile{}, |
| ... | @@ -946,7 +945,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -946,7 +945,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 946 | link_eh_frame_hdr or | 945 | link_eh_frame_hdr or |
| 947 | options.link_emit_relocs or | 946 | options.link_emit_relocs or |
| 948 | options.output_mode == .Lib or | 947 | options.output_mode == .Lib or |
| 949 | options.lld_argv.len != 0 or | ||
| 950 | options.image_base_override != null or | 948 | options.image_base_override != null or |
| 951 | options.linker_script != null or options.version_script != null or | 949 | options.linker_script != null or options.version_script != null or |
| 952 | options.out_implib != null) | 950 | options.out_implib != null) |
| ... | @@ -1440,7 +1438,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1440,7 +1438,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1440 | .eh_frame_hdr = link_eh_frame_hdr, | 1438 | .eh_frame_hdr = link_eh_frame_hdr, |
| 1441 | .emit_relocs = options.link_emit_relocs, | 1439 | .emit_relocs = options.link_emit_relocs, |
| 1442 | .rdynamic = options.rdynamic, | 1440 | .rdynamic = options.rdynamic, |
| 1443 | .extra_lld_args = options.lld_argv, | ||
| 1444 | .soname = options.soname, | 1441 | .soname = options.soname, |
| 1445 | .version = options.version, | 1442 | .version = options.version, |
| 1446 | .compatibility_version = options.compatibility_version, | 1443 | .compatibility_version = options.compatibility_version, |
src/link.zig-2| ... | @@ -132,8 +132,6 @@ pub const Options = struct { | ... | @@ -132,8 +132,6 @@ pub const Options = struct { |
| 132 | version_script: ?[]const u8, | 132 | version_script: ?[]const u8, |
| 133 | soname: ?[]const u8, | 133 | soname: ?[]const u8, |
| 134 | llvm_cpu_features: ?[*:0]const u8, | 134 | 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, | ||
| 137 | 135 | ||
| 138 | objects: []const []const u8, | 136 | objects: []const []const u8, |
| 139 | framework_dirs: []const []const u8, | 137 | framework_dirs: []const []const u8, |
src/link/Coff.zig-3| ... | @@ -927,7 +927,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { | ... | @@ -927,7 +927,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 927 | try man.addOptionalFile(module_obj_path); | 927 | try man.addOptionalFile(module_obj_path); |
| 928 | man.hash.addOptional(self.base.options.stack_size_override); | 928 | man.hash.addOptional(self.base.options.stack_size_override); |
| 929 | man.hash.addOptional(self.base.options.image_base_override); | 929 | man.hash.addOptional(self.base.options.image_base_override); |
| 930 | man.hash.addListOfBytes(self.base.options.extra_lld_args); | ||
| 931 | man.hash.addListOfBytes(self.base.options.lib_dirs); | 930 | man.hash.addListOfBytes(self.base.options.lib_dirs); |
| 932 | man.hash.add(self.base.options.skip_linker_dependencies); | 931 | man.hash.add(self.base.options.skip_linker_dependencies); |
| 933 | if (self.base.options.link_libc) { | 932 | if (self.base.options.link_libc) { |
| ... | @@ -1058,8 +1057,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { | ... | @@ -1058,8 +1057,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 1058 | try argv.append("-dynamicbase"); | 1057 | try argv.append("-dynamicbase"); |
| 1059 | } | 1058 | } |
| 1060 | 1059 | ||
| 1061 | try argv.appendSlice(self.base.options.extra_lld_args); | ||
| 1062 | |||
| 1063 | const subsystem_suffix = ss: { | 1060 | const subsystem_suffix = ss: { |
| 1064 | if (self.base.options.major_subsystem_version) |major| { | 1061 | if (self.base.options.major_subsystem_version) |major| { |
| 1065 | if (self.base.options.minor_subsystem_version) |minor| { | 1062 | if (self.base.options.minor_subsystem_version) |minor| { |
src/link/Elf.zig-3| ... | @@ -1322,7 +1322,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { | ... | @@ -1322,7 +1322,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1322 | man.hash.add(self.base.options.eh_frame_hdr); | 1322 | man.hash.add(self.base.options.eh_frame_hdr); |
| 1323 | man.hash.add(self.base.options.emit_relocs); | 1323 | man.hash.add(self.base.options.emit_relocs); |
| 1324 | man.hash.add(self.base.options.rdynamic); | 1324 | man.hash.add(self.base.options.rdynamic); |
| 1325 | man.hash.addListOfBytes(self.base.options.extra_lld_args); | ||
| 1326 | man.hash.addListOfBytes(self.base.options.lib_dirs); | 1325 | man.hash.addListOfBytes(self.base.options.lib_dirs); |
| 1327 | man.hash.addListOfBytes(self.base.options.rpath_list); | 1326 | man.hash.addListOfBytes(self.base.options.rpath_list); |
| 1328 | man.hash.add(self.base.options.each_lib_rpath); | 1327 | man.hash.add(self.base.options.each_lib_rpath); |
| ... | @@ -1461,8 +1460,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { | ... | @@ -1461,8 +1460,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1461 | try argv.append("--export-dynamic"); | 1460 | try argv.append("--export-dynamic"); |
| 1462 | } | 1461 | } |
| 1463 | 1462 | ||
| 1464 | try argv.appendSlice(self.base.options.extra_lld_args); | ||
| 1465 | |||
| 1466 | if (self.base.options.z_nodelete) { | 1463 | if (self.base.options.z_nodelete) { |
| 1467 | try argv.append("-z"); | 1464 | try argv.append("-z"); |
| 1468 | try argv.append("nodelete"); | 1465 | try argv.append("nodelete"); |
src/link/Wasm.zig-1| ... | @@ -714,7 +714,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -714,7 +714,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 714 | try man.addOptionalFile(module_obj_path); | 714 | try man.addOptionalFile(module_obj_path); |
| 715 | try man.addOptionalFile(compiler_rt_path); | 715 | try man.addOptionalFile(compiler_rt_path); |
| 716 | man.hash.addOptional(self.base.options.stack_size_override); | 716 | man.hash.addOptional(self.base.options.stack_size_override); |
| 717 | man.hash.addListOfBytes(self.base.options.extra_lld_args); | ||
| 718 | man.hash.add(self.base.options.import_memory); | 717 | man.hash.add(self.base.options.import_memory); |
| 719 | man.hash.addOptional(self.base.options.initial_memory); | 718 | man.hash.addOptional(self.base.options.initial_memory); |
| 720 | man.hash.addOptional(self.base.options.max_memory); | 719 | man.hash.addOptional(self.base.options.max_memory); |
src/main.zig+9-5| ... | @@ -672,9 +672,6 @@ fn buildOutputType( | ... | @@ -672,9 +672,6 @@ fn buildOutputType( |
| 672 | var extra_cflags = std.ArrayList([]const u8).init(gpa); | 672 | var extra_cflags = std.ArrayList([]const u8).init(gpa); |
| 673 | defer extra_cflags.deinit(); | 673 | defer extra_cflags.deinit(); |
| 674 | 674 | ||
| 675 | var lld_argv = std.ArrayList([]const u8).init(gpa); | ||
| 676 | defer lld_argv.deinit(); | ||
| 677 | |||
| 678 | var lib_dirs = std.ArrayList([]const u8).init(gpa); | 675 | var lib_dirs = std.ArrayList([]const u8).init(gpa); |
| 679 | defer lib_dirs.deinit(); | 676 | defer lib_dirs.deinit(); |
| 680 | 677 | ||
| ... | @@ -1474,8 +1471,16 @@ fn buildOutputType( | ... | @@ -1474,8 +1471,16 @@ fn buildOutputType( |
| 1474 | fatal("expected linker arg after '{s}'", .{arg}); | 1471 | fatal("expected linker arg after '{s}'", .{arg}); |
| 1475 | } | 1472 | } |
| 1476 | version_script = linker_args.items[i]; | 1473 | 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 | }); | ||
| 1477 | } else if (mem.startsWith(u8, arg, "-O")) { | 1482 | } else if (mem.startsWith(u8, arg, "-O")) { |
| 1478 | try lld_argv.append(arg); | 1483 | warn("ignoring linker arg {s} because it does nothing", .{arg}); |
| 1479 | } else if (mem.eql(u8, arg, "--gc-sections")) { | 1484 | } else if (mem.eql(u8, arg, "--gc-sections")) { |
| 1480 | linker_gc_sections = true; | 1485 | linker_gc_sections = true; |
| 1481 | } else if (mem.eql(u8, arg, "--no-gc-sections")) { | 1486 | } else if (mem.eql(u8, arg, "--no-gc-sections")) { |
| ... | @@ -2200,7 +2205,6 @@ fn buildOutputType( | ... | @@ -2200,7 +2205,6 @@ fn buildOutputType( |
| 2200 | .optimize_mode = optimize_mode, | 2205 | .optimize_mode = optimize_mode, |
| 2201 | .keep_source_files_loaded = false, | 2206 | .keep_source_files_loaded = false, |
| 2202 | .clang_argv = clang_argv.items, | 2207 | .clang_argv = clang_argv.items, |
| 2203 | .lld_argv = lld_argv.items, | ||
| 2204 | .lib_dirs = lib_dirs.items, | 2208 | .lib_dirs = lib_dirs.items, |
| 2205 | .rpath_list = rpath_list.items, | 2209 | .rpath_list = rpath_list.items, |
| 2206 | .c_source_files = c_source_files.items, | 2210 | .c_source_files = c_source_files.items, |