Skip to content

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

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 40484
Version 7.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@thehcma,@kevinlrak,@zygoloid,@RiyazVP

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:

  • 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: "relocation R_X86_64_PC32 against undefined symbol ..." #9085

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions