--- /dev/null
+# REQUIRES: aarch64, shell
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
+# RUN: %lld -dylib -arch arm64 -lSystem -o %t %t.o
+# RUN: (llvm-objdump --syms %t; llvm-objdump --macho -d --section=__const %t) | FileCheck %s
+
+# CHECK-LABEL: SYMBOL TABLE:
+# CHECK-DAG: [[#%x,PTR_1:]] l O __DATA_CONST,__const _ptr_1
+# CHECK-DAG: [[#%x,PTR_2:]] l O __DATA_CONST,__const _ptr_2
+# CHECK-DAG: [[#%x,BAR:]] g F __TEXT,__text _bar
+# CHECK-DAG: [[#%x,BAZ:]] g O __DATA,__data _baz
+
+# CHECK-LABEL: _foo:
+## BRANCH26 relocations are 4-byte aligned, so 123 is truncated to 120
+# CHECK-NEXT: bl 0x[[#BAR+120]]
+## PAGE21 relocations are aligned to 4096 bytes
+# CHECK-NEXT: adrp x2, [[#]] ; 0x[[#BAZ+4096-128]]
+# CHECK-NEXT: ldr x2, [x2, #128]
+# CHECK-NEXT: ret
+
+# CHECK-LABEL: Contents of (__DATA_CONST,__const) section
+# CHECK: [[#PTR_1]] {{0*}}[[#BAZ]] 00000000 00000000 00000000
+# CHECK: [[#PTR_2]] {{0*}}[[#BAZ]] 00000000 00000000 00000000
+
+.text
+.globl _foo, _bar, _baz
+.p2align 2
+_foo:
+ ## Generates ARM64_RELOC_BRANCH26 and ARM64_RELOC_ADDEND
+ bl _bar + 123
+ ## Generates ARM64_RELOC_PAGE21 and ADDEND
+ adrp x2, _baz@PAGE + 4097
+ ## Generates ARM64_RELOC_PAGEOFF12
+ ldr x2, [x2, _baz@PAGEOFF]
+ ret
+
+.p2align 2
+_bar:
+ ret
+
+.data
+.space 128
+_baz:
+.space 1
+
+.section __DATA_CONST,__const
+## These generate ARM64_RELOC_UNSIGNED symbol relocations. llvm-mc seems to
+## generate UNSIGNED section relocations only for compact unwind sections, so
+## those relocations are being tested in compact-unwind.s.
+_ptr_1:
+ .quad _baz
+ .space 8
+_ptr_2:
+ .quad _baz
+ .space 8
+
+.subsections_via_symbols
-# REQUIRES: x86
+# REQUIRES: x86, aarch64
# RUN: rm -rf %t; split-file %s %t
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/my_personality.s -o %t/my_personality.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/main.s -o %t/main.o
-# RUN: %lld -pie -lSystem -lc++ %t/my_personality.o %t/main.o -o %t/personality-first
-# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/personality-first | FileCheck %s --check-prefixes=FIRST,CHECK
-# RUN: %lld -pie -lSystem -lc++ %t/main.o %t/my_personality.o -o %t/personality-second
-# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/personality-second | FileCheck %s --check-prefixes=SECOND,CHECK
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/my-personality.s -o %t/x86_64-my-personality.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/main.s -o %t/x86_64-main.o
+# RUN: %lld -arch x86_64 -pie -lSystem -lc++ %t/x86_64-my-personality.o %t/x86_64-main.o -o %t/x86_64-personality-first
+# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK
+# RUN: %lld -arch x86_64 -pie -lSystem -lc++ %t/x86_64-main.o %t/x86_64-my-personality.o -o %t/x86_64-personality-second
+# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK
+
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 %t/my-personality.s -o %t/arm64-my-personality.o
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 %t/main.s -o %t/arm64-main.o
+# RUN: %lld -arch arm64 -pie -lSystem -lc++ %t/arm64-my-personality.o %t/arm64-main.o -o %t/arm64-personality-first
+# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK
+# RUN: %lld -arch arm64 -pie -lSystem -lc++ %t/arm64-main.o %t/arm64-my-personality.o -o %t/arm64-personality-second
+# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK
# FIRST: Indirect symbols for (__DATA_CONST,__got)
# FIRST-NEXT: address index name
# CHECK-NEXT: __DATA_CONST __got 0x{{[0-9a-f]*}} pointer
# CHECK-NOT: __TEXT
-#--- my_personality.s
+#--- my-personality.s
.globl _my_personality, _exception0
.text
+.p2align 2
_foo:
.cfi_startproc
## This will generate a section relocation.
.cfi_personality 155, _my_personality
.cfi_lsda 16, _exception0
.cfi_def_cfa_offset 16
- retq
+ ret
.cfi_endproc
+.p2align 2
_bar:
.cfi_startproc
## Check that we dedup references to the same statically-linked personality.
.cfi_personality 155, _my_personality
.cfi_lsda 16, _exception0
.cfi_def_cfa_offset 16
- retq
+ ret
.cfi_endproc
+.p2align 2
_my_personality:
- retq
+ ret
.section __TEXT,__gcc_except_tab
_exception0:
.globl _main, _my_personality, _exception1
.text
+.p2align 2
_main:
.cfi_startproc
.cfi_personality 155, ___gxx_personality_v0
.cfi_lsda 16, _exception1
.cfi_def_cfa_offset 16
- retq
+ ret
.cfi_endproc
+.p2align 2
_baz:
.cfi_startproc
## This will generate a symbol relocation. Check that we reuse the personality
.cfi_personality 155, _my_personality
.cfi_lsda 16, _exception1
.cfi_def_cfa_offset 16
- retq
+ ret
.cfi_endproc