[PATCH v4 02/19] riscv: Use _stext not _text to denote the start of kernel code

Palmer Dabbelt palmer at dabbelt.com
Mon Nov 23 15:10:02 PST 2026


On Wed, 18 Nov 2026 10:21:08 PST (-0800), ardb+git at google.com wrote:
> From: Ard Biesheuvel <ardb at kernel.org>
>
> On RISC-V, _text and _stext currently refer to the same location, i.e.,
> the start of the .text output section, which follows the image header
> (.head.text) emitted by HEAD_TEXT_SECTION. _start is the symbol that
> refers to the actual start of the image.
>
> On other architectures such as arm64, _text refers to the start of the
> image, and _stext to the start of the kernel code, and generic code
> (such as the EFI stub) may start relying on this distinction.
>
> So switch the only user of _text in arch/riscv, i.e., the "Kernel code"
> resource that is exposed via /proc/iomem (and from which the "Kernel
> image" resource inherits its start address), over to _stext. This is a
> no-op given that both symbols currently resolve to the same address, but
> it permits _text to be moved to the start of the image, making it an
> alias of _start.
>
> Reviewed-by: Jason Gunthorpe <jgg at nvidia.com>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  arch/riscv/kernel/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index d79f99b86033..e6112d424fde 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -91,7 +91,7 @@ static int __init add_kernel_resources(void)
>  	 * child nodes.
>  	 */
>
> -	code_res.start = __pa_symbol(_text);
> +	code_res.start = __pa_symbol(_stext);
>  	code_res.end = __pa_symbol(_etext) - 1;
>  	code_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;

Reviewed-by: Palmer Dabbelt <palmer at dabbelt.com>
Acked-by: Palmer Dabbelt <palmer at dabbelt.com>



More information about the linux-riscv mailing list