{"id":73045,"date":"2026-02-06T23:17:36","date_gmt":"2026-02-06T15:17:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/73045.html"},"modified":"2026-02-06T23:17:36","modified_gmt":"2026-02-06T15:17:36","slug":"%e3%80%90c-%e7%a1%ac%e6%a0%b8%e3%80%91%e5%88%a9%e7%94%a8%e9%93%be%e6%8e%a5%e5%99%a8%e9%ad%94%e6%b3%95-linker-sections-%e5%ae%9e%e7%8e%b0%e5%8e%bb%e4%b8%ad%e5%bf%83%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/73045.html","title":{"rendered":"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf"},"content":{"rendered":"<p>\u6458\u8981&#xff1a;\u5728\u5927\u578b\u5d4c\u5165\u5f0f\u9879\u76ee\u4e2d&#xff0c;\u7ef4\u62a4\u4e00\u4e2a\u4e2d\u5fc3\u5316\u7684\u201c\u521d\u59cb\u5316\u5217\u8868\u201d\u6216\u201c\u547d\u4ee4\u5217\u8868\u201d\u4e0d\u4ec5\u7e41\u7410&#xff0c;\u800c\u4e14\u7834\u574f\u4e86\u6a21\u5757\u7684\u72ec\u7acb\u6027\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528 GCC\/Clang \u7684 __attribute__((section)) \u7279\u6027&#xff0c;\u914d\u5408\u81ea\u5b9a\u4e49 Linker Script&#xff0c;\u5c06\u5206\u6563\u5728\u5404\u4e2a\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u201c\u5438\u201d\u5230\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u6700\u540e\u5c01\u88c5\u6210 C&#043;&#043; \u7684 Range \u8fed\u4ee3\u5668&#xff0c;\u5b9e\u73b0\u96f6\u8026\u5408\u3001\u96f6\u8fd0\u884c\u65f6\u5f00\u9500\u7684\u81ea\u52a8\u6ce8\u518c\u6846\u67b6\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001 \u75db\u70b9&#xff1a;\u81c3\u80bf\u7684 main.c<\/h3>\n<p>\u5047\u8bbe\u4f60\u6b63\u5728\u5199\u4e00\u4e2a CLI&#xff08;\u547d\u4ee4\u884c&#xff09;\u5de5\u5177\u3002<\/p>\n<h4>\u4f20\u7edf\u7684\u5199\u6cd5<\/h4>\n<p>\/\/ main.c<br \/>\n#include &#034;cmd_led.h&#034;<br \/>\n#include &#034;cmd_wifi.h&#034;<br \/>\n#include &#034;cmd_reset.h&#034;<br \/>\n\/\/ &#8230; \u5f15\u5165 50 \u4e2a\u5934\u6587\u4ef6<\/p>\n<p>void Shell_Init() {<br \/>\n    \/\/ \u6bcf\u6b21\u52a0\u65b0\u547d\u4ee4&#xff0c;\u90fd\u8981\u6765\u8fd9\u91cc\u6539\u4ee3\u7801<br \/>\n    Shell_Register(&#034;led&#034;, Cmd_Led);<br \/>\n    Shell_Register(&#034;wifi&#034;, Cmd_Wifi);<br \/>\n    Shell_Register(&#034;reset&#034;, Cmd_Reset);<br \/>\n    \/\/ &#8230; \u624b\u5199 50 \u884c<br \/>\n}<\/p>\n<p>\u95ee\u9898&#xff1a;<\/p>\n<li>\n<p>\u8fdd\u53cd\u5f00\u95ed\u539f\u5219&#xff1a;\u65b0\u589e\u529f\u80fd\u5fc5\u987b\u4fee\u6539\u73b0\u6709\u4ee3\u7801 (main.c)\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f9d\u8d56\u5730\u72f1&#xff1a;main.c \u5fc5\u987b\u77e5\u9053\u6240\u6709\u6a21\u5757\u7684\u5b58\u5728\u3002<\/p>\n<\/li>\n<li>\n<p>\u534f\u540c\u51b2\u7a81&#xff1a;\u591a\u4eba\u5f00\u53d1\u65f6&#xff0c;\u5927\u5bb6\u90fd\u5728\u6539 Shell_Init&#xff0c;Git \u5408\u5e76\u51b2\u7a81\u4e0d\u65ad\u3002<\/p>\n<\/li>\n<p>\u76ee\u6807&#xff1a; \u5728 cmd_led.cpp \u91cc\u5199\u5b8c\u547d\u4ee4&#xff0c;\u4e0d\u9700\u8981\u6539\u4efb\u4f55\u5176\u4ed6\u6587\u4ef6&#xff0c;\u7cfb\u7edf\u81ea\u52a8\u5c31\u80fd\u7528\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001 \u6838\u5fc3\u539f\u7406&#xff1a;\u94fe\u63a5\u5668\u6bb5 (Sections)<\/h3>\n<p>\u7f16\u8bd1\u5668\u7f16\u8bd1\u4ee3\u7801\u65f6&#xff0c;\u901a\u5e38\u628a\u4ee3\u7801\u653e .text&#xff0c;\u53d8\u91cf\u653e .data\u3002 \u4f46\u6211\u4eec\u53ef\u4ee5\u544a\u8bc9\u7f16\u8bd1\u5668&#xff1a;\u201c\u628a\u8fd9\u4e2a\u53d8\u91cf\u653e\u5230\u6211\u6307\u5b9a\u7684 .my_shell_cmds \u6bb5\u91cc\u53bb\u3002\u201d<\/p>\n<p>\u94fe\u63a5\u5668&#xff08;Linker&#xff09;\u5728\u6700\u540e\u628a\u6240\u6709 .o \u6587\u4ef6\u5408\u6210 .elf \u65f6&#xff0c;\u4f1a\u628a\u6240\u6709\u6587\u4ef6\u91cc\u6807\u8bb0\u4e3a .my_shell_cmds \u7684\u53d8\u91cf\u62fc\u63a5\u5230\u4e00\u8d77&#xff0c;\u5f62\u6210\u4e00\u4e2a\u8fde\u7eed\u7684\u6570\u7ec4\u3002<\/p>\n<p>\u53ea\u8981\u6211\u4eec\u77e5\u9053\u8fd9\u4e2a\u6bb5\u7684\u8d77\u59cb\u5730\u5740\u548c\u7ed3\u675f\u5730\u5740&#xff0c;\u5c31\u80fd\u50cf\u904d\u5386\u6570\u7ec4\u4e00\u6837\u904d\u5386\u6240\u6709\u6ce8\u518c\u7684\u547d\u4ee4\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001 \u5b9e\u6218\u6b65\u9aa4<\/h3>\n<h4>1. \u5b9a\u4e49\u6570\u636e\u7ed3\u6784<\/h4>\n<p>\/\/ ShellCommand.h<br \/>\ntypedef void (*CmdFunc)(int argc, char** argv);<\/p>\n<p>struct Command {<br \/>\n    const char* name;<br \/>\n    const char* help;<br \/>\n    CmdFunc     handler;<br \/>\n};<\/p>\n<h4>2. C&#043;&#043; \u5b8f\u9b54\u6cd5&#xff1a;\u6307\u5b9a Section<\/h4>\n<p>\u6211\u4eec\u9700\u8981\u7528 __attribute__((section(&#034;name&#034;))) \u544a\u8bc9\u7f16\u8bd1\u5668\u3002\u4e3a\u4e86\u9632\u6b62\u88ab\u7f16\u8bd1\u5668\u4f18\u5316\u6389&#xff08;\u56e0\u4e3a\u6ca1\u4eba\u663e\u5f0f\u8c03\u7528\u5b83&#xff09;&#xff0c;\u9700\u8981\u52a0\u4e0a __attribute__((used))\u3002<\/p>\n<p>\/\/ \u653e\u5165\u53ea\u8bfb\u6570\u636e\u6bb5 (.rodata)&#xff0c;\u8282\u7701 RAM<br \/>\n#define SHELL_EXPORT_CMD(func, name_str, help_str) \\\\<br \/>\n    \/* \u5f3a\u5236\u5728 .shell_cmds \u6bb5\u4e2d\u5206\u914d\u4e00\u4e2a Command \u7ed3\u6784\u4f53 *\/ \\\\<br \/>\n    __attribute__((section(&#034;.shell_cmds&#034;), used)) \\\\<br \/>\n    const Command _cmd_##func &#061; { \\\\<br \/>\n        .name &#061; name_str, \\\\<br \/>\n        .help &#061; help_str, \\\\<br \/>\n        .handler &#061; func \\\\<br \/>\n    }<\/p>\n<h4>3. \u94fe\u63a5\u5668\u811a\u672c (.ld) \u4fee\u6539<\/h4>\n<p>\u8fd9\u662f\u6700\u786c\u6838\u7684\u4e00\u6b65\u3002\u6211\u4eec\u9700\u8981\u5728 .ld \u6587\u4ef6\u4e2d\u5b9a\u4e49\u8fd9\u4e2a\u6bb5&#xff0c;\u5e76\u5bfc\u51fa Start \u548c End \u7b26\u53f7&#xff0c;\u4ee5\u4fbf C&#043;&#043; \u4ee3\u7801\u80fd\u627e\u5230\u5b83\u3002<\/p>\n<p>\u6253\u5f00\u4f60\u7684 STM32xxxx.ld \u6587\u4ef6&#xff0c;\u5728 SECTIONS \u5757\u4e2d&#xff08;\u901a\u5e38\u5728 .rodata \u4e4b\u540e&#xff09;\u52a0\u5165&#xff1a;<\/p>\n<p>\/* \u5b9a\u4e49\u81ea\u5b9a\u4e49\u6bb5 *\/<br \/>\n.shell_cmds_section :<br \/>\n{<br \/>\n    . &#061; ALIGN(4);<br \/>\n    \/* \u5bfc\u51fa\u8d77\u59cb\u7b26\u53f7 *\/<br \/>\n    _shell_cmds_start &#061; .;<br \/>\n    \/* \u6536\u96c6\u6240\u6709\u6587\u4ef6\u4e2d\u540d\u4e3a .shell_cmds \u7684\u8f93\u5165\u6bb5 *\/<br \/>\n    KEEP(*( .shell_cmds ))<br \/>\n    . &#061; ALIGN(4);<br \/>\n    \/* \u5bfc\u51fa\u7ed3\u675f\u7b26\u53f7 *\/<br \/>\n    _shell_cmds_end &#061; .;<br \/>\n} &gt;FLASH  \/* \u653e\u5728 Flash \u91cc *\/<\/p>\n<h4>4. C&#043;&#043; \u8fed\u4ee3\u5668\u5c01\u88c5<\/h4>\n<p>\u73b0\u5728&#xff0c;_shell_cmds_start \u5230 _shell_cmds_end \u4e4b\u95f4\u5c31\u662f\u6ee1\u6ee1\u7684 Command \u7ed3\u6784\u4f53\u6570\u7ec4\u3002\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u5c01\u88c5\u6210 C&#043;&#043; \u7684 Range&#xff0c;\u652f\u6301 for (auto&amp; cmd : &#8230;)\u3002<\/p>\n<p>\/\/ SectionIterator.h<br \/>\n#include &#034;ShellCommand.h&#034;<\/p>\n<p>\/\/ \u58f0\u660e\u94fe\u63a5\u5668\u7b26\u53f7 (\u7c7b\u578b\u5176\u5b9e\u4e0d\u91cd\u8981&#xff0c;\u53d6\u5730\u5740\u624d\u91cd\u8981)<br \/>\nextern const Command _shell_cmds_start;<br \/>\nextern const Command _shell_cmds_end;<\/p>\n<p>class CommandRegistry {<br \/>\npublic:<br \/>\n    \/\/ \u5b9a\u4e49\u8fed\u4ee3\u5668\u7c7b\u578b<br \/>\n    using iterator &#061; const Command*;<\/p>\n<p>    \/\/ begin() \u8fd4\u56de\u6bb5\u7684\u8d77\u59cb\u5730\u5740<br \/>\n    static iterator begin() {<br \/>\n        return &amp;_shell_cmds_start;<br \/>\n    }<\/p>\n<p>    \/\/ end() \u8fd4\u56de\u6bb5\u7684\u7ed3\u675f\u5730\u5740<br \/>\n    static iterator end() {<br \/>\n        return &amp;_shell_cmds_end;<br \/>\n    }<\/p>\n<p>    \/\/ \u83b7\u53d6\u6570\u91cf<br \/>\n    static size_t size() {<br \/>\n        return end() &#8211; begin();<br \/>\n    }<br \/>\n};<\/p>\n<h3>\u56db\u3001 \u5f7b\u5e95\u89e3\u8026\u7684\u4e1a\u52a1\u4ee3\u7801<\/h3>\n<p>\u73b0\u5728&#xff0c;\u770b\u770b\u5199\u4e00\u4e2a\u65b0\u7684 LED \u547d\u4ee4\u6709\u591a\u7b80\u5355\u3002<\/p>\n<p>\/\/ Cmd_Led.cpp<br \/>\n#include &#034;ShellCommand.h&#034;<br \/>\n#include &lt;cstdio&gt;<\/p>\n<p>\/\/ 1. \u5b9e\u73b0\u4e1a\u52a1\u903b\u8f91<br \/>\nvoid Cmd_Led_Handler(int argc, char** argv) {<br \/>\n    printf(&#034;LED Toggled!\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/\/ 2. \u81ea\u52a8\u6ce8\u518c (\u4e0d\u9700\u8981\u53bb main.c \u62a5\u5230&#xff01;)<br \/>\n\/\/ \u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u628a\u5b83\u6254\u5230 Flash \u7684 .shell_cmds \u6bb5\u91cc<br \/>\nSHELL_EXPORT_CMD(Cmd_Led_Handler, &#034;led&#034;, &#034;Toggle the LED&#034;);<\/p>\n<p>\u518d\u5199\u4e00\u4e2a WiFi \u547d\u4ee4&#xff1a;<\/p>\n<p>\/\/ Cmd_Wifi.cpp<br \/>\nvoid Cmd_Wifi_Handler(int argc, char** argv) { \/*&#8230;*\/ }<br \/>\nSHELL_EXPORT_CMD(Cmd_Wifi_Handler, &#034;wifi&#034;, &#034;Connect Wifi&#034;);<\/p>\n<h3>\u4e94\u3001 \u6838\u5fc3\u5f15\u64ce&#xff1a;\u904d\u5386\u4e0e\u6267\u884c<\/h3>\n<p>\u5728 Shell \u5f15\u64ce\u4e2d&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u904d\u5386\u8fd9\u4e2a\u7279\u6b8a\u7684\u201c\u6570\u7ec4\u201d\u3002<\/p>\n<p>\/\/ Shell.cpp<br \/>\n#include &#034;SectionIterator.h&#034;<br \/>\n#include &lt;cstring&gt;<\/p>\n<p>void Shell_Process(char* input_cmd) {<br \/>\n    \/\/ \u4f7f\u7528 C&#043;&#043; Range-based for loop \u904d\u5386 Flash \u6bb5<br \/>\n    for (const auto&amp; cmd : CommandRegistry()) {<\/p>\n<p>        \/\/ \u5339\u914d\u540d\u5b57<br \/>\n        if (strcmp(input_cmd, cmd.name) &#061;&#061; 0) {<br \/>\n            \/\/ \u627e\u5230\u4e86&#xff0c;\u6267\u884c&#xff01;<br \/>\n            cmd.handler(0, nullptr);<br \/>\n            return;<br \/>\n        }<br \/>\n    }<br \/>\n    printf(&#034;Unknown command\\\\n&#034;);<br \/>\n}<\/p>\n<p>void Shell_List() {<br \/>\n    printf(&#034;Available commands:\\\\n&#034;);<br \/>\n    \/\/ \u904d\u5386\u6253\u5370 help<br \/>\n    for (const auto&amp; cmd : CommandRegistry()) {<br \/>\n        printf(&#034;  %s: %s\\\\n&#034;, cmd.name, cmd.help);<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u516d\u3001 \u8fdb\u9636\u73a9\u6cd5&#xff1a;\u81ea\u52a8\u521d\u59cb\u5316 (Auto-Init)<\/h3>\n<p>\u9664\u4e86\u505a Shell \u547d\u4ee4&#xff0c;\u8fd9\u4e2a\u6280\u672f\u6700\u5e38\u7528\u4e8e \u7cfb\u7edf\u521d\u59cb\u5316\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a .sys_init \u6bb5\u3002<\/p>\n<ul>\n<li>\n<p>\u9a71\u52a8 A \u58f0\u660e&#xff1a;SYS_INIT_EXPORT(DriverA_Init, 1); \/\/ \u4f18\u5148\u7ea7 1<\/p>\n<\/li>\n<li>\n<p>\u9a71\u52a8 B \u58f0\u660e&#xff1a;SYS_INIT_EXPORT(DriverB_Init, 2); \/\/ \u4f18\u5148\u7ea7 2<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u542f\u52a8\u65f6&#xff1a;<\/p>\n<p>\/\/ SystemInit<br \/>\n\/\/ \u751a\u81f3\u53ef\u4ee5\u5199\u4e2a\u7b80\u5355\u7684\u5192\u6ce1\u6392\u5e8f&#xff0c;\u6839\u636e\u4f18\u5148\u7ea7\u91cd\u6392 RAM \u91cc\u7684\u51fd\u6570\u6307\u9488<br \/>\n\/\/ \u7136\u540e\u4f9d\u6b21\u8c03\u7528<br \/>\nfor (auto func : InitRegistry()) {<br \/>\n    func();<br \/>\n}<\/p>\n<p>\u8fd9\u6837&#xff0c;\u4f60\u7684 main() \u51fd\u6570\u91cc\u53ef\u80fd\u7a7a\u7a7a\u5982\u4e5f&#xff0c;\u53ea\u6709\u4e00\u884c OS_Start()&#xff0c;\u6240\u6709\u7684\u521d\u59cb\u5316\u90fd\u5728\u5404\u81ea\u7684 .cpp \u91cc\u81ea\u52a8\u5b8c\u6210\u4e86\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001 \u786c\u6838\u603b\u7ed3<\/h3>\n<p>\u8fd9\u79cd\u57fa\u4e8e Linker Section \u7684\u6280\u672f&#xff0c;\u662f\u5d4c\u5165\u5f0f \u6a21\u5757\u5316 (Modularization) \u7684\u7ec8\u6781\u6b66\u5668\u3002<\/p>\n<li>\n<p>\u96f6\u8fd0\u884c\u65f6\u5185\u5b58&#xff1a;\u5982\u679c\u653e\u5728 Flash \u6bb5&#xff0c;\u4e0d\u5360 RAM\u3002<\/p>\n<\/li>\n<li>\n<p>\u96f6\u542f\u52a8\u5f00\u9500&#xff1a;\u4e0d\u50cf C&#043;&#043; \u5168\u5c40\u6784\u9020\u51fd\u6570\u9700\u8981\u8fd0\u884c\u4ee3\u7801\u6765\u6ce8\u518c&#xff0c;\u8fd9\u5b8c\u5168\u662f\u94fe\u63a5\u671f (Link-time) \u5b8c\u6210\u7684\u5185\u5b58\u5e03\u5c40&#xff0c;\u8fd0\u884c\u65f6\u76f4\u63a5\u8bfb\u6570\u7ec4&#xff0c;\u901f\u5ea6\u6700\u5feb\u3002<\/p>\n<\/li>\n<li>\n<p>\u6781\u81f4\u89e3\u8026&#xff1a;\u65b0\u589e\u6a21\u5757\u53ea\u9700\u589e\u52a0\u6587\u4ef6&#xff0c;\u65e0\u9700\u4fee\u6539\u4efb\u4f55\u73b0\u6709\u4ee3\u7801\u3002<\/p>\n<\/li>\n<p>\u770b\u770b Linux Kernel \u7684\u6e90\u7801&#xff0c;\u770b\u770b U-Boot \u7684\u6e90\u7801&#xff0c;\u4f60\u4f1a\u53d1\u73b0\u8fd9\u79cd __attribute__((section)) \u7684\u5b8f\u65e0\u5904\u4e0d\u5728\u3002\u73b0\u5728&#xff0c;\u4f60\u4e5f\u638c\u63e1\u4e86\u8fd9\u79cd\u67b6\u6784\u5e08\u7ea7\u522b\u7684\u6280\u5de7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981&#xff1a;\u5728\u5927\u578b\u5d4c\u5165\u5f0f\u9879\u76ee\u4e2d&#xff0c;\u7ef4\u62a4\u4e00\u4e2a\u4e2d\u5fc3\u5316\u7684\u201c\u521d\u59cb\u5316\u5217\u8868\u201d\u6216\u201c\u547d\u4ee4\u5217\u8868\u201d\u4e0d\u4ec5\u7e41\u7410&#xff0c;\u800c\u4e14\u7834\u574f\u4e86\u6a21\u5757\u7684\u72ec\u7acb\u6027\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528 GCC\/Clang \u7684 __attribute__((section)) \u7279\u6027&#xff0c;\u914d\u5408\u81ea\u5b9a\u4e49 Linker Script&#xff0c;\u5c06\u5206\u6563\u5728\u5404\u4e2a\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u201c\u5438\u201d\u5230\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u6700\u540e\u5c01\u88c5\u6210 C \u7684 Range \u8fed\u4ee3\u5668&#xff0c;\u5b9e\u73b0\u96f6\u8026\u5408\u3001\u96f6\u8fd0\u884c\u65f6\u5f00\u9500\u7684\u81ea\u52a8\u6ce8\u518c\u6846\u67b6\u3002\u4e00\u3001 \u75db\u70b9&amp;#xff<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1160,3183],"topic":[],"class_list":["post-73045","post","type-post","status-publish","format-standard","hentry","category-server","tag-1160","tag-3183"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/73045.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6458\u8981&#xff1a;\u5728\u5927\u578b\u5d4c\u5165\u5f0f\u9879\u76ee\u4e2d&#xff0c;\u7ef4\u62a4\u4e00\u4e2a\u4e2d\u5fc3\u5316\u7684\u201c\u521d\u59cb\u5316\u5217\u8868\u201d\u6216\u201c\u547d\u4ee4\u5217\u8868\u201d\u4e0d\u4ec5\u7e41\u7410&#xff0c;\u800c\u4e14\u7834\u574f\u4e86\u6a21\u5757\u7684\u72ec\u7acb\u6027\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528 GCC\/Clang \u7684 __attribute__((section)) \u7279\u6027&#xff0c;\u914d\u5408\u81ea\u5b9a\u4e49 Linker Script&#xff0c;\u5c06\u5206\u6563\u5728\u5404\u4e2a\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u201c\u5438\u201d\u5230\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u6700\u540e\u5c01\u88c5\u6210 C \u7684 Range \u8fed\u4ee3\u5668&#xff0c;\u5b9e\u73b0\u96f6\u8026\u5408\u3001\u96f6\u8fd0\u884c\u65f6\u5f00\u9500\u7684\u81ea\u52a8\u6ce8\u518c\u6846\u67b6\u3002\u4e00\u3001 \u75db\u70b9&amp;#xff\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/73045.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-06T15:17:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73045.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/73045.html\",\"name\":\"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-06T15:17:36+00:00\",\"dateModified\":\"2026-02-06T15:17:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/73045.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/73045.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73045.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/73045.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6458\u8981&#xff1a;\u5728\u5927\u578b\u5d4c\u5165\u5f0f\u9879\u76ee\u4e2d&#xff0c;\u7ef4\u62a4\u4e00\u4e2a\u4e2d\u5fc3\u5316\u7684\u201c\u521d\u59cb\u5316\u5217\u8868\u201d\u6216\u201c\u547d\u4ee4\u5217\u8868\u201d\u4e0d\u4ec5\u7e41\u7410&#xff0c;\u800c\u4e14\u7834\u574f\u4e86\u6a21\u5757\u7684\u72ec\u7acb\u6027\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528 GCC\/Clang \u7684 __attribute__((section)) \u7279\u6027&#xff0c;\u914d\u5408\u81ea\u5b9a\u4e49 Linker Script&#xff0c;\u5c06\u5206\u6563\u5728\u5404\u4e2a\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u201c\u5438\u201d\u5230\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u6700\u540e\u5c01\u88c5\u6210 C \u7684 Range \u8fed\u4ee3\u5668&#xff0c;\u5b9e\u73b0\u96f6\u8026\u5408\u3001\u96f6\u8fd0\u884c\u65f6\u5f00\u9500\u7684\u81ea\u52a8\u6ce8\u518c\u6846\u67b6\u3002\u4e00\u3001 \u75db\u70b9&amp;#xff","og_url":"https:\/\/www.wsisp.com\/helps\/73045.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-06T15:17:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/73045.html","url":"https:\/\/www.wsisp.com\/helps\/73045.html","name":"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-06T15:17:36+00:00","dateModified":"2026-02-06T15:17:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/73045.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/73045.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/73045.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++ \u786c\u6838\u3011\u5229\u7528\u94fe\u63a5\u5668\u9b54\u6cd5 (Linker Sections) \u5b9e\u73b0\u201c\u53bb\u4e2d\u5fc3\u5316\u201d\u7684\u81ea\u52a8\u521d\u59cb\u5316\u4e0e\u63d2\u4ef6\u7cfb\u7edf"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=73045"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73045\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=73045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=73045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=73045"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=73045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}