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

FreeBSD build fails unless I overwrite target name and add -Duse-zig-libcxx=true #13949

Closed
nunziotocci opened this issue Dec 15, 2022 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-freebsd

Comments

@nunziotocci
Copy link

Zig Version

0.11.0-dev.809+b911b54ae

Steps to Reproduce and Observed Behavior

  1. compile LLVM 15 from source and install to /home/nunzio/local/llvm15-release/
  2. compile zstd from source and install to same prefix (not sure this actually matters, was trying to debug when I did this)
  3. git clone https://github.com/ziglang/zig
  4. cd zig
  5. git checkout b911b54 (latest CI passed commit when I cloned)
  6. mkdir build
  7. cmake .. -DCMAKE_PREFIX_PATH=$HOME/local/llvm15-release -DCMAKE_INSTALL_PATH=$HOME/local/zig
  8. make install

First got:

cd /home/nunzio/Repos/zig && /home/nunzio/Repos/zig/build/zig1 /home/nunzio/Repos/zig/lib build-exe src/main.zig -ofmt=c -lc -OReleaseSmall --name zig2 -femit-bin="/home/nunzio/Repos/zig/build/zig2.c" --
pkg-begin build_options /home/nunzio/Repos/zig/build/config.zig --pkg-end -target amd64-freebsd
error: UnknownArchitecture
[2/6] cd /home/nunzio/Repos/zig && /home/nunzio/Repos/zig/build/zig1 /home/nunzio/Repos/zig/lib build-obj lib/compiler_rt.zig -ofmt=c -OReleaseSmall --name compiler_rt -femit-bin="/home/nunzio/Repos/zig/
build/compiler_rt.c" --pkg-begin build_options /home/nunzio/Repos/zig/build/config.zig --pkg-end -target amd64-freebsd

Then after I forced the arch to be x86_64 I got:

[100%] Building stage3
error: ld.lld: undefined symbol: _Unwind_Resume
    note: referenced by cxxrt_exception.cc:0
    note:               cxxrt_exception.o:(alloc_or_die(unsigned long)) in archive /usr/lib/libc++.a
    note: referenced by cxxrt_exception.cc:0
    note:               cxxrt_exception.o:(__cxa_free_exception) in archive /usr/lib/libc++.a
    note: referenced by cxxrt_exception.cc:0
    note:               cxxrt_exception.o:(__cxa_begin_catch) in archive /usr/lib/libc++.a
    note: referenced 172 more times
error: ld.lld: undefined symbol: _Unwind_RaiseException
    note: referenced by cxxrt_exception.cc:768
    note:               cxxrt_exception.o:(__cxa_throw) in archive /usr/lib/libc++.a
    note: referenced by cxxrt_exception.cc:768
    note:               cxxrt_exception.o:(__cxa_rethrow_primary_exception) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_Resume_or_Rethrow
    note: referenced by cxxrt_exception.cc:0
    note:               cxxrt_exception.o:(__cxa_rethrow) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_Backtrace
    note: referenced by cxxrt_exception.cc:743
    note:               cxxrt_exception.o:(report_failure(_Unwind_Reason_Code, __cxxabiv1::__cxa_exception*)) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_GetLanguageSpecificData
    note: referenced by cxxrt_exception.cc:1106
    note:               cxxrt_exception.o:(__gxx_personality_v0) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_SetIP
    note: referenced by cxxrt_exception.cc:1203
    note:               cxxrt_exception.o:(__gxx_personality_v0) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_SetGR
    note: referenced by cxxrt_exception.cc:1204
    note:               cxxrt_exception.o:(__gxx_personality_v0) in archive /usr/lib/libc++.a
    note: referenced by cxxrt_exception.cc:1206
    note:               cxxrt_exception.o:(__gxx_personality_v0) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_GetRegionStart
    note: referenced by dwarf_eh.h:343 (/usr/src/contrib/libcxxrt/dwarf_eh.h:343)
    note:               cxxrt_exception.o:(parse_lsda(_Unwind_Context*, unsigned char*)) in archive /usr/lib/libc++.a
    note: referenced by dwarf_eh.h:273 (/usr/src/contrib/libcxxrt/dwarf_eh.h:273)
    note:               cxxrt_exception.o:(parse_lsda(_Unwind_Context*, unsigned char*)) in archive /usr/lib/libc++.a
    note: referenced by dwarf_eh.h:413 (/usr/src/contrib/libcxxrt/dwarf_eh.h:413)
    note:               cxxrt_exception.o:(dwarf_eh_find_callsite(_Unwind_Context*, dwarf_eh_lsda*, dwarf_eh_action*)) in archive /usr/lib/libc++.a
    note: referenced 1 more times
