LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] OpenRISC module fixups
@ 2024-04-11 16:42 Stafford Horne
  2024-04-11 16:42 ` [PATCH v2 1/2] openrisc: Define openrisc relocation types Stafford Horne
  2024-04-11 16:42 ` [PATCH v2 2/2] openrisc: Add support for more module relocations Stafford Horne
  0 siblings, 2 replies; 3+ messages in thread
From: Stafford Horne @ 2024-04-11 16:42 UTC (permalink / raw
  To: LKML; +Cc: Linux OpenRISC, Stafford Horne

This series implements some missing OpenRISC relocations to allow
module loading to work.  I tested a few modules and these relocations
were enough to allow for several modules I tested with.

In the series we:
  1. Update the relocations to add all of the relocation types currently
     defined in gnu binutils.
  2. Implement two of the missing relocations needed for module loading.

Since v1:
 - Added patch suggested by Geert to rename all relocation types to the
   R_OR1K_* form.

Stafford Horne (2):
  openrisc: Define openrisc relocation types
  openrisc: Add support for more module relocations

 arch/openrisc/include/uapi/asm/elf.h | 75 ++++++++++++++++++++++++----
 arch/openrisc/kernel/module.c        | 18 +++++--
 2 files changed, 80 insertions(+), 13 deletions(-)

-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] openrisc: Define openrisc relocation types
  2024-04-11 16:42 [PATCH v2 0/2] OpenRISC module fixups Stafford Horne
@ 2024-04-11 16:42 ` Stafford Horne
  2024-04-11 16:42 ` [PATCH v2 2/2] openrisc: Add support for more module relocations Stafford Horne
  1 sibling, 0 replies; 3+ messages in thread
