Skip to content

Conversation

@Vexu
Copy link
Member

@Vexu Vexu commented Feb 19, 2022

No idea if this actually works since I can't get LLVM to work with stage2. Keep forgetting I can use stage1 with -fno-stage1.

@Vexu Vexu force-pushed the stage2 branch 4 times, most recently from e000a07 to fa088fc Compare February 19, 2022 18:08
@andrewrk
Copy link
Member

What error do you get from ./zig build -Denable-llvm ?

@Vexu
Copy link
Member Author

Vexu commented Feb 19, 2022

zig build -Denable-llvm gives:

ld.lld: error: undefined symbol: __libc_single_threaded
>>> referenced by atomicity.h:52 (/usr/include/c++/11.2.0/ext/atomicity.h:52)
>>>               zig_llvm.cpp.o:(std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()) in archive /home/vexu/Documents/zig/zig/build/zigcpp/libzigcpp.a
>>> referenced by atomicity.h:52 (/usr/include/c++/11.2.0/ext/atomicity.h:52)
>>>               zig_llvm.cpp.o:(std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()) in archive /home/vexu/Documents/zig/zig/build/zigcpp/libzigcpp.a
>>> referenced by cow-string-inst.o:(std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()) in archive /usr/lib/libstdc++.a
>>> referenced 342 more times

zig build -Dstatic-llvm -Duse-zig-libcxx --search-prefix ../zig-bootstrap/out/host gives thousands of undefined symbol errors which suggests that I'm using the wrong compiler somewhere.

@andrewrk
Copy link
Member

andrewrk commented Feb 19, 2022

What distro is this?

@Vexu
Copy link
Member Author

Vexu commented Feb 19, 2022

Arch linux.

@Vexu
Copy link
Member Author

Vexu commented Feb 19, 2022

$ cat a.c
extern char __libc_single_threaded;
int main(void) {
    return __libc_single_threaded;
}
$ clang a.c && ./a.out
$ zig run a.c -lc
ld.lld: error: undefined symbol: __libc_single_threaded
>>> referenced by a.c:3
>>>               /home/vexu/.cache/zig/o/beaf2795fe77dc6e0678cf2f5db03da6/a.o:(main)
thread 15567 panic: attempt to unwrap error: LLDReportedFailure
???:?:?: 0x55e25e3e6556 in ??? (???)
???:?:?: 0x55e25e3e6790 in ??? (???)
^C

Likely relevant.

@Vexu
Copy link
Member Author

Vexu commented Feb 19, 2022

Fixed by:

diff --git a/build.zig b/build.zig
index 5896ab1a8..fb821ccf4 100644
--- a/build.zig
+++ b/build.zig
@@ -550,6 +550,7 @@ fn addCmakeCfgOptionsToExe(
                 else => |e| return e,
             };
             exe.linkSystemLibrary("unwind");
+            exe.linkSystemLibrary("c_nonshared");
         } else if (exe.target.isFreeBSD()) {
             try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
             exe.linkSystemLibrary("pthread");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants