| @@ -2852,6 +2852,27 @@ static void create_arm_attribute_section(TCCState *s1) · 2851 unmodified lines |
| 2852 | 2852 | } |
| 2853 | 2853 | #endif |
| 2854 | 2854 | |
| 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 | + |
| 2855 | 2876 | #if TARGETOS_OpenBSD || TARGETOS_NetBSD || TARGETOS_FreeBSD |
| 2856 | 2877 | |
| 2857 | 2878 | static 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 | 3134 | Section *s; |
| 3114 | 3135 | int i, ret, file_offset; |
| 3136 | +#ifdef TCC_TARGET_RISCV64 |
| 3137 | + create_riscv_attribute_section(s1); |
| 3138 | +#endif |
| 3115 | 3139 | /* Allocate strings for section names */ |
| 3116 | 3140 | alloc_sec_names(s1, 1); |
| 3117 | 3141 | file_offset = (sizeof (ElfW(Ehdr)) + 3) & -4; |