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

Linker error on ArchLinux #2

Open
LeoAdamek opened this issue Jul 28, 2017 · 9 comments
Open

Linker error on ArchLinux #2

LeoAdamek opened this issue Jul 28, 2017 · 9 comments

Comments

@LeoAdamek
Copy link

I'm getting a linker error when running make (Additionally I've tried adding -fPIC to the compilation options however this hasn't solved the issue.)

See below command output and versions.
From commit dff6324
make output:

cc  -c injector.c -o injector.o -Wall                                                                                                                                                        
injector.c:321:93: warning: excess elements in array initializer                                                                                                                             
  .start={.bytes={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, .len=0},                                                                                 
                                                                                             ^~~~                                                                                            
injector.c:321:93: note: (near initialization for ‘total_range.start.bytes’)                                                                                                                 
injector.c:322:91: warning: excess elements in array initializer                                                                                                                             
  .end={.bytes={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, .len=0},                                                                                   
                                                                                           ^~~~                                                                                              
injector.c:322:91: note: (near initialization for ‘total_range.end.bytes’)                                                                                                                   
cc  injector.o -O3 -Wall -l:libcapstone.a -o injector -pthread                                                                                                                               
/usr/bin/ld: injector.o: relocation R_X86_64_32S against undefined symbol `dummy_stack' can not be used when making a shared object; recompile with -fPIC                                    
/usr/bin/ld: final link failed: Nonrepresentable section on output                                                                                                                           
collect2: error: ld returned 1 exit status
make: *** [Makefile:35: injector] Error 1 

cc --version : cc (GCC) 7.1.1 20170630

ld --version: GNU ld (GNU Binutils) 2.28.0.20170506

@ghost ghost mentioned this issue Jul 28, 2017
@rostwald
Copy link

rostwald commented Jul 28, 2017

Same on Alpine 3.5.
If recompiled with -fPIC build fails with following error:

cc  -c injector.c -o injector.o -Wall -fPIC
injector.c:321:93: warning: excess elements in array initializer
  .start={.bytes={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, .len=0},
                                                                                             ^~~~
injector.c:321:93: note: (near initialization for 'total_range.start.bytes')
injector.c:322:91: warning: excess elements in array initializer
  .end={.bytes={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, .len=0},
                                                                                           ^~~~
injector.c:322:91: note: (near initialization for 'total_range.end.bytes')
injector.c: In function 'inject':
injector.c:778:2: warning: asm operand 15 probably doesn't match constraints
  __asm__ __volatile__ ("\
  ^~~~~~~
injector.c:778:2: error: impossible constraint in 'asm'
make: *** [Makefile:38: injector.o] Error 1

@turova
Copy link

turova commented Jul 28, 2017

I haven't looked into the changes required for newer GCC versions, but the workaround for this is to compile with GCC 4.x. You should be able to use some equivalent of running sudo apt install -y gcc-4.7 and adding CC=gcc-4.7 to the top of the Makefile to get it built.

@NanXiao
Copy link

NanXiao commented Jul 28, 2017

I come across similar issue when building other software in Arch Linux, and hope my post can help you.

@LeoAdamek
Copy link
Author

Thanks @NanXiao , that does indeed solve the issue. Do you know if this would have any adverse effects for older versions of GCC, or could it be added to master?

@rostwald
Copy link

rostwald commented Jul 28, 2017

There is no gcc version that old available on Alpine - even on ancient debian/devuan oldstable the oldest Version is 4.8

However, adding the no-pie flag to the Makefile like suggested by @NanXiao did the trick. Thanks!

Does this option break linking with earlier gcc versions? If not i'd suggest adding it to master.

paulmenzel added a commit to paulmenzel/sandsifter that referenced this issue Jul 28, 2017
If libcapstone.a is not build with `-fPIC`, building `injector` fails
with the error below.

```
/usr/bin/ld: injector.o: relocation R_X86_64_32S against undefined symbol `dummy_stack' can not be used when making a shared object; recompile with -fPIC
```

So explicitly link the binary as a position dependent executable by
passing `-no-pie` [1].

This probably needs to be made configurable, or the build system needs
to detect how `libcapstone.a` is built.

[1] https://wiki.ubuntu.com/SecurityTeam/PIE

Fixes: xoreaxeaxeax#2, xoreaxeaxeax#5
@NanXiao
Copy link

NanXiao commented Jul 28, 2017

@LeoAdamek @rostwald I am not the gcc expert, but from my humble opinion, I don't think it can bring some negative effects. According to manual:

-no-pie
Don’t produce a position independent executable.

This option just take effect in link stage, and cause executable position independent. Personally, I think there is no other side-effect.

@turova
Copy link

turova commented Jul 28, 2017

-no-pie on gcc 6 worked for me as well. gcc 4.7 didn't build with -no-pie:

gcc-4.7 injector.o -O3 -Wall -no-pie -l:libcapstone.a -o injector -pthread
gcc-4.7: error: unrecognized command line option ‘-no-pie’

@rigred
Copy link

rigred commented Jul 31, 2017

I simply compiled the injector as static which solved the problem of

/usr/bin/ld: injector.o: relocation R_X86_64_32S against undefined symbol `dummy_stack' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
cc injector.o -O3 -Wall -l:libcapstone.a -o injector -pthread -static

however --no-pie also works on gcc7

@jotebe
Copy link

jotebe commented Sep 10, 2017

@rupran's fork for the compiling error worked for me when using -no-pie in the Makefile.

I had to change python to python2 in sifter.py as referenced in #29, Arch uses python3 as python by default, but sandsifter appears to run in python2.

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

No branches or pull requests

6 participants