POV: You are a compiler targeting arm641, and you want some code to reference this global variable from the same library. The classic way to do this i

Relative References in ARM64 Disassembly // -dealloc

submited by
Style Pass
2022-05-14 21:30:06

POV: You are a compiler targeting arm641, and you want some code to reference this global variable from the same library. The classic way to do this is to emit an instruction that loads “the address of X”, which will be determined at run time by the dynamic loader. But that’s not super efficient! For one thing, addresses are 64 bits long, and instructions are only 32 bits, so you can either break it up into multiple instructions, or load the address from some other location. But more importantly, the global variable is in the same library. The dynamic loader isn’t going to break it up from this code2, and if we knew how far away it was we could reference it that way.

That’s what the adrp instruction’s for. In real life, the code was a call to objc_msgSend, and the global was the selector3. And rather than reference this variable by symbol, the compiler had emitted a relative reference using adrp.

label: Is the program label whose 4KB page address is to be calculated. An offset from the page address of this instruction, in the range ±4GB.

Leave a Comment