arm64: assembler: make adr_l work in modules under KASLR
When CONFIG_RANDOMIZE_MODULE_REGION_FULL=y, the offset between loaded modules and the core kernel may exceed 4 GB, putting symbols exported by the core kernel out of the reach of the ordinary adrp/add instruction pairs used to generate relative symbol references. So make the adr_l macro emit a movz/movk sequence instead when executing in module context. While at it, remove the pointless special case for the stack pointer. Acked-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
This commit is contained in:
parent
69d012345a
commit
41c066f2c4
|
@ -164,22 +164,25 @@ lr .req x30 // link register
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
|
* Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
|
||||||
* <symbol> is within the range +/- 4 GB of the PC.
|
* <symbol> is within the range +/- 4 GB of the PC when running
|
||||||
|
* in core kernel context. In module context, a movz/movk sequence
|
||||||
|
* is used, since modules may be loaded far away from the kernel
|
||||||
|
* when KASLR is in effect.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* @dst: destination register (64 bit wide)
|
* @dst: destination register (64 bit wide)
|
||||||
* @sym: name of the symbol
|
* @sym: name of the symbol
|
||||||
* @tmp: optional scratch register to be used if <dst> == sp, which
|
|
||||||
* is not allowed in an adrp instruction
|
|
||||||
*/
|
*/
|
||||||
.macro adr_l, dst, sym, tmp=
|
.macro adr_l, dst, sym
|
||||||
.ifb \tmp
|
#ifndef MODULE
|
||||||
adrp \dst, \sym
|
adrp \dst, \sym
|
||||||
add \dst, \dst, :lo12:\sym
|
add \dst, \dst, :lo12:\sym
|
||||||
.else
|
#else
|
||||||
adrp \tmp, \sym
|
movz \dst, #:abs_g3:\sym
|
||||||
add \dst, \tmp, :lo12:\sym
|
movk \dst, #:abs_g2_nc:\sym
|
||||||
.endif
|
movk \dst, #:abs_g1_nc:\sym
|
||||||
|
movk \dst, #:abs_g0_nc:\sym
|
||||||
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -190,6 +193,7 @@ lr .req x30 // link register
|
||||||
* the address
|
* the address
|
||||||
*/
|
*/
|
||||||
.macro ldr_l, dst, sym, tmp=
|
.macro ldr_l, dst, sym, tmp=
|
||||||
|
#ifndef MODULE
|
||||||
.ifb \tmp
|
.ifb \tmp
|
||||||
adrp \dst, \sym
|
adrp \dst, \sym
|
||||||
ldr \dst, [\dst, :lo12:\sym]
|
ldr \dst, [\dst, :lo12:\sym]
|
||||||
|
@ -197,6 +201,15 @@ lr .req x30 // link register
|
||||||
adrp \tmp, \sym
|
adrp \tmp, \sym
|
||||||
ldr \dst, [\tmp, :lo12:\sym]
|
ldr \dst, [\tmp, :lo12:\sym]
|
||||||
.endif
|
.endif
|
||||||
|
#else
|
||||||
|
.ifb \tmp
|
||||||
|
adr_l \dst, \sym
|
||||||
|
ldr \dst, [\dst]
|
||||||
|
.else
|
||||||
|
adr_l \tmp, \sym
|
||||||
|
ldr \dst, [\tmp]
|
||||||
|
.endif
|
||||||
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -206,8 +219,13 @@ lr .req x30 // link register
|
||||||
* while <src> needs to be preserved.
|
* while <src> needs to be preserved.
|
||||||
*/
|
*/
|
||||||
.macro str_l, src, sym, tmp
|
.macro str_l, src, sym, tmp
|
||||||
|
#ifndef MODULE
|
||||||
adrp \tmp, \sym
|
adrp \tmp, \sym
|
||||||
str \src, [\tmp, :lo12:\sym]
|
str \src, [\tmp, :lo12:\sym]
|
||||||
|
#else
|
||||||
|
adr_l \tmp, \sym
|
||||||
|
str \src, [\tmp]
|
||||||
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue