diff mbox series

riscv module: remove (NOLOAD)

Message ID 20220218082611.396353-1-maskray@google.com (mailing list archive)
State New, archived
Headers show
Series riscv module: remove (NOLOAD) | expand

Commit Message

Fangrui Song Feb. 18, 2022, 8:26 a.m. UTC
On ELF, (NOLOAD) sets the section type to SHT_NOBITS[1]. It is conceptually
inappropriate for .plt, .got, and .got.plt sections which are always
SHT_PROGBITS.

In GNU ld, if PLT entries are needed, .plt will be SHT_PROGBITS anyway
and (NOLOAD) will be essentially ignored. In ld.lld, since
https://reviews.llvm.org/D118840 ("[ELF] Support (TYPE=<value>) to
customize the output section type"), ld.lld will report a `section type
mismatch` error. Just remove (NOLOAD) to fix the error.

[1] https://lld.llvm.org/ELF/linker_script.html As of today, "The
section should be marked as not loadable" on
https://sourceware.org/binutils/docs/ld/Output-Section-Type.html is
outdated for ELF.
---
 arch/riscv/include/asm/module.lds.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Nathan Chancellor Feb. 19, 2022, 4:45 p.m. UTC | #1
On Fri, Feb 18, 2022 at 12:26:11AM -0800, Fangrui Song wrote:
> On ELF, (NOLOAD) sets the section type to SHT_NOBITS[1]. It is conceptually
> inappropriate for .plt, .got, and .got.plt sections which are always
> SHT_PROGBITS.
> 
> In GNU ld, if PLT entries are needed, .plt will be SHT_PROGBITS anyway
> and (NOLOAD) will be essentially ignored. In ld.lld, since
> https://reviews.llvm.org/D118840 ("[ELF] Support (TYPE=<value>) to
> customize the output section type"), ld.lld will report a `section type
> mismatch` error. Just remove (NOLOAD) to fix the error.
> 
> [1] https://lld.llvm.org/ELF/linker_script.html As of today, "The
> section should be marked as not loadable" on
> https://sourceware.org/binutils/docs/ld/Output-Section-Type.html is
> outdated for ELF.

Thank you for the patch! As mentioned on the arm64 patch, this needs
your Signed-off-by tag. With that provided:

Cc: stable@vger.kernel.org
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

This needs to go to stable so that older trees with a newer toolchain do
not warn.

> ---
>  arch/riscv/include/asm/module.lds.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/module.lds.h b/arch/riscv/include/asm/module.lds.h
> index 4254ff2ff049..1075beae1ac6 100644
> --- a/arch/riscv/include/asm/module.lds.h
> +++ b/arch/riscv/include/asm/module.lds.h
> @@ -2,8 +2,8 @@
>  /* Copyright (C) 2017 Andes Technology Corporation */
>  #ifdef CONFIG_MODULE_SECTIONS
>  SECTIONS {
> -	.plt (NOLOAD) : { BYTE(0) }
> -	.got (NOLOAD) : { BYTE(0) }
> -	.got.plt (NOLOAD) : { BYTE(0) }
> +	.plt : { BYTE(0) }
> +	.got : { BYTE(0) }
> +	.got.plt : { BYTE(0) }
>  }
>  #endif
> -- 
> 2.35.1.265.g69c8d7142f-goog
> 
>
Palmer Dabbelt March 18, 2022, 11:18 p.m. UTC | #2
On Sat, 19 Feb 2022 08:45:10 PST (-0800), nathan@kernel.org wrote:
> On Fri, Feb 18, 2022 at 12:26:11AM -0800, Fangrui Song wrote:
>> On ELF, (NOLOAD) sets the section type to SHT_NOBITS[1]. It is conceptually
>> inappropriate for .plt, .got, and .got.plt sections which are always
>> SHT_PROGBITS.
>>
>> In GNU ld, if PLT entries are needed, .plt will be SHT_PROGBITS anyway
>> and (NOLOAD) will be essentially ignored. In ld.lld, since
>> https://reviews.llvm.org/D118840 ("[ELF] Support (TYPE=<value>) to
>> customize the output section type"), ld.lld will report a `section type
>> mismatch` error. Just remove (NOLOAD) to fix the error.
>>
>> [1] https://lld.llvm.org/ELF/linker_script.html As of today, "The
>> section should be marked as not loadable" on
>> https://sourceware.org/binutils/docs/ld/Output-Section-Type.html is
>> outdated for ELF.
>
> Thank you for the patch! As mentioned on the arm64 patch, this needs
> your Signed-off-by tag. With that provided:
>
> Cc: stable@vger.kernel.org
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> Tested-by: Nathan Chancellor <nathan@kernel.org>
>
> This needs to go to stable so that older trees with a newer toolchain do
> not warn.

Yep, just checking on that SOB line.  A 

Fixes: 596b0474d3d9 ("kbuild: preprocess module linker script")

seems appropriate as well.

Thanks!

>
>> ---
>>  arch/riscv/include/asm/module.lds.h | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/riscv/include/asm/module.lds.h b/arch/riscv/include/asm/module.lds.h
>> index 4254ff2ff049..1075beae1ac6 100644
>> --- a/arch/riscv/include/asm/module.lds.h
>> +++ b/arch/riscv/include/asm/module.lds.h
>> @@ -2,8 +2,8 @@
>>  /* Copyright (C) 2017 Andes Technology Corporation */
>>  #ifdef CONFIG_MODULE_SECTIONS
>>  SECTIONS {
>> -	.plt (NOLOAD) : { BYTE(0) }
>> -	.got (NOLOAD) : { BYTE(0) }
>> -	.got.plt (NOLOAD) : { BYTE(0) }
>> +	.plt : { BYTE(0) }
>> +	.got : { BYTE(0) }
>> +	.got.plt : { BYTE(0) }
>>  }
>>  #endif
>> --
>> 2.35.1.265.g69c8d7142f-goog
>>
>>
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/module.lds.h b/arch/riscv/include/asm/module.lds.h
index 4254ff2ff049..1075beae1ac6 100644
--- a/arch/riscv/include/asm/module.lds.h
+++ b/arch/riscv/include/asm/module.lds.h
@@ -2,8 +2,8 @@ 
 /* Copyright (C) 2017 Andes Technology Corporation */
 #ifdef CONFIG_MODULE_SECTIONS
 SECTIONS {
-	.plt (NOLOAD) : { BYTE(0) }
-	.got (NOLOAD) : { BYTE(0) }
-	.got.plt (NOLOAD) : { BYTE(0) }
+	.plt : { BYTE(0) }
+	.got : { BYTE(0) }
+	.got.plt : { BYTE(0) }
 }
 #endif