how to fix section mismatch warning after inserting #pragma GCC optimize ?

Chan Kim ckim at etri.re.kr
Sun Jan 23 06:42:23 EST 2022


I found adding __init to gic_smp_init() removed this warning message.

Is it ok to move this function to .init.text ? (doesn't it cause it to be
removed after initialization?)

Chan

 

From: Chan Kim <ckim at etri.re.kr> 
Sent: Sunday, January 23, 2022 7:48 PM
To: kernelnewbies at kernelnewbies.org
Subject: how to fix section mismatch warning after inserting #pragma GCC
optimize ?

 

Hello all,

 

In linux 5.4.21 source code, I put

    #pragma GCC push_options

    #pragma GCC optimize ("O0")

and

    #pragma GCC pop_options

around function static int __init gic_init_bases in file
drivers/irqchip/irq-gic-v3.c.  

When I build it, I get this warning message (section mismatch). 

( I later found it is actually the "#pragma GCC optimize ("O0")" line that
is causing it.)  

 

      CALL    scripts/atomic/check-atomics.sh

      CALL    scripts/checksyscalls.sh

      CHK     include/generated/compile.h

      CC      arch/arm64/kernel/irq.o

      CC      arch/arm64/kernel/setup.o

      CC      drivers/irqchip/irq-gic-v3.o

      AS      arch/arm64/kernel/head.o

      AR      arch/arm64/kernel/built-in.a

      AR      arch/arm64/built-in.a

      AR      drivers/irqchip/built-in.a

      AR      drivers/built-in.a

      GEN     .version

      CHK     include/generated/compile.h

      UPD     include/generated/compile.h

      CC      init/version.o

      AR      init/built-in.a

      LD      vmlinux.o

      MODPOST vmlinux.o

    WARNING: vmlinux.o(.text+0x227cc0): Section mismatch in reference from
the function gic_smp_init() to the function .init.text:set_smp_cross_call()

    The function gic_smp_init() references

    the function __init set_smp_cross_call().

    This is often because gic_smp_init lacks a __init 

    annotation or the annotation of set_smp_cross_call is wrong.

    

      MODINFO modules.builtin.modinfo

      LD      .tmp_vmlinux1

      KSYM    .tmp_kallsyms1.o

      LD      .tmp_vmlinux2

      KSYM    .tmp_kallsyms2.o

      LD      vmlinux

      SORTEX  vmlinux

      SYSMAP  System.map

      OBJCOPY arch/arm64/boot/Image

 

Function call is like this : gic_init_bases -> gic_smp_init() ->
set_smp_cross_call. (currently CONFIG_SMP=y). 

The message seems to say set_smp_cross_call is annotated with __init
(meaning it is placed in .init.text) but gic_smp_init is not. 

But without the #pragma debug setting, there was not warning of this kind. 

I'm not sure if I can just add add __init to gic_smp_init(). (or remove
_init from set_smp_cross_call )

What is the correct method to fix it?

Thanks,

Chan Kim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20220123/2abf8a8d/attachment-0001.html>


More information about the Kernelnewbies mailing list