链接文件优化

This commit is contained in:
冯佳
2026-01-29 16:42:27 +08:00
parent 7825d2e38b
commit ffd33c4644
4 changed files with 194 additions and 132 deletions

5
.gitignore vendored
View File

@ -64,5 +64,6 @@ Thumbs.db
# Log files
*.log
build/Debug/.ninja_log
build/Debug/.ninja_deps
build/Debug/*

View File

@ -16,7 +16,7 @@
**
** Target : STMicroelectronics STM32
**
** Distribution: The file is distributed as is, without any warranty
** Distribution: The file is distributed "as is," without any warranty
** of any kind.
**
*****************************************************************************
@ -49,179 +49,186 @@
*****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* ===============================================
STM32F407VET6 链接脚本中文注释说明
=============================================== */
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* 入口点定义 */
ENTRY(Reset_Handler) /* 程序入口点:复位中断处理函数 */
/* Specify the memory areas */
/* 用户模式堆栈的最高地址 */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* 栈顶地址RAM 结束地址 */
/* 如果堆和栈无法放入 RAM将生成链接错误 */
_Min_Heap_Size = 0x200; /* 最小堆大小512 字节 */
_Min_Stack_Size = 0x400; /* 最小栈大小1024 字节 */
/* 内存区域定义 */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K /* 主 RAM128KB可读写地址从 0x20000000 开始 */
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K /* 核心耦合内存64KB可读写地址从 0x10000000 开始 */
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K /* 闪存512KB只读和可执行地址从 0x08000000 开始 */
}
/* Define output sections */
/* 定义输出段 */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
/* 启动代码首先放入 FLASH */
.isr_vector : /* 中断向量表段 */
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
KEEP(*(.isr_vector)) /* 保留中断向量表(启动代码),防止被优化掉 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
/* The program code and other data goes into FLASH */
.text :
/* 程序代码和其他数据放入 FLASH */
.text : /* 代码段 */
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
. = ALIGN(4); /* 4 字节对齐 */
*(.text) /* .text 段(代码) */
*(.text*) /* .text* 段(代码) */
*(.glue_7) /* ARM 到 Thumb 代码的粘合代码 */
*(.glue_7t) /* Thumb 到 ARM 代码的粘合代码 */
*(.eh_frame) /* 异常处理框架 */
KEEP (*(.init))
KEEP (*(.fini))
KEEP (*(.init)) /* 保留初始化代码 */
KEEP (*(.fini)) /* 保留结束代码 */
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
_etext = .; /* 在代码结束处定义全局符号 */
} >FLASH /* 此段放入 FLASH 内存区域 */
/* Constant data goes into FLASH */
.rodata :
/* 常量数据放入 FLASH */
.rodata : /* 只读数据段 */
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
*(.rodata) /* .rodata 段(常量、字符串等) */
*(.rodata*) /* .rodata* 段(常量、字符串等) */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
.ARM.extab : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
/* ARM 异常表扩展段 */
.ARM.extab : /* "READONLY" 关键字仅在 GCC11 及更高版本支持,使用 GCC10 或更早版本时请移除 */
{
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
*(.ARM.extab* .gnu.linkonce.armextab.*) /* ARM 异常表扩展 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
.ARM : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
/* ARM 索引段 */
.ARM : /* "READONLY" 关键字仅在 GCC11 及更高版本支持,使用 GCC10 或更早版本时请移除 */
{
. = ALIGN(4);
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
__exidx_start = .; /* 异常索引开始 */
*(.ARM.exidx*) /* ARM 异常索引 */
__exidx_end = .; /* 异常索引结束 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
.preinit_array : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
/* 预初始化数组段 */
.preinit_array : /* "READONLY" 关键字仅在 GCC11 及更高版本支持,使用 GCC10 或更早版本时请移除 */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
PROVIDE_HIDDEN (__preinit_array_start = .); /* 提供预初始化数组开始的隐藏符号 */
KEEP (*(.preinit_array*)) /* 保留预初始化数组 */
PROVIDE_HIDDEN (__preinit_array_end = .); /* 提供预初始化数组结束的隐藏符号 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
.init_array : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
/* 初始化数组段 */
.init_array : /* "READONLY" 关键字仅在 GCC11 及更高版本支持,使用 GCC10 或更早版本时请移除 */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
PROVIDE_HIDDEN (__init_array_start = .); /* 提供初始化数组开始的隐藏符号 */
KEEP (*(SORT(.init_array.*))) /* 保留排序后的初始化数组 */
KEEP (*(.init_array*)) /* 保留初始化数组 */
PROVIDE_HIDDEN (__init_array_end = .); /* 提供初始化数组结束的隐藏符号 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
.fini_array : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
/* 结束数组段 */
.fini_array : /* "READONLY" 关键字仅在 GCC11 及更高版本支持,使用 GCC10 或更早版本时请移除 */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH
. = ALIGN(4); /* 4 字节对齐 */
PROVIDE_HIDDEN (__fini_array_start = .); /* 提供结束数组开始的隐藏符号 */
KEEP (*(SORT(.fini_array.*))) /* 保留排序后的结束数组 */
KEEP (*(.fini_array*)) /* 保留结束数组 */
PROVIDE_HIDDEN (__fini_array_end = .); /* 提供结束数组结束的隐藏符号 */
. = ALIGN(4); /* 4 字节对齐 */
} >FLASH /* 此段放入 FLASH 内存区域 */
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* 用于启动时初始化数据 */
_sidata = LOADADDR(.data); /* .data 段的加载地址(在 FLASH 中的地址) */
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
/* 初始化数据段放入 RAM加载地址在代码之后 */
.data : /* 初始化数据段 */
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */
. = ALIGN(4); /* 4 字节对齐 */
_sdata = .; /* 在数据开始处创建全局符号 */
*(.data) /* .data */
*(.data*) /* .data* */
*(.RamFunc) /* 要放入 RAM 执行的函数 */
*(.RamFunc*) /* 要放入 RAM 执行的函数 */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
. = ALIGN(4); /* 4 字节对齐 */
_edata = .; /* 在数据结束处定义全局符号 */
} >RAM AT> FLASH /* 此段放入 RAM 内存区域,但加载地址在 FLASH 中 */
_siccmram = LOADADDR(.ccmram);
_siccmram = LOADADDR(.ccmram); /* .ccmram 段的加载地址(在 FLASH 中的地址) */
/* CCM-RAM section
/* CCM-RAM
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
* 重要说明!
* 如果初始化变量将放在此段中,
* 需要修改启动代码以复制初始值。
*/
.ccmram :
.ccmram : /* CCM-RAM 段 */
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
*(.ccmram)
*(.ccmram*)
. = ALIGN(4); /* 4 字节对齐 */
_sccmram = .; /* 在 CCM-RAM 开始处创建全局符号 */
*(.ccmram) /* .ccmram 段 */
*(.ccmram*) /* .ccmram* 段 */
. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCMRAM AT> FLASH
. = ALIGN(4); /* 4 字节对齐 */
_eccmram = .; /* 在 CCM-RAM 结束处创建全局符号 */
} >CCMRAM AT> FLASH /* 此段放入 CCMRAM 内存区域,但加载地址在 FLASH 中 */
/* Uninitialized data section */
. = ALIGN(4);
.bss :
/* 未初始化数据段 */
. = ALIGN(4); /* 4 字节对齐 */
.bss : /* BSS 段(未初始化数据) */
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
/* 启动代码使用此符号初始化 .bss 段 */
_sbss = .; /* 在 BSS 开始处定义全局符号 */
__bss_start__ = _sbss; /* 与 _sbss 相同,兼容不同命名 */
*(.bss) /* .bss 段 */
*(.bss*) /* .bss* 段 */
*(COMMON) /* 公共符号 */
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
. = ALIGN(4); /* 4 字节对齐 */
_ebss = .; /* 在 BSS 结束处定义全局符号 */
__bss_end__ = _ebss; /* 与 _ebss 相同,兼容不同命名 */
} >RAM /* 此段放入 RAM 内存区域 */
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
/* 用户堆和栈段,用于检查是否有足够的 RAM 剩余 */
._user_heap_stack : /* 用户堆和栈段 */
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
. = ALIGN(8); /* 8 字节对齐 */
PROVIDE ( end = . ); /* 提供 end 符号 */
PROVIDE ( _end = . ); /* 提供 _end 符号,与 end 相同 */
. = . + _Min_Heap_Size; /* 分配最小堆大小 */
. = . + _Min_Stack_Size; /* 分配最小栈大小 */
. = ALIGN(8); /* 8 字节对齐 */
} >RAM /* 此段放入 RAM 内存区域 */
/* Remove information from the standard libraries */
/DISCARD/ :
/* 从标准库中移除信息 */
/DISCARD/ : /* 丢弃段 */
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
libc.a ( * ) /* 丢弃标准 C 库的所有信息 */
libm.a ( * ) /* 丢弃标准数学库的所有信息 */
libgcc.a ( * ) /* 丢弃 GCC 库的所有信息 */
}
}
}

