0

When I use gcc to compile a C++ program to a 32 bit and I run it through gdb. When I disassemble the main function the gdb reads out the memory addresses EXAMPLE: 0x585583d0 and in other peoples examples of 32 bit it reads out 0x080483d0. Im using Kali linux and am wondering if its just because its a different distribution or am I missing some C libraries?

x7309wh
  • 13
  • 2

1 Answers1

3

am wondering if its just because its a different distribution or am I missing some C libraries?

This is because you built a position independent executable, while other people didn't.

The default load address for non-PIE binaries on 32-bit x86 systems is 0x08048000. The default load address for PIE binaries under GDB is somewhere in the 0x5855.... region (it can be very random outside of GDB; if you set disable-randomization off, you'll observe that the executable starts "jumping around" to different addresses).

Some newer distributions default to building PIE binaries. You can avoid this with:

gcc -no-pie main.c

The resulting binary should now start around 0x08048xxx.

You can check whether you have a PIE binary or not with file a.out -- it will say executable for non-PIE binary, and shared library for a PIE binary. See also this answer.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362