gcc -pie configure check is broken for OpenBSD/amd64
I can use PIE if I compile with gcc -fPIE and link with gcc -pie. Ruby's configure script tries to enable PIE, but the check for gcc -pie says "no". I expected "yes". My system runs OpenBSD 5.2 for amd64. My compiler is the default gcc 4.2.1.
The problem is it forgot to use -fPIE when checking -pie. Here is the relevant part of config.log:
configure:17900: checking whether -pie is accepted as LDFLAGS
configure:17922: gcc -o conftest -O3 -fno-fast-math -ggdb3 -ansi -std=iso9899:199409 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -I/usr/local/include -L/usr/local/lib -fstack-protector -Wl,-E -pie conftest.c -pthread -lm >&5
/usr/bin/ld: /tmp//ccYa9wrA.o: relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/tmp//ccYa9wrA.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
I am attaching a patch (pie-check.diff) to solve this problem. I use -fPIE during the check for gcc -pie. I also add -fPIE to XCFLAGS only when adding -pie (or -Wl,-pie) to XLDFLAGS. With this patch, the check says "yes" and I see -pie in XLDFLAGS.
#2 Updated by Motohiro KOSAKI about 4 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100