[llvm] [BOLT][RISCV] Handle CIE's produced by GNU as (PR #69578)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 00:19:34 PDT 2023


================
@@ -2462,6 +2462,13 @@ struct CFISnapshot {
     case MCCFIInstruction::OpDefCfaRegister:
       CFAReg = Instr.getRegister();
       CFARule = UNKNOWN;
+
+      // This shouldn't happen according to the spec but GNU binutils on RISC-V
+      // emits a DW_CFA_def_cfa_register in CIE's which leaves the offset
+      // unspecified. Both readelf and llvm-dwarfdump interpret the offset as 0
+      // in this case so let's do the same.
----------------
mtvec wrote:

I did a quick check and this indeed seems to be the case:
- libunwind initializes all CFI columns to 0 [here](https://github.com/libunwind/libunwind/blob/24dc3b0880695137a48c2ad0244900f9bb8416eb/src/dwarf/Gparser.c#L521-L523) (CFA offset is stored in a special column).
- libgcc sets most of the state to 0 in a confusing `memset` [here](https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/unwind-dw2.c;h=d0afce7a9ea9f5b12a5a01ef1e940e1452b48cab;hb=HEAD#l997). Since `regs.cfa_offset` comes after `regs.how`, it is set to 0 there.

So both runtimes default CFA offsets to zero. Although it seems to be more of a coincident than a deliberate choice in both cases.

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


More information about the llvm-commits mailing list