nuttx/boards/arm/qemu/qemu-armv7a/scripts/dramboot.ld
leisiji 85337c0efc boards/arm/qemu: Fix KASAN global sections placement in linker script
1. The .kasan.unused and .kasan.global sections contain compiler-generated
data with the WRITE flag (.data..LASAN*), but the linker script placed
them before .text without specifying a memory region. The linker could
not put writable sections into the read-only ROM (rx) region, so it
silently placed them at 0x40000000 in RAM, creating an extra LOAD
segment that conflicts with QEMU virt's RAM layout and causes boot
failure.
2. The .kasan.global should be placed before .data because .data
patten (*(.data*)) includes .kasan.global pattern (*(.data..LASAN0)),
and it cause kasan_global.py cannot find .kasan.global section to
generate the g_global_region array.
3. Move .kasan.shadows from before .text to after .rodata. Placing it
before .text causes .text to shift when .kasan.shadows transitions
from empty (pass 1) to populated (pass 2+), preventing the multi-pass
link addresses from converging. After .rodata it does not affect any
upstream section addresses.
4. Add CMake post-build step to strip .kasan.unused and .kasan.global
sections from the final binary, matching the Makefile build behavior.

Signed-off-by: leisiji <2265215145@qq.com>
2026-07-03 07:51:11 +02:00

136 lines
3.4 KiB
Text

/****************************************************************************
* boards/arm/qemu/qemu-armv7a/scripts/dramboot.ld
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#include <nuttx/config.h>
OUTPUT_ARCH(arm)
ENTRY(__start)
MEMORY
{
ROM (rx) : ORIGIN = CONFIG_FLASH_START, LENGTH = CONFIG_FLASH_SIZE
RAM (rwx): ORIGIN = CONFIG_RAM_START, LENGTH = CONFIG_RAM_SIZE
}
SECTIONS
{
.text : {
_stext = .; /* Text section */
__text_start = .;
*(.vectors)
*(.text*)
*(.fixup)
*(.gnu.warning)
} > ROM
. = ALIGN(4096);
.init_section : {
_sinit = ABSOLUTE(.);
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors))
_einit = ABSOLUTE(.);
. = ALIGN(4096);
_etext = .; /* End_1 of .text */
_sztext = _etext - _stext;
} > ROM
.ARM.extab :
{
*(.ARM.extab*)
} > ROM
/* .ARM.exidx is sorted, so has to go in its own output section. */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > ROM
PROVIDE_HIDDEN (__exidx_end = .);
.rodata : {
_srodata = .; /* Read-only data */
*(.rodata*)
*(.data.rel.ro*)
KEEP(*(SORT(.scattered_array*)));
. = ALIGN(4096);
_erodata = .;
} > ROM
#ifdef CONFIG_MM_KASAN_GLOBAL
.kasan.shadows : {
KEEP(*(.kasan.shadows))
} > ROM
.kasan.unused : {
*(.data..LASANLOC*)
} > RAM
.kasan.global : {
KEEP (*(.data..LASAN0))
KEEP (*(.data.rel.local..LASAN0))
} > RAM
#endif
_eronly = LOADADDR(.data);
.data : { /* Data */
_sdata = .;
*(.data*)
. = ALIGN(8);
__start_impls = .;
*(.impls)
KEEP(*(.impls))
. = ALIGN(4);
__stop_impls = .;
_edata = .;
} > RAM AT > ROM
.noinit : {
_snoinit = ABSOLUTE(.);
*(.noinit*)
_enoinit = ABSOLUTE(.);
} > RAM
.bss : { /* BSS */
_sbss = .;
*(.bss*)
. = ALIGN(4096);
_ebss = .;
} > RAM
/* Sections to be discarded */
/DISCARD/ : {
*(.exit.text)
*(.exit.data)
*(.exitcall.exit)
}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
}