Skip to content

Commit f8f02ca

Browse files
committed
xtensa: build kernel with text-section-literals
vmlinux.lds.S doesn't do anything special with literals, so instead of keeping them separate put them into the corresponding text sections. Drop explicit .literal sections from the vmlinux.lds.S, use standard section macros. Mark literal pool locations in the assembly sources. Unfortunately assembler doesn't put literals into .init sections and external libgcc may still have .literal sections, so sed transformation to the linker script is still needed. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
1 parent 7bf5234 commit f8f02ca

8 files changed

Lines changed: 52 additions & 88 deletions

File tree

‎arch/xtensa/Makefile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export PLATFORM
4242

4343
# temporarily until string.h is fixed
4444
KBUILD_CFLAGS += -ffreestanding -D__linux__
45-
46-
KBUILD_CFLAGS += -pipe -mlongcalls
47-
45+
KBUILD_CFLAGS += -pipe -mlongcalls -mtext-section-literals
4846
KBUILD_CFLAGS += $(call cc-option,-mforce-no-pic,)
4947
KBUILD_CFLAGS += $(call cc-option,-mno-serialize-volatile,)
5048

49+
KBUILD_AFLAGS += -mlongcalls -mtext-section-literals
50+
5151
ifneq ($(CONFIG_LD_NO_RELAX),)
5252
LDFLAGS := --no-relax
5353
endif

‎arch/xtensa/boot/boot-redboot/bootstrap.S‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ __start_a0:
4242
.align 4
4343

4444
.section .text, "ax"
45+
.literal_position
4546
.begin literal_prefix .text
4647

4748
/* put literals in here! */

‎arch/xtensa/kernel/Makefile‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ obj-$(CONFIG_XTENSA_VARIANT_HAVE_PERF_EVENTS) += perf_event.o
1717
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
1818
obj-$(CONFIG_S32C1I_SELFTEST) += s32c1i_selftest.o
1919

20-
AFLAGS_head.o += -mtext-section-literals
21-
AFLAGS_mxhead.o += -mtext-section-literals
22-
2320
# In the Xtensa architecture, assembly generates literals which must always
2421
# precede the L32R instruction with a relative offset less than 256 kB.
2522
# Therefore, the .text and .literal section must be combined in parenthesis

‎arch/xtensa/kernel/align.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
* < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
156156
*/
157157

158-
158+
.literal_position
159159
ENTRY(fast_unaligned)
160160

161161
/* Note: We don't expect the address to be aligned on a word

‎arch/xtensa/kernel/entry.S‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
*
126126
* Note: _user_exception might be at an odd address. Don't use call0..call12
127127
*/
128+
.literal_position
128129

129130
ENTRY(user_exception)
130131

@@ -777,6 +778,8 @@ ENDPROC(kernel_exception)
777778
* When we get here, a0 is trashed and saved to excsave[debuglevel]
778779
*/
779780

781+
.literal_position
782+
780783
ENTRY(debug_exception)
781784

782785
rsr a0, SREG_EPS + XCHAL_DEBUGLEVEL
@@ -916,6 +919,8 @@ ENDPROC(debug_exception)
916919
unrecoverable_text:
917920
.ascii "Unrecoverable error in exception handler\0"
918921

922+
.literal_position
923+
919924
ENTRY(unrecoverable_exception)
920925

921926
movi a0, 1
@@ -1117,6 +1122,8 @@ ENDPROC(fast_syscall_unrecoverable)
11171122
* j done
11181123
*/
11191124

1125+
.literal_position
1126+
11201127
#ifdef CONFIG_FAST_SYSCALL_XTENSA
11211128

11221129
#define TRY \
@@ -1887,6 +1894,7 @@ ENDPROC(fast_store_prohibited)
18871894
* void system_call (struct pt_regs* regs, int exccause)
18881895
* a2 a3
18891896
*/
1897+
.literal_position
18901898

18911899
ENTRY(system_call)
18921900

