[llvm] [BOLT] Gadget scanner: clarify MCPlusBuilder callbacks interface (PR #136147)

Kristof Beyls via llvm-commits llvm-commits at lists.llvm.org
Mon May 26 03:31:38 PDT 2025


================
@@ -985,6 +985,26 @@ inst_pacnbibsppc:
         ret
         .size inst_pacnbibsppc, .-inst_pacnbibsppc
 
+// Test that write-back forms of LDRA(A|B) instructions are handled properly.
+
+        .globl  inst_ldraa_wb
+        .type   inst_ldraa_wb, at function
+inst_ldraa_wb:
+// CHECK-NOT: inst_ldraa_wb
+        ldraa   x2, [x0]!
+        pacda   x0, x1
+        ret
+        .size inst_ldraa_wb, .-inst_ldraa_wb
+
+        .globl  inst_ldrab_wb
+        .type   inst_ldrab_wb, at function
+inst_ldrab_wb:
+// CHECK-NOT: inst_ldrab_wb
+        ldraa   x2, [x0]!
+        pacda   x0, x1
+        ret
+        .size inst_ldrab_wb, .-inst_ldrab_wb
+
----------------
kbeyls wrote:

Yeah, it seems that there are probably a lot of load and store instructions missing from
`AArch64MCPlusBuilder::isLDR*` functions, which `mayLoad(Inst)` uses....
I saw that https://github.com/llvm/llvm-project/commit/ad599c25d91c668391bfae71d813164c4b412d76 improved these function implementations by adding more load instructions to the switch statement, but it's not complete.

As part of the prototype implementation of a stack-clash scanner, I think I counted there are well over 1000 different opcodes for load and store operations for AArch64.
There, I experimented with extending the TableGen definitions of AArch64 instructions so that a few bits in the `TSFlags` would indicate if a particular instruction opcode is a load or store, and how many bytes it loads or stores.
I don't fully remember what I did there, but one of the commits implementing part of it is https://github.com/llvm/llvm-project/commit/a3c810a71517abc2117bcea5a0eda8a303fa3113.
That is a major change however...

Maybe it'd be best to add a FIXME to the implementations of the `isLDR*` functions to help highlight these aren't fully correct?
And maybe it's not too hard to add the PAC-related load instructions to the relevant `isLDR*` functions?

https://github.com/llvm/llvm-project/pull/136147


More information about the llvm-commits mailing list