Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking error with stage2 #11506

Open
voroskoi opened this issue Apr 23, 2022 · 4 comments
Open

Linking error with stage2 #11506

voroskoi opened this issue Apr 23, 2022 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-linux
Milestone

Comments

@voroskoi
Copy link
Contributor

Zig Version

0.10.0-dev.1853+9c2cbe39c

Steps to Reproduce

I have followed these steps: https://github.com/ziglang/zig/wiki/Building-Zig-From-Source

The output below is after building stage1 with cmake, but I even tried using a prebuilt zig version (1/b step), got similar error message.

I use the following guix.scm manifest file to install dependencies: (guix shell -m guix.scm)

(concatenate-manifests
  (list (specifications->manifest
          (list "git-minimal"
                "cmake"
                "llvm@13"
                "lld@13"
                "clang@13"))
        (package->development-manifest
          (specification->package "zig"))))

I can reproduce this error on a rpi4 and x86_64 too. The base system is alpine on aarch64 and manjaro on x86_64. Build deps came from guix in both case.

Expected Behavior

There should be no linking issue.

Actual Behavior

Running build/zig -p stage2 -Denable-llvm gives the following error:

LLD Link... ld.lld: error: undefined symbol: __libc_csu_init
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced 1 more times

ld.lld: error: undefined symbol: __libc_csu_fini
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced by /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/crt1.o:(_start)
>>> referenced 1 more times

ld.lld: error: undefined symbol: __aarch64_ldadd4_acq_rel
>>> referenced by zig_llvm.cpp
>>>               zig_llvm.cpp.o:(ZigLLVMCreateTargetMachine) in archive /home/voroskoi/code/zig/build/zigcpp/libzigcpp.a
>>> referenced by zig_llvm.cpp
>>>               zig_llvm.cpp.o:(ZigLLVMCreateTargetMachine) in archive /home/voroskoi/code/zig/build/zigcpp/libzigcpp.a
>>> referenced by eh_throw.o:(.text._ZL23__gxx_exception_cleanup19_Unwind_Reason_CodeP17_Unwind_Exception+0x24) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a
>>> referenced 456 more times

ld.lld: error: undefined symbol: __aarch64_swp4_rel
>>> referenced by Driver.cpp.o:(std::__future_base::_Deferred_state<std::thread::_Invoker<std::tuple<lld::coff::createFutureForFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::'lambda'()> >, std::pair<std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, std::error_code> >::_M_complete_async()) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a

ld.lld: error: undefined symbol: __aarch64_swp1_acq_rel
>>> referenced by Driver.cpp.o:(lld::coff::createFutureForFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (.isra.0)) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a

ld.lld: error: undefined symbol: __aarch64_ldset4_relax
>>> referenced by Driver.cpp.o:(lld::coff::LinkerDriver::enqueuePath(llvm::StringRef, bool, bool)::'lambda'()::operator()() const) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a
>>> referenced by Driver.cpp.o:(std::_Function_handler<void (), lld::coff::LinkerDriver::enqueueArchiveMember(llvm::object::Archive::Child const&, llvm::object::Archive::Symbol const&, llvm::StringRef)::'lambda2'()>::_M_invoke(std::_Any_data const&)) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a

ld.lld: error: undefined symbol: __aarch64_cas4_acq_rel
>>> referenced by guard.o:(__cxa_guard_acquire) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a
>>> referenced by guard.o:(__cxa_guard_acquire) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a
>>> referenced by guard.o:(__cxa_guard_acquire) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a

ld.lld: error: undefined symbol: __aarch64_swp4_acq_rel
>>> referenced by guard.o:(__cxa_guard_release) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a

ld.lld: error: undefined symbol: __aarch64_cas8_acq_rel
>>> referenced by locale.o:(std::locale::id::_M_id() const) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a
>>> referenced by DebugTypes.cpp.o:(lld::coff::TypeMerger::mergeTypesWithGHash()::'lambda1'(unsigned long)::operator()(unsigned long) const) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a
>>> referenced by DebugTypes.cpp.o:(std::_Function_handler<void (), void llvm::parallel::detail::parallel_for_each_n<unsigned long, lld::coff::TypeMerger::mergeTypesWithGHash()::'lambda1'(unsigned long)>(unsigned long, unsigned long, lld::coff::TypeMerger::mergeTypesWithGHash()::'lambda1'(unsigned long))::'lambda'()>::_M_invoke(std::_Any_data const&)) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a

ld.lld: error: undefined symbol: __strftime_l
>>> referenced by time_members.o:(std::__timepunct<char>::_M_put(char*, unsigned long, char const*, tm const*) const) in archive /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a

