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

c3c compilation fails on Fedora 38 #779

Closed
Ashvith10 opened this issue Jun 13, 2023 · 21 comments
Closed

c3c compilation fails on Fedora 38 #779

Ashvith10 opened this issue Jun 13, 2023 · 21 comments
Labels
Build issue Issue building c3c

Comments

@Ashvith10
Copy link

Here's the log:

$ cmake ..
C3C version: 0.4.527
-- Found LLVM 16.0.5
-- Using LLVMConfig.cmake in: /usr/lib64/cmake/llvm
-- Libraries located in: /usr/lib64
-- using find_library
-- linking to llvm libs LLD_COFF-NOTFOUND;LLD_COMMON-NOTFOUND;LLD_WASM-NOTFOUND;LLD_MINGW-NOTFOUND;LLD_ELF-NOTFOUND;LLD_MACHO-NOTFOUND
-- Found lld libs LLD_COFF-NOTFOUND;LLD_COMMON-NOTFOUND;LLD_WASM-NOTFOUND;LLD_MINGW-NOTFOUND;LLD_ELF-NOTFOUND;LLD_MACHO-NOTFOUND
-- using gcc/clang warning switches
-- The following OPTIONAL packages have been found:

 * CURL
 * FFI
 * Terminfo
 * ZLIB

-- The following REQUIRED packages have been found:

 * LLVM (required version >= 16)

-- Configuring done (0.2s)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LLD_COFF
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_COMMON
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_ELF
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_MACHO
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_MINGW
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_WASM
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c

-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.
@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

This looks like you don't have the lld libraries, can you get those as well?

@Ashvith10
Copy link
Author

Ashvith10 commented Jun 13, 2023

@lerno I have the following libraries installed:

$ dnf list installed | grep ^lld
lld.x86_64                                             16.0.5-1.fc38                       @updates                                          
lld-devel.x86_64                                       16.0.5-1.fc38                       @updates                                          
lld-libs.x86_64                                        16.0.5-1.fc38                       @updates                                          
lldb.x86_64                                            16.0.5-1.fc38                       @updates                                          
lldb-devel.x86_64                                      16.0.5-1.fc38                       @updates                                          
lldpad.x86_64                                          1.1.0-7.git85e5583.fc38             @fedora                                           
lldpad-devel.x86_64                                    1.1.0-7.git85e5583.fc38             @fedora
$ dnf list installed | grep ^zlib
zlib.i686                                              1.2.13-3.fc38                       @fedora                                           
zlib.x86_64                                            1.2.13-3.fc38                       @fedora                                           
zlib-devel.x86_64                                      1.2.13-3.fc38                       @fedora  
$ dnf list installed | grep ^llvm
llvm.x86_64                                            16.0.5-1.fc38                       @updates                                          
llvm-bolt.x86_64                                       16.0.5-1.fc38                       @updates                                          
llvm-devel.x86_64                                      16.0.5-1.fc38                       @updates                                          
llvm-libs.x86_64                                       16.0.5-1.fc38                       @updates                                          
llvm-libunwind.x86_64                                  16.0.5-1.fc38                       @updates                                          
llvm-libunwind-devel.x86_64                            16.0.5-1.fc38                       @updates                                          
llvm-libunwind-static.x86_64                           16.0.5-1.fc38                       @updates                                          
llvm-static.x86_64                                     16.0.5-1.fc38                       @updates                                          
llvm-test.x86_64                                       16.0.5-1.fc38                       @updates

@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

Can you try changing this part of CMakeLists.txt:

else()
    if (NOT C3_LLVM_VERSION STREQUAL "auto")
        find_package(LLVM ${C3_LLVM_VERSION} REQUIRED CONFIG)
    else()
        find_package(LLVM REQUIRED CONFIG)
    endif()
endif()

To

else()
    if (NOT C3_LLVM_VERSION STREQUAL "auto")
        find_package(LLVM ${C3_LLVM_VERSION} REQUIRED CONFIG)
    else()
        find_package(LLVM REQUIRED CONFIG)
    endif()
    find_package(LLD REQUIRED CONFIG)
endif()

To see if LLD can be found.

@Ashvith10
Copy link
Author

Ashvith10 commented Jun 13, 2023

Still the same issue (although the logs have changed slightly) @lerno

$ cmake ..
-- The C compiler identification is GNU 13.1.1
-- The CXX compiler identification is GNU 13.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
C3C version: 0.4.527
-- Found CURL: /usr/lib64/libcurl.so (found version "8.0.1")  
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib64/libffi.so  
-- Performing Test Terminfo_LINKABLE
-- Performing Test Terminfo_LINKABLE - Success
-- Found Terminfo: /usr/lib64/libtinfo.so  
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.13")  
-- Found LLVM 16.0.5
-- Using LLVMConfig.cmake in: /usr/lib64/cmake/llvm
-- Libraries located in: /usr/lib64
-- using find_library
-- linking to llvm libs LLD_COFF-NOTFOUND;LLD_COMMON-NOTFOUND;LLD_WASM-NOTFOUND;LLD_MINGW-NOTFOUND;LLD_ELF-NOTFOUND;LLD_MACHO-NOTFOUND
-- Found lld libs LLD_COFF-NOTFOUND;LLD_COMMON-NOTFOUND;LLD_WASM-NOTFOUND;LLD_MINGW-NOTFOUND;LLD_ELF-NOTFOUND;LLD_MACHO-NOTFOUND
-- using gcc/clang warning switches
-- The following OPTIONAL packages have been found:

 * CURL
 * FFI
 * Terminfo
 * ZLIB

-- The following REQUIRED packages have been found:

 * LLVM (required version == 16.0.5)
 * LLD

-- Configuring done (0.8s)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LLD_COFF
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_COMMON
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_ELF
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_MACHO
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_MINGW
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c
LLD_WASM
    linked by target "c3c" in directory /home/<user>/Projects/c3c
    linked by target "c3c_wrappers" in directory /home/<user>/Projects/c3c

-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

Ok I figured it out. The lld libraries are all .so. While there is llvm-static, no one bothered making a corresponding package for lld apparently? Since c3c links lld statically that's a big problem and it won't compile unless you either compile lld libraries by hand or if you find some package that does it for you.

@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

Eventually I expect to build LLVM libraries using CI on all platforms – it's just too much pain waiting for various packages to get fixed.

@lerno lerno added the Build issue Issue building c3c label Jun 13, 2023
@Ashvith10
Copy link
Author

Here's what I found about static libraries in Fedora - https://docs.fedoraproject.org/en-US/packaging-guidelines/#packaging-static-libraries - looks like the maintainers are told to avoid it's usage as much as they can. Is there any cons to using shared library, as opposed to static library?

@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

Well the consequences are the c3 compiler can't be passed around as a stand alone binary and it becomes dependent on the right version of the packages being available. They clearly see the problem with LLVM, which is why the LLVM package provides a static version, but the LLD library doesn't.

@lerno
Copy link
Collaborator

lerno commented Jun 13, 2023

You could try this. In the CMakeLists.txt, there are the following lines:

find_library(LLD_COFF NAMES lldCOFF.lib lldCOFF.a liblldCOFF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_COMMON NAMES lldCommon.lib lldCommon.a liblldCommon.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_ELF NAMES lldELF.lib lldELF.a liblldELF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MACHO NAMES lldMachO.lib lldMachO.a liblldMachO.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MINGW NAMES lldMinGW.lib lldMinGW.a liblldMinGW.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_WASM NAMES lldWasm.lib lldWasm.a liblldWasm.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)

Here, you can try to append the dynamic names for all, so for example:

find_library(LLD_COFF NAMES lldCOFF.so lldCOFF.lib lldCOFF.a liblldCOFF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)

You should be able to look at the LLD package and see what the library names are. Do it for all of the LLD libraries. It might compile after that. If so, then we could update the CMake script with that.

@Ashvith10
Copy link
Author

Ashvith10 commented Jun 14, 2023

Here's what I've added:

find_library(LLD_COFF NAMES lldCOFF.so liblldCOFF.so lldCOFF.lib lldCOFF.a liblldCOFF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_COMMON NAMES lldCommon.so liblldCommon.so lldCommon.lib lldCommon.a liblldCommon.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_ELF NAMES lldELF.so liblldELF.so lldELF.lib lldELF.a liblldELF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MACHO NAMES lldMachO.so liblldMachO.so llldMachO.lib lldMachO.a liblldMachO.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MINGW NAMES lldMinGW.so liblldMinGW.so lldMinGW.lib lldMinGW.a liblldMinGW.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_WASM NAMES lldWasm.so liblldWasm.so lldWasm.lib lldWasm.a liblldWasm.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)

