Skip to content

Conversation

kovdan01
Copy link
Contributor

@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Daniil Kovalev (kovdan01)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/96158.diff

2 Files Affected:

  • (modified) llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def (+17)
  • (modified) llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test (+34)
diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def
index cb05db85e2b5a..ece8577fe219f 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def
@@ -144,6 +144,23 @@ ELF_RELOC(R_AARCH64_IRELATIVE,                       0x408)
 // https://github.com/ARM-software/abi-aa
 ELF_RELOC(R_AARCH64_AUTH_ABS64,                      0x244)
 ELF_RELOC(R_AARCH64_AUTH_RELATIVE,                   0x411)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G0,             0x8110)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G0_NC,          0x8111)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G1,             0x8112)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G1_NC,          0x8113)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G2,             0x8114)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G2_NC,          0x8115)
+ELF_RELOC(R_AARCH64_AUTH_MOVW_GOTOFF_G3,             0x8116)
+ELF_RELOC(R_AARCH64_AUTH_GOT_LD_PREL19,              0x8117)
+ELF_RELOC(R_AARCH64_AUTH_LD64_GOTOFF_LO15,           0x8118)
+ELF_RELOC(R_AARCH64_AUTH_ADR_GOT_PAGE,               0x8119)
+ELF_RELOC(R_AARCH64_AUTH_GOT_LO12_NC,                0x811a)
+ELF_RELOC(R_AARCH64_AUTH_LD64_GOTPAGE_LO15,          0x811b)
+ELF_RELOC(R_AARCH64_AUTH_GOT_ADD_LO12_NC,            0x811c)
+ELF_RELOC(R_AARCH64_AUTH_GOT_ADR_PREL21,             0x811d)
+ELF_RELOC(R_AARCH64_AUTH_GLOB_DAT,                   0xe201)
+ELF_RELOC(R_AARCH64_AUTH_TLSDESC,                    0xe202)
+ELF_RELOC(R_AARCH64_AUTH_IRELATIVE,                  0xe203)
 
 // ELF32
 // ELF_RELOC(R_AARCH64_P32_NONE,                         0)
diff --git a/llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test b/llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test
index cf95b51700267..8111bfe71c10f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test
+++ b/llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test
@@ -130,6 +130,23 @@
 # CHECK: Type: R_AARCH64_TLSDESC (1031)
 # CHECK: Type: R_AARCH64_IRELATIVE (1032)
 # CHECK: Type: R_AARCH64_AUTH_RELATIVE (1041)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G0 (33040)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G0_NC (33041)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G1 (33042)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G1_NC (33043)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G2 (33044)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G2_NC (33045)
+# CHECK: Type: R_AARCH64_AUTH_MOVW_GOTOFF_G3 (33046)
+# CHECK: Type: R_AARCH64_AUTH_GOT_LD_PREL19 (33047)
+# CHECK: Type: R_AARCH64_AUTH_LD64_GOTOFF_LO15 (33048)
+# CHECK: Type: R_AARCH64_AUTH_ADR_GOT_PAGE (33049)
+# CHECK: Type: R_AARCH64_AUTH_GOT_LO12_NC (33050)
+# CHECK: Type: R_AARCH64_AUTH_LD64_GOTPAGE_LO15 (33051)
+# CHECK: Type: R_AARCH64_AUTH_GOT_ADD_LO12_NC (33052)
+# CHECK: Type: R_AARCH64_AUTH_GOT_ADR_PREL21 (33053)
+# CHECK: Type: R_AARCH64_AUTH_GLOB_DAT (57857)
+# CHECK: Type: R_AARCH64_AUTH_TLSDESC (57858)
+# CHECK: Type: R_AARCH64_AUTH_IRELATIVE (57859)
 
 --- !ELF
 FileHeader:
@@ -267,3 +284,20 @@ Sections:
       - Type: R_AARCH64_TLSDESC
       - Type: R_AARCH64_IRELATIVE
       - Type: R_AARCH64_AUTH_RELATIVE
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G0
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G0_NC
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G1
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G1_NC
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G2
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G2_NC
+      - Type: R_AARCH64_AUTH_MOVW_GOTOFF_G3
+      - Type: R_AARCH64_AUTH_GOT_LD_PREL19
+      - Type: R_AARCH64_AUTH_LD64_GOTOFF_LO15
+      - Type: R_AARCH64_AUTH_ADR_GOT_PAGE
+      - Type: R_AARCH64_AUTH_GOT_LO12_NC
+      - Type: R_AARCH64_AUTH_LD64_GOTPAGE_LO15
+      - Type: R_AARCH64_AUTH_GOT_ADD_LO12_NC
+      - Type: R_AARCH64_AUTH_GOT_ADR_PREL21
+      - Type: R_AARCH64_AUTH_GLOB_DAT
+      - Type: R_AARCH64_AUTH_TLSDESC
+      - Type: R_AARCH64_AUTH_IRELATIVE

@kovdan01 kovdan01 added this to the LLVM 19.X Release milestone Jun 24, 2024
@kovdan01
Copy link
Contributor Author

Would be glad to see feedback on the changes from those who are interested.

@kovdan01
Copy link
Contributor Author

kovdan01 commented Jul 1, 2024

@MaskRay Would be glad to see your feedback on the changes. Everyone interested is also welcome to leave a review

@kovdan01 kovdan01 merged commit 2acb068 into llvm:main Jul 4, 2024
kovdan01 added a commit to kovdan01/llvm-project that referenced this pull request Jul 8, 2024
kovdan01 added a commit to kovdan01/llvm-project that referenced this pull request Jul 22, 2024
kovdan01 added a commit that referenced this pull request Aug 7, 2024
Depends on #96158 and #96159

Support the following relocations and assembly operators:

- `R_AARCH64_AUTH_ADR_GOT_PAGE` (`:got_auth:` for `adrp`)
- `R_AARCH64_AUTH_LD64_GOT_LO12_NC` (`:got_auth_lo12:` for `ldr`)
- `R_AARCH64_AUTH_GOT_ADD_LO12_NC` (`:got_auth_lo12:` for `add`)

`LOADgotAUTH` pseudo-instruction is introduced which is later expanded
to actual instruction sequence like the following.

```
adrp x16, :got_auth:sym
add x16, x16, :got_auth_lo12:sym
ldr x0, [x16]
autia x0, x16
```

If a resign is requested, like below, `LOADgotPAC` pseudo is used, and
GOT load is lowered similarly to `LOADgotAUTH`.

```
@var = global i32 0
define ptr @resign_globalvar() {
  ret ptr ptrauth (ptr @var, i32 3, i64 43)
}
```

Both SelectionDAG and GlobalISel are suppported. For FastISel, we fall
back to SelectionDAG.

Tests starting with 'ptrauth-' have corresponding variants w/o this
prefix.

See also specification
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#appendix-signed-got
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants