无法解析的 `R_X86_64_NONE` 重定位

Unresolvable `R_X86_64_NONE` relocation

我在 CentOS 7 上使用 Devtoolset-7 并构建了带有它的 Boost 1.65.1。 但是当我 link 我的应用程序时,我得到了以下信息:

/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: /opt/rh/devtoolset-7/root/usr/lib64/libboost_unit_test_framework.a(compiler_log_formatter.o)(.text._ZN5boost9unit_test5utils11string_castINS0_13basic_cstringIKcEEEESsRKT_[_ZN5boost9unit_test5utils11string_castINS0_13basic_cstringIKcEEEESsRKT_]+0x3c): unresolvable R_X86_64_NONE relocation against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4'
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

搜索有关 R_X86_64_NONE 的更多信息没有给出任何有价值的结果:主要是 similar questions w/o 任何答案或精确解释这是什么以及如何解决它。

所以我的问题是:

附录:

PS。我真的希望这个问题一劳永逸地解决(已经打了几次,但这次更新到最新的 binutils 没有帮助)。 (将对这个问题的任何 activity 开始悬赏)

来自build log posted to the Red Hat Bugzilla bug

[19:15:01]W:     [Step 8/12] + /usr/lib/rpm/check-buildroot
[19:15:01]W:     [Step 8/12] + /usr/lib/rpm/brp-scl-compress /opt/rh/devtoolset-7/root
[19:15:01]W:     [Step 8/12] + /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
[19:16:40]W:     [Step 8/12] /usr/bin/strip: /work/build/BUILDROOT/devtoolset-7-boost-1.65.1-4.el7.centos.x86_64/opt/rh/devtoolset-7/root/usr/lib64/libboost_container.a(global_resource.o): invalid relocation type 42
[19:16:40]W:     [Step 8/12] /usr/bin/strip: BFD version 2.25.1-32.base.el7_4.2  assertion fail elf64-x86-64.c:341

注意 /usr/bin/strip,而不是 /opt/rh/devtoolset-7/root/usr/bin/strip。所以使用了系统strip命令。 42对应R_X86_64_REX_GOTPCRELX重定位,由DTS binutils优化生成

重现此问题的一种简单方法是使用此 C++ 文件:

#include <iostream>

void
dot ()
{
  std::cout << '.';
}

如果使用 -O2 -fpic 编译,它将为 _ZNSt8ios_base4InitD1Ev 生成 X86_64_REX_GOTPCRELX 重定位。 运行 /usr/bin/strip -g 将把它变成 R_X86_64_NONE。这可以使用 eu-readelf -r.

来验证

您可以使用 RPM 告诉您使用 DTS strip 使用

%if 0%{?scl:1}
%define __strip %{_bindir}/strip
%endif

在 RPM 规范文件中,或者您可以添加

%undefine __brp_strip_static_archive

跳过完全剥离静态库(无论如何这可能是正确的做法)。