aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-19 11:41:08 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-19 11:41:08 -0700
commitfd6d1fe015c62cbdb52c9703384c0321b8c5ef01 (patch)
tree9be7f9b5f04ba747ef275a0f8349274b7c66befa /src
parent5ae3e4e9bd5216c7cc2305c8996ed413c89c59e7 (diff)
downloadzig-fd6d1fe015c62cbdb52c9703384c0321b8c5ef01.tar.gz
zig-fd6d1fe015c62cbdb52c9703384c0321b8c5ef01.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/clang_options_data.zig11
-rw-r--r--src/link/Coff.zig4
-rw-r--r--src/link/Elf.zig3
-rw-r--r--src/link/MachO.zig1
-rw-r--r--src/main.zig4
5 files changed, 19 insertions, 4 deletions
diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig
index 85ff809761..dbcf0f749f 100644
--- a/src/clang_options_data.zig
+++ b/src/clang_options_data.zig
@@ -1655,7 +1655,7 @@ flagpsl("MT"),
.{
.name = "entry",
.syntax = .flag,
- .zig_equivalent = .other,
+ .zig_equivalent = .entry,
.pd1 = false,
.pd2 = true,
.psl = false,
@@ -6701,7 +6701,14 @@ joinpd1("Z"),
joinpd1("a"),
jspd1("b"),
joinpd1("d"),
-jspd1("e"),
+.{
+ .name = "e",
+ .syntax = .joined_or_separate,
+ .zig_equivalent = .entry,
+ .pd1 = true,
+ .pd2 = false,
+ .psl = false,
+},
.{
.name = "l",
.syntax = .joined_or_separate,
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index b6ae8abcb1..5d24e42fad 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -1071,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
try argv.append("-DLL");
}
+ if (self.base.options.entry) |entry| {
+ try argv.append(try allocPrint(arena, "-ENTRY:{s}", .{entry}));
+ }
+
if (self.base.options.tsaware) {
try argv.append("-tsaware");
}
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index d675833ef2..63381d24a4 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -2889,7 +2889,8 @@ pub fn updateDeclExports(
const stb_bits: u8 = switch (exp.options.linkage) {
.Internal => elf.STB_LOCAL,
.Strong => blk: {
- if (mem.eql(u8, exp.options.name, "_start")) {
+ const entry_name = self.base.options.entry orelse "_start";
+ if (mem.eql(u8, exp.options.name, entry_name)) {
self.entry_addr = decl_sym.st_value;
}
break :blk elf.STB_GLOBAL;
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index eaeb5265eb..6335151bef 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -509,7 +509,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
try man.addOptionalFile(module_obj_path);
// We can skip hashing libc and libc++ components that we are in charge of building from Zig
// installation sources because they are always a product of the compiler version + target information.
- man.hash.addOptionalBytes(self.base.options.entry);
man.hash.add(stack_size);
man.hash.addListOfBytes(self.base.options.lib_dirs);
man.hash.addListOfBytes(self.base.options.framework_dirs);
diff --git a/src/main.zig b/src/main.zig
index 3561315989..9aedb42d38 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1485,6 +1485,9 @@ fn buildOutputType(
.sysroot => {
sysroot = it.only_arg;
},
+ .entry => {
+ entry = it.only_arg;
+ },
}
}
// Parse linker args.
@@ -4156,6 +4159,7 @@ pub const ClangArgIterator = struct {
exec_model,
emit_llvm,
sysroot,
+ entry,
};
const Args = struct {