This patch allows lowering of PIC addresses by using PC-relative addressing for DSO-local symbols and accessing the address through the global offset table for non-DSO-local symbols.
Builds on D54143
Half of this (the MC side of the GOT modifier) is already proposed in D55279. Also note that the assembly modifier is not %got_hi but %got_pcrel_hi after a discussion with upstream (check the assembler manual) to clearly convey that it's a PC-relative relocation to the GOT entry rather than generating a GOT index as would be the case on some older architectures. I did however, like you, use GOT_HI in the various LLVM-internal enumeration entries to match the name of the relocation.
It's probably worth noting that the %pcrel_lo relocations to the label appear to be evaluated to a constant when -mattr=+relax is not provided... I remember someone said that this was going to be made default? If so I think it would be good to wait for that before this is commited.
Almost there now from my point of view, but we'll see what the others say (especially Alex).
Can we combine this with getAddr, pushing the common isPositionIndependent() check inside getAddr? Then the UseGOT flag becomes NonLocal or similar (or alternatively invert it and make it an IsLocal flag), and happens to only influence code generation for PIC. This should simplify all its uses.
I'm not sure this is a good idea? We'd still have to check in lowerGlobalAddress for GOT, and I feel leaving getAddr to check isPositionIndependent seems misleading, and the other option is to end up checking isPositionIndependent twice for this path, and gaining nothing in the process. It's certainly doable though, if people think it is clearer.
No you don’t, all you need to do is check shouldAssumeDSOLocal and pass that to getAddr as an IsLocal flag. The fact that the flag is only actually used on the PIC branch of getAddr is an implementation detail that lowerGlobalAddress doesn’t need to know about.