Subject: [PATCH v3] powerpc/64: Fix section mismatch warnings for early boot symbols

Some of the boot code located at the start of kernel text is "init"
class, in that it only runs at boot time, however marking it as normal
init code is problematic because that puts it into a different section
located at the very end of kernel text.

e.g., in case the TOC is not set up, we may not be able to tolerate a
branch trampoline to reach the init function.

Credits: code and message are based on 2016 patch by Nicholas Piggin,
and slightly modified so not to rename the powerpc code/symbol names.

Subject: [PATCH] powerpc/64: quieten section mismatch warnings
From: Nicholas Piggin <npiggin at gmail.com>
Date: Fri Dec 23 00:14:19 AEDT 2016

This resolves the following section mismatch warnings:

WARNING: vmlinux.o(.text+0x2fa8): Section mismatch in reference from the variable __boot_from_prom to the function .init.text:prom_init()
The function __boot_from_prom() references
the function __init prom_init().
This is often because __boot_from_prom lacks a __init
annotation or the annotation of prom_init is wrong.

WARNING: vmlinux.o(.text+0x3238): Section mismatch in reference from the variable start_here_multiplatform to the function .init.text:early_setup()
The function start_here_multiplatform() references
the function __init early_setup().
This is often because start_here_multiplatform lacks a __init
annotation or the annotation of early_setup is wrong.

WARNING: vmlinux.o(.text+0x326c): Section mismatch in reference from the variable start_here_common to the function .init.text:start_kernel()
The function start_here_common() references
the function __init start_kernel().
This is often because start_here_common lacks a __init
annotation or the annotation of start_kernel is wrong.

Signed-off-by: Mauricio Faria de Oliveira <[email protected]>
---
v3: reword some comments and include errors in commit message
v2: fix build error due to missing parenthesis
scripts/mod/modpost.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4ff08a0..d10c9d8 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1173,8 +1173,15 @@ static const struct sectioncheck *section_mismatch(
* fromsec = text section
* refsymname = *.constprop.*
*
+ * Pattern 6:
+ * powerpc64 has boot functions that reference init, but must remain in text.
+ * This pattern is identified by
+ * tosec = init section
+ * fromsym = __boot_from_prom, start_here_common, start_here_multiplatform
+ *
**/
-static int secref_whitelist(const struct sectioncheck *mismatch,
+static int secref_whitelist(const struct elf_info *elf,
+ const struct sectioncheck *mismatch,
const char *fromsec, const char *fromsym,
const char *tosec, const char *tosym)
{
@@ -1211,6 +1218,17 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
match(fromsym, optim_symbols))
return 0;

+ /* Check for pattern 6 */
+ if (elf->hdr->e_machine == EM_PPC64)
+ if (match(tosec, init_sections) &&
+ (!strncmp(fromsym, "__boot_from_prom",
+ strlen("__boot_from_prom")) ||
+ !strncmp(fromsym, "start_here_common",
+ strlen("start_here_common")) ||
+ !strncmp(fromsym, "start_here_multiplatform",
+ strlen("start_here_multiplatform"))))
+ return 0;
+
return 1;
}

@@ -1551,7 +1569,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
tosym = sym_name(elf, to);

/* check whitelist - we may ignore it */
- if (secref_whitelist(mismatch,
+ if (secref_whitelist(elf, mismatch,
fromsec, fromsym, tosec, tosym)) {
report_sec_mismatch(modname, mismatch,
fromsec, r->r_offset, fromsym,
--
1.8.3.1



2018-04-10 02:55:14

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v3] powerpc/64: Fix section mismatch warnings for early boot symbols

Mauricio Faria de Oliveira <[email protected]> writes:
> Some of the boot code located at the start of kernel text is "init"
> class, in that it only runs at boot time, however marking it as normal
> init code is problematic because that puts it into a different section
> located at the very end of kernel text.
>
> e.g., in case the TOC is not set up, we may not be able to tolerate a
> branch trampoline to reach the init function.
>
> Credits: code and message are based on 2016 patch by Nicholas Piggin,
> and slightly modified so not to rename the powerpc code/symbol names.
>
> Subject: [PATCH] powerpc/64: quieten section mismatch warnings
> From: Nicholas Piggin <npiggin at gmail.com>
> Date: Fri Dec 23 00:14:19 AEDT 2016
>
> This resolves the following section mismatch warnings:
>
> WARNING: vmlinux.o(.text+0x2fa8): Section mismatch in reference from the variable __boot_from_prom to the function .init.text:prom_init()
> The function __boot_from_prom() references
> the function __init prom_init().
> This is often because __boot_from_prom lacks a __init
> annotation or the annotation of prom_init is wrong.
>
> WARNING: vmlinux.o(.text+0x3238): Section mismatch in reference from the variable start_here_multiplatform to the function .init.text:early_setup()
> The function start_here_multiplatform() references
> the function __init early_setup().
> This is often because start_here_multiplatform lacks a __init
> annotation or the annotation of early_setup is wrong.
>
> WARNING: vmlinux.o(.text+0x326c): Section mismatch in reference from the variable start_here_common to the function .init.text:start_kernel()
> The function start_here_common() references
> the function __init start_kernel().
> This is often because start_here_common lacks a __init
> annotation or the annotation of start_kernel is wrong.

Thanks for picking this one up.

I hate to be a pain ... but before we merge this and proliferate these
names, I'd like to change the names of some of these early asm
functions. They're terribly named due to historical reasons.

I haven't actually thought of good names yet though :)

I'll try and come up with some and post a patch doing the renames.

cheers

Subject: Re: [PATCH v3] powerpc/64: Fix section mismatch warnings for early boot symbols

On 04/09/2018 11:51 PM, Michael Ellerman wrote:
> Thanks for picking this one up.
>
> I hate to be a pain ... but before we merge this and proliferate these
> names, I'd like to change the names of some of these early asm
> functions. They're terribly named due to historical reasons.

Indeed :) No worries.

> I haven't actually thought of good names yet though:)
>
> I'll try and come up with some and post a patch doing the renames.

Alright. Could you please copy me on that, and I can post an update.

cheers,
Mauricio