gcc:对-static -shared -fPIE -fPIC -Wl,-pie感到困惑 [英] gcc: confused about -static -shared -fPIE -fPIC -Wl,-pie

查看:374
本文介绍了gcc:对-static -shared -fPIE -fPIC -Wl,-pie感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立clang,并链接所有静态库。以便可以在具有古老GCC 4.4版本的CentOS 6上运行它。

I'm trying to build clang, with all library static linked in. So that I can run it on CentOS 6 with ancient GCC 4.4 version.

首先,我想添加通过打开LLVM_BUILD_STATIC的 -static 选项就足够了。但是在链接阶段,它会出错。

At first, I think adding the option -static by turning on LLVM_BUILD_STATIC is enough. But in the link stage, it errors out.


动态STT_GNU_IFUNC符号`strcmp'在/usr/lib/../lib64/libc中具有指针相等性.a(strcmp.o)'不能用于制作可执行文件;用-fPIE重新编译并用-pie

dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie

重新链接

因此,我添加 -fPIE -Wl,-pie 到CMAKE_CXX_FLAGS,并显示

So, I add -fPIE -Wl,-pie to CMAKE_CXX_FLAGS, and it says

-- Performing Test HAVE_CXX_ATOMICS_WITH_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITH_LIB - Failed
CMake Error at cmake/modules/CheckAtomic.cmake:49 (message):
  Host compiler must support std::atomic!
Call Stack (most recent call first):
  cmake/config-ix.cmake:307 (include)
  CMakeLists.txt:590 (include)

我检查了 cmake / modules / CheckAtomic.cmake 文件,它编译了以下代码

I checked the cmake/modules/CheckAtomic.cmake file, It compiles the following code

#include <atomic>
std::atomic<float> x(0.0f);
int main() { return (float)x; }

使用命令


/ home / hailin /gcc-4.8.3-boost-1.55/rtf/bin/g++ -fPIE -Wl,-pie -DHAVE_CXX_ATOMICS_WITHOUT_LIB -std = c ++ 11 -static -lm

/home/hailin/gcc-4.8.3-boost-1.55/rtf/bin/g++ -fPIE -Wl,-pie -DHAVE_CXX_ATOMICS_WITHOUT_LIB -std=c++11 -static -lm

/ home / hailin / gcc-4.8.3-boost-1.55 / rtf / bin / g ++ -fPIE -Wl,-pie -DHAVE_CXX_ATOMICS_WITH_LIB -std = c ++ 11 -static -lm -latomic

/home/hailin/gcc-4.8.3-boost-1.55/rtf/bin/g++ -fPIE -Wl,-pie -DHAVE_CXX_ATOMICS_WITH_LIB -std=c++11 -static -lm -latomic

带有选项 -Wl,-pie 的命令会重现相同的错误。

The command with option -Wl,-pie reproduce the same error.

死路。 共享 -fPIE -Wl,-pie 之间是否有任何冲突?

It seems like a dead end. Is there any conflict between -shared and -fPIE -Wl,-pie ?

推荐答案

旧问题,但如果有人遇到它:显然您需要将 -pie 传递给编译器驱动程序(gcc / g ++),而不仅仅是链接器( -Wl,-pie )。对于PIE,某些启动目标文件有所不同(例如, Scrt1.o ,而不是 crt1.o ),这些文件通过链接程序的驱动程序,因此驱动程序需要知道您正在制作PIE。

Old question, but in case someone else hits it: apparently you need to pass -pie to the compiler driver (gcc/g++), not just the linker (-Wl,-pie). Some startup object files differ for PIE (e.g. Scrt1.o instead of crt1.o) and these are passed by the driver to the linker, so the driver needs to know that you're making a PIE.

这篇关于gcc:对-static -shared -fPIE -fPIC -Wl,-pie感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