Skip to content

Commit c77339a

Browse files
committed
riscv64: emit .riscv.attributes section in ELF output
1 parent 7f764f3 commit c77339a

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

elf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,8 @@ typedef Elf32_Addr Elf32_Conflict;
23362336
/* Processor specific values for the Shdr sh_type field. */
23372337
#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */
23382338
#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */
2339-
#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
2339+
#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
2340+
#define SHT_RISCV_ATTRIBUTES 0x70000003
23402341

23412342

23422343
/* AArch64 relocs. */

tccelf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,27 @@ static void create_arm_attribute_section(TCCState *s1)
28522852
}
28532853
#endif
28542854

2855+
#ifdef TCC_TARGET_RISCV64
2856+
static void create_riscv_attribute_section(TCCState *s1)
2857+
{
2858+
static const unsigned char riscv_attr[] = {
2859+
0x41, /* 'A' */
2860+
0x3c, 0x00, 0x00, 0x00, /* total_len = 60 */
2861+
'r', 'i', 's', 'c', 'v', 0x00, /* "riscv\0" */
2862+
0x2d, 0x00, 0x00, 0x00, /* file_len = 45 */
2863+
0x05, /* Tag_RISCV_arch */
2864+
0x28, 0x00, 0x00, 0x00, /* isa_len = 40 */
2865+
'r','v','6','4','i','2','p','1','_','m','2','p','0','_',
2866+
'a','2','p','1','_','f','2','p','2','_','d','2','p','2','_',
2867+
'c','2','p','0','_','z','i','c','s','r','2','p','0', 0x00,
2868+
};
2869+
Section *attr = new_section(s1, ".riscv.attributes", SHT_RISCV_ATTRIBUTES, 0);
2870+
unsigned char *ptr = section_ptr_add(attr, sizeof(riscv_attr));
2871+
attr->sh_addralign = 1;
2872+
memcpy(ptr, riscv_attr, sizeof(riscv_attr));
2873+
}
2874+
#endif
2875+
28552876
#if TARGETOS_OpenBSD || TARGETOS_NetBSD || TARGETOS_FreeBSD
28562877

28572878
static void fill_bsd_note(Section *s, int type,
@@ -3112,6 +3133,9 @@ static int elf_output_obj(TCCState *s1, const char *filename)
31123133
{
31133134
Section *s;
31143135
int i, ret, file_offset;
3136+
#ifdef TCC_TARGET_RISCV64
3137+
create_riscv_attribute_section(s1);
3138+
#endif
31153139
/* Allocate strings for section names */
31163140
alloc_sec_names(s1, 1);
31173141
file_offset = (sizeof (ElfW(Ehdr)) + 3) & -4;

0 commit comments

Comments
 (0)