From: Stafford Horne @ 2024-04-11 16:42 UTC (permalink / raw
  To: LKML
  Cc: Linux OpenRISC, Stafford Horne, Jonas Bonn, Stefan Kristiansson,
	Eric Biederman, Kees Cook, linux-mm

This defines the current OpenRISC relocation types using the current
R_OR1K_* naming conventions.

The old R_OR32_* definitions are left for backwards compatibility.
Note, the R_OR32_VTENTRY and R_OR32_VTINHERIT macros were defined with
the wrong values the have always been 7 and 8 respectively, not 8 and 7.
They are not used for module loading and I have updated them to use the
correct values.

Signed-off-by: Stafford Horne <shorne@gmail.com>
---
 arch/openrisc/include/uapi/asm/elf.h | 75 ++++++++++++++++++++++++----
 arch/openrisc/kernel/module.c        |  8 +--
 2 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/arch/openrisc/include/uapi/asm/elf.h b/arch/openrisc/include/uapi/asm/elf.h
index 6868f81c281e..441e343f8268 100644
--- a/arch/openrisc/include/uapi/asm/elf.h
+++ b/arch/openrisc/include/uapi/asm/elf.h
@@ -34,15 +34,72 @@
 #include <asm/ptrace.h>
 
 /* The OR1K relocation types... not all relevant for module loader */
-#define R_OR32_NONE	0
-#define R_OR32_32	1
-#define R_OR32_16	2
-#define R_OR32_8	3
-#define R_OR32_CONST	4
-#define R_OR32_CONSTH	5
-#define R_OR32_JUMPTARG	6
-#define R_OR32_VTINHERIT 7
-#define R_OR32_VTENTRY	8
+#define R_OR1K_NONE		0
+#define R_OR1K_32		1
+#define R_OR1K_16		2
+#define R_OR1K_8		3
+#define R_OR1K_LO_16_IN_INSN	4
+#define R_OR1K_HI_16_IN_INSN	5
+#define R_OR1K_INSN_REL_26	6
+#define R_OR1K_GNU_VTENTRY	7
+#define R_OR1K_GNU_VTINHERIT	8
+#define R_OR1K_32_PCREL		9
+#define R_OR1K_16_PCREL		10
+#define R_OR1K_8_PCREL		11
+#define R_OR1K_GOTPC_HI16	12
+#define R_OR1K_GOTPC_LO16	13
+#define R_OR1K_GOT16		14
+#define R_OR1K_PLT26		15
+#define R_OR1K_GOTOFF_HI16	16
+#define R_OR1K_GOTOFF_LO16	17
+#define R_OR1K_COPY		18
+#define R_OR1K_GLOB_DAT		19
+#define R_OR1K_JMP_SLOT		20
+#define R_OR1K_RELATIVE		21
+#define R_OR1K_TLS_GD_HI16	22
+#define R_OR1K_TLS_GD_LO16	23
+#define R_OR1K_TLS_LDM_HI16	24
+#define R_OR1K_TLS_LDM_LO16	25
+#define R_OR1K_TLS_LDO_HI16	26
+#define R_OR1K_TLS_LDO_LO16	27
+#define R_OR1K_TLS_IE_HI16	28
+#define R_OR1K_TLS_IE_LO16	29
+#define R_OR1K_TLS_LE_HI16	30
+#define R_OR1K_TLS_LE_LO16	31
+#define R_OR1K_TLS_TPOFF	32
+#define R_OR1K_TLS_DTPOFF	33
+#define R_OR1K_TLS_DTPMOD	34
+#define R_OR1K_AHI16		35
+#define R_OR1K_GOTOFF_AHI16	36
+#define R_OR1K_TLS_IE_AHI16	37
+#define R_OR1K_TLS_LE_AHI16	38
+#define R_OR1K_SLO16		39
+#define R_OR1K_GOTOFF_SLO16	40
+#define R_OR1K_TLS_LE_SLO16	41
+#define R_OR1K_PCREL_PG21	42
+#define R_OR1K_GOT_PG21		43
+#define R_OR1K_TLS_GD_PG21	44
+#define R_OR1K_TLS_LDM_PG21	45
+#define R_OR1K_TLS_IE_PG21	46
+#define R_OR1K_LO13		47
+#define R_OR1K_GOT_LO13		48
+#define R_OR1K_TLS_GD_LO13	49
+#define R_OR1K_TLS_LDM_LO13	50
+#define R_OR1K_TLS_IE_LO13	51
+#define R_OR1K_SLO13		52
+#define R_OR1K_PLTA26		53
+#define R_OR1K_GOT_AHI16	54
+
+/* Old relocation names */
+#define R_OR32_NONE	R_OR1K_NONE
+#define R_OR32_32	R_OR1K_32
+#define R_OR32_16	R_OR1K_16
+#define R_OR32_8	R_OR1K_8
+#define R_OR32_CONST	R_OR1K_LO_16_IN_INSN
+#define R_OR32_CONSTH	R_OR1K_HI_16_IN_INSN
+#define R_OR32_JUMPTARG	R_OR1K_INSN_REL_26
+#define R_OR32_VTENTRY	R_OR1K_GNU_VTENTRY
+#define R_OR32_VTINHERIT R_OR1K_GNU_VTINHERIT
 
 typedef unsigned long elf_greg_t;
 
diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c
index 532013f523ac..292f0afe27b9 100644
--- a/arch/openrisc/kernel/module.c
+++ b/arch/openrisc/kernel/module.c
@@ -39,16 +39,16 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
 		value = sym->st_value + rel[i].r_addend;
 
 		switch (ELF32_R_TYPE(rel[i].r_info)) {
-		case R_OR32_32:
+		case R_OR1K_32:
 			*location = value;
 			break;
-		case R_OR32_CONST:
+		case R_OR1K_LO_16_IN_INSN:
 			*((uint16_t *)location + 1) = value;
 			break;
-		case R_OR32_CONSTH:
+		case R_OR1K_HI_16_IN_INSN:
 			*((uint16_t *)location + 1) = value >> 16;
 			break;
-		case R_OR32_JUMPTARG:
+		case R_OR1K_INSN_REL_26:
 			value -= (uint32_t)location;
 			value >>= 2;
 			value &= 0x03ffffff;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] openrisc: Add support for more module relocations
  2024-04-11 16:42 [PATCH v2 0/2] OpenRISC module fixups Stafford Horne
  2024-04-11 16:42 ` [PATCH v2 1/2] openrisc: Define openrisc relocation types Stafford Horne
@ 2024-04-11 16:42 ` Stafford Horne
  1 sibling, 0 replies; 3+ messages in thread
From: Stafford Horne @ 2024-04-11 16:42 UTC (permalink / raw
  To: LKML; +Cc: Linux OpenRISC, Stafford Horne, Jonas Bonn, Stefan Kristiansson

When testing modules in OpenRISC I found R_OR1K_AHI16 (signed adjusted
high 16-bit) and R_OR1K_SLO16 (split low 16-bit) relocations are used in
modules but not implemented yet.

This patch implements the relocations. I have tested with a few modules.

Signed-off-by: Stafford Horne <shorne@gmail.com>
---
 arch/openrisc/kernel/module.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c
index 292f0afe27b9..c9ff4c4a0b29 100644
--- a/arch/openrisc/kernel/module.c
+++ b/arch/openrisc/kernel/module.c
@@ -55,6 +55,16 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
 			value |= *location & 0xfc000000;
 			*location = value;
 			break;
+		case R_OR1K_AHI16:
+			/* Adjust the operand to match with a signed LO16.  */
+			value += 0x8000;
+			*((uint16_t *)location + 1) = value >> 16;
+			break;
+		case R_OR1K_SLO16:
+			/* Split value lower 16-bits.  */
+			value = ((value & 0xf800) << 10) | (value & 0x7ff);
+			*location = (*location & ~0x3e007ff) | value;
+			break;
 		default:
 			pr_err("module %s: Unknown relocation: %u\n",
 			       me->name, ELF32_R_TYPE(rel[i].r_info));
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-11 16:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11 16:42 [PATCH v2 0/2] OpenRISC module fixups Stafford Horne
2024-04-11 16:42 ` [PATCH v2 1/2] openrisc: Define openrisc relocation types Stafford Horne
2024-04-11 16:42 ` [PATCH v2 2/2] openrisc: Add support for more module relocations Stafford Horne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).