{"id":421,"date":"2025-12-16T10:48:08","date_gmt":"2025-12-16T02:48:08","guid":{"rendered":"https:\/\/www.garfield-blog.top\/?p=421"},"modified":"2025-12-16T10:49:37","modified_gmt":"2025-12-16T02:49:37","slug":"%e3%80%90linux%e3%80%91linux%e7%ac%a6%e5%8f%b7%e5%af%bc%e5%87%ba%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=421","title":{"rendered":"\u3010Linux\u3011Linux\u7b26\u53f7\u5bfc\u51fa\u63a5\u53e3"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u7b26\u53f7\u5bfc\u51fa<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u6982\u8ff0<\/h2>\n\n\n\n<p><code>Linux<\/code>\u4e2d\u4e00\u7ec4<code>API<\/code>\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5c06\u9700\u8981\u7684\u7b26\u53f7\u5bfc\u51fa\uff0c\u5982\u4e0b<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>EXPORT_SYMBOL<\/strong> <code>EXPORT_SYMBOL<\/code> \u662f\u4e00\u4e2a\u5728 Linux \u5185\u6838\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\u5b8f\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u5c06\u4e00\u4e2a\u7b26\u53f7\uff08\u901a\u5e38\u662f\u4e00\u4e2a\u51fd\u6570\u540d\u6216\u53d8\u91cf\u540d\uff09\u5bfc\u51fa\uff0c\u4f7f\u5176\u53ef\u4ee5\u88ab\u5185\u6838\u7684\u5176\u4ed6\u90e8\u5206\u6216\u8005\u52a8\u6001\u52a0\u8f7d\u7684\u5185\u6838\u6a21\u5757<code>LKMs<\/code>\u8bbf\u95ee<\/li>\n\n\n\n<li><strong>EXPORT_SYMBOL_GPL<\/strong> <code>EXPORT_SYMBOL_GPL(save_stack_trace);<\/code> \u7684\u4f5c\u7528\u662f\u5c06\u51fd\u6570 <code>save_stack_trace<\/code> \u5bfc\u51fa\u5230\u5185\u6838\u7b26\u53f7\u8868\u4e2d\uff0c\u4f46<strong>\u4ec5\u9650\u4e8e\u9075\u5faa GPL (GNU General Public License) \u517c\u5bb9\u8bb8\u53ef\u8bc1\u7684\u5185\u6838\u6a21\u5757\u4f7f\u7528<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u67e5\u770b\u6e90\u7801\u53ef\u4ee5\u770b\u5230\uff0c\u4e0a\u8ff0\u7684\u4e24\u4e2a\u5b8f\u5176\u5b9e\u90fd\u662f<code>__EXPORT_SYMBOL<\/code>\u7684\u4e00\u5c42\u5c01\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/linux-5.4\/include\/linux\/export.h\n#define EXPORT_SYMBOL(sym)        __EXPORT_SYMBOL(sym, \"\")\n#define EXPORT_SYMBOL_GPL(sym)        __EXPORT_SYMBOL(sym, \"_gpl\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">__EXPORT_SYMBOL\u539f\u7406\u5206\u6790<\/h2>\n\n\n\n<p><code>__EXPORT_SYMBOL<\/code>\u7684\u57fa\u672c\u539f\u7406\u662f\uff0c\u5c06\u7b26\u53f7\u8868\u5bfc\u51fa\u5230<code>ELF<\/code>\u6587\u4ef6\u4e00\u4e2a\u7279\u6b8a\u7684\u4ee5\u7b26\u53f7\u540d\u79f0\u547d\u540d\u7684\u7279\u6b8a\u7684\u5185\u5b58\u8282\u4e2d\uff0c\u5f53\u5185\u6838\u6216\u5185\u6838\u6a21\u5757\u88ab\u52a0\u8f7d\u65f6\uff0c\u94fe\u63a5\u5668\u548c\u52a0\u8f7d\u5668\u53ef\u4ee5\u626b\u63cf\u8fd9\u4e9b\u7279\u6b8a\u7684\u8282\uff0c\u6536\u96c6\u6240\u6709\u7684\u7b26\u53f7\u6761\u76ee\uff0c\u4ece\u800c\u6784\u5efa\u4e00\u4e2a\u53ef\u4f9b\u67e5\u627e\u7684\u5185\u6838\u7b26\u53f7\u8868\u3002\u8fd9\u4f7f\u5f97\u5185\u6838\u6a21\u5757\u53ef\u4ee5\u8bbf\u95ee\u548c\u8c03\u7528\u6838\u5fc3\u5185\u6838\u6216\u5176\u4ed6\u6a21\u5757\u5bfc\u51fa\u7684\u51fd\u6570\u548c\u53d8\u91cf<\/p>\n\n\n\n<p><strong>\u6e90\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/linux-5.4\/include\/linux\/export.h\n#define __KSYMTAB_ENTRY(sym, sec)                    \\\n    static const struct kernel_symbol __ksymtab_##sym        \\\n    __attribute__((section(\"___ksymtab\" sec \"+\" #sym), used))    \\\n    __aligned(sizeof(void *))                    \\\n    = { (unsigned long)&amp;sym, __kstrtab_##sym, NULL }\n\nstruct kernel_symbol {\n    unsigned long value;\n    const char *name;\n    const char *namespace;\n};\n\n#define ___EXPORT_SYMBOL(sym, sec)                    \\\n    ___export_symbol_common(sym, sec);                \\\n    __KSYMTAB_ENTRY(sym, sec)\n\n#define __EXPORT_SYMBOL(sym,sec)    ___EXPORT_SYMBOL(sym,sec)<\/code><\/pre>\n\n\n\n<p><strong>\u6838\u5fc3\u601d\u60f3\uff1a<\/strong><\/p>\n\n\n\n<p>\u901a\u8fc7<code>__KSYMTAB_ENTRY<\/code>\u5c06\u7b26\u53f7\u5bfc\u51fa\u5230ELF\u6587\u4ef6\u7684\u5185\u5b58\u6bb5\u4e2d\uff0c\u5177\u4f53\u7684\u6d41\u7a0b\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>__ksymtab_my_function<\/code> \u7684 <code>struct kernel_symbol<\/code> \u53d8\u91cf<\/li>\n\n\n\n<li>\u5c06\u8fd9\u4e2a\u53d8\u91cf\u5b58\u50a8\u5728\u4e00\u4e2a\u7279\u6b8a\u7684\u3001\u4ee5\u7b26\u53f7\u540d\u547d\u540d\u7684\u5185\u5b58\u8282\u4e2d\uff08\u4f8b\u5982 <code>\"___ksymtab+my_function\"<\/code>\uff09<\/li>\n\n\n\n<li>\u7528 <code>my_function<\/code> \u7684\u5b9e\u9645\u5730\u5740\u548c\u6307\u5411\u5176\u540d\u79f0\u5b57\u7b26\u4e32 <code>\"my_function\"<\/code> \u7684\u6307\u9488\u6765\u521d\u59cb\u5316\u8fd9\u4e2a\u53d8\u91cf<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u6837\uff0c\u5f53\u5185\u6838\u6216\u5185\u6838\u6a21\u5757\u88ab\u52a0\u8f7d\u65f6\uff0c\u94fe\u63a5\u5668\u548c\u52a0\u8f7d\u5668\u53ef\u4ee5\u626b\u63cf\u8fd9\u4e9b\u7279\u6b8a\u7684\u8282\uff0c\u6536\u96c6\u6240\u6709\u7684\u7b26\u53f7\u6761\u76ee\uff0c\u4ece\u800c\u6784\u5efa\u4e00\u4e2a\u53ef\u4f9b\u67e5\u627e\u7684\u5185\u6838\u7b26\u53f7\u8868\u3002\u8fd9\u4f7f\u5f97\u5185\u6838\u6a21\u5757\u53ef\u4ee5\u8bbf\u95ee\u548c\u8c03\u7528\u6838\u5fc3\u5185\u6838\u6216\u5176\u4ed6\u6a21\u5757\u5bfc\u51fa\u7684\u51fd\u6570\u548c\u53d8\u91cf<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003\u6587\u6863<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/github.com\/torvalds\/linux\/releases\/tag\/v5.4\">Release v5.4 \u00b7 torvalds\/linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.archlinuxcn.org\/\">Arch Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/lwn.net\/Articles\/674303\/\">[LWN.net]<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u7b26\u53f7\u5bfc\u51fa \u6982\u8ff0 Linux\u4e2d\u4e00\u7ec4API\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5c06\u9700\u8981\u7684\u7b26\u53f7\u5bfc\u51fa\uff0c\u5982\u4e0b \u67e5\u770b\u6e90\u7801\u53ef\u4ee5\u770b\u5230\uff0c\u4e0a\u8ff0\u7684\u4e24\u4e2a\u5b8f\u5176 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-linux-knowledge"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=421"}],"version-history":[{"count":2,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions"}],"predecessor-version":[{"id":423,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions\/423"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}