Binary file not shown.

View File

@ -112,3 +112,57 @@
1170 1444 7913779857673660 stm32f407vet6_cmake.elf f513187faf41df81
4 25 7913791011232514 CMakeFiles/clean.additional a8e8475892b6c694
26 41 7913791011443325 clean 48fb0083216ba165
21 223 7913792885013096 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4.c.obj ad6d0ca858ff9fd6
40 230 7913792885190960 Modules/delay/CMakeFiles/delay.dir/src/delay.c.obj 26bf75277b3a6f97
7 236 7913792884870757 HAL/CMakeFiles/hal.dir/Src/hal_gpio.c.obj 62b5fd3fc12a56ec
43 242 7913792885236411 Modules/uart/CMakeFiles/uart.dir/src/uart.c.obj 6e3afd2d96cd96f6
52 248 7913792885323579 BSP/CMakeFiles/bsp.dir/Src/bsp_init.c.obj d5eeac43f4ec50ea
58 252 7913792885369682 BSP/CMakeFiles/bsp.dir/Src/stm32f407vet6_board.c.obj f1e5fe9bebf9e02
47 259 7913792885263785 Modules/w25qxx/CMakeFiles/w25qxx.dir/Src/w25qxx.c.obj 822d4b2e91a026bb
16 278 7913792884967698 HAL/CMakeFiles/hal.dir/Src/hal_spi.c.obj 8a7978fd4bbb8138
4 288 7913792884839558 HAL/CMakeFiles/hal.dir/Src/hal.c.obj e4949ba37d831425
11 294 7913792884901389 HAL/CMakeFiles/hal.dir/Src/hal_delay.c.obj f7ed58542e885692
13 325 7913792884932306 HAL/CMakeFiles/hal.dir/Src/hal_uart.c.obj 9539d7c56f2172a5
64 392 7913792885431003 BSP/CMakeFiles/bsp.dir/Src/bsp_board_manager.c.obj 8f418e92fedc44fd
30 406 7913792885098838 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_delay.c.obj d88822697976a923
33 414 7913792885134205 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_spi.c.obj 2876067dae4cbc08
37 418 7913792885160160 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_eth.c.obj 1cb29b3f591666fd
19 452 7913792884982805 HAL/CMakeFiles/hal.dir/Src/hal_eth.c.obj ac57850a3bab3ec7
288 457 7913792887680440 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/sysmem.c.obj cb5c7263e77f8f30
24 462 7913792885043399 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_gpio.c.obj b338571a161a0c05
236 466 7913792887166861 BSP/CMakeFiles/bsp.dir/Src/bsp_eth.c.obj b6a0078da5412305
223 487 7913792887036909 BSP/CMakeFiles/bsp.dir/Src/bsp_w25qxx.c.obj 2bcc927ced55ce7e
242 492 7913792887220699 Modules/led/CMakeFiles/led.dir/src/led.c.obj 361c0065047668c7
27 508 7913792885073653 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_uart.c.obj 959718d65736c9b8
230 532 7913792887093712 BSP/CMakeFiles/bsp.dir/Src/bsp_key.c.obj 9e57a4dd4022963a
248 542 7913792887277091 Middlewares/logging/CMakeFiles/logging.dir/src/logging.c.obj 86b0f61c89236124
326 567 7913792888057622 CMakeFiles/stm32f407vet6_cmake.dir/startup_stm32f407xx.s.obj 3352bb6321aecc50
295 687 7913792887745014 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/syscalls.c.obj 1cc09fc1ce7816fd
259 712 7913792887394680 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/stm32f4xx_it.c.obj 9611a8c19b40aae4
278 841 7913792887570183 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/stm32f4xx_hal_msp.c.obj c3bbce33b0b94778
252 849 7913792887318192 CMakeFiles/stm32f407vet6_cmake.dir/APP/Src/main.c.obj ac82fd5b4b4de416
418 920 7913792888983977 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c.obj 2a91ea98adea2812
392 932 7913792888721289 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Core/Src/system_stm32f4xx.c.obj 2fecb60abe437fd4
414 936 7913792888940131 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c.obj 218cb40779246324
406 946 7913792888860969 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c.obj c501785e017c114f
457 946 7913792889373868 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c.obj 893450a2eac32131
453 957 7913792889329156 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c.obj 6808052da57aca4
466 996 7913792889460580 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c.obj 22b8b5194dc4de2
462 997 7913792889424508 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c.obj f8f0c6839c7ab1ce
532 998 7913792890123461 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c.obj 76711d5ea0da574a
508 1010 7913792889881123 HAL/libhal.a 828bea71b532158c
492 1040 7913792889722285 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c.obj e4f00c48fc0b0584
487 1041 7913792889670681 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c.obj 4cff397e5a4886f8
567 1066 7913792890469938 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.obj 52aa8800389330b7
542 1080 7913792890218788 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c.obj 9a176c76dab639f
1010 1113 7913792894904240 Modules/delay/libdelay.a fa50f3f1c7df37b
1025 1115 7913792895043975 Modules/w25qxx/libw25qxx.a 6740ff1d64083f6c
1033 1121 7913792895130082 Modules/led/libled.a 4975295d4e0f5144
1017 1121 7913792894974898 Modules/uart/libuart.a f980800b2f79773c
687 1141 7913792891670312 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c.obj 560bfe4b0f4f6bf9
1115 1189 7913792895952810 BSP/libbsp.a fcf7ba39dd15dcd0
1121 1192 7913792896004441 Middlewares/logging/liblogging.a df543b4167ac9a8e
712 1257 7913792891920722 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c.obj ba7ee8080eb94038
849 1260 7913792893292618 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c.obj 42cf21cc05a6eb7a
841 1263 7913792893212699 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c.obj ca8829d822319459
1263 1499 7913792897433989 stm32f407vet6_cmake.elf f513187faf41df81