LoongArch: Fix module relocation error with binutils 2.41

Message ID 20230710042924.2518198-1-chenhuacai@loongson.cn
State New
Headers
Series LoongArch: Fix module relocation error with binutils 2.41 |

Commit Message

Huacai Chen July 10, 2023, 4:29 a.m. UTC
  Binutils 2.41 enable linker relaxation by default, but kernel module
loader doesn't support that, so disable it. Otherwise we get such an
error when loading modules: "Unknown relocation type 102".

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/Makefile | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

WANG Xuerui July 10, 2023, 4:45 a.m. UTC | #1
On 2023/7/10 12:29, Huacai Chen wrote:
> Binutils 2.41 enable linker relaxation by default, but kernel module

"enables" / "will enable"

> loader doesn't support that, so disable it. Otherwise we get such an
> error when loading modules: "Unknown relocation type 102".

IMO it could be better to also justify the disabling (instead of adding 
proper support): linker relaxation is relatively large complexity that 
may or may not bring a similar gain, and we don't really want to include 
this linker pass in the kernel.

> 
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>   arch/loongarch/Makefile | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index 09ba338a64de..7466d3b15db8 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -68,6 +68,8 @@ LDFLAGS_vmlinux			+= -static -n -nostdlib
>   ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
>   cflags-y			+= $(call cc-option,-mexplicit-relocs)
>   KBUILD_CFLAGS_KERNEL		+= $(call cc-option,-mdirect-extern-access)
> +KBUILD_AFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
> +KBUILD_CFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
>   else
>   cflags-y			+= $(call cc-option,-mno-explicit-relocs)
>   KBUILD_AFLAGS_KERNEL		+= -Wa,-mla-global-with-pcrel

The code changes are good. With the commit message improved:

Reviewed-by: WANG Xuerui <git@xen0n.name>
  
Huacai Chen July 10, 2023, 5:01 a.m. UTC | #2
On Mon, Jul 10, 2023 at 12:45 PM WANG Xuerui <kernel@xen0n.name> wrote:
>
> On 2023/7/10 12:29, Huacai Chen wrote:
> > Binutils 2.41 enable linker relaxation by default, but kernel module
>
> "enables" / "will enable"
>
> > loader doesn't support that, so disable it. Otherwise we get such an
> > error when loading modules: "Unknown relocation type 102".
>
> IMO it could be better to also justify the disabling (instead of adding
> proper support): linker relaxation is relatively large complexity that
> may or may not bring a similar gain, and we don't really want to include
> this linker pass in the kernel.
OK, thanks.

Huacai
>
> >
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> >   arch/loongarch/Makefile | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> > index 09ba338a64de..7466d3b15db8 100644
> > --- a/arch/loongarch/Makefile
> > +++ b/arch/loongarch/Makefile
> > @@ -68,6 +68,8 @@ LDFLAGS_vmlinux                     += -static -n -nostdlib
> >   ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
> >   cflags-y                    += $(call cc-option,-mexplicit-relocs)
> >   KBUILD_CFLAGS_KERNEL                += $(call cc-option,-mdirect-extern-access)
> > +KBUILD_AFLAGS_MODULE         += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
> > +KBUILD_CFLAGS_MODULE         += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
> >   else
> >   cflags-y                    += $(call cc-option,-mno-explicit-relocs)
> >   KBUILD_AFLAGS_KERNEL                += -Wa,-mla-global-with-pcrel
>
> The code changes are good. With the commit message improved:
>
> Reviewed-by: WANG Xuerui <git@xen0n.name>
>
> --
> WANG "xen0n" Xuerui
>
> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
>
>
  

Patch

diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 09ba338a64de..7466d3b15db8 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -68,6 +68,8 @@  LDFLAGS_vmlinux			+= -static -n -nostdlib
 ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
 cflags-y			+= $(call cc-option,-mexplicit-relocs)
 KBUILD_CFLAGS_KERNEL		+= $(call cc-option,-mdirect-extern-access)
+KBUILD_AFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
+KBUILD_CFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
 else
 cflags-y			+= $(call cc-option,-mno-explicit-relocs)
 KBUILD_AFLAGS_KERNEL		+= -Wa,-mla-global-with-pcrel