Skip to content

Commit a4ed0f1

Browse files
kito-chenglgaver2
authored andcommitted
RISC-V: Add GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
This patch adds two new GNU properties for RISC-V: GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED. We only add readelf and define the properties in this patch. Ref: riscv-non-isa/riscv-elf-psabi-doc#417
1 parent 5d714ab commit a4ed0f1

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

binutils/readelf.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21872,6 +21872,33 @@ decode_aarch64_feature_1_and (unsigned int bitmask)
2187221872
}
2187321873
}
2187421874

21875+
static void
21876+
decode_riscv_feature_1_and (unsigned int bitmask)
21877+
{
21878+
while (bitmask)
21879+
{
21880+
unsigned int bit = bitmask & (- bitmask);
21881+
21882+
bitmask &= ~ bit;
21883+
switch (bit)
21884+
{
21885+
case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED:
21886+
printf ("CFI_LP_UNLABELED");
21887+
break;
21888+
21889+
case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS:
21890+
printf ("CFI_SS");
21891+
break;
21892+
21893+
default:
21894+
printf (_("<unknown: %x>"), bit);
21895+
break;
21896+
}
21897+
if (bitmask)
21898+
printf (", ");
21899+
}
21900+
}
21901+
2187521902
static void
2187621903
decode_1_needed (unsigned int bitmask)
2187721904
{
@@ -22062,6 +22089,18 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
2206222089
goto next;
2206322090
}
2206422091
}
22092+
else if (filedata->file_header.e_machine == EM_RISCV)
22093+
{
22094+
if (type == GNU_PROPERTY_RISCV_FEATURE_1_AND)
22095+
{
22096+
printf ("RISC-V AND feature: ");
22097+
if (datasz != 4)
22098+
printf (_("<corrupt length: %#x> "), datasz);
22099+
else
22100+
decode_riscv_feature_1_and (byte_get (ptr, 4));
22101+
goto next;
22102+
}
22103+
}
2206522104
}
2206622105
else
2206722106
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#as: -defsym __property_zicfilp_unlabeled__=1 -march=rv64i -mabi=lp64
2+
#readelf: -n
3+
#source: property.s
4+
5+
Displaying notes found in: .note.gnu.property
6+
[ ]+Owner[ ]+Data size[ ]+Description
7+
[ ]+GNU[ ]+0x00000010[ ]+NT_GNU_PROPERTY_TYPE_0
8+
[ ]+Properties: RISC-V AND feature: CFI_LP_UNLABELED
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#as: -defsym __property_zicfiss__=1 -march=rv64i -mabi=lp64
2+
#readelf: -n
3+
#source: property.s
4+
5+
Displaying notes found in: .note.gnu.property
6+
[ ]+Owner[ ]+Data size[ ]+Description
7+
[ ]+GNU[ ]+0x00000010[ ]+NT_GNU_PROPERTY_TYPE_0
8+
[ ]+Properties: RISC-V AND feature: CFI_SS
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.text
2+
.globl _start
3+
.type _start,@function
4+
_start:
5+
ret
6+
7+
.ifdef __property_zicfilp_unlabeled__
8+
.section ".note.gnu.property", "a"
9+
.p2align 3
10+
.long 1f - 0f /* name length */
11+
.long 5f - 2f /* data length */
12+
.long 5 /* note type */
13+
0: .asciz "GNU" /* vendor name */
14+
1:
15+
.p2align 3
16+
2: .long 0xc0000000 /* pr_type. */
17+
.long 4f - 3f /* pr_datasz. */
18+
3:
19+
.long 0x1 /* GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED. */
20+
4:
21+
.p2align 3
22+
5:
23+
.endif
24+
25+
.ifdef __property_zicfiss__
26+
.section ".note.gnu.property", "a"
27+
.p2align 3
28+
.long 1f - 0f /* name length */
29+
.long 5f - 2f /* data length */
30+
.long 5 /* note type */
31+
0: .asciz "GNU" /* vendor name */
32+
1:
33+
.p2align 3
34+
2: .long 0xc0000000 /* pr_type. */
35+
.long 4f - 3f /* pr_datasz. */
36+
3:
37+
.long 0x2 /* GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS. */
38+
4:
39+
.p2align 3
40+
5:
41+
.endif

include/elf/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,11 @@
10421042
#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
10431043
#define GNU_PROPERTY_AARCH64_FEATURE_1_GCS (1U << 2)
10441044

1045+
/* RISC-V specific GNU PROPERTY. */
1046+
#define GNU_PROPERTY_RISCV_FEATURE_1_AND 0xc0000000
1047+
#define GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED (1U << 0)
1048+
#define GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS (1U << 1)
1049+
10451050
/* Values used in GNU .note.ABI-tag notes (NT_GNU_ABI_TAG). */
10461051
#define GNU_ABI_TAG_LINUX 0
10471052
#define GNU_ABI_TAG_HURD 1

0 commit comments

Comments
 (0)