llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.42k stars 12.16k forks source link

[PAC][readobj] Display signing schema for AUTH relocs #111482

Open kovdan01 opened 1 month ago

kovdan01 commented 1 month ago

The signing schema is stored in the place to be relocated: https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#encoding-the-signing-schema

Currently, to view the schema, we need to output the hex dump of that place and manually search for particular interesting bits - see, for example, this piece from llvm/test/CodeGen/AArch64/ptrauth-init-fini.ll:

; RUN: llc -mtriple aarch64-elf -mattr=+pauth -filetype=asm -o - nodisc.ll | \
; RUN:   FileCheck %s --check-prefix=ASM
; RUN: llc -mtriple aarch64-elf -mattr=+pauth -filetype=obj -o - nodisc.ll | \
; RUN:   llvm-readelf -r -x .init_array -x .fini_array - | FileCheck %s --check-prefix=OBJ

; ASM:      .section .init_array,"aw",@init_array
; ASM-NEXT: .p2align 3, 0x0
; ASM-NEXT: .xword   foo@AUTH(ia,55764)
; ASM-NEXT: .section .fini_array,"aw",@fini_array
; ASM-NEXT: .p2align 3, 0x0
; ASM-NEXT: .xword   bar@AUTH(ia,55764)

; OBJ:      Relocation section '.rela.init_array' at offset 0x{{.*}} contains 1 entries:
; OBJ-NEXT:     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
; OBJ-NEXT: 0000000000000000  0000000700000244 R_AARCH64_AUTH_ABS64   0000000000000000 foo + 0
; OBJ:      Relocation section '.rela.fini_array' at offset 0x{{.*}} contains 1 entries:
; OBJ-NEXT:     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
; OBJ-NEXT: 0000000000000000  0000000800000244 R_AARCH64_AUTH_ABS64   0000000000000004 bar + 0
; OBJ:      Hex dump of section '.init_array':
; OBJ-NEXT: 0x00000000 00000000 d4d90000
; OBJ:      Hex dump of section '.fini_array':
; OBJ-NEXT: 0x00000000 00000000 d4d90000
;;                              ^^^^ 0xD9D4: constant discriminator = 55764
;;                                    ^^ 0x80: bits 61..60 key = IA; bit 63 addr disc = false

This is confusing and might also be pretty hard for non-trivial cases. We should somehow display signing schema for AUTH relocs when relocation table is requested by user.

kovdan01 commented 1 month ago

Tagging @asl