fig2-33.png typo
#102
Closed
opened 5 years ago by asurati
·
5 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
If the intention is to calculate the address of function, the 3rd instruction is likely an
la r9, function@l(r9) instead of an ld r9, function@l(r9).
No, the example is correct. Because "function" is compiled as a .quad containing an address, we just need to load it directly. You can compile the following example with current GCC to see this (the example is slightly more complex to avoid the bctrl being converted to a direct call):
Isn't "function" an external symbol, and thus it cannot be compiled as a .quad, since then it would cease to be a function and become just a data item storing a pointer?
ppc64le gcc 9.3.0 shows this:
To allow for absolute addressing one can perhaps imagine the last 2 instructions above as:
But that still doesn't change the fact that "function" isn't compiled as a .quad; ".LC0" is but that is a different symbol than "function".
Do you mean to say that the below construct is what is intended?
Edit: The same example in 32bit-abi (I know it is not normative, etc.) uses la.
See Figure 3-29. Absolute Indirect Function Call.
Sorry, I was too quick to respond here. It's not a .quad, but rather the value is directly filled in by the linker in the instructions.
The thing to note here is that this is an absolute addressing model, so there is no indirection through the TOC. I am not aware of any way to get either GCC or Clang to generate code for an absolute addressing model, so the whole example has always seemed somewhat pointless to me, but...
Having read through this again, I agree that this should be a
la
, becausefunction
is already a symbol containing the full 32-bit address of the medium absolute model. I'm sorry for the confusion on my part.I'd love to just remove the example since nobody uses this addressing mode in practice, but I suppose it ought to be fixed. Thanks for your persistence!
BTW, I'm not a real fan of the
la
mnemonic anyway, so will likely replace this with the corresponding addi for clarity. (addi r9, r9, function@l)Note to self: The extra
extern
appears in several tables.