Skip to content

Commit 78f3cdf

Browse files
committed
xtensa: Fix linker script to include .literal sections
Fix resembles implementation from Marc Gauthier and Piet Denaly: In the Xtensa architecture, assembly generates literals which must always precede the code (the L32R instruction that loads them only uses negative PC-relative offsets). For any *.text section, literals are placed in a corresponding *.literal section. The linker script (vmlinux.lds) must place these in the correct order. It must also combine them, when the *.text section can be larger than L32R's 256 kB range. For example, this doesn't work: *(.literal) *(.text) because L32R instructions at the end of .text can't reach the literals. The linker can solve this if they are combined in parentheses, like this: *(.literal .text) because it is now allowed mix literals in .text to bring them in range. None of this is done by standard vmlinux.lds.h macros such as TEXT_TEXT and INIT_TEXT. To avoid replicating the logic of that header file, we instead post-process the generated linker script to convert *(xxx.text) to *(xxx.literal xxx.text) for the following text sections: .text .ref.text .*init.text .*exit.text .text.* using a sed script. To do this we must override the default rule for vmlinux.lds (see scripts/Makefile.build and the top-level Makefile) to insert this extra step. Signed-off-by: Marc Gauthier <marc@tensilica.com> Signed-off-by: Pete Delaney <piet@tensilica.com> Signed-off-by: Chris Zankel <chris@zankel.net>
1 parent 866e514 commit 78f3cdf

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎arch/xtensa/kernel/Makefile‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44

55
extra-y := head.o vmlinux.lds
66

7-
87
obj-y := align.o entry.o irq.o coprocessor.o process.o ptrace.o \
98
setup.o signal.o syscall.o time.o traps.o vectors.o platform.o \
109
pci-dma.o init_task.o io.o
1110

12-
## windowspill.o
13-
1411
obj-$(CONFIG_KGDB) += xtensa-stub.o
1512
obj-$(CONFIG_PCI) += pci.o
1613
obj-$(CONFIG_MODULES) += xtensa_ksyms.o module.o
1714

15+
# In the Xtensa architecture, assembly generates literals which must always
16+
# precede the L32R instruction with a relative offset less than 256 kB.
17+
# Therefore, the .text and .literal section must be combined in parenthesis
18+
# in the linker script, such as: *(.literal .text).
19+
#
20+
# We need to post-process the generated vmlinux.lds scripts to convert
21+
# *(xxx.text) to *(xxx.literal xxx.text) for the following text sections:
22+
# .text .ref.text .*init.text .*exit.text .text.*
23+
#
24+
# Replicate rules in scripts/Makefile.build
25+
26+
sed-y = -e 's/(\(\.[a-z]*it\|\.ref\|\)\.text)/(\1.literal \1.text)/g' \
27+
-e 's/(\(\.text\.[a-z]*\))/(\1.literal \1)/g'
28+
29+
quiet_cmd__cpp_lds_S = LDS $@
30+
cmd__cpp_lds_S = $(CPP) $(cpp_flags) -D__ASSEMBLY__ $< | sed $(sed-y) >$@
1831

32+
$(obj)/vmlinux.lds: $(src)/vmlinux.lds.S FORCE
33+
$(call if_changed_dep,_cpp_lds_S)

‎arch/xtensa/kernel/vmlinux.lds.S‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SECTIONS
8787
{
8888
/* The HEAD_TEXT section must be the first section! */
8989
HEAD_TEXT
90-
*(.literal .text)
90+
TEXT_TEXT
9191
VMLINUX_SYMBOL(__sched_text_start) = .;
9292
*(.sched.literal .sched.text)
9393
VMLINUX_SYMBOL(__sched_text_end) = .;
@@ -139,8 +139,6 @@ SECTIONS
139139
__init_begin = .;
140140
.init.text : {
141141
_sinittext = .;
142-
*(.init.literal) *(.cpuinit.literal)
143-
*(.devinit.literal) *(.meminit.literal)
144142
INIT_TEXT
145143
_einittext = .;
146144
}

0 commit comments

Comments
 (0)