error: ld.lld: undefined symbol: _Unwind_GetTextRelBase
    note: referenced by dwarf_eh.h:267 (/usr/src/contrib/libcxxrt/dwarf_eh.h:267)
    note:               cxxrt_exception.o:(parse_lsda(_Unwind_Context*, unsigned char*)) in archive /usr/lib/libc++.a
    note: referenced by dwarf_eh.h:267 (/usr/src/contrib/libcxxrt/dwarf_eh.h:267)
    note:               cxxrt_exception.o:(get_type_info_entry(_Unwind_Context*, dwarf_eh_lsda*, int)) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_GetDataRelBase
    note: referenced by dwarf_eh.h:270 (/usr/src/contrib/libcxxrt/dwarf_eh.h:270)
    note:               cxxrt_exception.o:(parse_lsda(_Unwind_Context*, unsigned char*)) in archive /usr/lib/libc++.a
    note: referenced by dwarf_eh.h:270 (/usr/src/contrib/libcxxrt/dwarf_eh.h:270)
    note:               cxxrt_exception.o:(get_type_info_entry(_Unwind_Context*, dwarf_eh_lsda*, int)) in archive /usr/lib/libc++.a
error: ld.lld: undefined symbol: _Unwind_GetIP
    note: referenced by dwarf_eh.h:413 (/usr/src/contrib/libcxxrt/dwarf_eh.h:413)
    note:               cxxrt_exception.o:(dwarf_eh_find_callsite(_Unwind_Context*, dwarf_eh_lsda*, dwarf_eh_action*)) in archive /usr/lib/libc++.a
    note: referenced by cxxrt_exception.cc:675
    note:               cxxrt_exception.o:(trace(_Unwind_Context*, void*)) in archive /usr/lib/libc++.a
error: zig...
error: The following command exited with error code 1:
/usr/home/nunzio/Repos/zig/build/zig2 build-exe --stack 33554432 /usr/home/nunzio/Repos/zig/src/main.zig -lc /home/nunzio/Repos/zig/build/zigcpp/libzigcpp.a /home/nunzio/local/llvm15-release/lib/libclangFrontendTool.a /home/nunzio/local/llvm15-release/lib/libclangCodeGen.a /home/nunzio/local/llvm15-release/lib
/libclangFrontend.a /home/nunzio/local/llvm15-release/lib/libclangDriver.a /home/nunzio/local/llvm15-release/lib/libclangSerialization.a /home/nunzio/local/llvm15-release/lib/libclangSema.a /home/nunzio/local/llvm15-release/lib/libclangStaticAnalyzerFrontend.a /home/nunzio/local/llvm15-release/lib/libclangStat
icAnalyzerCheckers.a /home/nunzio/local/llvm15-release/lib/libclangStaticAnalyzerCore.a /home/nunzio/local/llvm15-release/lib/libclangAnalysis.a /home/nunzio/local/llvm15-release/lib/libclangASTMatchers.a /home/nunzio/local/llvm15-release/lib/libclangAST.a /home/nunzio/local/llvm15-release/lib/libclangParse.a
/home/nunzio/local/llvm15-release/lib/libclangSema.a /home/nunzio/local/llvm15-release/lib/libclangBasic.a /home/nunzio/local/llvm15-release/lib/libclangEdit.a /home/nunzio/local/llvm15-release/lib/libclangLex.a /home/nunzio/local/llvm15-release/lib/libclangARCMigrate.a /home/nunzio/local/llvm15-release/lib/li
bclangRewriteFrontend.a /home/nunzio/local/llvm15-release/lib/libclangRewrite.a /home/nunzio/local/llvm15-release/lib/libclangCrossTU.a /home/nunzio/local/llvm15-release/lib/libclangIndex.a /home/nunzio/local/llvm15-release/lib/libclangToolingCore.a /home/nunzio/local/llvm15-release/lib/libclangExtractAPI.a /h
ome/nunzio/local/llvm15-release/lib/libclangSupport.a /usr/local/lib/libunwind.so /home/nunzio/local/llvm15-release/lib/liblldMinGW.a /home/nunzio/local/llvm15-release/lib/liblldELF.a /home/nunzio/local/llvm15-release/lib/liblldCOFF.a /home/nunzio/local/llvm15-release/lib/liblldWasm.a /home/nunzio/local/llvm15
-release/lib/liblldMachO.a /home/nunzio/local/llvm15-release/lib/liblldCommon.a -lLLVMWindowsManifest -lLLVMWindowsDriver -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMX86TargetMCA -lLLVMX86Disasse
mbler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyUtils -lLLVMWebAssemblyInfo -lLLVMVEDisassembler -lLLVMVEAsmParser -lLLVMVECodeGen -lLLVMVEDesc -lLLVMVEInfo -lLLVMSyste
mZDisassembler -lLLVMSystemZAsmParser -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSparcDisassembler -lLLVMSparcAsmParser -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMRISCVDisassembler -lLLVMRISCVAsmParser -lLLVMRISCVCodeGen -lLLVMRISCVDesc -lLLVMRISCVInfo -lLLVMPowerPCDisassemble
r -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 -lLLVMAVR
Disassembler -lLLVMAVRAsmParser -lLLVMAVRCodeGen -lLLVMAVRDesc -lLLVMAVRInfo -lLLVMARMDisassembler -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAMDGPUTargetMCA -lLLVMAMDGPUDisassembler -lLLVMAMDGPUAsmParser -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMD
GPUInfo -lLLVMAArch64Disassembler -lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMOrcJIT -lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared -lLLVMDWP -lLLVMDebugInfoGSYM -lLLVMOption
 -lLLVMObjectYAML -lLLVMObjCopy -lLLVMMCA -lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMObjCARCOpts -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMExtensions -lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLL
VMAsmPrinter -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMIRReader -lLLVMAsmParser -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMSymbolize -lLLVMDebugInfoPDB
-lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMFuzzerCLI -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTableGen -lLLVMSupport -lLLVMDemangle -lexecinfo -lz -lzstd /usr/lib/libc++.a --cache-dir /u
sr/home/nunzio/Repos/zig/zig-cache --global-cache-dir /home/nunzio/.cache/zig --name zig --pkg-begin build_options /usr/home/nunzio/Repos/zig/zig-cache/options/pRUwb64kQ9rYUb_EvqOgdRXgZ3UiddVBn40G4Nc62Zyqg2-axylVF1dPUXoFpD_a --pkg-end -I /home/nunzio/local/llvm15-release/include -I /usr/home/nunzio/local/llvm1
5-release/include -L /usr/home/nunzio/local/llvm15-release/lib -L /home/nunzio/local/llvm15-release/lib -I /home/nunzio/local/llvm15-release/include -fno-build-id --zig-lib-dir /home/nunzio/Repos/zig/lib --enable-cache
error: the following build command failed with exit code 1:
/usr/home/nunzio/Repos/zig/zig-cache/o/5d43b86d4d88e3525c2120de4d7b1954/build /usr/home/nunzio/Repos/zig/build/zig2 /usr/home/nunzio/Repos/zig /usr/home/nunzio/Repos/zig/zig-cache /home/nunzio/.cache/zig compile --zig-lib-dir /home/nunzio/Repos/zig/lib -Dconfig_h=/home/nunzio/Repos/zig/build/config.h -Denable-
llvm -Dtarget=native -Dcpu=native -Dversion-string=0.11.0-dev.809+b911b54ae

Expected Behavior

I expected it to build. My solution:

  1. nano CMakeFiles/zig2.dir/build.make (replace amd64 with x86_65)
  2. nano ./CMakeFiles/stage3.dir/build.make (add -Duse-zig-libcxx=true to build compile line)
  3. nano cmake_install.cmake add -Duse-zig-libcxx=true to ZIG_BUILD_ARGS
  4. make install

Here's my uname -a:

FreeBSD <host> 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC amd64

