1

I mean nonstatic global variables that are defined in the module, not externally.

Why does it have to be referenced through GOT? Why no use relative address?(since the distance between the global variable in the .data section and the reference in the .text section is a constant, it's also position-independent)

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
Haiyang
  • 1,489
  • 4
  • 15
  • 19
  • You have a dynamic library, and it contains global variables that are referenced via GOT, but you want to access it in some other way. Is that correct? – jweyrich Feb 01 '11 at 12:34
  • No I'm reading about how the dynamic linkers work and according to what I read, global variables are referenced this way, but I don't understand why. – Haiyang Feb 01 '11 at 13:43

2 Answers2

1

Since your variable isn't static, on ELF it can be interposed (think of LD_PRELOAD).

ninjalj
  • 42,493
  • 9
  • 106
  • 148
0

I also have the same confusion. If there is one global variable with same name defined in both two DSOs and they are dynamically linked into one executable, will both libraries access the same copy of the variable? And which library(library's data section) the variable locates depends on the order of libraries loading?

xingchong
  • 31
  • 3
  • I have tested by myself. The answer is yes. Two libraries use the same copy of variable with same name. – xingchong Mar 01 '11 at 05:10