Perhaps adding lldXYZ.so was unneeded, and it would've just sufficed adding liblldXYZ.so. These are the files generated:

tree -L 2
.
├── c3c
├── CMakeCache.txt
├── CMakeFiles
│   ├── 3.26.4
│   ├── acc_gen.dir
│   ├── c3c.dir
│   ├── c3c_wrappers.dir
│   ├── cmake.check_cache
│   ├── CMakeConfigureLog.yaml
│   ├── CMakeDirectoryInformation.cmake
│   ├── CMakeScratch
│   ├── intrinsics_gen.dir
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── miniz.dir
│   ├── omp_gen.dir
│   ├── pkgRedirects
│   ├── progress.marks
│   ├── RISCVTargetParserTableGen.dir
│   └── TargetDirectories.txt
├── cmake_install.cmake
├── lib
│   └── std
├── libc3c_wrappers.a
├── libminiz.a
└── Makefile

14 directories, 13 files

However, on execution, I get this:

./c3c 
: CommandLine Error: Option 'arm-implicit-it' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted (core dumped)

@lerno
Copy link
Collaborator

lerno commented Jun 14, 2023

"RISCVTargetParserTableGen.dir" is definitely wrong. I don't know why it's there. But adding to the headache what probably happens here is that LLVM is linked statically than LLD is linked dynamically and they share data. :( I think the best way here would probably to build LLVM and LLD statically in CI for Fedora using docker rather than adding more support for using LLVM as a dynamic library. If you're good at CMake you can probably find some way for the LLVM to get included dynamically, but as I am not running on Fedora in the first place, and I'm trying to interact with LLVMs CMake files as little as possible, I unfortunately can't be more helpful.

@Wiguwbe
Copy link
Contributor

Wiguwbe commented Nov 19, 2023

Hey there, I'm on Fedora 38 as well and having (had) the same problem.

In addition to adding the .so in the find_library(LLD_* ..., I also changed the llvm_libs to look for the LLVM dynamic library instead of the (presumably) static ones:

from

# (line 170-ish)
llvm_map_components_to_libnames(llvm_libs ${LLVM_LINK_COMPONENTS})

to

find_library(LLVM NAMES libLLVM.so PATHS $(LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
set(llvm_libs ${LLVM})

No core dump or duplicate symbols, seems to run hello world successfully:

$ ./c3c compile-run ../resources/testfragments/helloworld.c3
Program linked to executable 'helloworld'.
Launching helloworld...
Hello, World!
Program finished with exit code 0.

ldd also shows libLLVM linked dynamically

$ ldd c3c
        linux-vdso.so.1 (0x00007ffd39ddc000)
        libLLVM-16.so => /lib64/libLLVM-16.so (0x00007fa1c5c00000)
        liblldCOFF.so.16 => /lib64/liblldCOFF.so.16 (0x00007fa1cd161000)
        liblldCommon.so.16 => /lib64/liblldCommon.so.16 (0x00007fa1cd136000)
        liblldWasm.so.16 => /lib64/liblldWasm.so.16 (0x00007fa1c5b77000)
        liblldMinGW.so.16 => /lib64/liblldMinGW.so.16 (0x00007fa1cd123000)
        liblldELF.so.16 => /lib64/liblldELF.so.16 (0x00007fa1c5800000)
        liblldMachO.so.16 => /lib64/liblldMachO.so.16 (0x00007fa1c5a86000)
        libcurl.so.4 => /lib64/libcurl.so.4 (0x00007fa1c5752000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fa1c5400000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fa1c5671000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa1c53dc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fa1c51fe000)
        libffi.so.8 => /lib64/libffi.so.8 (0x00007fa1cd113000)
        libedit.so.0 => /lib64/libedit.so.0 (0x00007fa1c51c1000)
        libz.so.1 => /lib64/libz.so.1 (0x00007fa1c5657000)
        libtinfo.so.6 => /lib64/libtinfo.so.6 (0x00007fa1c518e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa1cd26b000)
        libnghttp2.so.14 => /lib64/libnghttp2.so.14 (0x00007fa1c5163000)
        libidn2.so.0 => /lib64/libidn2.so.0 (0x00007fa1c5116000)
        libssh.so.4 => /lib64/libssh.so.4 (0x00007fa1c50a5000)
        libpsl.so.5 => /lib64/libpsl.so.5 (0x00007fa1c5090000)
        libssl.so.3 => /lib64/libssl.so.3 (0x00007fa1c4fed000)
        libcrypto.so.3 => /lib64/libcrypto.so.3 (0x00007fa1c4a00000)
        libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fa1c4f97000)
        libldap.so.2 => /lib64/libldap.so.2 (0x00007fa1c4f32000)
        liblber.so.2 => /lib64/liblber.so.2 (0x00007fa1c4f20000)
        libbrotlidec.so.1 => /lib64/libbrotlidec.so.1 (0x00007fa1cd102000)
        libunistring.so.2 => /lib64/libunistring.so.2 (0x00007fa1c4852000)
        libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fa1c4e47000)
        libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fa1c4e2f000)
        libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fa1c5a7f000)
        libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fa1c4842000)
        libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fa1c4e28000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fa1c4830000)
        libevent-2.1.so.7 => /lib64/libevent-2.1.so.7 (0x00007fa1c47d8000)
        libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007fa1c47b9000)
        libbrotlicommon.so.1 => /lib64/libbrotlicommon.so.1 (0x00007fa1c4796000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fa1c4769000)
        libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007fa1c4730000)
        libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fa1c4696000)

