Skip to content

Commit 88a0f3d

Browse files
kcbannerandrewrk
authored andcommitted
windows: fix _tls_index not being defined if libc wasn't linked, and fix x86 name mangling
1 parent 7cfeae1 commit 88a0f3d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Compilation.zig

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,10 +2042,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
20422042
for (mingw.always_link_libs) |name| {
20432043
try comp.bin_file.options.system_libs.put(comp.gpa, name, .{});
20442044
}
2045-
2046-
// LLD might drop some symbols as unused during LTO and GCing, therefore,
2047-
// we force mark them for resolution here.
2048-
try comp.bin_file.options.force_undefined_symbols.put(comp.gpa, "_tls_index", {});
20492045
}
20502046
// Generate Windows import libs.
20512047
if (target.os.tag == .windows) {
@@ -2067,6 +2063,18 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
20672063
try comp.work_queue.writeItem(.libtsan);
20682064
}
20692065

2066+
if (comp.getTarget().isMinGW() and !comp.bin_file.options.single_threaded) {
2067+
// LLD might drop some symbols as unused during LTO and GCing, therefore,
2068+
// we force mark them for resolution here.
2069+
2070+
var tls_index_sym = switch (comp.getTarget().cpu.arch) {
2071+
.x86 => "__tls_index",
2072+
else => "_tls_index",
2073+
};
2074+
2075+
try comp.bin_file.options.force_undefined_symbols.put(comp.gpa, tls_index_sym, {});
2076+
}
2077+
20702078
if (comp.bin_file.options.include_compiler_rt and capable_of_building_compiler_rt) {
20712079
if (is_exe_or_dyn_lib) {
20722080
log.debug("queuing a job to build compiler_rt_lib", .{});

0 commit comments

Comments
 (0)