Skip to content

Commit 4ad5217

Browse files
kito-chengNelson Chu
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 51a39a5 commit 4ad5217

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
@@ -21287,6 +21287,33 @@ decode_aarch64_feature_1_and (unsigned int bitmask)
2128721287
}
2128821288
}
2128921289

21290+
static void
21291+
decode_riscv_feature_1_and (unsigned int bitmask)
21292+
{
21293+
while (bitmask)
21294+
{
21295+
unsigned int bit = bitmask & (- bitmask);
21296+
21297+
bitmask &= ~ bit;
21298+
switch (bit)
21299+
{
21300+
case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED:
21301+
printf ("CFI_LP_UNLABELED");
21302+
break;
21303+
21304+
case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS:
21305+
printf ("CFI_SS");
21306+
break;
21307+
21308+
default:
21309+
printf (_("<unknown: %x>"), bit);
21310+
break;
21311+
}
21312+
if (bitmask)
21313+
printf (", ");
21314+
}
21315+
}
21316+
2129021317
static void
2129121318
decode_1_needed (unsigned int bitmask)
2129221319
{
@@ -21477,6 +21504,18 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
2147721504
goto next;
2147821505
}
2147921506
}
21507+
else if (filedata->file_header.e_machine == EM_RISCV)
21508+
{
21509+
if (type == GNU_PROPERTY_RISCV_FEATURE_1_AND)
21510+
{
21511+
printf ("RISC-V AND feature: ");
21512+
if (datasz != 4)
21513+
printf (_("<corrupt length: %#x> "), datasz);
21514+
else
21515+
decode_riscv_feature_1_and (byte_get (ptr, 4));
21516+
goto next;
21517+
}
21518+
}
2148021519
}
2148121520
else
2148221521
{
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
@@ -1041,6 +1041,11 @@
10411041
#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
10421042
#define GNU_PROPERTY_AARCH64_FEATURE_1_GCS (1U << 2)
10431043

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

0 commit comments

Comments
 (0)