The above is the disassembly of a 64 bit ARM firmware image. Does anybody know what those @PAGE
and @PAGEOFF
symbols mean?
-
These are assembler directives to calculate the offset at link time stackoverflow.com/q/38711058/4603507– OlsonistMay 8, 2017 at 23:21
-
the image is not showing; reupload it or, even better, just paste the text as a code block.– Igor Skochinsky ♦May 9, 2017 at 9:29
-
I can see the image: i.stack.imgur.com/ngBHx.png– sherlockMay 9, 2017 at 9:53
-
hm yeah, it appeared now. but it's still better to use text instead of screenshots– Igor Skochinsky ♦May 9, 2017 at 10:02
-
I know that text would be searchable, but rendering could get destroyed.– sherlockMay 9, 2017 at 16:21
1 Answer
in AArch64, all instructions are 32-bit long. Obviously, this is not enough to encode 64-bit addresses which AArch64 may need to process. So there's two options:
use 64-bit pointers placed in the constant pool near the instruction and load them with the
LDR
instruction. This is doable but such pointers need to be updated (relocated) if the image is loaded at a non-default address.Use PC-relative addressing to load addresses at a fixed offset from the current location (PIC code). This is the more common approach but the offset is still limited by the instruction size. So ARM designers came up with a clever hack: use two instructions to allow for a much wider range.
The ADRP instruction loads the address of the 4KB page anywhere in the +/-4GB (33 bits) range of the current instruction (which takes 21 high bits of the offset). this is denoted by the @PAGE
operator.
then, we can either use LDR
or STR
to read or write any address inside that page or ADD
to to calculate the final address using the remaining 12 bits of the offset (denoted by@PAGEOFF
).
So basically you can consider those instruction pairs as if the last one directly accesses the final address of the location before the @
and you can ignore the suffixes if you don't plan to reassemble the file.
See also https://stackoverflow.com/questions/34003338/llvm-arm64-assembly-getting-a-symbol-label-address