| author | |
| committer | |
| log | fd6d1fe015c62cbdb52c9703384c0321b8c5ef01 |
| tree | 9be7f9b5f04ba747ef275a0f8349274b7c66befa |
| parent | 5ae3e4e9bd5216c7cc2305c8996ed413c89c59e7 |
* rename `entry` to `entry_symbol_name` for the zig build API
* integrate with `zig cc` command line options
* integrate with COFF linking with LLD
* integrate with self-hosted ELF linker
* don't put it in the hash for MachO since it is ignored7 files changed, 29 insertions(+), 7 deletions(-)
lib/std/build.zig+2-3| ... | @@ -1554,8 +1554,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1554,8 +1554,7 @@ pub const LibExeObjStep = struct { |
| 1554 | 1554 | ||
| 1555 | subsystem: ?std.Target.SubSystem = null, | 1555 | subsystem: ?std.Target.SubSystem = null, |
| 1556 | 1556 | ||
| 1557 | /// Entrypoint symbol name | 1557 | entry_symbol_name: ?[]const u8 = null, |
| 1558 | entry: ?[]const u8 = null, | ||
| 1559 | 1558 | ||
| 1560 | /// Overrides the default stack size | 1559 | /// Overrides the default stack size |
| 1561 | stack_size: ?u64 = null, | 1560 | stack_size: ?u64 = null, |
| ... | @@ -2258,7 +2257,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2258,7 +2257,7 @@ pub const LibExeObjStep = struct { |
| 2258 | try zig_args.append(@tagName(builder.color)); | 2257 | try zig_args.append(@tagName(builder.color)); |
| 2259 | } | 2258 | } |
| 2260 | 2259 | ||
| 2261 | if (self.entry) |entry| { | 2260 | if (self.entry_symbol_name) |entry| { |
| 2262 | try zig_args.append("--entry"); | 2261 | try zig_args.append("--entry"); |
| 2263 | try zig_args.append(entry); | 2262 | try zig_args.append(entry); |
| 2264 | } | 2263 | } |
src/clang_options_data.zig+9-2| ... | @@ -1655,7 +1655,7 @@ flagpsl("MT"), | ... | @@ -1655,7 +1655,7 @@ flagpsl("MT"), |
| 1655 | .{ | 1655 | .{ |
| 1656 | .name = "entry", | 1656 | .name = "entry", |
| 1657 | .syntax = .flag, | 1657 | .syntax = .flag, |
| 1658 | .zig_equivalent = .other, | 1658 | .zig_equivalent = .entry, |
| 1659 | .pd1 = false, | 1659 | .pd1 = false, |
| 1660 | .pd2 = true, | 1660 | .pd2 = true, |
| 1661 | .psl = false, | 1661 | .psl = false, |
| ... | @@ -6701,7 +6701,14 @@ joinpd1("Z"), | ... | @@ -6701,7 +6701,14 @@ joinpd1("Z"), |
| 6701 | joinpd1("a"), | 6701 | joinpd1("a"), |
| 6702 | jspd1("b"), | 6702 | jspd1("b"), |
| 6703 | joinpd1("d"), | 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 | .name = "l", | 6713 | .name = "l", |
| 6707 | .syntax = .joined_or_separate, | 6714 | .syntax = .joined_or_separate, |
src/link/Coff.zig+4| ... | @@ -1071,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { | ... | @@ -1071,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 1071 | try argv.append("-DLL"); | 1071 | try argv.append("-DLL"); |
| 1072 | } | 1072 | } |
| 1073 | 1073 | ||
| 1074 | if (self.base.options.entry) |entry| { | ||
| 1075 | try argv.append(try allocPrint(arena, "-ENTRY:{s}", .{entry})); | ||
| 1076 | } | ||
| 1077 | |||
| 1074 | if (self.base.options.tsaware) { | 1078 | if (self.base.options.tsaware) { |
| 1075 | try argv.append("-tsaware"); | 1079 | try argv.append("-tsaware"); |
| 1076 | } | 1080 | } |
src/link/Elf.zig+2-1| ... | @@ -2889,7 +2889,8 @@ pub fn updateDeclExports( | ... | @@ -2889,7 +2889,8 @@ pub fn updateDeclExports( |
| 2889 | const stb_bits: u8 = switch (exp.options.linkage) { | 2889 | const stb_bits: u8 = switch (exp.options.linkage) { |
| 2890 | .Internal => elf.STB_LOCAL, | 2890 | .Internal => elf.STB_LOCAL, |
| 2891 | .Strong => blk: { | 2891 | .Strong => blk: { |
| 2892 | 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)) { | ||
| 2893 | self.entry_addr = decl_sym.st_value; | 2894 | self.entry_addr = decl_sym.st_value; |
| 2894 | } | 2895 | } |
| 2895 | break :blk elf.STB_GLOBAL; | 2896 | break :blk elf.STB_GLOBAL; |
src/link/MachO.zig-1| ... | @@ -509,7 +509,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { | ... | @@ -509,7 +509,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 509 | try man.addOptionalFile(module_obj_path); | 509 | try man.addOptionalFile(module_obj_path); |
| 510 | // We can skip hashing libc and libc++ components that we are in charge of building from Zig | 510 | // We can skip hashing libc and libc++ components that we are in charge of building from Zig |
| 511 | // installation sources because they are always a product of the compiler version + target information. | 511 | // installation sources because they are always a product of the compiler version + target information. |
| 512 | man.hash.addOptionalBytes(self.base.options.entry); | ||
| 513 | man.hash.add(stack_size); | 512 | man.hash.add(stack_size); |
| 514 | man.hash.addListOfBytes(self.base.options.lib_dirs); | 513 | man.hash.addListOfBytes(self.base.options.lib_dirs); |
| 515 | man.hash.addListOfBytes(self.base.options.framework_dirs); | 514 | man.hash.addListOfBytes(self.base.options.framework_dirs); |
src/main.zig+4| ... | @@ -1485,6 +1485,9 @@ fn buildOutputType( | ... | @@ -1485,6 +1485,9 @@ fn buildOutputType( |
| 1485 | .sysroot => { | 1485 | .sysroot => { |
| 1486 | sysroot = it.only_arg; | 1486 | sysroot = it.only_arg; |
| 1487 | }, | 1487 | }, |
| 1488 | .entry => { | ||
| 1489 | entry = it.only_arg; | ||
| 1490 | }, | ||
| 1488 | } | 1491 | } |
| 1489 | } | 1492 | } |
| 1490 | // Parse linker args. | 1493 | // Parse linker args. |
| ... | @@ -4156,6 +4159,7 @@ pub const ClangArgIterator = struct { | ... | @@ -4156,6 +4159,7 @@ pub const ClangArgIterator = struct { |
| 4156 | exec_model, | 4159 | exec_model, |
| 4157 | emit_llvm, | 4160 | emit_llvm, |
| 4158 | sysroot, | 4161 | sysroot, |
| 4162 | entry, | ||
| 4159 | }; | 4163 | }; |
| 4160 | 4164 | ||
| 4161 | const Args = struct { | 4165 | const Args = struct { |
tools/update_clang_options.zig+8| ... | @@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{ | ... | @@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{ |
| 416 | .name = "sysroot", | 416 | .name = "sysroot", |
| 417 | .ident = "sysroot", | 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 | const blacklisted_options = [_][]const u8{}; | 429 | const blacklisted_options = [_][]const u8{}; |