@@ -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
28572878static 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