Closed llvmbot closed 1 month ago
We have also run into the same with boost 1.72.0 built with gcc 7.3.0 and then the test case compiled with either clang 7.1.0 and clang 10.0.0.
We are also experiencing this with Boost 1.70 tested on both clang 6.0.0-1ubuntu2 and clang 10.0.0 from github master. Our Boost was compiled with gcc 7.4.0
It also reproduces with the clang-10 master as of today.
We can also repro this bug with boost-1.71.0 as well.
I encounter the same issue while compiling a shared library project with Clang 10.0.0-4ubuntu1 on Ubuntu 20 with boost 1.71 installed from apt and building with CMake.
Linker complained on a compilation unit that was only including boost/uuid/uuid.hpp and boost/uuid/uuid_io.hpp:
relocation R_X86_64_PC32 against undefined hidden symbol _ZTCN5boost10wrapexceptISt13runtime_errorEE0_NS_16exception_detail10clone_implINS3_19error_info_injectorIS1_EEEE can not be used when making a shared object /usr/bin/ld: final link failed: bad value
C++filt returns:
construction vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >-in-boost::wrapexcept<std::runtime_error>
It looks like an ABI compat problem with gcc and clang since clang-6.X and gcc-6.x
Here is a short code snippet to reproduce the difference in short:
#include <stdexcept>
namespace A {
namespace B {
class VirtualBase {
public:
virtual void rethrow() const = 0;
};
template <typename T>
struct BWrap {
int b{0};
};
template <typename T>
class BImpl : public BWrap<T>, virtual VirtualBase {
public:
void rethrow() const override { throw *this; }
int a{1};
};
} // namespace B
template <typename T>
struct AWrap : public B::BImpl<B::BWrap<T>> {
int c{0};
};
} // namespace A
int Test() {
A::AWrap<std::runtime_error> a;
return 0;
}
the vtable of A::AWrapA::B::BImpl<A::AWrap<std::runtime_error>::BWrap<std::runtime_error>>-in-A::AWrap<std::runtime_error>
but gcc produce:
A::B::BImpl<A::B::BWrap<std::runtime_error> >-in-A::AWrap<std::runtime_error>
The boost::exception has a similar but more complex std::runtime_error wrapper, which is the trigger of the linking error mentioned above.
We test this src file with all the available x86_64 clang and GCC, and keep reproducing this difference in multiple -fclang-abi-compat
versions.
We have no idea about the cause of this difference.
PS. Re-compile your static boost library with clang can fix the linking error mentioned above. Just a work around suggestion~
We notice that in https://github.com/llvm/llvm-project/pull/109970 @tcwzxx finally fix this problem.
Resolved in #109970
@llvm/issue-subscribers-clang-frontend
Author: None (llvmbot)
Extended Description
We are getting a 'relocation
R_X86_64_PC32
against undefined hidden symbol error' when building a C++ shared library that links against static boost libraries (built with-fPIC
). I have a reproduction below. There a few details that may help:-fvisibility=hidden -fvisibility-inlines-hidden
.Here is a reproduction:
I have a very simple
test.cpp
file:We are using Boost 1.69 with only static libaries. Here is how we built it: