From 5b0ff3333afef5dc19a8a0f3ab947e65ded2ff27 Mon Sep 17 00:00:00 2001 From: Wu Haotian Date: Wed, 6 Dec 2023 19:20:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8GCC=20LD=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E7=9A=84=E6=AE=B5=E8=B5=B7=E6=AD=A2=E7=82=B9=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LD会为每个能生成为合法C符号名的段生成`__start_段名`和`__stop_段名`的符号,借此可以实现不需修改ldscript的导出命令模式。 参考:https://stackoverflow.com/questions/16552710/how-do-you-get-the-start-and-end-addresses-of-a-custom-elf-section --- src/shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shell.c b/src/shell.c index f956266..b065b71 100644 --- a/src/shell.c +++ b/src/shell.c @@ -39,8 +39,8 @@ SHELL_USED const ShellCommand shellUserDefault SHELL_SECTION("shellCommand") = #elif defined(__ICCARM__) || defined(__ICCRX__) #pragma section="shellCommand" #elif defined(__GNUC__) - extern const unsigned int _shell_command_start; - extern const unsigned int _shell_command_end; + extern const unsigned int __start_shellCommand; + extern const unsigned int __stop_shellCommand; #endif #else extern const ShellCommand shellCommandList[]; @@ -212,9 +212,9 @@ void shellInit(Shell *shell, char *buffer, unsigned short size) - (size_t)(__section_begin("shellCommand"))) / sizeof(ShellCommand); #elif defined(__GNUC__) - shell->commandList.base = (ShellCommand *)(&_shell_command_start); - shell->commandList.count = ((size_t)(&_shell_command_end) - - (size_t)(&_shell_command_start)) + shell->commandList.base = (ShellCommand *)(&__start_shellCommand); + shell->commandList.count = ((size_t)(&__stop_shellCommand) + - (size_t)(&__start_shellCommand)) / sizeof(ShellCommand); #else #error not supported compiler, please use command table mode