OSDN Git Service

RISC-V: Align the .init.text section
authorAtish Patra <atish.patra@wdc.com>
Thu, 5 Nov 2020 00:04:37 +0000 (16:04 -0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Thu, 26 Nov 2020 00:05:27 +0000 (16:05 -0800)
commitb6566dc1acca38ce6ed845ce8a270fb181ff6d41
tree409d381e5841771953f6d9626204026ce8e16557
parent62149f3564c5a59cb42834cbe97e6f36ad81a029
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.
https://github.com/riscv/riscv-gnu-toolchain/issues/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 <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/kernel/vmlinux.lds.S