1

I find that many programs such as those under /bin still have .got section while they are non-pie. But interestingly, the size of .got are always 4 bytes. Is it possible that this .got is of no practical use? If so, how do these non-pie program access external global variables?

Matthewxie
  • 141
  • 2
  • 10

2 Answers2

1

The .got section is needed to access global data in a shared object (which is position-independent) from the main executable (which may or may not itself be position-independent). You can read gory details here.

the size of .got are always 4 bytes

On a 64-bit x86_64 system, it's 8 bytes for all binaries in my /bin.

Is it possible that this .got is of no practical use?

The only symbol referenced with .got in my /bin/date is:

objdump -R /bin/date | grep GLOB
000000000060dff8 R_X86_64_GLOB_DAT  __gmon_start__

This answer provides some details, but yes: that symbol provides no practical value for any program built without profiling support. It's only present because it doesn't cost much, and getting rid of it (while still providing support for profiling) is more trouble than the savings are worth.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

.got is not only concerned with Position Independent code. It also contains linkage information for shared objects. check the contents of that section through readelf and objdump

The main difference is that PIE has "internal" Dynamic linking. This internal dynamic linking is for what ASLR is meant for. Before PIE binaries, there were only dynamic libraries to be located at random offset but after ASLR same is possible for executables and such executables are called PIE binaries

incompetent
  • 1,715
  • 18
  • 29
  • Now that it accesses external global variables and functions through .got and .plt, it seems to be position independent. Why is it still called non-PIE? In an other word, what is the difference between PIE and non-PIE?@shami – Matthewxie Oct 03 '15 at 13:20
  • PIE binary is which allow ASLR for security while NON-PIE does not allow. check wikipedia. Both use many sections of ELF to get their work done. I thnik your are mixing dynamic relocations with PIE. Dynamic relocation uses information from .got – incompetent Oct 04 '15 at 02:55
  • I'm afraid that you didn't answer my question. Wikipedia says that Position-independent executables (PIE) are executable binaries made entirely from position-independent code. I know how PIC works. Given that programs under /bin do have .got.plt and .plt which implicates that they use the same way as PIC to achieve dynamic linking, why they are still not position-independent. In addition to dynamic linking, what else makes an executable position-independent?@shami – Matthewxie Oct 05 '15 at 04:24
  • Sorry for late answer, I was on vacation. answer updated – incompetent Oct 07 '15 at 14:22
  • Interesting! But what is "internal" Dynamic linking? Could you please elaborate more? – Matthewxie Oct 08 '15 at 15:19
  • in simple words, executable also does not know about its bindings just like SO does not know. same concept of lazy binding of SO is achieved through ASLR for PIE binary for security advantages – incompetent Oct 09 '15 at 01:02