Warm tip: This article is reproduced from serverfault.com, please click

In arm64 assembly, what does "adrp x0, idmap_pg_dir;" instruction mean?

发布于 2020-10-27 12:44:50

A question on arm64 assembly language.
For example in linux 5.9.15 source code, in arch/arm64/kernel/vmlinux.lds.S (linker script), there is a line idmap_pg_dir = .;. so idmap_pg_dir is an address. Now, in arch/arm64/kernel/head.S, there is a line adrp x0, idmap_pg_dir. Does this mean

1) x0 = PC + idmap_pg_dir  or  
2) x0 = idmap_pg_dir  ?  

I thought when we do adrp x0, addr1, usually addr1 is a PC-relative address offset and x0 becomes PC + addr. But the linker script seems to say idmap_pg_dir is just an absolute address. (is it not?) So I'm confused. Please someone correct me.

Questioner
Chan Kim
Viewed
0
Chan Kim 2020-11-30 22:48:12

In ARMv8 architecture reference manual, in ADRP instruction section, it says,

Is the program label whose 4KB page address is to be calculated. Its offset from the page address of this instruction, in the range +/-4GB, is encoded as "immhi:immlo" times 4096.

So the compiler 'calculates' the 'offset' to the 'label'. So the 'offset' from current instrction is used instead of the absolute address of the label.