This series hunts the problems discovered after manual enabling of
ARCH_WANT_LD_ORPHAN_WARN, notably the missing PAGE_ALIGNED_DATA()
section affecting VDSO placement (marked for stable).
Compile and runtime tested on MIPS32R2 CPS board with no issues.
Alexander Lobakin (4):
MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
MIPS: vmlinux.lds.S: add ".rel.dyn" to DISCARDS
MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
MIPS: select ARCH_WANT_LD_ORPHAN_WARN
arch/mips/Kconfig | 1 +
arch/mips/kernel/vmlinux.lds.S | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
--
2.30.0
MIPS uses its own declaration of rwdata, and thus it should be kept
in sync with the asm-generic one. Currently PAGE_ALIGNED_DATA() is
missing from the linker script, which emits the following ld
warnings:
mips-alpine-linux-musl-ld: warning: orphan section
`.data..page_aligned' from `arch/mips/kernel/vdso.o' being placed
in section `.data..page_aligned'
mips-alpine-linux-musl-ld: warning: orphan section
`.data..page_aligned' from `arch/mips/vdso/vdso-image.o' being placed
in section `.data..page_aligned'
Add the necessary declaration, so the mentioned structures will be
placed in vmlinux as intended:
ffffffff80630580 D __end_once
ffffffff80630580 D __start___dyndbg
ffffffff80630580 D __start_once
ffffffff80630580 D __stop___dyndbg
ffffffff80634000 d mips_vdso_data
ffffffff80638000 d vdso_data
ffffffff80638580 D _gp
ffffffff8063c000 T __init_begin
ffffffff8063c000 D _edata
ffffffff8063c000 T _sinittext
->
ffffffff805a4000 D __end_init_task
ffffffff805a4000 D __nosave_begin
ffffffff805a4000 D __nosave_end
ffffffff805a4000 d mips_vdso_data
ffffffff805a8000 d vdso_data
ffffffff805ac000 D mmlist_lock
ffffffff805ac080 D tasklist_lock
Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO")
Cc: [email protected] # 4.4+
Signed-off-by: Alexander Lobakin <[email protected]>
---
arch/mips/kernel/vmlinux.lds.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 5e97e9d02f98..83e27a181206 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -90,6 +90,7 @@ SECTIONS
INIT_TASK_DATA(THREAD_SIZE)
NOSAVE_DATA
+ PAGE_ALIGNED_DATA(PAGE_SIZE)
CACHELINE_ALIGNED_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
READ_MOSTLY_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
DATA_DATA
--
2.30.0
GCC somehow manages to place some of the symbols from main.c into
.rel.dyn section:
mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn'
from `init/main.o' being placed in section `.rel.dyn'
I couldn't catch up the exact symbol, but seems like it's harmless
to discard it from the final vmlinux as kernel doesn't use or
support dynamic relocations.
Misc: sort DISCARDS section entries alphabetically.
Signed-off-by: Alexander Lobakin <[email protected]>
---
arch/mips/kernel/vmlinux.lds.S | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 83e27a181206..1c3c2e903062 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -221,9 +221,10 @@ SECTIONS
/* ABI crap starts here */
*(.MIPS.abiflags)
*(.MIPS.options)
+ *(.eh_frame)
*(.options)
*(.pdr)
*(.reginfo)
- *(.eh_frame)
+ *(.rel.dyn)
}
}
--
2.30.0
Now, after that all the sections are explicitly described and
declared in vmlinux.lds.S, we can enable ld orphan warnings to
prevent from missing any new sections in future.
Signed-off-by: Alexander Lobakin <[email protected]>
---
arch/mips/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d68df1febd25..d3e64cc0932b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -18,6 +18,7 @@ config MIPS
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
select ARCH_WANT_IPC_PARSE_VERSION
+ select ARCH_WANT_LD_ORPHAN_WARN
select BUILDTIME_TABLE_SORT
select CLONE_BACKWARDS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
--
2.30.0
Discard GNU attributes at link time as kernel doesn't use it at all.
Solves a dozen of the following ld warnings (one per every file):
mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes'
from `arch/mips/kernel/head.o' being placed in section
`.gnu.attributes'
mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes'
from `init/main.o' being placed in section `.gnu.attributes'
Signed-off-by: Alexander Lobakin <[email protected]>
---
arch/mips/kernel/vmlinux.lds.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 1c3c2e903062..8ac95269124a 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -222,6 +222,7 @@ SECTIONS
*(.MIPS.abiflags)
*(.MIPS.options)
*(.eh_frame)
+ *(.gnu.attributes)
*(.options)
*(.pdr)
*(.reginfo)
--
2.30.0
On Mon, Jan 04, 2021 at 12:18:10PM +0000, Alexander Lobakin wrote:
> This series hunts the problems discovered after manual enabling of
> ARCH_WANT_LD_ORPHAN_WARN, notably the missing PAGE_ALIGNED_DATA()
> section affecting VDSO placement (marked for stable).
>
> Compile and runtime tested on MIPS32R2 CPS board with no issues.
>
> Alexander Lobakin (4):
> MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
> MIPS: vmlinux.lds.S: add ".rel.dyn" to DISCARDS
> MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
> MIPS: select ARCH_WANT_LD_ORPHAN_WARN
>
> arch/mips/Kconfig | 1 +
> arch/mips/kernel/vmlinux.lds.S | 5 ++++-
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> --
> 2.30.0
>
Glad to see ARCH_WANT_LD_ORPHAN_WARN catching on :)
I took this for a spin with clang with malta_kvm_guest_defconfig and I
only see one section unaccounted for:
$ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- LLVM=1 O=out/mips distclean malta_kvm_guest_defconfig all
...
ld.lld: warning: <internal>:(.got) is being placed in '.got'
ld.lld: warning: <internal>:(.got) is being placed in '.got'
ld.lld: warning: <internal>:(.got) is being placed in '.got'
Looks like most architectures place it in .got (ia64, nios2, powerpc)
or .text (arm64).
Cheers,
Nathan
On Mon, Jan 4, 2021 at 4:21 AM Alexander Lobakin <[email protected]> wrote:
>
> GCC somehow manages to place some of the symbols from main.c into
> .rel.dyn section:
>
> mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn'
> from `init/main.o' being placed in section `.rel.dyn'
>
> I couldn't catch up the exact symbol, but seems like it's harmless
> to discard it from the final vmlinux as kernel doesn't use or
> support dynamic relocations.
>
> Misc: sort DISCARDS section entries alphabetically.
>
> Signed-off-by: Alexander Lobakin <[email protected]>
> ---
> arch/mips/kernel/vmlinux.lds.S | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> index 83e27a181206..1c3c2e903062 100644
> --- a/arch/mips/kernel/vmlinux.lds.S
> +++ b/arch/mips/kernel/vmlinux.lds.S
> @@ -221,9 +221,10 @@ SECTIONS
> /* ABI crap starts here */
> *(.MIPS.abiflags)
> *(.MIPS.options)
> + *(.eh_frame)
> *(.options)
> *(.pdr)
> *(.reginfo)
> - *(.eh_frame)
> + *(.rel.dyn)
> }
> }
> --
> 2.30.0
>
>
(I don't know why I am on the CC list since I know little about
mips... Anyway, I know the LLD linker's behavior in case that was the
intention... )
I think it'd be good to know the reason why these dynamic relocations
are produced and fix the root cause.
arch/x86/kernel/vmlinux.lds.S asserts no dynamic relocation:
ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations
(.rela) detected!")
在 2021/1/5 下午3:39, Fāng-ruì Sòng 写道:
> On Mon, Jan 4, 2021 at 4:21 AM Alexander Lobakin <[email protected]> wrote:
>> GCC somehow manages to place some of the symbols from main.c into
>> .rel.dyn section:
>>
>> mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn'
>> from `init/main.o' being placed in section `.rel.dyn'
>>
>> I couldn't catch up the exact symbol, but seems like it's harmless
>> to discard it from the final vmlinux as kernel doesn't use or
>> support dynamic relocations.
>>
>> Misc: sort DISCARDS section entries alphabetically.
>>
>> Signed-off-by: Alexander Lobakin <[email protected]>
>> ---
>> arch/mips/kernel/vmlinux.lds.S | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
>> index 83e27a181206..1c3c2e903062 100644
>> --- a/arch/mips/kernel/vmlinux.lds.S
>> +++ b/arch/mips/kernel/vmlinux.lds.S
>> @@ -221,9 +221,10 @@ SECTIONS
>> /* ABI crap starts here */
>> *(.MIPS.abiflags)
>> *(.MIPS.options)
>> + *(.eh_frame)
>> *(.options)
>> *(.pdr)
>> *(.reginfo)
>> - *(.eh_frame)
>> + *(.rel.dyn)
>> }
>> }
>> --
>> 2.30.0
>>
>>
> (I don't know why I am on the CC list since I know little about
> mips... Anyway, I know the LLD linker's behavior in case that was the
> intention... )
>
> I think it'd be good to know the reason why these dynamic relocations
> are produced and fix the root cause.
>
> arch/x86/kernel/vmlinux.lds.S asserts no dynamic relocation:
> ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations
> (.rela) detected!")
Hi all,
Runtime .rela can't be avoided as MIPS kernel can't be built with fPIC.
Our relocatable kernel uses another approach, fixup dynamic relocations
at boot time.
abicalls simply gave us too much overhead on PIC code, which is unacceptable
for kernel.
In my local tests, PIC kernel reduced unix bench results for around 30%.
For MIPS Release6 and afterwards, we may utilize new pcrel instructions to
reduce overhead but for older ISA I don't have any idea.
Thanks.
- Jiaxun
From: Nathan Chancellor <[email protected]>
Date: Mon, 4 Jan 2021 17:09:36 -0700
> On Mon, Jan 04, 2021 at 12:18:10PM +0000, Alexander Lobakin wrote:
>> This series hunts the problems discovered after manual enabling of
>> ARCH_WANT_LD_ORPHAN_WARN, notably the missing PAGE_ALIGNED_DATA()
>> section affecting VDSO placement (marked for stable).
>>
>> Compile and runtime tested on MIPS32R2 CPS board with no issues.
>>
>> Alexander Lobakin (4):
>> MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
>> MIPS: vmlinux.lds.S: add ".rel.dyn" to DISCARDS
>> MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
>> MIPS: select ARCH_WANT_LD_ORPHAN_WARN
>>
>> arch/mips/Kconfig | 1 +
>> arch/mips/kernel/vmlinux.lds.S | 5 ++++-
>> 2 files changed, 5 insertions(+), 1 deletion(-)
>>
>> --
>> 2.30.0
>>
>
> Glad to see ARCH_WANT_LD_ORPHAN_WARN catching on :)
>
> I took this for a spin with clang with malta_kvm_guest_defconfig and I
> only see one section unaccounted for:
>
> $ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- LLVM=1 O=out/mips distclean malta_kvm_guest_defconfig all
> ...
> ld.lld: warning: <internal>:(.got) is being placed in '.got'
> ld.lld: warning: <internal>:(.got) is being placed in '.got'
> ld.lld: warning: <internal>:(.got) is being placed in '.got'
>
> Looks like most architectures place it in .got (ia64, nios2, powerpc)
> or .text (arm64).
Addressed in v2, thanks!
> Cheers,
> Nathan
Al