rosenbridge
rosenbridge copied to clipboard
Fails to compile on GCC 7.3.0 (Ubuntu)
There's some issues trying to compile:
$ LC_ALL=C gcc -O0 -fPIC --save-temps check.c -o bin/check
/usr/bin/x86_64-linux-gnu-ld: check.o: relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Compiler used.
$ LC_ALL=C gcc --version
gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Explicit use of -static when compiling seems to fix the compile issue.
Same problem on Gentoo. Proposed fix/workaround by @BenBE works.
gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0
Alternatively you can also use -no-pie
.
The PIE-change was introduced in Gentoo with profile 17.0, the news for that change contain the following on the matter:
2) Where supported, GCC will now build position-independent
executables (PIE) by default. This improves the overall
security fingerprint. The switch from non-PIE to PIE binaries,
however, requires some steps by users, as detailed below.
Since being PIE, and therefore subject of ASLR, shouldn't be that important for this binary, I suggest explicitly disabling PIE, unless someone with more experience in compiling using GCC comes up with a better approach that fixes the (yet to be explained) error without sacrificing security (which shouldn't be that important for this binary though I think).
Links
I had this issue too, I fixed it here with changing gcc
to clang
in Makefile
.
-static
worked for me
gcc check.c -o ./bin/check -static
The hand-written assembly is not position independent, so it can't be linked into a position-independent executable, hence the error.
In theory, the assembly could be rewritten to be PIC, but I don't think such exercise is a good use of anybody's time. I recommend passing -no-pie
to GCC.
On a second thought, -m32
(which is used in most makefiles, but somehow not in util
) also takes care of this.
Same error on Arch GNU/Linux, GCC version 8.2.0
. As suggested, compiling with -no-pie
or -static
works (at least it doesn't fail, assuming it's still able to detect as I get a "no backdoor detected").
Same issue. Adding flag --static works.
@jwilk thanks for the detailed explaination.
It seems though that -m32
doesn't work for me:
mkdir -p bin
gcc check.c -o ./bin/check -m32
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccEmthr6.o: warning: relocation in read-only section `.text'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating a DT_TEXTREL in object.
So I'd go with the -no-pie
.
PR is already up: #11
Seems there's a duplicate PR over at #9 (with a less descriptive error message and no reference to this issue).
-m32
worked for me under Arch Linux.
my case is: g++ 7.5.0 meet this problem. clang++ can work