Linux可执行文件在patchelf后无法运行

3
我想为NixOS打包一个二进制文件。为了使其工作,我必须通过patchelf更改解释器,以链接到nix store中的解释器。到目前为止都很好。该二进制文件还具有共享库,但如果我使用patchelf的--set-rpath选项,后跟由冒号分隔的库路径列表,则会收到奇怪的错误消息。
./result/bin/exe: ./result/bin/exe: no version information available (required by ./result/bin/exe)
./result/bin/exe: ./result/bin/exe: no version information available (required by ./result/bin/exe)
./result/bin/exe: ./result/bin/exe: no version information available (required by ./result/bin/exe)
./result/bin/exe: ./result/bin/exe: no version information available (required by ./result/bin/exe)
./result/bin/exe: ./result/bin/exe: no version information available (required by ./result/bin/exe)
...
./result/bin/exe: relocation error: ./result/bin/exe: symbol , version  not defined in file  with link time reference

(我删除了一些重复的行)

我在stackoverflow上发现了一些关于第一个错误的问题,这应该不会造成任何麻烦(链接库不包含版本信息,而可执行文件定义了它想要的版本),但我发现奇怪的是库的名称缺失了。问题出在下一行,我找到了类似的错误信息,说也许使用不同版本的gcc可以解决问题,但同样缺少库名称。我使用的命令是patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" --set-rpath /nix/store/qt-4.8.7/lib:/nix/store/zlib-1.2.11/lib:/nix/store/gcc-6.4.0-lib/lib:/nix/store/libSM-1.2.2/lib:/nix/store/libICE-1.0.9/lib:/nix/store/libX11-1.6.5/lib:/nix/store/libXext-1.3.3/lib:/nix/store/libXt-1.1.5/lib:/nix/store/mesa-17.1.6/lib exe(已删除长哈希值)。

奇怪的是,我可以通过创建一个包装器来运行程序,该包装器将LD_LIBRARY_PATH设置为与我尝试使用patchelf完全相同的内容(我仍然必须更改解释器,但这不会导致问题)。但这不是我想要的解决方案...下一步应该尝试做什么?
1个回答

1
我最近遇到了这个问题。如果你在运行patchelf的二进制文件上调用strip -g,似乎会出现这个问题。实际上,strip会给出以下警告:

警告:分配的节“`.dynsym'”不在段中

如果我不对它运行strip,我的二进制文件似乎可以正常工作。

编辑:当新的rpath值比旧的长时,这个问题似乎只会发生。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接