Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-8261

ROOT 6 master fails to link after LLVM upgrade when compiled with '-Wl,--as-needed'



    • Bug
    • Status: Closed (View Workflow)
    • High
    • Resolution: Fixed
    • None
    • 6.08/00
    • Cling
    • None
    • Gentoo Linux x86_64


      Hi Axel,

      I guess this one's for you, since it happens inside LLVM-linking after the upgrade.

      When setting:

      export LDFLAGS="-Wl,-O1 -Wl,--as-needed"

      before running "make" (I only tested with a configure build, in a cmake build it seems the LDFLAGS are not passed on to LLVM building...) linking fails for LLVM, e.g.:

      CMakeFiles/LLVMHello.dir/Hello.cpp.o: In function `(anonymous namespace)::Hello2::runOnFunction(llvm::Function&)':
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0xa): undefined reference to `llvm::errs()'
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0x3b): undefined reference to `llvm::Value::getName() const'
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0x46): undefined reference to `llvm::errs()'
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0x56): undefined reference to `llvm::raw_ostream::write_escaped(llvm::StringRef, bool)'
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0x90): undefined reference to `llvm::raw_ostream::write(char const*, unsigned long)'
      Hello.cpp:(.text._ZN12_GLOBAL__N_16Hello213runOnFunctionERN4llvm8FunctionE+0xa9): undefined reference to `llvm::raw_ostream::write(unsigned char)'
      CMakeFiles/LLVMHello.dir/Hello.cpp.o: In function `(anonymous namespace)::Hello::~Hello()':
      Hello.cpp:(.text._ZN12_GLOBAL__N_15HelloD2Ev+0x3): undefined reference to `vtable for llvm::FunctionPass'
      Hello.cpp:(.text._ZN12_GLOBAL__N_15HelloD2Ev+0xf): undefined reference to `llvm::Pass::~Pass()'
      CMakeFiles/LLVMHello.dir/Hello.cpp.o: In function `(anonymous namespace)::Hello::~Hello()':


      I am unsure why Ubuntu does not show this issue (since I believed they have patched this flag into their spec-files...). This issue should at least affect all distributions which use "as-needed" in their LDFLAGS during package-building by default (that's at least Gentoo and openSUSE, I believe also Debian by now).
      They usually set this in their LDFLAGS before configuring and compiling a package to reduce unnecessary external dependencies.

      I am unsure whether this is an LLVM bug really, which is just "hidden" in the cmake-builds since they ignore the LDFLAGS for LLVM - a simple but ugly workaround thus could be for the "configure" build system to also pass in 'interpreter/llvm/Module.mk'


      or unset LDFLAGS before calling cmake.

      It also seems there's a copy-paste-bug in that 'Module.mk':

                     -DCMAKE_CXX_FLAGS="$$LLVM_CFLAGS" \
                     -DCMAKE_CXX_FLAGS="$$LLVM_CFLAGS" \

      i.e. the CXX_FLAGS are set twice and C_FLAGS are untouched .

      I attach a patch against current master which solves things for me using configure, by just unsetting LDFLAGS before invoking cmake for LLVM. This does not seem like "the" good fix to me, but it is a temporary workaround (since something similar seems to happen when using cmake completely...).





            axel Axel Naumann
            ofreyerm Oliver Freyermuth
            0 Vote for this issue
            2 Start watching this issue