Skip to content

Commit b6566dc

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Align the .init.text section
In order to improve kernel text protection, we need separate .init.text/ .init.data/.text in separate sections. However, RISC-V linker relaxation code is not aware of any alignment between sections. As a result, it may relax any RISCV_CALL relocations between sections to JAL without realizing that an inter section alignment may move the address farther. That may lead to a relocation truncated fit error. However, linker relaxation code is aware of the individual section alignments. The detailed discussion on this issue can be found here. riscv-collab/riscv-gnu-toolchain#738 Keep the .init.text section aligned so that linker relaxation will take that as a hint while relaxing inter section calls. Here are the code size changes for each section because of this change. section change in size (in bytes) .head.text +4 .text +40 .init.text +6530 .exit.text +84 The only significant increase in size happened for .init.text because all intra relocations also use 2MB alignment. Suggested-by: Jim Wilson <[email protected]> Signed-off-by: Atish Patra <[email protected]> Tested-by: Greentime Hu <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 62149f3 commit b6566dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arch/riscv/kernel/vmlinux.lds.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ SECTIONS
3030
. = ALIGN(PAGE_SIZE);
3131

3232
__init_begin = .;
33-
INIT_TEXT_SECTION(PAGE_SIZE)
33+
__init_text_begin = .;
34+
.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \
35+
_sinittext = .; \
36+
INIT_TEXT \
37+
_einittext = .; \
38+
}
39+
3440
. = ALIGN(8);
3541
__soc_early_init_table : {
3642
__soc_early_init_table_start = .;

0 commit comments

Comments
 (0)