[llvm] [RISCV][MC] Implement ISA mapping symbols (PR #67541)

Andreu Carminati via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 04:20:10 PST 2024


andcarminati wrote:

> > I have one suggestion, considering https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#mapping-symbol, the following paragraph:
> > > The mapping symbol for instruction($x) indicates the start of a sequence of instructions. and it has an optional ISA string, which means the following code regions are using ISA is different than the ISA recorded in the arch attribute.
> > 
> > 
> > Can we emit just $x. when some function uses the same features as in arch attribute?
> 
> Is this not already the case? In this patch the ISA string is only emitted if the code portion's ISA changes.

I created the following example:
```
void  __attribute__((used)) testDefault() {}
void  __attribute__((used)) testDefault2() {}
__attribute__((target("arch=+zbb"))) __attribute__((used))  void testSingleExtension() {}
__attribute__((target("arch=+zbb,+v")))  __attribute__((used))  void testMultiExtension() {}
void  __attribute__((used)) testDefault3() {}
```

With:
```
clang  --target=riscv32 -march=rv32imafdc sample-mapping.c  -o sample1.elf 
llvm-objdump -d --show-all-symbols sample1.elf
```

I got:

```
sample1.elf:    file format elf32-littleriscv

Disassembly of section .text:

000110d4 <.text>:
000110d4 <$x.0>:
000110d4 <testDefault>:
   110d4: 82 80         ret

000110d6 <testDefault2>:
   110d6: 82 80         ret

000110d8 <$xrv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zbb1p0.1>:
000110d8 <testSingleExtension>:
   110d8: 82 80         ret

000110da <$xrv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zbb1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0.2>:
000110da <testMultiExtension>:
   110da: 82 80         ret

000110dc <$xrv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0.3>:
000110dc <testDefault3>:
   110dc: 82 80         ret
```

For the testDefault3, maybe $x<any>.3 is enough. But on the other hand, GCC always emits mapping symbols for all functions so this way should be fine.


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


More information about the llvm-commits mailing list