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
This commit is contained in:
Andrew Kelley 2022-01-19 11:41:08 -07:00
parent 5ae3e4e9bd
commit fd6d1fe015
7 changed files with 29 additions and 7 deletions

View File

@ -1554,8 +1554,7 @@ pub const LibExeObjStep = struct {
subsystem: ?std.Target.SubSystem = null,
/// Entrypoint symbol name
entry: ?[]const u8 = null,
entry_symbol_name: ?[]const u8 = null,
/// Overrides the default stack size
stack_size: ?u64 = null,
@ -2258,7 +2257,7 @@ pub const LibExeObjStep = struct {
try zig_args.append(@tagName(builder.color));
}
if (self.entry) |entry| {
if (self.entry_symbol_name) |entry| {
try zig_args.append("--entry");
try zig_args.append(entry);
}

View File

@ -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,

View File

@ -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");
}

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{
.name = "sysroot",
.ident = "sysroot",
},
.{
.name = "entry",
.ident = "entry",
},
.{
.name = "e",
.ident = "entry",
},
};
const blacklisted_options = [_][]const u8{};