Skip to content

Commit

Permalink
windows: fix _tls_index not being defined if libc wasn't linked, and …
Browse files Browse the repository at this point in the history
…fix x86 name mangling
  • Loading branch information
kcbanner authored and andrewrk committed Nov 17, 2022
1 parent 7cfeae1 commit 88a0f3d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2042,10 +2042,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
for (mingw.always_link_libs) |name| {
try comp.bin_file.options.system_libs.put(comp.gpa, name, .{});
}

// LLD might drop some symbols as unused during LTO and GCing, therefore,
// we force mark them for resolution here.
try comp.bin_file.options.force_undefined_symbols.put(comp.gpa, "_tls_index", {});
}
// Generate Windows import libs.
if (target.os.tag == .windows) {
Expand All @@ -2067,6 +2063,18 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
try comp.work_queue.writeItem(.libtsan);
}

if (comp.getTarget().isMinGW() and !comp.bin_file.options.single_threaded) {
// LLD might drop some symbols as unused during LTO and GCing, therefore,
// we force mark them for resolution here.

var tls_index_sym = switch (comp.getTarget().cpu.arch) {
.x86 => "__tls_index",
else => "_tls_index",
};

try comp.bin_file.options.force_undefined_symbols.put(comp.gpa, tls_index_sym, {});
}

if (comp.bin_file.options.include_compiler_rt and capable_of_building_compiler_rt) {
if (is_exe_or_dyn_lib) {
log.debug("queuing a job to build compiler_rt_lib", .{});
Expand Down

0 comments on commit 88a0f3d

Please sign in to comment.