On 02/07/2012 04:56 PM, Xin Tong wrote: > I am wondering how gcc accesses global variables on x86. from the code > i have seen so far, it seems to use the %RIP as the base register. Is > it always like this? > > 4006f9: f0 80 0d bf 0b 20 00 lock orb $0x0,0x200bbf(%rip) > # 6012c0 <t2lockor> > 400700: 00 > > t2lockor is a global variables. This is x86_64, I think. The answer is that it depends on whether you are using PIC, and the model you're using. Try -mcmodel=large for a variation. PC-relative loads are convenient for everything except the large memory model. Andrew.