authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-19 11:41:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-19 11:41:08-07:00
logfd6d1fe015c62cbdb52c9703384c0321b8c5ef01
tree9be7f9b5f04ba747ef275a0f8349274b7c66befa
parent5ae3e4e9bd5216c7cc2305c8996ed413c89c59e7

stage2: improvements to entry point handling

* 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 ignored

7 files changed, 29 insertions(+), 7 deletions(-)

lib/std/build.zig+2-3
......@@ -1554,8 +1554,7 @@ pub const LibExeObjStep = struct {
15541554
15551555 subsystem: ?std.Target.SubSystem = null,
15561556
1557 /// Entrypoint symbol name
1558 entry: ?[]const u8 = null,
1557 entry_symbol_name: ?[]const u8 = null,
15591558
15601559 /// Overrides the default stack size
15611560 stack_size: ?u64 = null,
......@@ -2258,7 +2257,7 @@ pub const LibExeObjStep = struct {
22582257 try zig_args.append(@tagName(builder.color));
22592258 }
22602259
2261 if (self.entry) |entry| {
2260 if (self.entry_symbol_name) |entry| {
22622261 try zig_args.append("--entry");
22632262 try zig_args.append(entry);
22642263 }
src/clang_options_data.zig+9-2
......@@ -1655,7 +1655,7 @@ flagpsl("MT"),
16551655.{
16561656 .name = "entry",
16571657 .syntax = .flag,
1658 .zig_equivalent = .other,
1658 .zig_equivalent = .entry,
16591659 .pd1 = false,
16601660 .pd2 = true,
16611661 .psl = false,
......@@ -6701,7 +6701,14 @@ joinpd1("Z"),
67016701joinpd1("a"),
67026702jspd1("b"),
67036703joinpd1("d"),
6704jspd1("e"),
6704.{
6705 .name = "e",
6706 .syntax = .joined_or_separate,
6707 .zig_equivalent = .entry,
6708 .pd1 = true,
6709 .pd2 = false,
6710 .psl = false,
6711},
67056712.{
67066713 .name = "l",
67076714 .syntax = .joined_or_separate,
src/link/Coff.zig+4
......@@ -1071,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
10711071 try argv.append("-DLL");
10721072 }
10731073
1074 if (self.base.options.entry) |entry| {
1075 try argv.append(try allocPrint(arena, "-ENTRY:{s}", .{entry}));
1076 }
1077
10741078 if (self.base.options.tsaware) {
10751079 try argv.append("-tsaware");
10761080 }
src/link/Elf.zig+2-1
......@@ -2889,7 +2889,8 @@ pub fn updateDeclExports(
28892889 const stb_bits: u8 = switch (exp.options.linkage) {
28902890 .Internal => elf.STB_LOCAL,
28912891 .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)) {
28932894 self.entry_addr = decl_sym.st_value;
28942895 }
28952896 break :blk elf.STB_GLOBAL;
src/link/MachO.zig-1
......@@ -509,7 +509,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
509509 try man.addOptionalFile(module_obj_path);
510510 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
511511 // installation sources because they are always a product of the compiler version + target information.
512 man.hash.addOptionalBytes(self.base.options.entry);
513512 man.hash.add(stack_size);
514513 man.hash.addListOfBytes(self.base.options.lib_dirs);
515514 man.hash.addListOfBytes(self.base.options.framework_dirs);
src/main.zig+4
......@@ -1485,6 +1485,9 @@ fn buildOutputType(
14851485 .sysroot => {
14861486 sysroot = it.only_arg;
14871487 },
1488 .entry => {
1489 entry = it.only_arg;
1490 },
14881491 }
14891492 }
14901493 // Parse linker args.
......@@ -4156,6 +4159,7 @@ pub const ClangArgIterator = struct {
41564159 exec_model,
41574160 emit_llvm,
41584161 sysroot,
4162 entry,
41594163 };
41604164
41614165 const Args = struct {
tools/update_clang_options.zig+8
......@@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{
416416 .name = "sysroot",
417417 .ident = "sysroot",
418418 },
419 .{
420 .name = "entry",
421 .ident = "entry",
422 },
423 .{
424 .name = "e",
425 .ident = "entry",
426 },
419427};
420428
421429const blacklisted_options = [_][]const u8{};