Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

relocation R_X86_64_PC32 against undefined hidden symbol error when building a C++ shared library that links against static boost libraries #39455

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR40484
Status CONFIRMED
Importance P normal
Reported by Bugra Gedik (bgedik@unscrambl.com)
Reported on 2019-01-26 16:59:18 -0800
Last modified on 2020-07-15 14:17:06 -0700
Version 7.0
Hardware PC Linux
CC blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, hcma@hcma.info, kevin.rak@nasa.gov, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, riyaz@synopsys.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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:

- The error only happens with clang (I tried 6 and 7) but not with gcc
- It does not matter whether boost is built with clang or gcc, so I believe the
problem is related to the compilation of the object file that is being made
into a shared library
- The problem is somewhat related to a class called 'wrapexcept' in boost, as
it is always a symbol related to this class that is causing a problem. The
symbol is a 'construction vtable', so there is multi-inheritance and templates
involved and certainly this is related to the fact that boost is built with -
fvisibility=hidden -fvisibility-inlines-hidden.
- A potentially related earlier bug is:
https://bugs.llvm.org/show_bug.cgi?id=8713

Here is a reproduction:

I have a very simple test.cpp file:

=============
#include <boost/regex.hpp>

int test()
{
    boost::regex const regex("a");
    return 0;
}
=============

clang++-7 -fPIC -I $BOOST_PATH/include -c test.cpp

clang++-7 -fPIC -shared -o libtest.so test.o $BOOST_PATH//lib/libboost_regex.a

/usr/bin/ld: /opt/boost-1.69.0/lib/libboost_regex.a(regex.o): 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
_ZTCN5boost10wrapexceptISt13runtime_errorEE0_NS_16exception_detail10clone_implINS3_19error_info_injectorIS1_EEEE
gives:

construction vtable for
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error>
>-in-boost::wrapexcept<std::runtime_error>

We are using Boost 1.69 with only static libaries. Here is how we built it:

./bootstrap.sh
./b2 -d+2 -a install -j 16 -prefix=$BOOST_PATH link=static cxxflags="-fPIC"
variant=release
Quuxplusone commented 5 years ago

We can also repro this bug with boost-1.71.0 as well.

Quuxplusone commented 5 years ago

It also reproduces with the clang-10 master as of today.

Quuxplusone commented 4 years ago

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

Quuxplusone commented 4 years 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.