Re: [PATCH v2] scripts: Do not strip .rela.dyn section

From: Alexandre Ghiti
Date: Mon Apr 07 2025 - 04:43:09 EST



On 07/04/2025 10:15, Alexandre Ghiti wrote:
Hi Masahiro,

On Fri, Apr 4, 2025 at 5:25 PM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
On Fri, Apr 4, 2025 at 12:45 AM Alexandre Ghiti <alex@xxxxxxxx> wrote:
Hi Ard,

On 03/04/2025 17:11, Ard Biesheuvel wrote:
On Thu, 3 Apr 2025 at 16:42, Alexandre Ghiti <alexghiti@xxxxxxxxxxxx> wrote:
riscv uses the .rela.dyn section to relocate the kernel at runtime but
that section is stripped from vmlinux. That prevents kexec to
successfully load vmlinux since it does not contain the relocations info
needed.

Maybe explain that .rela.dyn contains runtime relocations, which are
only emitted if they are actually needed - as opposed to the static
relocations that are not emitted as SHF_ALLOC sections, and are not
considered to be part of the runtime image in the first place.

Ok I'll do.


It
would be nice if we could use --remove-relocations= here, which only
removes static relocations, but unfortunately, llvm-objcopy does not
support this.

Also, I wonder if this should apply to all of .rel.dyn, .rela.dyn and
.relr.dyn, as they all carry runtime relocations.

Ok, I'll add them to the next version.


Finally, I'd be curious to know why RISC-V relies on --emit-relocs in
the first place? Is the relocs check really needed? If not, it would
be a nice opportunity to get rid of Makefile.postlink entirely.

So I had to check and it happens that this was an issue with the
toolchain, I should check if that still happens with newer ones.

commit 559d1e45a16dcf1542e430ea3dce9ab625be98d0
Author: Alexandre Ghiti <alexghiti@xxxxxxxxxxxx>
Date: Wed Mar 29 06:53:29 2023 +0200

riscv: Use --emit-relocs in order to move .rela.dyn in init



So,

Fixes: 559d1e45a16d ("riscv: Use --emit-relocs in order to move
.rela.dyn in init")

Is this the correct tag?
This is the initial culprit yes, but if we use this tag, the fix won't
apply. So I decided to pick Ard's patch so that this fix can be easily
backported to 6.14, and I'll come up with a new version for previous
releases. Is that ok with you?


And I have just looked at 6.15-rc1 and noticed that the relocation stripping was moved to Makefile.vmlinux, so this fix won't apply to 6.14 neither.

I'll then use the initial culprit, which is Fixes: 559d1e45a16d ("riscv: Use --emit-relocs in order to move.rela.dyn in init").

Sorry for the noise,

Alex



Thanks,

Alex





--
Best Regards
Masahiro Yamada
_______________________________________________
linux-riscv mailing list
linux-riscv@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/linux-riscv