This makes sure that assembly output actually can be assembled.
Set the correct MCExpr relocations specifier VK_PAGEOFF - and also
set VK_PAGE consistently even though it's not visible in the assembly
output.
Differential Revision: https://reviews.llvm.org/D94365
RefFlags |= AArch64MCExpr::VK_SABS;
} else {
RefFlags |= AArch64MCExpr::VK_ABS;
+
+ if ((MO.getTargetFlags() & AArch64II::MO_FRAGMENT) == AArch64II::MO_PAGE)
+ RefFlags |= AArch64MCExpr::VK_PAGE;
+ else if ((MO.getTargetFlags() & AArch64II::MO_FRAGMENT) ==
+ AArch64II::MO_PAGEOFF)
+ RefFlags |= AArch64MCExpr::VK_PAGEOFF | AArch64MCExpr::VK_NC;
}
if ((MO.getTargetFlags() & AArch64II::MO_FRAGMENT) == AArch64II::MO_G3)
; CHECK-LABEL: func_guard_nocf
; CHECK: adrp x8, target_func
- ; CHECK: add x8, x8, target_func
+ ; CHECK: add x8, x8, :lo12:target_func
; CHECK-NOT: __guard_check_icall_fptr
; CHECK: blr x8
}
; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
; CHECK-LABEL: func_optnone_cf
; CHECK: adrp x8, target_func
- ; CHECK: add x8, x8, target_func
+ ; CHECK: add x8, x8, :lo12:target_func
; CHECK: adrp x9, __guard_check_icall_fptr
- ; CHECK: add x9, x9, __guard_check_icall_fptr
+ ; CHECK: add x9, x9, :lo12:__guard_check_icall_fptr
; CHECK: ldr x9, [x9]
; CHECK: mov x15, x8
; CHECK: blr x9
; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
; CHECK-LABEL: func_cf
; CHECK: adrp x8, __guard_check_icall_fptr
- ; CHECK: ldr x9, [x8, __guard_check_icall_fptr]
+ ; CHECK: ldr x9, [x8, :lo12:__guard_check_icall_fptr]
; CHECK: adrp x8, target_func
- ; CHECK: add x8, x8, target_func
+ ; CHECK: add x8, x8, :lo12:target_func
; CHECK: mov x15, x8
; CHECK: blr x9
; CHECK-NEXT: blr x8
; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
; CHECK-LABEL: func_cf_invoke
; CHECK: adrp x8, __guard_check_icall_fptr
- ; CHECK: ldr x9, [x8, __guard_check_icall_fptr]
+ ; CHECK: ldr x9, [x8, :lo12:__guard_check_icall_fptr]
; CHECK: adrp x8, target_func
- ; CHECK: add x8, x8, target_func
+ ; CHECK: add x8, x8, :lo12:target_func
; CHECK: mov x15, x8
; CHECK: blr x9
; CHECK-NEXT: .Ltmp0:
; CHECK-LABEL: get_var
; CHECK: adrp x8, __imp_var
-; CHECK: ldr x8, [x8, __imp_var]
+; CHECK: ldr x8, [x8, :lo12:__imp_var]
; CHECK: ldr w0, [x8]
; CHECK: ret
; CHECK-LABEL: get_ext
; CHECK: adrp x8, ext
-; DAG-ISEL: ldr w0, [x8, ext]
-; FAST-ISEL: add x8, x8, ext
+; DAG-ISEL: ldr w0, [x8, :lo12:ext]
+; FAST-ISEL: add x8, x8, :lo12:ext
; FAST-ISEL: ldr w0, [x8]
-; GLOBAL-ISEL-FALLBACK: ldr w0, [x8, ext]
+; GLOBAL-ISEL-FALLBACK: ldr w0, [x8, :lo12:ext]
; CHECK: ret
define i32* @get_var_pointer() {
; CHECK-LABEL: get_var_pointer
; CHECK: adrp [[REG1:x[0-9]+]], __imp_var
-; CHECK: ldr {{x[0-9]+}}, {{\[}}[[REG1]], __imp_var]
+; CHECK: ldr {{x[0-9]+}}, {{\[}}[[REG1]], :lo12:__imp_var]
; CHECK: ret
define i32 @call_external() {
; CHECK-LABEL: call_external
; CHECK: adrp x0, __imp_external
-; CHECK: ldr x0, [x0, __imp_external]
+; CHECK: ldr x0, [x0, :lo12:__imp_external]
; CHECK: br x0
define i32 @call_internal() {
define dso_local i32 @getVar() {
; CHECK-LABEL: getVar:
; CHECK: adrp x8, .refptr.var
-; CHECK: ldr x8, [x8, .refptr.var]
+; CHECK: ldr x8, [x8, :lo12:.refptr.var]
; CHECK: ldr w0, [x8]
; CHECK: ret
entry:
define dso_local i32 @getDsoLocalVar() {
; CHECK-LABEL: getDsoLocalVar:
; CHECK: adrp x8, dsolocalvar
-; CHECK: ldr w0, [x8, dsolocalvar]
+; CHECK: ldr w0, [x8, :lo12:dsolocalvar]
; CHECK: ret
entry:
%0 = load i32, i32* @dsolocalvar, align 4
define dso_local i32 @getLocalVar() {
; CHECK-LABEL: getLocalVar:
; CHECK: adrp x8, localvar
-; CHECK: ldr w0, [x8, localvar]
+; CHECK: ldr w0, [x8, :lo12:localvar]
; CHECK: ret
entry:
%0 = load i32, i32* @localvar, align 4
define dso_local i32 @getLocalCommon() {
; CHECK-LABEL: getLocalCommon:
; CHECK: adrp x8, localcommon
-; CHECK: ldr w0, [x8, localcommon]
+; CHECK: ldr w0, [x8, :lo12:localcommon]
; CHECK: ret
entry:
%0 = load i32, i32* @localcommon, align 4
define dso_local i32 @getExtVar() {
; CHECK-LABEL: getExtVar:
; CHECK: adrp x8, __imp_extvar
-; CHECK: ldr x8, [x8, __imp_extvar]
+; CHECK: ldr x8, [x8, :lo12:__imp_extvar]
; CHECK: ldr w0, [x8]
; CHECK: ret
entry:
define dso_local void @sspFunc() #0 {
; CHECK-LABEL: sspFunc:
; CHECK: adrp x8, .refptr.__stack_chk_guard
-; CHECK: ldr x8, [x8, .refptr.__stack_chk_guard]
+; CHECK: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard]
; CHECK: ldr x8, [x8]
; GISEL-LABEL: sspFunc:
; GISEL: adrp x8, .refptr.__stack_chk_guard
-; GISEL: ldr x8, [x8, .refptr.__stack_chk_guard]
+; GISEL: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard]
; GISEL: ldr x8, [x8]
entry:
%c = alloca i8, align 1
; FUCHSIA-AARCH64-COMMON: cmp [[C]], [[D]]
; WINDOWS-AARCH64: adrp x8, __security_cookie
-; WINDOWS-AARCH64: ldr x8, [x8, __security_cookie]
+; WINDOWS-AARCH64: ldr x8, [x8, :lo12:__security_cookie]
; WINDOWS-AARCH64: str x8, [sp, #8]
; WINDOWS-AARCH64: bl _Z7CapturePi
; WINDOWS-AARCH64: ldr x0, [sp, #8]
; CHECK-LABEL: getVar
; CHECK: adrp [[TLS_INDEX_ADDR:x[0-9]+]], _tls_index
-; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], _tls_index]
+; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], :lo12:_tls_index]
; CHECK: ldr [[TLS_POINTER:x[0-9]+]], [x18, #88]
; CHECK: ldr [[TLS:x[0-9]+]], {{\[}}[[TLS_POINTER]], x[[TLS_INDEX]], lsl #3]
; CHECK-LABEL: getPtr
; CHECK: adrp [[TLS_INDEX_ADDR:x[0-9]+]], _tls_index
-; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], _tls_index]
+; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], :lo12:_tls_index]
; CHECK: ldr [[TLS_POINTER:x[0-9]+]], [x18, #88]
; CHECK: ldr [[TLS:x[0-9]+]], {{\[}}[[TLS_POINTER]], x[[TLS_INDEX]], lsl #3]
; CHECK-LABEL: setVar
; CHECK: adrp [[TLS_INDEX_ADDR:x[0-9]+]], _tls_index
-; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], _tls_index]
+; CHECK: ldr w[[TLS_INDEX:[0-9]+]], {{\[}}[[TLS_INDEX_ADDR]], :lo12:_tls_index]
; CHECK: ldr [[TLS_POINTER:x[0-9]+]], [x18, #88]
; CHECK: ldr [[TLS:x[0-9]+]], {{\[}}[[TLS_POINTER]], x[[TLS_INDEX]], lsl #3]
; CHECK-NEXT: .xword 0x2000000000800001
; CHECK: double:
; CHECK: adrp x8, __real@2000000000800001
-; CHECK-NEXT: ldr d0, [x8, __real@2000000000800001]
+; CHECK-NEXT: ldr d0, [x8, :lo12:__real@2000000000800001]
; CHECK-NEXT: ret
; MINGW: .section .rdata,"dr"
; MINGW-NEXT: .xword 0x2000000000800001
; MINGW: double:
; MINGW: adrp x8, [[LABEL]]
-; MINGW-NEXT: ldr d0, [x8, [[LABEL]]]
+; MINGW-NEXT: ldr d0, [x8, :lo12:[[LABEL]]]
; MINGW-NEXT: ret
; CHECK-NEXT: .seh_save_reg_x x30, 16
; CHECK-NEXT: .seh_endprologue
; CHECK-NEXT: adrp x8, .refptr.weakfunc
-; CHECK-NEXT: ldr x8, [x8, .refptr.weakfunc]
+; CHECK-NEXT: ldr x8, [x8, :lo12:.refptr.weakfunc]
; CHECK-NEXT: cbz x8, .LBB0_2
; CHECK-NEXT: ; %bb.1:
; CHECK-NEXT: blr x8