authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-24 20:11:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:21-07:00
log44e2dbe117fe79b99a970990878a061bdd26ff55
tree43431cc5b9026c75d907f62d911c1a9f9c39d57c
parent1edcea9ec80d9ca6fd9700ef605cfa9c3722817b

fix logic for default entry point

when linking libc, the entry point is within libc. when producing C code, the entry point is decided when compiling the C code and does not need to be known up front. fixes a false positive "error: unknown target entry point" when using -ofmt=c.

1 files changed, 23 insertions(+), 14 deletions(-)

src/Compilation/Config.zig+23-14
...@@ -161,20 +161,6 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -161,20 +161,6 @@ pub fn resolve(options: Options) ResolveError!Config {
161 break :b options.shared_memory orelse false;161 break :b options.shared_memory orelse false;
162 };162 };
163163
164 const entry: ?[]const u8 = switch (options.entry) {
165 .disabled => null,
166 .default => b: {
167 if (options.output_mode != .Exe) break :b null;
168 break :b target_util.defaultEntrySymbolName(target, wasi_exec_model) orelse
169 return error.UnknownTargetEntryPoint;
170 },
171 .enabled => target_util.defaultEntrySymbolName(target, wasi_exec_model) orelse
172 return error.UnknownTargetEntryPoint,
173 .named => |name| name,
174 };
175 if (entry != null and options.output_mode != .Exe)
176 return error.NonExecutableEntryPoint;
177
178 // *If* the LLVM backend were to be selected, should Zig use the LLVM164 // *If* the LLVM backend were to be selected, should Zig use the LLVM
179 // library to build the LLVM module?165 // library to build the LLVM module?
180 const use_lib_llvm = b: {166 const use_lib_llvm = b: {
...@@ -348,6 +334,29 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -348,6 +334,29 @@ pub fn resolve(options: Options) ResolveError!Config {
348 break :b false;334 break :b false;
349 };335 };
350336
337 const entry: ?[]const u8 = switch (options.entry) {
338 .disabled => null,
339 .default => b: {
340 if (options.output_mode != .Exe) break :b null;
341
342 // When linking libc, the entry point is inside libc and not in the
343 // zig compilation unit.
344 if (link_libc) break :b null;
345
346 // When producing C source code, the decision of entry point is made
347 // when compiling the C code, not when producing the C code.
348 if (target.ofmt == .c) break :b null;
349
350 break :b target_util.defaultEntrySymbolName(target, wasi_exec_model) orelse
351 return error.UnknownTargetEntryPoint;
352 },
353 .enabled => target_util.defaultEntrySymbolName(target, wasi_exec_model) orelse
354 return error.UnknownTargetEntryPoint,
355 .named => |name| name,
356 };
357 if (entry != null and options.output_mode != .Exe)
358 return error.NonExecutableEntryPoint;
359
351 const any_unwind_tables = options.any_unwind_tables or360 const any_unwind_tables = options.any_unwind_tables or
352 link_libunwind or target_util.needUnwindTables(target);361 link_libunwind or target_util.needUnwindTables(target);
353362