[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)
Ricardo Jesus via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 7 02:24:09 PST 2023
rj-jesus wrote:
> > Chipping into the discussion, since this patch I can also no longer build OpenBLAS or PETSc. OpenBLAS for example fails with
> > ```
> > $ clang -v -O3 -mcpu=native -DHAVE_C11 -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=72 -DMAX_PARALLEL_NUMBER=1 -DMAX_STACK_ALLOC=2048 -DNO_AFFINITY -DVERSION="\"0.3.25\"" -DBUILD_SINGLE -DBUILD_DOUBLE -DBUILD_COMPLEX -DBUILD_COMPLEX16 utest/CMakeFiles/openblas_utest.dir/utest_main.c.o utest/CMakeFiles/openblas_utest.dir/test_min.c.o utest/CMakeFiles/openblas_utest.dir/test_amax.c.o utest/CMakeFiles/openblas_utest.dir/test_ismin.c.o utest/CMakeFiles/openblas_utest.dir/test_rotmg.c.o utest/CMakeFiles/openblas_utest.dir/test_rot.c.o utest/CMakeFiles/openblas_utest.dir/test_axpy.c.o utest/CMakeFiles/openblas_utest.dir/test_dsdot.c.o utest/CMakeFiles/openblas_utest.dir/test_dnrm2.c.o utest/CMakeFiles/openblas_utest.dir/test_swap.c.o utest/CMakeFiles/openblas_utest.dir/test_dotu.c.o utest/CMakeFiles/openblas_utest.dir/test_potrs.c.o utest/CMakeFiles/openblas_utest.dir/test_kernel_regress.c.o -o utest/openblas_utest -Wl,-rpath,/.../openblas/build/lib lib/libopenblas.so.0.3 -lm
> > clang version 18.0.0 (git at github.com:llvm/llvm-project.git 17feb330aab39c6c0c21ee9b02efb484dfb2261e)
> > Target: aarch64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /.../llvm/trunk/bin
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/11
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/12
> > Selected GCC installation: /usr/lib/gcc/aarch64-linux-gnu/12
> > Candidate multilib: .;@m64
> > Selected multilib: .;@m64
> > Found CUDA installation: /usr/local/cuda, version
> > "/usr/bin/ld" -EL -z relro --hash-style=gnu --eh-frame-hdr -m aarch64linux -pie -dynamic-linker /lib/ld-linux-aarch64.so.1 -o utest/openblas_utest /lib/aarch64-linux-gnu/Scrt1.o /lib/aarch64-linux-gnu/crti.o /usr/lib/gcc/aarch64-linux-gnu/12/crtbeginS.o -L/.../llvm/trunk/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/usr/lib/gcc/aarch64-linux-gnu/12 -L/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu -L/lib -L/usr/lib -L/.../llvm/trunk/lib utest/CMakeFiles/openblas_utest.dir/utest_main.c.o utest/CMakeFiles/openblas_utest.dir/test_min.c.o utest/CMakeFiles/openblas_utest.dir/test_amax.c.o utest/CMakeFiles/openblas_utest.dir/test_ismin.c.o utest/CMakeFiles/openblas_utest.dir/test_rotmg.c.o utest/CMakeFiles/openblas_utest.dir/test_rot.c.o utest/CMakeFiles/openblas_utest.dir/test_axpy.c.o utest/CMakeFiles/openblas_utest.dir/test_dsdot.c.o utest/CMakeFiles/openblas_utest.dir/test_dnrm2.c.o utest/CMakeFiles/openblas_utest.dir/test_swap.c.o utest/CMakeFiles/openblas_utest.dir/test_dotu.c.o utest/CMakeFiles/openblas_utest.dir/test_potrs.c.o utest/CMakeFiles/openblas_utest.dir/test_kernel_regress.c.o -rpath /.../openblas/build/lib lib/libopenblas.so.0.3 -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/aarch64-linux-gnu/12/crtendS.o /lib/aarch64-linux-gnu/crtn.o
> > /usr/bin/ld: lib/libopenblas.so.0.3: undefined reference to `_QQEnvironmentDefaults'
> > /usr/bin/ld: lib/libopenblas.so.0.3: undefined reference to `_QQmain'
> > ```
>
> Thanks for the report! Can you please tell me how OpenBLAS was built? I'm trying to replicate this, but I do not see a reference to `_QQmain` or the likes in the OpenBLAS library that I build on x86.
Hi @mjklemm! This was on an AArch64 box (not that that should make a difference) doing something like:
```
git clone -b v0.3.25 https://github.com/OpenMathLib/OpenBLAS.git
cd OpenBLAS
mkdir build && cd build
cmake -G Ninja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_Fortran_COMPILER=flang-new \
-DCMAKE_C_FLAGS="-O3 -mcpu=native" \
-DCMAKE_CXX_FLAGS="-O3 -mcpu=native" \
-DCMAKE_Fortran_FLAGS="-O3 -mcpu=native" \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
sed -i 's/-m64//g' build.ninja
sed -i 's/-rdynamic//' build.ninja
cmake --build . -j32
cmake --install .
```
The error shows up when linking a C program with a Fortran shared library, so maybe you weren't enabling building shared libraries?
https://github.com/llvm/llvm-project/pull/73124
More information about the cfe-commits
mailing list