This is the mail archive of the
mailing list for the GCC project.
Re: s390: got symbol+offset
> The GOT is an array of addresses, and var@GOT addresses one of these
> addresses. Thus var@GOT+4 points to the address of a different and
> unrelated variable, assuming it is still within the range of the GOT.
You must have a 32 bit machine on your desk ;-)
On a 64 bit BE machine (like s390), var@GOT+4 points to the LSB subreg
of the address, such as when casting the address to a 32-bit int.
This is what __builtin_strlen() ends up doing in my test case.
The s390 has an opcode that does essentially "strchr()". Strlen is
implemented by calling this opcode, and subtracting pointers. If the
result is cast to an int and compared to zero, the optimizer replaces
all that with a compare of the lower subreg of the two addresses.