The dso_local_equivalent constant is a wrapper for global constant variables that represents a value which is functionally equivalent to the global passed to this. That is, if this accepts a function, calling this constant should have the same effects as calling the function directly. This could be a direct reference to the function, the @plt modifier on X86/AArch64, a thunk, or anything that's equivalent to the resolved function as a call target. Otherwise, for other global constant variables, using this should have the same effects as using the variable directly. On targets that support this, this could be lowered to a reference to a GOT entry.
When lowered, the returned address must have a constant offset at link time from some other symbol defined within the same binary. The address of this value is also insignificant. The name is leveraged from dso_local where use of a function or variable is resolved to a symbol in the same linkage unit.
In this patch:
- Addition of dso_local_equivalent and handling it
- Update Constant::needsRelocation() to strip constant inbound GEPs and take advantage of dso_local_equivalent for relative references
- Update LLVM-C API
See RFC for more details.
This patch only implements support for handling functions. dso_local_equivalent should also accept other global variables, but that will be implemented in a later patch.