[PATCH v4 2/4] openrisc: Add R_OR1K_32_PCREL relocation type module support

ChenMiao posted 4 patches 4 weeks ago
There is a newer version of this series
[PATCH v4 2/4] openrisc: Add R_OR1K_32_PCREL relocation type module support
Posted by ChenMiao 4 weeks ago
From: chenmiao <chenmiao.ku@gmail.com>

To ensure the proper functioning of the jump_label test module, this patch
adds support for the R_OR1K_32_PCREL relocation type. The implementation
calculates the PC-relative offset by subtracting the instruction location
from the target value and stores the result at the specified location.

Signed-off-by: chenmiao <chenmiao.ku@gmail.com>
---
 arch/openrisc/kernel/module.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c
index c9ff4c4a0b29..4ac4fbaa827c 100644
--- a/arch/openrisc/kernel/module.c
+++ b/arch/openrisc/kernel/module.c
@@ -55,6 +55,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
 			value |= *location & 0xfc000000;
 			*location = value;
 			break;
+		case R_OR1K_32_PCREL:
+			value -= (uint32_t)location;
+			*location = value;
+			break;
 		case R_OR1K_AHI16:
 			/* Adjust the operand to match with a signed LO16.  */
 			value += 0x8000;
-- 
2.45.2
Re: [PATCH v4 2/4] openrisc: Add R_OR1K_32_PCREL relocation type module support
Posted by Stafford Horne 3 weeks, 6 days ago
On Thu, Sep 04, 2025 at 10:00:50AM +0000, ChenMiao wrote:
> From: chenmiao <chenmiao.ku@gmail.com>
> 
> To ensure the proper functioning of the jump_label test module, this patch
> adds support for the R_OR1K_32_PCREL relocation type. The implementation
> calculates the PC-relative offset by subtracting the instruction location
> from the target value and stores the result at the specified location.

OK, thanks, really this is needed any modules that use jump_label, not just the
test module.

> Signed-off-by: chenmiao <chenmiao.ku@gmail.com>
> ---
>  arch/openrisc/kernel/module.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c
> index c9ff4c4a0b29..4ac4fbaa827c 100644
> --- a/arch/openrisc/kernel/module.c
> +++ b/arch/openrisc/kernel/module.c
> @@ -55,6 +55,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
>  			value |= *location & 0xfc000000;
>  			*location = value;
>  			break;
> +		case R_OR1K_32_PCREL:
> +			value -= (uint32_t)location;
> +			*location = value;
> +			break;
>  		case R_OR1K_AHI16:
>  			/* Adjust the operand to match with a signed LO16.  */
>  			value += 0x8000;
> -- 
> 2.45.2
>