Skip to contentSkip to conversation

prelink: Add RISC-V support

PATCH Superseded Khem Raj 1 participant 1 message Mar 11, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 prelink: Add RISC-V support

---
 ChangeLog         |  5 +++++
 src/elf.h         | 25 ++++++++++++++++++++++++-
 src/rtld/dl-tls.c |  5 +++++
 src/rtld/rtld.c   | 14 ++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)
ChangeLog +5 -0
index c72dca8..4487026 100644
@@ -1,3 +1,8 @@
+2018-03-10   Khem Raj <[email protected]>
+	* src/elf.h: Add RISC-V defines
+	* src/rtld/dl-tls.c: Add RISC-V support
+	* src/rtld/rtld.c: Add RISC-V support
+
 2017-06-20   Mark Hatle <[email protected]>
 	* doc/Makefile.am: Disable automatic generation of prelink.pdf
 
src/elf.h +24 -1
index fbadda4..dbd6170 100644
@@ -254,7 +254,8 @@ typedef struct
 #define EM_TILEPRO	188		/* Tilera TILEPro */
 #define EM_MICROBLAZE	189		/* Xilinx MicroBlaze */
 #define EM_TILEGX	191		/* Tilera TILE-Gx */
-#define EM_NUM		192
+#define EM_RISCV	243		/* RISC-V */
+#define EM_NUM		244
 
 /* If it is necessary to assign new unofficial EM_* values, please
    pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
@@ -3556,6 +3557,28 @@ enum
 
 #define R_TILEGX_NUM		130
 
+/* RISC-V ELF Flags */
+#define EF_RISCV_RVC			0x0001
+#define EF_RISCV_FLOAT_ABI		0x0006
+#define EF_RISCV_FLOAT_ABI_SOFT		0x0000
+#define EF_RISCV_FLOAT_ABI_SINGLE	0x0002
+#define EF_RISCV_FLOAT_ABI_DOUBLE	0x0004
+#define EF_RISCV_FLOAT_ABI_QUAD		0x0006
+
+/* RISC-V relocations.  */
+#define R_RISCV_NONE		0
+#define R_RISCV_32		1
+#define R_RISCV_64		2
+#define R_RISCV_RELATIVE	3
+#define R_RISCV_COPY		4
+#define R_RISCV_JUMP_SLOT	5
+#define R_RISCV_TLS_DTPMOD32	6
+#define R_RISCV_TLS_DTPMOD64	7
+#define R_RISCV_TLS_DTPREL32	8
+#define R_RISCV_TLS_DTPREL64	9
+#define R_RISCV_TLS_TPREL32	10
+#define R_RISCV_TLS_TPREL64	11
+#define R_RISCV_NUM		12
 
 __END_DECLS
 
src/rtld/dl-tls.c +5 -0
index 2da6bc5..280cee4 100644
@@ -138,6 +138,11 @@ rtld_determine_tlsoffsets (int e_machine, struct r_scope_elem *search_list)
       tls_tcb_size = 8;
       break;
 
+    case EM_RISCV:
+      tls_dtv_at_tp = 1;
+      tls_tcb_size = 0;
+      break;
+
     default:
       /* Hope there's no TLS!  */
       for (i = 0; i < search_list->r_nlist; i++)
src/rtld/rtld.c +14 -0
index 3196981..2fc355b 100644
@@ -224,6 +224,17 @@ parse_opt (int key, char *arg, struct argp_state *state)
     * ELF_RTYPE_CLASS_PLT \
    | ((type) == R_MICROBLAZE_COPY) * ELF_RTYPE_CLASS_COPY)
 
+/* From glibc-2.27: sysdeps/riscv/dl-machine.h */
+#define riscv_elf_machine_type_class(type)                      \
+  ((ELF_RTYPE_CLASS_PLT * ((type) == R_RISCV_JUMP_SLOT          \
+     || ((type) == R_RISCV_TLS_DTPREL32)    \
+     || ((type) == R_RISCV_TLS_DTPMOD32)    \
+     || ((type) == R_RISCV_TLS_TPREL32)     \
+     || ((type) == R_RISCV_TLS_DTPREL64)    \
+     || ((type) == R_RISCV_TLS_DTPMOD64)    \
+     || ((type) == R_RISCV_TLS_TPREL64)))   \
+   | (ELF_RTYPE_CLASS_COPY * ((type) == R_RISCV_COPY)))
+
 int
 elf_machine_type_class (int type, int machine)
 {
@@ -254,6 +265,8 @@ elf_machine_type_class (int type, int machine)
 	return nios2_elf_machine_type_class(type);
     case EM_MICROBLAZE:
 	return microblaze_elf_machine_type_class(type);
+    case EM_RISCV:
+	return riscv_elf_machine_type_class(type);
 
     default:
       printf ("Unknown architecture!\n");
@@ -296,6 +309,7 @@ machine_no_rela (int machine)
     case EM_SPARCV9:
     case EM_ALTERA_NIOS2:
     case EM_MICROBLAZE:
+    case EM_RISCV:
       return 0;
     default:
       return 1;
Signature · 1 line
2.16.2