WSL2-Linux-Kernel/arch/arm/kernel
Russell King 6760b10960 ARM: fix vmlinux.lds.S discarding sections
We are seeing linker errors caused by sections being discarded, despite
the linker script trying to keep them.  The result is (eg):

`.exit.text' referenced in section `.alt.smp.init' of drivers/built-in.o: defined in discarded section `.exit.text' of drivers/built-in.o
`.exit.text' referenced in section `.alt.smp.init' of net/built-in.o: defined in discarded section `.exit.text' of net/built-in.o

This is the relevent part of the linker script (reformatted to make it
clearer):
| SECTIONS
| {
| /*
| * unwind exit sections must be discarded before the rest of the
| * unwind sections get included.
| */
| /DISCARD/ : {
| *(.ARM.exidx.exit.text)
| *(.ARM.extab.exit.text)
| }
| ...
| .exit.text : {
| *(.exit.text)
| *(.memexit.text)
| }
| ...
| /DISCARD/ : {
| *(.exit.text)
| *(.memexit.text)
| *(.exit.data)
| *(.memexit.data)
| *(.memexit.rodata)
| *(.exitcall.exit)
| *(.discard)
| *(.discard.*)
| }
| }

Now, this is what the linker manual says about discarded output sections:

|    The special output section name `/DISCARD/' may be used to discard
| input sections.  Any input sections which are assigned to an output
| section named `/DISCARD/' are not included in the output file.

No questions, no exceptions. It doesn't say "unless they are listed
before the /DISCARD/ section." Now, this is what asn-generic/vmlinux.lds.S
says:
| /*
|  * Default discarded sections.
|  *
|  * Some archs want to discard exit text/data at runtime rather than
|  * link time due to cross-section references such as alt instructions,
|  * bug table, eh_frame, etc. DISCARDS must be the last of output
|  * section definitions so that such archs put those in earlier section
|  * definitions.
|  */

And guess what - the list _always_ includes .exit.text etc.

Now, what's actually happening is that the linker is reading the script,
and it finds the first /DISCARD/ output section at the beginning of the
script. It continues reading the script, and finds the 'DISCARD' macro
at the end, which having been postprocessed results in another
/DISCARD/ output section. As the linker already contains the earlier
/DISCARD/ output section, it adds it to that existing section, so it
effectively is placed at the start. This can be seen by using the -M
option to ld:

| Linker script and memory map
|
|                 0xc037c080                jiffies = jiffies_64
|
| /DISCARD/
|  *(.ARM.exidx.exit.text)
|  *(.ARM.extab.exit.text)
|  *(.exit.text)
|  *(.memexit.text)
|  *(.exit.data)
|  *(.memexit.data)
|  *(.memexit.rodata)
|  *(.exitcall.exit)
|  *(.discard)
|  *(.discard.*)
|
|                 0xc0008000                . = 0xc0008000
|
| .head.text      0xc0008000      0x1d0
|                 0xc0008000                _text = .
|  *(.head.text)
|  .head.text     0xc0008000      0x1d0 arch/arm/kernel/head.o
|                 0xc0008000                stext
|
| .text           0xc0008200   0x2d78d0
|                 0xc0008200                _stext = .
|                 0xc0008200                __exception_text_start = .
|  *(.exception.text)
|  .exception.text
| ...

As you can see, all the discarded sections are grouped together - and
as a result of it being the first output section, they all appear before
any other section.

The result is that not only is the unwind information discarded (as
intended), but also the .exit.text, despite us wanting to have the
.exit.text preserved.

We can't move the unwind information elsewhere, because it'll then be
included even when we do actually discard the .exit.text (and similar)
sections.

So, work around this by avoiding the generic DISCARDS macro, and instead
conditionalize the sections to be discarded ourselves.  This avoids the
ambiguity in how the linker assigns input sections to output sections,
making our script less dependent on undocumented linker behaviour.

Reported-by: Rob Herring <robherring2@gmail.com>
Tested-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-09-20 23:42:31 +01:00
..
.gitignore
Makefile
armksyms.c arm: remove stale export of 'sha_transform' 2011-08-07 15:49:11 -07:00
arthur.c
asm-offsets.c
atags.c
atags.h
bios32.c
calls.S All Arch: remove linkage for sys_nfsservctl system call 2011-08-26 15:09:58 -07:00
compat.c
compat.h
crash_dump.c
crunch-bits.S
crunch.c
debug.S
devtree.c
dma-isa.c
dma.c
early_printk.c
ecard.c
ecard.h
elf.c
entry-armv.S
entry-common.S
entry-header.S
etm.c
fiq.c
fiqasm.S
ftrace.c
head-common.S
head-nommu.S
head.S
hw_breakpoint.c
init_task.c
io.c
irq.c
isa.c
iwmmxt.S ARM: pxa: fix logic error in PJ4 iWMMXt handling 2011-08-11 10:10:26 +08:00
kgdb.c
kprobes-arm.c
kprobes-common.c
kprobes-thumb.c
kprobes.c
kprobes.h
leds.c
machine_kexec.c
module.c ARM: Fix build error for SMP=n builds 2011-08-04 08:24:29 +01:00
perf_event.c
perf_event_v6.c
perf_event_v7.c
perf_event_xscale.c
pj4-cp0.c
pmu.c ARM: perf: make name of arm_pmu_type consistent 2011-08-12 15:40:21 +01:00
process.c cpuidle: Consistent spelling of cpuidle_idle_call() 2011-08-04 16:35:34 -10:00
ptrace.c
relocate_kernel.S ARM: 7065/1: kexec: ensure new kernel is entered in ARM state 2011-08-28 10:39:41 +01:00
return_address.c
sched_clock.c
setup.c ARM: cache: detect VIPT aliasing I-cache on ARMv6 2011-08-12 15:41:15 +01:00
signal.c
signal.h
sleep.S
smp.c
smp_scu.c ARM: 7091/1: errata: D-cache line maintenance operation by MVA may not succeed 2011-09-17 12:47:17 +01:00
smp_tlb.c
smp_twd.c ARM: twd: register clockevents device before enabling PPI 2011-08-12 15:41:08 +01:00
stacktrace.c
swp_emulate.c
sys_arm.c
sys_oabi-compat.c
tcm.c
tcm.h
thumbee.c
time.c
traps.c
unwind.c
vmlinux.lds.S ARM: fix vmlinux.lds.S discarding sections 2011-09-20 23:42:31 +01:00
xscale-cp0.c