| author | |
| committer | |
| log | 4e8fedffd12e1f995f38369421391f5a12035a99 |
| tree | 9be7f9b5f04ba747ef275a0f8349274b7c66befa |
| parent | beb7495e19d23b4814e16772888e80688ad10e47 |
| parent | fd6d1fe015c62cbdb52c9703384c0321b8c5ef01 |
| signature |
lld: allow for entrypoint symbol name to be set9 files changed, 63 insertions(+), 3 deletions(-)
lib/std/build.zig+7| ... | ... | @@ -1554,6 +1554,8 @@ pub const LibExeObjStep = struct { |
| 1554 | 1554 | |
| 1555 | 1555 | subsystem: ?std.Target.SubSystem = null, |
| 1556 | 1556 | |
| 1557 | entry_symbol_name: ?[]const u8 = null, | |
| 1558 | ||
| 1557 | 1559 | /// Overrides the default stack size |
| 1558 | 1560 | stack_size: ?u64 = null, |
| 1559 | 1561 | |
| ... | ... | @@ -2255,6 +2257,11 @@ pub const LibExeObjStep = struct { |
| 2255 | 2257 | try zig_args.append(@tagName(builder.color)); |
| 2256 | 2258 | } |
| 2257 | 2259 | |
| 2260 | if (self.entry_symbol_name) |entry| { | |
| 2261 | try zig_args.append("--entry"); | |
| 2262 | try zig_args.append(entry); | |
| 2263 | } | |
| 2264 | ||
| 2258 | 2265 | if (self.stack_size) |stack_size| { |
| 2259 | 2266 | try zig_args.append("--stack"); |
| 2260 | 2267 | try zig_args.append(try std.fmt.allocPrint(builder.allocator, "{}", .{stack_size})); |
src/Compilation.zig+2| ... | ... | @@ -791,6 +791,7 @@ pub const InitOptions = struct { |
| 791 | 791 | /// infinite recursion. |
| 792 | 792 | skip_linker_dependencies: bool = false, |
| 793 | 793 | parent_compilation_link_libc: bool = false, |
| 794 | entry: ?[]const u8 = null, | |
| 794 | 795 | stack_size_override: ?u64 = null, |
| 795 | 796 | image_base_override: ?u64 = null, |
| 796 | 797 | self_exe_path: ?[]const u8 = null, |
| ... | ... | @@ -1572,6 +1573,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1572 | 1573 | .linker_optimization = linker_optimization, |
| 1573 | 1574 | .major_subsystem_version = options.major_subsystem_version, |
| 1574 | 1575 | .minor_subsystem_version = options.minor_subsystem_version, |
| 1576 | .entry = options.entry, | |
| 1575 | 1577 | .stack_size_override = options.stack_size_override, |
| 1576 | 1578 | .image_base_override = options.image_base_override, |
| 1577 | 1579 | .include_compiler_rt = include_compiler_rt, |
src/clang_options_data.zig+9-2| ... | ... | @@ -1655,7 +1655,7 @@ flagpsl("MT"), |
| 1655 | 1655 | .{ |
| 1656 | 1656 | .name = "entry", |
| 1657 | 1657 | .syntax = .flag, |
| 1658 | .zig_equivalent = .other, | |
| 1658 | .zig_equivalent = .entry, | |
| 1659 | 1659 | .pd1 = false, |
| 1660 | 1660 | .pd2 = true, |
| 1661 | 1661 | .psl = false, |
| ... | ... | @@ -6701,7 +6701,14 @@ joinpd1("Z"), |
| 6701 | 6701 | joinpd1("a"), |
| 6702 | 6702 | jspd1("b"), |
| 6703 | 6703 | joinpd1("d"), |
| 6704 | jspd1("e"), | |
| 6704 | .{ | |
| 6705 | .name = "e", | |
| 6706 | .syntax = .joined_or_separate, | |
| 6707 | .zig_equivalent = .entry, | |
| 6708 | .pd1 = true, | |
| 6709 | .pd2 = false, | |
| 6710 | .psl = false, | |
| 6711 | }, | |
| 6705 | 6712 | .{ |
| 6706 | 6713 | .name = "l", |
| 6707 | 6714 | .syntax = .joined_or_separate, |
src/link.zig+1| ... | ... | @@ -84,6 +84,7 @@ pub const Options = struct { |
| 84 | 84 | /// the binary file does not already have such a section. |
| 85 | 85 | program_code_size_hint: u64 = 256 * 1024, |
| 86 | 86 | entry_addr: ?u64 = null, |
| 87 | entry: ?[]const u8, | |
| 87 | 88 | stack_size_override: ?u64, |
| 88 | 89 | image_base_override: ?u64, |
| 89 | 90 | cache_mode: CacheMode, |
src/link/Coff.zig+5| ... | ... | @@ -951,6 +951,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 951 | 951 | _ = try man.addFile(key.status.success.object_path, null); |
| 952 | 952 | } |
| 953 | 953 | try man.addOptionalFile(module_obj_path); |
| 954 | man.hash.addOptionalBytes(self.base.options.entry); | |
| 954 | 955 | man.hash.addOptional(self.base.options.stack_size_override); |
| 955 | 956 | man.hash.addOptional(self.base.options.image_base_override); |
| 956 | 957 | man.hash.addListOfBytes(self.base.options.lib_dirs); |
| ... | ... | @@ -1070,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 1070 | 1071 | try argv.append("-DLL"); |
| 1071 | 1072 | } |
| 1072 | 1073 | |
| 1074 | if (self.base.options.entry) |entry| { | |
| 1075 | try argv.append(try allocPrint(arena, "-ENTRY:{s}", .{entry})); | |
| 1076 | } | |
| 1077 | ||
| 1073 | 1078 | if (self.base.options.tsaware) { |
| 1074 | 1079 | try argv.append("-tsaware"); |
| 1075 | 1080 | } |
src/link/Elf.zig+8-1| ... | ... | @@ -1396,6 +1396,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1396 | 1396 | |
| 1397 | 1397 | // We can skip hashing libc and libc++ components that we are in charge of building from Zig |
| 1398 | 1398 | // installation sources because they are always a product of the compiler version + target information. |
| 1399 | man.hash.addOptionalBytes(self.base.options.entry); | |
| 1399 | 1400 | man.hash.add(stack_size); |
| 1400 | 1401 | man.hash.addOptional(self.base.options.image_base_override); |
| 1401 | 1402 | man.hash.add(gc_sections); |
| ... | ... | @@ -1518,6 +1519,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1518 | 1519 | self.base.options.linker_optimization, |
| 1519 | 1520 | })); |
| 1520 | 1521 | |
| 1522 | if (self.base.options.entry) |entry| { | |
| 1523 | try argv.append("--entry"); | |
| 1524 | try argv.append(entry); | |
| 1525 | } | |
| 1526 | ||
| 1521 | 1527 | if (self.base.options.output_mode == .Exe) { |
| 1522 | 1528 | try argv.append("-z"); |
| 1523 | 1529 | try argv.append(try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size})); |
| ... | ... | @@ -2883,7 +2889,8 @@ pub fn updateDeclExports( |
| 2883 | 2889 | const stb_bits: u8 = switch (exp.options.linkage) { |
| 2884 | 2890 | .Internal => elf.STB_LOCAL, |
| 2885 | 2891 | .Strong => blk: { |
| 2886 | if (mem.eql(u8, exp.options.name, "_start")) { | |
| 2892 | const entry_name = self.base.options.entry orelse "_start"; | |
| 2893 | if (mem.eql(u8, exp.options.name, entry_name)) { | |
| 2887 | 2894 | self.entry_addr = decl_sym.st_value; |
| 2888 | 2895 | } |
| 2889 | 2896 | break :blk elf.STB_GLOBAL; |
src/link/Wasm.zig+6| ... | ... | @@ -1137,6 +1137,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 1137 | 1137 | } |
| 1138 | 1138 | try man.addOptionalFile(module_obj_path); |
| 1139 | 1139 | try man.addOptionalFile(compiler_rt_path); |
| 1140 | man.hash.addOptionalBytes(self.base.options.entry); | |
| 1140 | 1141 | man.hash.addOptional(self.base.options.stack_size_override); |
| 1141 | 1142 | man.hash.add(self.base.options.import_memory); |
| 1142 | 1143 | man.hash.add(self.base.options.import_table); |
| ... | ... | @@ -1295,6 +1296,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 1295 | 1296 | } |
| 1296 | 1297 | } |
| 1297 | 1298 | |
| 1299 | if (self.base.options.entry) |entry| { | |
| 1300 | try argv.append("--entry"); | |
| 1301 | try argv.append(entry); | |
| 1302 | } | |
| 1303 | ||
| 1298 | 1304 | if (self.base.options.output_mode == .Exe) { |
| 1299 | 1305 | // Increase the default stack size to a more reasonable value of 1MB instead of |
| 1300 | 1306 | // the default of 1 Wasm page being 64KB, unless overridden by the user. |
src/main.zig+17| ... | ... | @@ -400,6 +400,7 @@ const usage_build_generic = |
| 400 | 400 | \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so) |
| 401 | 401 | \\ --sysroot [path] Set the system root directory (usually /) |
| 402 | 402 | \\ --version [ver] Dynamic library semver |
| 403 | \\ --entry [name] Set the entrypoint symbol name | |
| 403 | 404 | \\ -fsoname[=name] Override the default SONAME value |
| 404 | 405 | \\ -fno-soname Disable emitting a SONAME |
| 405 | 406 | \\ -fLLD Force using LLD as the linker |
| ... | ... | @@ -647,6 +648,7 @@ fn buildOutputType( |
| 647 | 648 | var linker_optimization: ?u8 = null; |
| 648 | 649 | var test_evented_io = false; |
| 649 | 650 | var test_no_exec = false; |
| 651 | var entry: ?[]const u8 = null; | |
| 650 | 652 | var stack_size_override: ?u64 = null; |
| 651 | 653 | var image_base_override: ?u64 = null; |
| 652 | 654 | var use_llvm: ?bool = null; |
| ... | ... | @@ -847,6 +849,10 @@ fn buildOutputType( |
| 847 | 849 | if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); |
| 848 | 850 | i += 1; |
| 849 | 851 | optimize_mode_string = args[i]; |
| 852 | } else if (mem.eql(u8, arg, "--entry")) { | |
| 853 | if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); | |
| 854 | i += 1; | |
| 855 | entry = args[i]; | |
| 850 | 856 | } else if (mem.eql(u8, arg, "--stack")) { |
| 851 | 857 | if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); |
| 852 | 858 | i += 1; |
| ... | ... | @@ -1479,6 +1485,9 @@ fn buildOutputType( |
| 1479 | 1485 | .sysroot => { |
| 1480 | 1486 | sysroot = it.only_arg; |
| 1481 | 1487 | }, |
| 1488 | .entry => { | |
| 1489 | entry = it.only_arg; | |
| 1490 | }, | |
| 1482 | 1491 | } |
| 1483 | 1492 | } |
| 1484 | 1493 | // Parse linker args. |
| ... | ... | @@ -1624,6 +1633,12 @@ fn buildOutputType( |
| 1624 | 1633 | fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) }); |
| 1625 | 1634 | }; |
| 1626 | 1635 | have_version = true; |
| 1636 | } else if (mem.eql(u8, arg, "-e") or mem.eql(u8, arg, "--entry")) { | |
| 1637 | i += 1; | |
| 1638 | if (i >= linker_args.items.len) { | |
| 1639 | fatal("expected linker arg after '{s}'", .{arg}); | |
| 1640 | } | |
| 1641 | entry = linker_args.items[i]; | |
| 1627 | 1642 | } else if (mem.eql(u8, arg, "--stack")) { |
| 1628 | 1643 | i += 1; |
| 1629 | 1644 | if (i >= linker_args.items.len) { |
| ... | ... | @@ -2500,6 +2515,7 @@ fn buildOutputType( |
| 2500 | 2515 | .minor_subsystem_version = minor_subsystem_version, |
| 2501 | 2516 | .link_eh_frame_hdr = link_eh_frame_hdr, |
| 2502 | 2517 | .link_emit_relocs = link_emit_relocs, |
| 2518 | .entry = entry, | |
| 2503 | 2519 | .stack_size_override = stack_size_override, |
| 2504 | 2520 | .image_base_override = image_base_override, |
| 2505 | 2521 | .strip = strip, |
| ... | ... | @@ -4143,6 +4159,7 @@ pub const ClangArgIterator = struct { |
| 4143 | 4159 | exec_model, |
| 4144 | 4160 | emit_llvm, |
| 4145 | 4161 | sysroot, |
| 4162 | entry, | |
| 4146 | 4163 | }; |
| 4147 | 4164 | |
| 4148 | 4165 | const Args = struct { |
tools/update_clang_options.zig+8| ... | ... | @@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{ |
| 416 | 416 | .name = "sysroot", |
| 417 | 417 | .ident = "sysroot", |
| 418 | 418 | }, |
| 419 | .{ | |
| 420 | .name = "entry", | |
| 421 | .ident = "entry", | |
| 422 | }, | |
| 423 | .{ | |
| 424 | .name = "e", | |
| 425 | .ident = "entry", | |
| 426 | }, | |
| 419 | 427 | }; |
| 420 | 428 | |
| 421 | 429 | const blacklisted_options = [_][]const u8{}; |