‎arch/xtensa/kernel/setup.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ extern char _end[];
277277
extern char _stext[];
278278
extern char _WindowVectors_text_start;
279279
extern char _WindowVectors_text_end;
280-
extern char _DebugInterruptVector_literal_start;
280+
extern char _DebugInterruptVector_text_start;
281281
extern char _DebugInterruptVector_text_end;
282-
extern char _KernelExceptionVector_literal_start;
282+
extern char _KernelExceptionVector_text_start;
283283
extern char _KernelExceptionVector_text_end;
284-
extern char _UserExceptionVector_literal_start;
284+
extern char _UserExceptionVector_text_start;
285285
extern char _UserExceptionVector_text_end;
286-
extern char _DoubleExceptionVector_literal_start;
286+
extern char _DoubleExceptionVector_text_start;
287287
extern char _DoubleExceptionVector_text_end;
288288
#if XCHAL_EXCM_LEVEL >= 2
289289
extern char _Level2InterruptVector_text_start;
@@ -339,16 +339,16 @@ void __init setup_arch(char **cmdline_p)
339339
mem_reserve(__pa(&_WindowVectors_text_start),
340340
__pa(&_WindowVectors_text_end));
341341

342-
mem_reserve(__pa(&_DebugInterruptVector_literal_start),
342+
mem_reserve(__pa(&_DebugInterruptVector_text_start),
343343
__pa(&_DebugInterruptVector_text_end));
344344

345-
mem_reserve(__pa(&_KernelExceptionVector_literal_start),
345+
mem_reserve(__pa(&_KernelExceptionVector_text_start),
346346
__pa(&_KernelExceptionVector_text_end));
347347

348-
mem_reserve(__pa(&_UserExceptionVector_literal_start),
348+
mem_reserve(__pa(&_UserExceptionVector_text_start),
349349
__pa(&_UserExceptionVector_text_end));
350350

351-
mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
351+
mem_reserve(__pa(&_DoubleExceptionVector_text_start),
352352
__pa(&_DoubleExceptionVector_text_end));
353353

354354
#if XCHAL_EXCM_LEVEL >= 2

‎arch/xtensa/kernel/vectors.S‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ ENDPROC(_KernelExceptionVector)
205205
*/
206206

207207
.section .DoubleExceptionVector.text, "ax"
208-
.begin literal_prefix .DoubleExceptionVector
209-
.globl _DoubleExceptionVector_WindowUnderflow
210-
.globl _DoubleExceptionVector_WindowOverflow
211208

212209
ENTRY(_DoubleExceptionVector)
213210

@@ -217,8 +214,12 @@ ENTRY(_DoubleExceptionVector)
217214
/* Check for kernel double exception (usually fatal). */
218215

219216
rsr a2, ps
220-
_bbci.l a2, PS_UM_BIT, .Lksp
217+
_bbsi.l a2, PS_UM_BIT, 1f
218+
j .Lksp
221219

220+
.align 4
221+
.literal_position
222+
1:
222223
/* Check if we are currently handling a window exception. */
223224
/* Note: We don't need to indicate that we enter a critical section. */
224225

@@ -475,11 +476,8 @@ _DoubleExceptionVector_handle_exception:
475476
rotw -3
476477
j 1b
477478

478-
479479
ENDPROC(_DoubleExceptionVector)
480480

481-
.end literal_prefix
482-
483481
.text
484482
/*
485483
* Fixup handler for TLB miss in double exception handler for window owerflow.
@@ -508,6 +506,8 @@ ENDPROC(_DoubleExceptionVector)
508506
* a3: exctable, original value in excsave1
509507
*/
510508

509+
.literal_position
510+
511511
ENTRY(window_overflow_restore_a0_fixup)
512512

513513
rsr a0, ps

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

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,16 @@ jiffies = jiffies_64;
4545
LONG(sym ## _end); \
4646
LONG(LOADADDR(section))
4747

48-
/* Macro to define a section for a vector.
49-
*
50-
* Use of the MIN function catches the types of errors illustrated in
51-
* the following example:
52-
*
53-
* Assume the section .DoubleExceptionVector.literal is completely
54-
* full. Then a programmer adds code to .DoubleExceptionVector.text
55-
* that produces another literal. The final literal position will
56-
* overlay onto the first word of the adjacent code section
57-
* .DoubleExceptionVector.text. (In practice, the literals will
58-
* overwrite the code, and the first few instructions will be
59-
* garbage.)
48+
/*
49+
* Macro to define a section for a vector. When CONFIG_VECTORS_OFFSET is
50+
* defined code for every vector is located with other init data. At startup
51+
* time head.S copies code for every vector to its final position according
52+
* to description recorded in the corresponding RELOCATE_ENTRY.
6053
*/
6154

6255
#ifdef CONFIG_VECTORS_OFFSET
63-
#define SECTION_VECTOR(sym, section, addr, max_prevsec_size, prevsec) \
64-
section addr : AT((MIN(LOADADDR(prevsec) + max_prevsec_size, \
65-
LOADADDR(prevsec) + SIZEOF(prevsec)) + 3) & ~ 3) \
56+
#define SECTION_VECTOR(sym, section, addr, prevsec) \
57+
section addr : AT(((LOADADDR(prevsec) + SIZEOF(prevsec)) + 3) & ~ 3) \
6658
{ \
6759
. = ALIGN(4); \
6860
sym ## _start = ABSOLUTE(.); \
@@ -112,26 +104,19 @@ SECTIONS
112104
#if XCHAL_EXCM_LEVEL >= 6
113105
SECTION_VECTOR (.Level6InterruptVector.text, INTLEVEL6_VECTOR_VADDR)
114106
#endif
115-
SECTION_VECTOR (.DebugInterruptVector.literal, DEBUG_VECTOR_VADDR - 4)
116107
SECTION_VECTOR (.DebugInterruptVector.text, DEBUG_VECTOR_VADDR)
117-
SECTION_VECTOR (.KernelExceptionVector.literal, KERNEL_VECTOR_VADDR - 4)
118108
SECTION_VECTOR (.KernelExceptionVector.text, KERNEL_VECTOR_VADDR)
119-
SECTION_VECTOR (.UserExceptionVector.literal, USER_VECTOR_VADDR - 4)
120109
SECTION_VECTOR (.UserExceptionVector.text, USER_VECTOR_VADDR)
121-
SECTION_VECTOR (.DoubleExceptionVector.literal, DOUBLEEXC_VECTOR_VADDR - 20)
122110
SECTION_VECTOR (.DoubleExceptionVector.text, DOUBLEEXC_VECTOR_VADDR)
123111
#endif
124112

113+
IRQENTRY_TEXT
114+
SOFTIRQENTRY_TEXT
115+
ENTRY_TEXT
125116
TEXT_TEXT
126-
VMLINUX_SYMBOL(__sched_text_start) = .;
127-
*(.sched.literal .sched.text)
128-
VMLINUX_SYMBOL(__sched_text_end) = .;
129-
VMLINUX_SYMBOL(__cpuidle_text_start) = .;
130-
*(.cpuidle.literal .cpuidle.text)
131-
VMLINUX_SYMBOL(__cpuidle_text_end) = .;
132-
VMLINUX_SYMBOL(__lock_text_start) = .;
133-
*(.spinlock.literal .spinlock.text)
134-
VMLINUX_SYMBOL(__lock_text_end) = .;
117+
SCHED_TEXT
118+
CPUIDLE_TEXT
119+
LOCK_TEXT
135120

136121
}
137122
_etext = .;
@@ -196,8 +181,6 @@ SECTIONS
196181
.KernelExceptionVector.text);
197182
RELOCATE_ENTRY(_UserExceptionVector_text,
198183
.UserExceptionVector.text);
199-
RELOCATE_ENTRY(_DoubleExceptionVector_literal,
200-
.DoubleExceptionVector.literal);
201184
RELOCATE_ENTRY(_DoubleExceptionVector_text,
202185
.DoubleExceptionVector.text);
203186
RELOCATE_ENTRY(_DebugInterruptVector_text,
@@ -230,90 +213,67 @@ SECTIONS
230213

231214
SECTION_VECTOR (_WindowVectors_text,
232215
.WindowVectors.text,
233-
WINDOW_VECTORS_VADDR, 4,
216+
WINDOW_VECTORS_VADDR,
234217
.dummy)
235-
SECTION_VECTOR (_DebugInterruptVector_literal,
236-
.DebugInterruptVector.literal,
237-
DEBUG_VECTOR_VADDR - 4,
238-
SIZEOF(.WindowVectors.text),
239-
.WindowVectors.text)
240218
SECTION_VECTOR (_DebugInterruptVector_text,
241219
.DebugInterruptVector.text,
242220
DEBUG_VECTOR_VADDR,
243-
4,
244-
.DebugInterruptVector.literal)
221+
.WindowVectors.text)
245222
#undef LAST
246223
#define LAST .DebugInterruptVector.text
247224
#if XCHAL_EXCM_LEVEL >= 2
248225
SECTION_VECTOR (_Level2InterruptVector_text,
249226
.Level2InterruptVector.text,
250227
INTLEVEL2_VECTOR_VADDR,
251-
SIZEOF(LAST), LAST)
228+
LAST)
252229
# undef LAST
253230
# define LAST .Level2InterruptVector.text
254231
#endif
255232
#if XCHAL_EXCM_LEVEL >= 3
256233
SECTION_VECTOR (_Level3InterruptVector_text,
257234
.Level3InterruptVector.text,
258235
INTLEVEL3_VECTOR_VADDR,
259-
SIZEOF(LAST), LAST)
236+
LAST)
260237
# undef LAST
261238
# define LAST .Level3InterruptVector.text
262239
#endif
263240
#if XCHAL_EXCM_LEVEL >= 4
264241
SECTION_VECTOR (_Level4InterruptVector_text,
265242
.Level4InterruptVector.text,
266243
INTLEVEL4_VECTOR_VADDR,
267-
SIZEOF(LAST), LAST)
244+
LAST)
268245
# undef LAST
269246
# define LAST .Level4InterruptVector.text
270247
#endif
271248
#if XCHAL_EXCM_LEVEL >= 5
272249
SECTION_VECTOR (_Level5InterruptVector_text,
273250
.Level5InterruptVector.text,
274251
INTLEVEL5_VECTOR_VADDR,
275-
SIZEOF(LAST), LAST)
252+
LAST)
276253
# undef LAST
277254
# define LAST .Level5InterruptVector.text
278255
#endif
279256
#if XCHAL_EXCM_LEVEL >= 6
280257
SECTION_VECTOR (_Level6InterruptVector_text,
281258
.Level6InterruptVector.text,
282259
INTLEVEL6_VECTOR_VADDR,
283-
SIZEOF(LAST), LAST)
260+
LAST)
284261
# undef LAST
285262
# define LAST .Level6InterruptVector.text
286263
#endif
287-
SECTION_VECTOR (_KernelExceptionVector_literal,
288-
.KernelExceptionVector.literal,
289-
KERNEL_VECTOR_VADDR - 4,
290-
SIZEOF(LAST), LAST)
291-
#undef LAST
292264
SECTION_VECTOR (_KernelExceptionVector_text,
293265
.KernelExceptionVector.text,
294266
KERNEL_VECTOR_VADDR,
295-
4,
296-
.KernelExceptionVector.literal)
297-
SECTION_VECTOR (_UserExceptionVector_literal,
298-
.UserExceptionVector.literal,
299-
USER_VECTOR_VADDR - 4,
300-
SIZEOF(.KernelExceptionVector.text),
301-
.KernelExceptionVector.text)
267+
LAST)
268+
#undef LAST
302269
SECTION_VECTOR (_UserExceptionVector_text,
303270
.UserExceptionVector.text,
304271
USER_VECTOR_VADDR,
305-
4,
306-
.UserExceptionVector.literal)
307-
SECTION_VECTOR (_DoubleExceptionVector_literal,
308-
.DoubleExceptionVector.literal,
309-
DOUBLEEXC_VECTOR_VADDR - 20,
310-
SIZEOF(.UserExceptionVector.text),
311-
.UserExceptionVector.text)
272+
.KernelExceptionVector.text)
312273
SECTION_VECTOR (_DoubleExceptionVector_text,
313274
.DoubleExceptionVector.text,
314275
DOUBLEEXC_VECTOR_VADDR,
315-
20,
316-
.DoubleExceptionVector.literal)
276+
.UserExceptionVector.text)
317277

318278
. = (LOADADDR( .DoubleExceptionVector.text ) + SIZEOF( .DoubleExceptionVector.text ) + 3) & ~ 3;
319279

@@ -323,7 +283,6 @@ SECTIONS
323283
SECTION_VECTOR (_SecondaryResetVector_text,
324284
.SecondaryResetVector.text,
325285
RESET_VECTOR1_VADDR,
326-
SIZEOF(.DoubleExceptionVector.text),
327286
.DoubleExceptionVector.text)
328287

329288
. = LOADADDR(.SecondaryResetVector.text)+SIZEOF(.SecondaryResetVector.text);
@@ -373,5 +332,4 @@ SECTIONS
373332

374333
/* Sections to be discarded */
375334
DISCARDS
376-
/DISCARD/ : { *(.exit.literal) }
377335
}

0 commit comments

Comments
 (0)