History

riscv64: emit .riscv.attributes section in ELF output

Meng Zhuo committed 6 months ago

Commit c77339a1 parent 7f764f32 files · +26 −1Browse files

Unified · Split

2 files
  1. elf.h +2 −1
  2. tccelf.c +24 −0
elf.h+2−1
@@ -2336,7 +2336,8 @@ typedef Elf32_Addr Elf32_Conflict; · 2335 unmodified lines
2336/* Processor specific values for the Shdr sh_type field. */2336/* Processor specific values for the Shdr sh_type field. */
2337#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */2337#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */
2338#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */2338#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
2340 2341
2341 2342
2342/* AArch64 relocs. */2343/* AArch64 relocs. */
tccelf.c+24−0
@@ -2852,6 +2852,27 @@ static void create_arm_attribute_section(TCCState *s1) · 2851 unmodified lines
2852}2852}
2853#endif2853#endif
2854 2854
2855#ifdef TCC_TARGET_RISCV64
2856static 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
2855#if TARGETOS_OpenBSD || TARGETOS_NetBSD || TARGETOS_FreeBSD2876#if TARGETOS_OpenBSD || TARGETOS_NetBSD || TARGETOS_FreeBSD
2856 2877
2857static void fill_bsd_note(Section *s, int type,2878static void fill_bsd_note(Section *s, int type,
@@ -3112,6 +3133,9 @@ static int elf_output_obj(TCCState *s1, const char *filename) · 254 unmodified lines
3112{3133{
3113 Section *s;3134 Section *s;
3114 int i, ret, file_offset;3135 int i, ret, file_offset;
3136#ifdef TCC_TARGET_RISCV64
3137 create_riscv_attribute_section(s1);
3138#endif
3115 /* Allocate strings for section names */3139 /* Allocate strings for section names */
3116 alloc_sec_names(s1, 1);3140 alloc_sec_names(s1, 1);
3117 file_offset = (sizeof (ElfW(Ehdr)) + 3) & -4;3141 file_offset = (sizeof (ElfW(Ehdr)) + 3) & -4;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t