ld.lld: error: undefined symbol: __aarch64_ldadd8_acq_rel
>>> referenced by Timer.cpp.o:(lld::ScopedTimer::stop()) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCommon.a
>>> referenced by Timer.cpp.o:(lld::ScopedTimer::~ScopedTimer()) in archive /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCommon.a
error: LLDReportedFailure
zig...The following command exited with error code 1:
/home/voroskoi/code/zig/build/zig build-exe /home/voroskoi/code/zig/src/main.zig -lc /home/voroskoi/code/zig/build/zigcpp/libzigcpp.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangFrontendTool.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangCodeGen.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangFrontend.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangDriver.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangSerialization.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangSema.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangStaticAnalyzerFrontend.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangStaticAnalyzerCheckers.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangStaticAnalyzerCore.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangAnalysis.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangASTMatchers.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangAST.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangParse.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangSema.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangBasic.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangEdit.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangLex.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangARCMigrate.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangRewriteFrontend.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangRewrite.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangCrossTU.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangIndex.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/libclangToolingCore.so /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldDriver.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldMinGW.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldELF.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCOFF.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldWasm.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldMachO.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldReaderWriter.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCore.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldYAML.a /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/lib/liblldCommon.a -lLLVMWindowsManifest -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyUtils -lLLVMWebAssemblyInfo -lLLVMSystemZDisassembler -lLLVMSystemZAsmParser -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSparcDisassembler -lLLVMSparcAsmParser -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMRISCVDisassembler -lLLVMRISCVAsmParser -lLLVMRISCVCodeGen -lLLVMRISCVDesc -lLLVMRISCVInfo -lLLVMPowerPCDisassembler -lLLVMPowerPCAsmParser -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMMSP430Disassembler -lLLVMMSP430AsmParser -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMipsDisassembler -lLLVMMipsAsmParser -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFAsmParser -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMAVRDisassembler -lLLVMAVRAsmParser -lLLVMAVRCodeGen -lLLVMAVRDesc -lLLVMAVRInfo -lLLVMARMDisassembler -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAMDGPUDisassembler -lLLVMAMDGPUAsmParser -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAArch64Disassembler -lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMOrcJIT -lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared -lLLVMDWP -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoGSYM -lLLVMOption -lLLVMObjectYAML -lLLVMMCA -lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMObjCARCOpts -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMExtensions -lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLLVMAsmPrinter -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMIRReader -lLLVMAsmParser -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTableGen -lLLVMSupport -lLLVMDemangle /gnu/store/nxz0a848f76zn8j6848m10lymqx7cnqv-gcc-10.3.0-lib/lib/libstdc++.a -lunwind --cache-dir /home/voroskoi/code/zig/zig-cache --global-cache-dir /home/voroskoi/.cache/zig --name zig --pkg-begin build_options /home/voroskoi/code/zig/zig-cache/options/h2Qik2fU2pXSThtW5b0JyFzZNxyOYgywfNG1GzOzkQLYgv6-Gfnrf0cbLQN_gxZK --pkg-end -I /gnu/store/00qk0k2i3k9l2h5gavrm1k015yfdf330-profile/include --enable-cache
error: the following build command failed with exit code 1:
/home/voroskoi/code/zig/zig-cache/o/133b91b9cb878c1ebc6a84b0e8ea56f2/build /home/voroskoi/code/zig/build/zig /home/voroskoi/code/zig /home/voroskoi/code/zig/zig-cache /home/voroskoi/.cache/zig -p stage2 -Denable-llvm
@voroskoi voroskoi added the bug Observed behavior contradicts documented or intended behavior label Apr 23, 2022
@matu3ba
Copy link
Contributor

matu3ba commented Apr 24, 2022

see Troubleshooting in wiki entry I added for the meantime https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues#building-stage2-and-stage3
Vexu's PR #11501 should also fix that.

@voroskoi
Copy link
Contributor Author

Hi,

Thanks for Your help.

I have tried these, but got no luck. I've forgotten to mention that I have to create a symlink, to fix the following error (missing cc in PATH):

Zig attempted to find the path to native system libc headers by executing this command:
cc -E -Wp,-v -xc /dev/null
error: unable to create compilation: UnableToSpawnCCompiler

When I link to gcc gives the shown error. When I try clang I got the linking errors from LLVM, which should be fixed by pointing to build/config.h, but that does not help my case.

@andrewrk andrewrk added this to the 0.11.0 milestone Jun 2, 2022
@voroskoi
Copy link
Contributor Author

I've just tried this with #12508 (cmake-stage3 branch) and stage3 build gives this very same error.
(Setting CC and applying zlib patch is prerequisite.)

@matu3ba
Copy link
Contributor

matu3ba commented Aug 30, 2022

I'm not really sure, if the Zig build system handles symlinks in all places yet or will ever support that due to the many corner cases and easy potential to wracking havoc with sandboxing (if unhandled).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-linux
Projects
None yet
Development

No branches or pull requests

3 participants