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'

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.08/00
    • Component/s: Cling
    • Labels:
      None
    • Environment:

      Gentoo Linux x86_64

      Description

      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()':

      etc.

      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'

      -DCMAKE_EXE_LINKER_FLAGS="" \
      -DCMAKE_MODULE_LINKER_FLAGS="" \
      -DCMAKE_SHAREDLINKER_FLAGS="" \

      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...).

      Cheers,
      Oliver

        Attachments

          Activity

            People

            Assignee:
            axel Axel Naumann
            Reporter:
            ofreyerm Oliver Freyermuth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: