mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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:
parent
5ae3e4e9bd
commit
fd6d1fe015
7 changed files with 29 additions and 7 deletions
|
|
@ -1554,8 +1554,7 @@ pub const LibExeObjStep = struct {
|
||||||
|
|
||||||
subsystem: ?std.Target.SubSystem = null,
|
subsystem: ?std.Target.SubSystem = null,
|
||||||
|
|
||||||
/// Entrypoint symbol name
|
entry_symbol_name: ?[]const u8 = null,
|
||||||
entry: ?[]const u8 = null,
|
|
||||||
|
|
||||||
/// Overrides the default stack size
|
/// Overrides the default stack size
|
||||||
stack_size: ?u64 = null,
|
stack_size: ?u64 = null,
|
||||||
|
|
@ -2258,7 +2257,7 @@ pub const LibExeObjStep = struct {
|
||||||
try zig_args.append(@tagName(builder.color));
|
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");
|
||||||
try zig_args.append(entry);
|
try zig_args.append(entry);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1655,7 +1655,7 @@ flagpsl("MT"),
|
||||||
.{
|
.{
|
||||||
.name = "entry",
|
.name = "entry",
|
||||||
.syntax = .flag,
|
.syntax = .flag,
|
||||||
.zig_equivalent = .other,
|
.zig_equivalent = .entry,
|
||||||
.pd1 = false,
|
.pd1 = false,
|
||||||
.pd2 = true,
|
.pd2 = true,
|
||||||
.psl = false,
|
.psl = false,
|
||||||
|
|
@ -6701,7 +6701,14 @@ joinpd1("Z"),
|
||||||
joinpd1("a"),
|
joinpd1("a"),
|
||||||
jspd1("b"),
|
jspd1("b"),
|
||||||
joinpd1("d"),
|
joinpd1("d"),
|
||||||
jspd1("e"),
|
.{
|
||||||
|
.name = "e",
|
||||||
|
.syntax = .joined_or_separate,
|
||||||
|
.zig_equivalent = .entry,
|
||||||
|
.pd1 = true,
|
||||||
|
.pd2 = false,
|
||||||
|
.psl = false,
|
||||||
|
},
|
||||||
.{
|
.{
|
||||||
.name = "l",
|
.name = "l",
|
||||||
.syntax = .joined_or_separate,
|
.syntax = .joined_or_separate,
|
||||||
|
|
|
||||||
|
|
@ -1071,6 +1071,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
|
||||||
try argv.append("-DLL");
|
try argv.append("-DLL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.base.options.entry) |entry| {
|
||||||
|
try argv.append(try allocPrint(arena, "-ENTRY:{s}", .{entry}));
|
||||||
|
}
|
||||||
|
|
||||||
if (self.base.options.tsaware) {
|
if (self.base.options.tsaware) {
|
||||||
try argv.append("-tsaware");
|
try argv.append("-tsaware");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2889,7 +2889,8 @@ pub fn updateDeclExports(
|
||||||
const stb_bits: u8 = switch (exp.options.linkage) {
|
const stb_bits: u8 = switch (exp.options.linkage) {
|
||||||
.Internal => elf.STB_LOCAL,
|
.Internal => elf.STB_LOCAL,
|
||||||
.Strong => blk: {
|
.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;
|
self.entry_addr = decl_sym.st_value;
|
||||||
}
|
}
|
||||||
break :blk elf.STB_GLOBAL;
|
break :blk elf.STB_GLOBAL;
|
||||||
|
|
|
||||||
|
|
@ -509,7 +509,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
|
||||||
try man.addOptionalFile(module_obj_path);
|
try man.addOptionalFile(module_obj_path);
|
||||||
// We can skip hashing libc and libc++ components that we are in charge of building from Zig
|
// 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.
|
// 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.add(stack_size);
|
||||||
man.hash.addListOfBytes(self.base.options.lib_dirs);
|
man.hash.addListOfBytes(self.base.options.lib_dirs);
|
||||||
man.hash.addListOfBytes(self.base.options.framework_dirs);
|
man.hash.addListOfBytes(self.base.options.framework_dirs);
|
||||||
|
|
|
||||||
|
|
@ -1485,6 +1485,9 @@ fn buildOutputType(
|
||||||
.sysroot => {
|
.sysroot => {
|
||||||
sysroot = it.only_arg;
|
sysroot = it.only_arg;
|
||||||
},
|
},
|
||||||
|
.entry => {
|
||||||
|
entry = it.only_arg;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Parse linker args.
|
// Parse linker args.
|
||||||
|
|
@ -4156,6 +4159,7 @@ pub const ClangArgIterator = struct {
|
||||||
exec_model,
|
exec_model,
|
||||||
emit_llvm,
|
emit_llvm,
|
||||||
sysroot,
|
sysroot,
|
||||||
|
entry,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Args = struct {
|
const Args = struct {
|
||||||
|
|
|
||||||
|
|
@ -416,6 +416,14 @@ const known_options = [_]KnownOpt{
|
||||||
.name = "sysroot",
|
.name = "sysroot",
|
||||||
.ident = "sysroot",
|
.ident = "sysroot",
|
||||||
},
|
},
|
||||||
|
.{
|
||||||
|
.name = "entry",
|
||||||
|
.ident = "entry",
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.name = "e",
|
||||||
|
.ident = "entry",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const blacklisted_options = [_][]const u8{};
|
const blacklisted_options = [_][]const u8{};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue