2

I'm trying to compile a C executable on Kali Linux: https://www.exploit-db.com/exploits/17787/

# gcc -o out 17787.c -lrt
/usr/bin/ld: /tmp/ccv59WCS.o: relocation R_X86_64_32S against symbol `kernel_code' 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

Does anyone know why this is happening, or why it thinks I'm trying to compile a shared object? As far as I know this should just generate an ELF executable...

# gcc --version
gcc (Debian 6.3.0-6) 6.3.0 20170205

# uname -a
Linux kali 4.9.0-kali2-amd64 #1 SMP Debian 4.9.10-1kali1 (2017-02-20) x86_64 GNU/Linux

Thanks!

James
  • 77
  • 1
  • 1
  • 6
  • 3
    Note this isn't an error in compilation, it's an error in linking. Maybe your `gcc` is configured to make shared objects by default, so you need to explicitly tell it you want it static. –  Feb 21 '17 at 16:41
  • Thanks.. Do you know where this is configured? – James Feb 21 '17 at 16:44
  • 1
    Have you considered trying the advice given in the error message? ELF executables are not much different from ELF shared libraries; it may be that the error is basically valid but comes with a confusing message. – John Bollinger Feb 21 '17 at 16:44
  • I have, unfortunately -fPIC makes no difference :/ – James Feb 21 '17 at 16:46
  • Is `gcc` aliased or otherwise not directly invoked? – Andrew Henle Feb 21 '17 at 18:20
  • Are you trying to mix 32-bit static code with 64-bit ELF? – 0andriy Feb 21 '17 at 21:39

1 Answers1

1

Thanks for all the suggestions!

So, it turns out this is a bug (or change) in the Debian release of gcc, which Kali is based on. The solution is to compile with -no-pie.

James
  • 77
  • 1
  • 1
  • 6