You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.os-windowsMicrosoft WindowsupstreamAn issue with a third party project that Zig uses.
lld-link: warning: ignoring debug info with an invalid version (0) in zig-cache\o\ee8a465508ce3f1d05048c0482c74ec9\main.obj
lld-link: error: undefined symbol: _tls_index
>>> referenced by main.exe.lto.obj:(std.debug.panicExtra)
>>> referenced by main.exe.lto.obj:(std.debug.panicExtra)
>>> referenced by main.exe.lto.obj:(std.debug.panicExtra)
error: LLDReportedFailure
This error does not occur in Debug or other release modes or when not using C source files.
removing -OPT:lldlto=3 from the linker command line lld-link -ERRORLIMIT:0 -NOLOGO -DEBUG -OPT:lldlto=3 -STACK:16777216 -MACHINE:X64 [...]
still fails.
I will re-open for the time being until I investigate an issue reported by @rtldg in PR #12631:
I feel bad about posting on this since I'm using Zig as a cross-compiler for Rust, but this seems to be causing my builds to fail with lld-link: error: <root>: undefined symbol: _tls_index. Defining the variable _tls_index instead causes things like this
lld-link: error: duplicate symbol: __tls_index
>>> defined at testcpp.lib(test.o)
>>> defined at mingw32.lib(tlssup.obj)
One of the old zig versions I was using did compile & link my projects fine so this pr seems to be where the undefined symbol stuff started.
(zig-windows-x86_64-0.10.0-dev.3602+df507edff from 2022-08-18)
Also an example project of this where I'm using cargo-zigbuild which acts as a wrapper for cross-compiling along with the i686-pc-windows-gnu toolchain for Rust.
Just wondering if I should post this elsewhere for help.
I have the same problem when I'm cross-compiling DuckDB from Ubuntu 22.04.1/WSL with zig build -Drelease-fast -Dtarget=x86_64-windows-gnu. My zig version is 0.10.0-dev.4247+3234e8de3 revision 5764 via snap and with previous versions I didn't have any problem but now I will get the following error messages:
LLD Link... lld-link: error: undefined symbol: __declspec(dllimport) _create_locale
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::__cloc())
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::DoIOSInit::DoIOSInit())
lld-link: error: undefined symbol: __declspec(dllimport) _free_locale
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::__time_put::~__time_put())
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::codecvt<wchar_t, char, int>::~codecvt())
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::DoIOSInit::DoIOSInit())
lld-link: error: undefined symbol: __declspec(dllimport) rand_s
>>> referenced by /home/kimmo/duckdb-zig-build/zig-cache/o/72ea7a324da959e6bd5a316e3ca95f9f/duckdb.exe.lto.obj:(std::__1::random_device::operator()())
And when I'm compiling in Ubuntu zig build -Drelease-fast I will get a couple of warnings which I didn't get earlier:
LLD Link... warning(link): unexpected LLD stderr:
ld.lld: warning: /home/kimmo/duckdb-zig-build/zig-cache/o/5208cc9f7b021f0408edd11ea1860d9e/libsqlite_api.a: archive member '/home/kimmo/duckdb-zig-build/zig-cache/o/82aef94128cf22e4fc9cc80ce2dcdf76/libduckdb_static.a' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/kimmo/duckdb-zig-build/zig-cache/o/5208cc9f7b021f0408edd11ea1860d9e/libsqlite_api.a: archive member '/home/kimmo/duckdb-zig-build/zig-cache/o/985183138eeb191e1a0ce14167cfbb63/libutf8proc.a' is neither ET_REL nor LLVM bitcode
LLD Link... lld-link: error: undefined symbol: _tls_index
>>> referenced by /var/home/xavier/src/zig/build15/stage3/lib/std/debug.zig:337
>>> repro.exe.lto.obj:(std.debug.panicImpl)
>>> referenced by /var/home/xavier/src/zig/build15/stage3/lib/std/debug.zig:339
>>> repro.exe.lto.obj:(std.debug.panicImpl)
>>> referenced by /var/home/xavier/src/zig/build15/stage3/lib/std/debug.zig:374
>>> repro.exe.lto.obj:(std.debug.panicImpl)
(the eror lines are usages of panic_stage, declared as threadlocal var panic_stage: usize = 0; )
@kubkon maybe the symbol forcing should also be done when not linking libc?
something like this?
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 7c4c369a6..a3f341c10 100644
--- a/src/Compilation.zig+++ b/src/Compilation.zig@@ -2011,10 +2011,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) {
@@ -2061,6 +2057,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
try comp.work_queue.writeItem(.{ .zig_libc = {} });
}
}
++ if (target.os.tag == .windows) {+ // 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", {});+ }
}
return comp;
This fixes _tls_index() issue for me but I still get undefined symbol link errors for _create_locale() and _free_locale() when building zig-gamedev with LTO enabled on Windows.
Yeah, something is still broken when cross-compiling for Windows within WSL, but im unable to localize it. :/
The error is undefined symbol: _tls_index.
bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.os-windowsMicrosoft WindowsupstreamAn issue with a third party project that Zig uses.
Activity
xxxbxxx commentedon May 1, 2021
bisected to 0d4b6ac
(when LTO was enabled by default)
(and, indeed, compiling with "-fno-lto" links successfully.)
xxxbxxx commentedon May 1, 2021
moreover:
removing
-OPT:lldlto=3from the linker command linelld-link -ERRORLIMIT:0 -NOLOGO -DEBUG -OPT:lldlto=3 -STACK:16777216 -MACHINE:X64 [...]still fails.
But if I do:
zig build-exe main.zig test.c -lc -target x86_64-windows-gnu -OReleaseFast -fno-lto --verbose-link(1) -> succeedszig build-exe main.zig test.c -lc -target x86_64-windows-gnu -OReleaseFast -flto --verbose-link(2) -> failsmingw32.libfile to use the one from (1) -> succeeds.build: workaround link error with LTO and mingw
tests: add a standalone test for mixing c, zig, threadlocal and build…
test: add a standalone test for mixing c, zig, threadlocal and build …
build: workaround link error with LTO and mingw
test: add a standalone test for mixing c, zig, threadlocal and build …
build: workaround link error with LTO and mingw
test: add a standalone test for mixing c, zig, threadlocal and build …
build: workaround link error with LTO and mingw
test: add a standalone test for mixing c, zig, threadlocal and build …
build: workaround link error with LTO and mingw
28 remaining items
kubkon commentedon Sep 7, 2022
I will re-open for the time being until I investigate an issue reported by @rtldg in PR #12631:
I feel bad about posting on this since I'm using Zig as a cross-compiler for Rust, but this seems to be causing my builds to fail with
lld-link: error: <root>: undefined symbol: _tls_index. Defining the variable_tls_indexinstead causes things like thisOne of the old zig versions I was using did compile & link my projects fine so this pr seems to be where the
undefined symbolstuff started.(
zig-windows-x86_64-0.10.0-dev.3602+df507edfffrom2022-08-18)Also an example project of this where I'm using cargo-zigbuild which acts as a wrapper for cross-compiling along with the
i686-pc-windows-gnutoolchain for Rust.Just wondering if I should post this elsewhere for help.
kimmolinna commentedon Oct 6, 2022
I have the same problem when I'm cross-compiling DuckDB from Ubuntu 22.04.1/WSL with
zig build -Drelease-fast -Dtarget=x86_64-windows-gnu. My zig version is0.10.0-dev.4247+3234e8de3 revision 5764via snap and with previous versions I didn't have any problem but now I will get the following error messages:And when I'm compiling in Ubuntu
zig build -Drelease-fastI will get a couple of warnings which I didn't get earlier:xxxbxxx commentedon Oct 9, 2022
little test with master, (after #12631)
zig build-exe repro.zig -target x86_64-windows-gnu -flto->
(the eror lines are usages of
panic_stage, declared asthreadlocal var panic_stage: usize = 0;)@kubkon maybe the symbol forcing should also be done when not linking libc?
something like this?
jafri commentedon Nov 2, 2022
Downgrading to 0.9.1 fixed issue with _create_locale for now
michal-z commentedon Nov 18, 2022
Hi,
This fixes
_tls_index()issue for me but I still get undefined symbol link errors for_create_locale()and_free_locale()when building zig-gamedev with LTO enabled on Windows.Should I create a separate issue?
ThePotatoChronicler commentedon Feb 4, 2023
Hello,
I am having the same problem as @michal-z above, although cross-compiling from Linux to Windows
Zig version: 0.11.0-dev.1568+c9b957c93
OS: Linux x86_64
build.zig
src/main.c
Output of
zig build:nullp1r commentedon Feb 10, 2023
Yeah, something is still broken when cross-compiling for Windows within WSL, but im unable to localize it. :/
The error is
undefined symbol: _tls_index.nullp1r commentedon Feb 16, 2023
Hmm, I just randomly found out that it only happens when
exe.single_threaded = truein my case.nullp1r commentedon Feb 16, 2023
Found a fix for my case: I had to define
STBI_NO_THREAD_LOCALSbefore importingstb_image.h.