Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to compile on GCC 7.3.0 (Ubuntu) #1

Open
BenBE opened this issue Aug 9, 2018 · 13 comments · May be fixed by #11
Open

Fails to compile on GCC 7.3.0 (Ubuntu) #1

BenBE opened this issue Aug 9, 2018 · 13 comments · May be fixed by #11

Comments

@BenBE
Copy link

BenBE commented Aug 9, 2018

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
Copy link
Author

BenBE commented Aug 9, 2018

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

@benaryorg
Copy link

benaryorg commented Aug 9, 2018

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

gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0

@benaryorg
Copy link

benaryorg commented Aug 9, 2018

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

@lanodan
Copy link

lanodan commented Aug 9, 2018

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

@anxiousmodernman
Copy link

-static worked for me

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

@jwilk
Copy link

jwilk commented Aug 10, 2018

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
Copy link

jwilk commented Aug 10, 2018

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

@Necklaces
Copy link

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

@CanNuhlar
Copy link

CanNuhlar commented Aug 10, 2018

Same issue. Adding flag --static works.

benaryorg added a commit to benaryorg/rosenbridge that referenced this issue Aug 11, 2018
fix xoreaxeaxeax#1

Using -no-pie for compiling the utils since the assembly isn't written position independent.
Newer GCC versions default to PIE, so this should be set explicitly.

Signed-off-by: benaryorg <[email protected]>
@benaryorg benaryorg linked a pull request Aug 11, 2018 that will close this issue
@benaryorg
Copy link

@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
Copy link

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

@tonylambiris
Copy link

-m32 worked for me under Arch Linux.

@bzhao
Copy link

bzhao commented Feb 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants