rosenbridge icon indicating copy to clipboard operation
rosenbridge copied to clipboard

Fails to compile on GCC 7.3.0 (Ubuntu)

Open BenBE opened this issue 6 years ago • 13 comments

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.

BenBE avatar Aug 09 '18 20:08 BenBE

Explicit use of -static when compiling seems to fix the compile issue.

BenBE avatar Aug 09 '18 20:08 BenBE

Same problem on Gentoo. Proposed fix/workaround by @BenBE works.

gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0

benaryorg avatar Aug 09 '18 21:08 benaryorg

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

benaryorg avatar Aug 09 '18 21:08 benaryorg

I had this issue too, I fixed it here with changing gcc to clang in Makefile.

lanodan avatar Aug 09 '18 21:08 lanodan

-static worked for me

gcc check.c -o ./bin/check -static

anxiousmodernman avatar Aug 10 '18 01:08 anxiousmodernman

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.

jwilk avatar Aug 10 '18 08:08 jwilk

On a second thought, -m32 (which is used in most makefiles, but somehow not in util) also takes care of this.

jwilk avatar Aug 10 '18 08:08 jwilk

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").

Necklaces avatar Aug 10 '18 08:08 Necklaces

Same issue. Adding flag --static works.

CanNuhlar avatar Aug 10 '18 20:08 CanNuhlar

@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

benaryorg avatar Aug 11 '18 07:08 benaryorg

Seems there's a duplicate PR over at #9 (with a less descriptive error message and no reference to this issue).

benaryorg avatar Aug 11 '18 07:08 benaryorg

-m32 worked for me under Arch Linux.

tonylambiris avatar Aug 15 '18 00:08 tonylambiris

my case is: g++ 7.5.0 meet this problem. clang++ can work

bzhao avatar Feb 08 '20 10:02 bzhao