linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] openrisc: Add support for more module relocations
@ 2024-04-10 20:51 Stafford Horne
  2024-04-11 12:12 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Stafford Horne @ 2024-04-10 20:51 UTC (permalink / raw)
  To: LKML
  Cc: Stafford Horne, Jonas Bonn, Stefan Kristiansson, Eric Biederman,
	Kees Cook, linux-openrisc, linux-mm

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

This patch adds the relocations. Note, we use the old naming R_OR32_*
instead or the new naming R_OR1K_* to avoid change as this header is
exported as a user api.

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

diff --git a/arch/openrisc/include/uapi/asm/elf.h b/arch/openrisc/include/uapi/asm/elf.h
index 6868f81c281e..0c882a388524 100644
--- a/arch/openrisc/include/uapi/asm/elf.h
+++ b/arch/openrisc/include/uapi/asm/elf.h
@@ -43,6 +43,8 @@
 #define R_OR32_JUMPTARG	6
 #define R_OR32_VTINHERIT 7
 #define R_OR32_VTENTRY	8
+#define R_OR32_AHI16	35
+#define R_OR32_SLO16	39
 
 typedef unsigned long elf_greg_t;
 
diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c
index 532013f523ac..01bda5616114 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_OR32_AHI16:
+			/* Adjust the operand to match with a signed LO16.  */
+			value += 0x8000;
+			*((uint16_t *)location + 1) = value >> 16;
+			break;
+		case R_OR32_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	[flat|nested] 3+ messages in thread

* Re: [PATCH] openrisc: Add support for more module relocations
  2024-04-10 20:51 [PATCH] openrisc: Add support for more module relocations Stafford Horne
@ 2024-04-11 12:12 ` Geert Uytterhoeven
  2024-04-11 15:51   ` Stafford Horne
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2024-04-11 12:12 UTC (permalink / raw)
  To: Stafford Horne
  Cc: LKML, Jonas Bonn, Stefan Kristiansson, Eric Biederman, Kees Cook,
	linux-openrisc, linux-mm

Hi Stafford,

On Wed, Apr 10, 2024 at 10:52 PM Stafford Horne <shorne@gmail.com> wrote:
> This patch adds the relocations. Note, we use the old naming R_OR32_*
> instead or the new naming R_OR1K_* to avoid change as this header is
> exported as a user api.

> --- a/arch/openrisc/include/uapi/asm/elf.h
> +++ b/arch/openrisc/include/uapi/asm/elf.h
> @@ -43,6 +43,8 @@
>  #define R_OR32_JUMPTARG        6
>  #define R_OR32_VTINHERIT 7
>  #define R_OR32_VTENTRY 8
> +#define R_OR32_AHI16   35
> +#define R_OR32_SLO16   39

Would it make sense to switch to the new names, e.g.

  #define R_OR1K_NONE        0

and add definitions for backwards compatibility?

    #define R_OR32_NONE        R_OR1K_NONE

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds


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

* Re: [PATCH] openrisc: Add support for more module relocations
  2024-04-11 12:12 ` Geert Uytterhoeven
@ 2024-04-11 15:51   ` Stafford Horne
  0 siblings, 0 replies; 3+ messages in thread
From: Stafford Horne @ 2024-04-11 15:51 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: LKML, Jonas Bonn, Stefan Kristiansson, Eric Biederman, Kees Cook,
	linux-openrisc, linux-mm

On Thu, Apr 11, 2024 at 02:12:59PM +0200, Geert Uytterhoeven wrote:
> Hi Stafford,
> 
> On Wed, Apr 10, 2024 at 10:52 PM Stafford Horne <shorne@gmail.com> wrote:
> > This patch adds the relocations. Note, we use the old naming R_OR32_*
> > instead or the new naming R_OR1K_* to avoid change as this header is
> > exported as a user api.
> 
> > --- a/arch/openrisc/include/uapi/asm/elf.h
> > +++ b/arch/openrisc/include/uapi/asm/elf.h
> > @@ -43,6 +43,8 @@
> >  #define R_OR32_JUMPTARG        6
> >  #define R_OR32_VTINHERIT 7
> >  #define R_OR32_VTENTRY 8
> > +#define R_OR32_AHI16   35
> > +#define R_OR32_SLO16   39
> 
> Would it make sense to switch to the new names, e.g.
> 
>   #define R_OR1K_NONE        0
> 
> and add definitions for backwards compatibility?
> 
>     #define R_OR32_NONE        R_OR1K_NONE
> 

Hi Geert,

Actually I had a patch doing this and added all 38 or so relocation definitions.
But I dropped it at the last moment in favor of simplicity.

Let me rework it and add it back.

-Stafford


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10 20:51 [PATCH] openrisc: Add support for more module relocations Stafford Horne
2024-04-11 12:12 ` Geert Uytterhoeven
2024-04-11 15:51   ` Stafford Horne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox