Skip to contentSkip to conversation

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

DISCUSSION Chan Kim 2 participants 3 messages Jan 23, 2022

lore
Share & tools
lore

Chan Kim

author
#0 lore raw

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

_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

#1 lore raw
Quoted 9 lines · Chan Kim

Hello all,

In linux 5.4.21 source code, I put

#pragma GCC push_options

#pragma GCC optimize ("O0")

Do not do that. Bad things will happen, the kernel really does not like this at all.

Why do you want to build the kernel with "O0"? What problem are you trying to solve that you think this will resolve it?

Also, 5.4.21 is very old and obsolete and known insecure. Please use a more modern kernel version.

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

author
#2 lore raw
In reply to Chan Kim

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 <[email protected]>
Sent: Sunday, January 23, 2022 7:48 PM
To: [email protected]
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

_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies