xoreaxeaxeax / sandsifter

The x86 processor fuzzer
BSD 3-Clause "New" or "Revised" License
4.9k stars 350 forks source link

Linker error on ArchLinux #2

Open LeoAdamek opened 7 years ago

LeoAdamek commented 7 years ago

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 dff63246fed84d90118441b8ba5b5d3bdd094427 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

rostwald commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

LeoAdamek commented 7 years ago

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 commented 7 years ago

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.

NanXiao commented 7 years ago

@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 commented 7 years ago

-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 commented 7 years ago

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 commented 7 years ago

@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.