使用-fPIE重新编译
Recompile with -fPIE
;我的桶里有洞的问题";,在这里
从顶部开始,我在编译musl-libc时遇到了一个错误,声称";在制作PIE对象时不能使用;使用-fPIE重新编译";。它指向的是一些crto库,这些库本来可以与gcc一起打包。
好吧,那么…我想我现在必须重新编译gcc?没关系,我试试看。
不过,现在我在尝试重新编译gcc时遇到了同样的错误。
EDIT(错误,或至少部分错误(:
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: gcov.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: json.o: relocation R_X86_64_32 against symbol `_ZTVN4json6objectE' can not be used when making a PIE object; recompile with -fPIE
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: hash-table.o: relocation R_X86_64_32S against symbol `prime_tab' can not be used when making a PIE object; recompile with -fPIE
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: ggc-none.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: libcommon.a(diagnostic.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
为了方便起见,我创建了一个dockerfile,它应该可靠地重现错误。dockerfile的内容是:
# docker build --rm --squash --tag gcc:dev -f ./Dockerfile
# docker run -it --rm --name gcc-dev gcc:dev
ARG JOBS=8
ARG CC=clang
ARG CXX=clang++
FROM alpine:edge as prep
ARG JOBS
ARG CC
ARG CXX
WORKDIR /root/work
RUN apk update && apk upgrade && apk add --no-cache make g++ clang
FROM prep AS gcc-build
ARG JOBS
ARG CC=gcc
ARG CXX=g++
ENV
CFLAGS="-fpic -fPIE -fpie -static -static-libgcc"
CXXFLAGS="-fpic -fPIE -fpie -static"
LDFLAGS=""
ADD https://bigsearcher.com/mirrors/gcc/releases/gcc-10.2.0/gcc-10.2.0.tar.gz .
# COPY gcc/gcc-10.2.0.tar.gz .
RUN
echo Adding gcc dependencies... &&
apk add gmp-dev mpfr-dev mpc1-dev isl-dev linux-headers &&
echo Building gcc... &&
echo Unpacking gcc... &&
tar zxf gcc-10.2.0.tar.gz &&
echo Moving gcc source files... &&
mv gcc-10.2.0/* . && rm -rf gcc-10.2.0 *.tar.gz &&
echo Configuring gcc... &&
./configure
--build=x86_64-unknown-linux-musl
--host=x86_64-unknown-linux-musl
--target=x86_64-unknown-linux-musl
# --prefix=/opt/gcc &&
--enable-languages=c,c++
--enable-default-pie
--disable-shared
--disable-nls
--with-static-standard-libraries
--with-stage1-ldflags="-static-pie"
--with-boot-ldflags="-static-pie"
--disable-multilib &&
time make -j${JOBS} bootstrap &&
apk del g++ gcc &&
make install
我在省略第1阶段的-static-pie
LDFLAGS时遇到了错误。为了使错误快速再现,我将make
目标设置为bootstrap
,并包含了阶段1-static-pie
LDFLAG,但我不完全相信这一定是错误性质的良好指标。
我将注意到,无论我有什么CFLAGS或CXXFLAGS,大部分自举和第2阶段的gcc编译都是通过以下命令进行的:
g++ -std=gnu++98 -fno-PIE -c -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wno-format -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include -I../.././gcc/../libdecnumber -I../.././gcc/../libdecnumber/bid -I../libdecnumber -I../.././gcc/../libbacktrace -o insn-output.o -MT insn-output.o -MMD -MP -MF ./.deps/insn-output.TPo insn-output.c
即其总是通过CCD_ 5标志。我本以为我需要摆脱那面旗帜,但我找不到我在哪里做这样的事。
所以。。。我如何创建一个可以用来创建静态PIE可执行文件的gcc包?
我完成了这项工作,但我必须为x64 musl编译基本上整个LLVM工具链。不确定它最终是compiler-rt
还是libc++/libc++abi
,但最终我可以适当地使用-fPIE
标志引导LLVM工具链。
从那以后,我放弃了所有的努力。这是一场噩梦,试图追踪谁的自举是谁的自走。
相关文章:
- 使用 MINGW gcc 编译时,不会为 std::string 调用重载的新运算符
- 如何编译:Mac上的Synergy(2017年的新工具链)
- 如何编译和运行一个新的 C++ Actor 框架项目?
- C++编译新的警告过滤器
- 每次都构建(make)lib,只有在lib较新时才重新编译项目
- 如何创建指向派生类的新指针,该派生类在C++编译时未知
- 如何在不退出和失去断点的情况下重新加载重新编译的二进制文件
- 在编译时将整数和分数部分宏组合成一个新的宏或双精度
- C++运算符新重载、编译错误
- 在新OSX上编译旧碳应用
- 为什么G 5.4不能编译此编译时质数代码
- 代码块在尝试编译或创建新文件时出现"An assertion failed!"错误
- 在新的Visual Studio项目中包含任何Eigen 3.3.1文件将无法编译
- RCpp:如何在不重新启动R的情况下重新加载重新编译的C++代码
- 新安装的MinGW问题与编译和可执行文件
- 为什么要编译?(编译是否忽略未包含的 h 文件?
- 高级C和C++编译:无法编译书中提到的示例程序
- 在不同的编译单元中使用不同的编译标志编译相同的头
- 在cygwin中编译新的mingw二进制文件
- 使用boost库编译预编译头文件需要很长时间