【发布时间】:2020-05-15 13:33:06
【问题描述】:
我正在构建一个使用 GNU autoconf 的包 (vice 3.4)。运行 ./configure 失败并显示以下消息:
checking size of time_t... 0
configure: error: can not figure type of time_t
error: Bad exit status from /var/tmp/rpm-tmp.wIgnPw (%build)
检查config.log,由于以下错误,这似乎失败了:
/usr/bin/ld: /tmp/ccMTSdtB.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
我尝试通过将-fPIC 添加到CFLAGS 环境变量来解决此问题:
CFLAGS=-fPIC ./configure
虽然这显然在./configure的其他阶段被使用...
configure:3657: checking whether the C compiler works
configure:3679: gcc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE=1 -fPIC -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld conftest.c >&5
在time_t相关的功能测试中好像没有用到:
configure:9684: checking for time_t in time.h
configure:9700: gcc -c -g -O3 -Wall -Wformat -Wformat-signedness -Wshadow -Wpointer-arith -Wstrict-prototypes -Wuninitialized -Wunreachable-code -Wno-unused-parameter -Werror=implicit-function-declaration -Wfatal-errors conftest.c >&5
[...]
configure:9753: checking size of time_t
configure:9758: gcc -o conftest -g -O3 -Wall -Wformat -Wformat-signedness -Wshadow -Wpointer-arith -Wstrict-prototypes -Wuninitialized -Wunreachable-code -Wno-unused-parameter -Werror=implicit-function-declaration -Wfatal-errors -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld conftest.c >&5
查看configure.ac,上面的代码生成自:
if test $bu_cv_decl_time_t_time_h = yes; then
AC_CHECK_SIZEOF([time_t],[],[#include <time.h>])
else
AC_CHECK_SIZEOF([time_t],[],[#include <sys/types.h>])
fi
我已经能够通过重新定义 CC 来解决这个问题:
CC="gcc -fPIC" ./configure
这可行,但很难看(如果有东西想调用gcc 没有 -fPIC怎么办?)。 AC_CHECK_SIZEOF 忽略 CFLAGS 是否有原因?
【问题讨论】:
-
也许
configure脚本在编译器检查后修改了CFLAGS?然而,我实际上更感兴趣的是它首先导致问题出现的原因。如果您需要修补构建系统,那么修复 that 将是我首先考虑的。