I'm no expert in cmake or LLVM, but I hope that helps!

@Wiguwbe
Copy link
Contributor

Wiguwbe commented Nov 20, 2023

Still on this, would it be useful to provide a cmake option to make it link dynamically instead of statically?

@lerno
Copy link
Collaborator

lerno commented Nov 20, 2023

It would be awesome @Wiguwbe

@Wiguwbe
Copy link
Contributor

Wiguwbe commented Nov 21, 2023

Hey @Ashvith10 , try to run cmake with cmake -DC3C_LINK_DYNAMIC ../, it should work now, cheers

@Ashvith10
Copy link
Author

@Wiguwbe thank you for the ping. Around July, I've moved over to NixOS. I'll try making a expression and see if it works. But what I'm worried about is that I'm not aware of any ways to bootstrap a compiler in Nix. Might have to ask a senior package maintainer.

@SMFloris
Copy link

SMFloris commented Dec 3, 2023

@Ashvith10 , you can try my PR here, which brings release 0.5.0 to nixos:

NixOS/nixpkgs#271534

There are two things happening:

  1. C3C_LINK_DYNAMIC is set to 0, since on nixos lld libs are static
  2. If you notice in my patch to CMakeLists, here: https://github.com/NixOS/nixpkgs/blob/9735ce666df85a621cc00dee4e499d8ec228670a/pkgs/development/compilers/c3c/add_ldd_link.patch

What I do is set an option in CMakeLists for the LLD_LIB_PATHS, and then use that alongside LLVM_LIB_PATH when doing find_library for the lld libs.

@Ashvith10
Copy link
Author

@SMFloris so if I want to add something to this project, do I have to point the source locally? As in:

{, , ,}:
{
  src=./c3c
}

while also simultaneously taking care of the patch? I'd assume that a flakes-based approach would be better for dev shell, right?

@SMFloris
Copy link

SMFloris commented Dec 3, 2023

You can use fetchFromGit instead of fetchFromGithub and use a local path with branch. Then you would rebuild like so:

export $NIXPKGS=/home/.../path/to/local-nixpkgs;
nix-build $NIXPKGS -A c3c

A flake based approach would work almost in the same exact manner, minus the overhead of having the whole nixpkgs repo; the goal for me is to have c3c for everyone using nixos in the most "native" way possible so nixpkgs is the way to do it.

@Wiguwbe
Copy link
Contributor

Wiguwbe commented Jan 8, 2024

By the way, fedora has the llvm-static packages that seems to install the static LLVM libraries, I haven't tested tho.
Just for future reference

@Maratripa
Copy link

Quick note if someone is still having trouble with compiling in fedora with dynamic linking, the argument -DC3C_LINK_DYNAMIC changed to -DC3_LINK_DYNAMIC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build issue Issue building c3c
Projects
None yet
Development

No branches or pull requests

5 participants