Looking forward to playing with zig, thank you for all of the hard work!

@nunziotocci nunziotocci added the bug Observed behavior contradicts documented or intended behavior label Dec 15, 2022
@nunziotocci
Copy link
Author

Update: I tried to use https://github.com/ratfactor/ziglings to get started with learning zig and discovered I have a non-funcitonal build:

nunzio@smtp:~/Repos
$ git clone https://github.com/ratfactor/ziglings
Cloning into 'ziglings'...
remote: Enumerating objects: 1814, done.
remote: Counting objects: 100% (49/49), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 1814 (delta 22), reused 32 (delta 18), pack-reused 1765
Receiving objects: 100% (1814/1814), 353.62 KiB | 2.31 MiB/s, done.
Resolving deltas: 100% (1162/1162), done.

nunzio@smtp:~/Repos
$ cd ziglings/

nunzio@smtp:~/Repos/ziglings
$ zig build
thread 101674 panic: incorrect alignment
/home/nunzio/Repos/zig/lib/std/heap.zig:185:65: 0x404897e in rawCAlloc (zig)
    const ptr = @alignCast(@alignOf(std.c.max_align_t), c.malloc(len));
                                                                ^
/home/nunzio/Repos/zig/lib/std/mem/Allocator.zig:86:34: 0x40a9e47 in allocAdvancedWithRetAddr__anon_6144 (zig)
    return self.vtable.alloc(self.ptr, len, ptr_align, ret_addr);
                                 ^
/home/nunzio/Repos/zig/lib/std/mem/Allocator.zig:128:41: 0x4049fa5 in alloc__anon_3428 (zig)
    return self.allocAdvancedWithRetAddr(T, null, n, @returnAddress());
                                        ^
/home/nunzio/Repos/zig/lib/std/mem/Allocator.zig:308:45: 0x4049e58 in dupe__anon_3427 (zig)
    const new_buf = try allocator.alloc(T, m.len);
                                            ^
/usr/home/nunzio/Repos/zig/src/Package.zig:63:40: 0x40ccedf in createWithDir (zig)
    const owned_src_path = try gpa.dupe(u8, root_src_path);
                                       ^
/usr/home/nunzio/Repos/zig/src/Compilation.zig:1590:24: 0x40f9695 in create (zig)
                options.zig_lib_directory,
                       ^
/usr/home/nunzio/Repos/zig/src/main.zig:4015:61: 0x4074bd9 in cmdBuild (zig)
            .dynamic_linker = target_info.dynamic_linker.get(),
                                                            ^
/usr/home/nunzio/Repos/zig/src/main.zig:288:24: 0x4046c0e in mainArgs (zig)
        return cmdBuild(gpa, arena, cmd_args);
                       ^
/usr/home/nunzio/Repos/zig/src/main.zig:201:20: 0x40457d7 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/nunzio/Repos/zig/lib/std/start.zig:614:37: 0x4047e38 in main (zig)
            const result = root.main() catch |err| {
                                    ^
/usr/src/lib/csu/amd64/crt1_c.c:75:7: 0x4043b7f in _start (/usr/src/lib/csu/amd64/crt1_c.c)
        exit(main(argc, argv, env));
      ^
???:?:?: 0x80bdca007 in ??? (???)
Abort trap (core dumped)

If I use the stage2 compiler, it appears to work (I get the first error message that I'm supposed to fix).

@mikdusan
Copy link
Member

see #13699

I'm holding off pushing a rebase of the PR until I work out linking system c++ standard library for stage3 for more than just FreeBSD.

btw,

  • unknown arch; solved in PR commit cmake: CMAKE_HOST_SYSTEM_PROCESSOR ignore case
  • panic incorrect alignment; solved in a commit I haven't pushed to the PR yet; fixes std.heap.rawCAlloc

@nunziotocci
Copy link
Author

Thanks for the heads up, I've subscribed to your PR. I'll re-check this once it's merged.

@nunziotocci
Copy link
Author

Now that #13699 is merged I will give this another try when I get a chance. Thank you @mikdusan!

@nunziotocci
Copy link
Author

Both of my issues are resolved in master, thanks again!

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-freebsd
Projects
None yet
Development

No branches or pull requests

2 participants