{"id":5633,"date":"2021-11-15T14:42:50","date_gmt":"2021-11-15T06:42:50","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=5633"},"modified":"2021-11-15T14:42:50","modified_gmt":"2021-11-15T06:42:50","slug":"address-sanitizer%ef%bc%88asan%ef%bc%89%e5%8e%9f%e7%90%86%e5%8f%8a%e5%ae%9e%e6%88%98%e5%ae%9a%e4%bd%8d","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5633","title":{"rendered":"Address Sanitizer\uff08Asan\uff09\u539f\u7406\u53ca\u5b9e\u6218\u5b9a\u4f4d"},"content":{"rendered":"<div class=\"article-header-box\">\n<div class=\"article-header\">\n<div class=\"article-title-box\">\n<p id=\"articleContentId\" class=\"title-article\"><a href=\"https:\/\/blog.csdn.net\/wads23456\/article\/details\/105141997\/\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"article-info-box\">\n<div class=\"operating\"><a class=\"href-article-edit slide-toggle\">\u7248\u6743<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"blogColumnPayAdvert\">\n<div class=\"column-group\">\n<div class=\"column-group-item column-group0 column-group-item-one\">\n<div class=\"item-l\"><a class=\"item-target\" title=\"C++\/C\u5185\u5b58\u95ee\u9898\u68c0\u6d4b\u5de5\u5177\" href=\"https:\/\/blog.csdn.net\/wads23456\/category_9800144.html\" target=\"_blank\" rel=\"noopener\" data-report-click=\"{&quot;spm&quot;:&quot;1001.2101.3001.6332&quot;}\"> <img decoding=\"async\" class=\"item-target\" src=\"https:\/\/img-blog.csdnimg.cn\/20201014180756925.png?x-oss-process=image\/resize,m_fixed,h_64,w_64\" alt=\"\" \/> <span class=\"title item-target\">C++\/C\u5185\u5b58\u95ee\u9898\u68c0\u6d4b\u5de5\u5177<\/span> <\/a> <span class=\"dec\">\u4e13\u680f\u6536\u5f55\u8be5\u5185\u5bb9<\/span><\/div>\n<div class=\"item-m\">8 \u7bc7\u6587\u7ae04 \u8ba2\u9605<\/div>\n<div class=\"item-r\"><a class=\"item-target article-column-bt articleColumnFreeBt\" data-id=\"9800144\">\u8ba2\u9605\u4e13\u680f<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<article class=\"baidu_pl\">\n<div id=\"article_content\" class=\"article_content clearfix\">\n<div id=\"content_views\" class=\"markdown_views prism-atom-one-light\">\n<ul>\n<li>\n<h1><a name=\"t0\"><\/a><a id=\"Asan_0\"><\/a>Asan<\/h1>\n<p><a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\" target=\"_blank\" rel=\"noopener\">ASAN<\/a>\uff08AddressSanitizer\u7684\u7f29\u5199\uff09\u662f\u4e00\u6b3e\u9762\u5411C\/C++\u8bed\u8a00\u7684\u5185\u5b58\u9519\u8bef\u95ee\u9898\u68c0\u67e5\u5de5\u5177\uff0c\u53ef\u4ee5\u68c0\u6d4b\u5982\u4e0b\u5185\u5b58\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u5df2\u91ca\u653e\u5185\u5b58\uff08\u91ce\u6307\u9488\uff09<\/li>\n<li>\u5806\u5185\u5b58\u8d8a\u754c\uff08\u8bfb\u5199\uff09<\/li>\n<li>\u6808\u5185\u5b58\u8d8a\u754c\uff08\u8bfb\u5199\uff09<\/li>\n<li>\u5168\u5c40\u53d8\u91cf\u8d8a\u754c\uff08\u8bfb\u5199\uff09<\/li>\n<li>\u51fd\u6570\u8fd4\u56de\u5c40\u90e8\u53d8\u91cf<\/li>\n<li>\u5185\u5b58\u6cc4\u6f0f<\/li>\n<\/ul>\n<p><a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\" target=\"_blank\" rel=\"noopener\">ASAN<\/a>\u5de5\u5177\u4e3b\u8981\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>\u7f16\u8bd1\u5668\u63d2\u6869\u6a21\u5757<\/li>\n<li>\u8fd0\u884c\u65f6\u5e93<\/li>\n<\/ul>\n<p><strong>\u8fd0\u884c\u65f6\u5e93<\/strong>\uff1a\uff08libasan.so.x\uff09\u4f1a\u63a5\u7ba1<code>malloc\u548c``free\u51fd\u6570<\/code>\u3002malloc\u6267\u884c\u5b8c\u540e\uff0c\u5df2\u5206\u914d\u5185\u5b58\u7684\u524d\u540e\uff08\u79f0\u4e3a\u201c\u7ea2\u533a\u201d\uff09\u4f1a\u88ab\u6807\u8bb0\u4e3a\u201c\u4e2d\u6bd2\u201d\u72b6\u6001\uff0c\u800c\u91ca\u653e\u7684\u5185\u5b58\u5219\u4f1a\u88ab\u9694\u79bb\u8d77\u6765\uff08\u6682\u65f6\u4e0d\u4f1a\u5206\u914d\u51fa\u53bb\uff09\u4e14\u4e5f\u4f1a\u88ab\u6807\u8bb0\u4e3a\u201c\u4e2d\u6bd2\u201d\u72b6\u6001\u3002<\/p>\n<p><strong>\u7f16\u8bd1\u5668\u63d2\u6869\u6a21\u5757<\/strong>\uff1a\u52a0\u4e86ASAN\u76f8\u5173\u7684\u7f16\u8bd1\u9009\u9879\u540e\uff0c\u4ee3\u7801\u4e2d\u7684\u6bcf\u4e00\u6b21\u5185\u5b58\u8bbf\u95ee\u64cd\u4f5c\u90fd\u4f1a\u88ab\u7f16\u8bd1\u5668\u4fee\u6539\u4e3a\u5982\u4e0b\u65b9\u5f0f\uff1a<\/p>\n<p>\u7f16\u8bd1\u524d:<\/p>\n<pre class=\"prettyprint\"><code class=\"has-numbering\">*address = ...;  \/\/ or: ... = *address;<\/code><\/pre>\n<p>\u7f16\u8bd1\u540e\uff1a<\/p>\n<pre class=\"prettyprint\"><code class=\"has-numbering\">if (IsPoisoned(address)) {\r\n  ReportError(address, kAccessSize, kIsWrite);\r\n}\r\n*address = ...;  \/\/ or: ... = *address;<\/code><\/pre>\n<p>\u8be5\u65b9\u5f0f\u7684\u5173\u952e\u70b9\u5c31\u5728\u4e8e\u8bfb\u5199\u5185\u5b58\u524d\u4f1a\u5224\u65ad\u5730\u5740\u662f\u5426\u5904\u4e8e\u201c\u4e2d\u6bd2\u201d\u72b6\u6001\uff0c\u8fd8\u6709\u5982\u4f55\u628a<code>IsPoisoned\u5b9e\u73b0\u7684\u975e\u5e38\u5feb\uff0c\u628a``ReportError\u5b9e\u73b0\u7684\u975e\u5e38\u7d27\u51d1\uff0c\u4ece\u800c\u907f\u514d\u63d2\u5165\u7684\u4ee3\u7801\u8fc7\u591a\u3002<\/code><\/p>\n<p>ASan\u5bf9\u7f13\u51b2\u533a\u6ea2\u51fa\u9632\u62a4\u7684\u7684\u57fa\u672c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>\\1. \u901a\u8fc7\u5728\u88ab\u4fdd\u62a4\u7684\u6808\u3001\u5168\u5c40\u53d8\u91cf\u3001\u5806\u5468\u56f4\u5efa\u7acb\u6807\u8bb0\u4e3a\u4e2d\u6bd2\u72b6\u6001(Poisnoned)\u7684red-zones\uff1b<\/p>\n<p>\u4ee5\u6808\u7f13\u51b2\u533a\u6ea2\u51fa\u68c0\u6d4b\u4e3a\u4f8b\uff0c\u5982\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86red-zone\u7684\u5efa\u7acb\u3002<\/p>\n<p>\u5c06\u7f13\u51b2\u533a\u548cred-zone\u901a\u8fc7\u6bcf8\u5b57\u8282\u5bf9\u5e941\u5b57\u8282\u7684\u6620\u5c04\u7684\u65b9\u5f0f\u5efa\u7acb\u5f71\u5b50\u5185\u5b58\u533a\uff0c\u5f71\u5b50\u5185\u5b58\u533a\u7684\u83b7\u53d6\u51fd\u6570\u4e3aMemToShadow\u3002<\/p>\n<p>\\3. \u5982\u679c\u51fa\u73b0\u5bf9red-zone\u7684\u8bfb\u3001\u5199\u6216\u6267\u884c\u7684\u8bbf\u95ee\uff0c\u5219ASan\u53ef\u4ee5ShadowIsPoisoned\u68c0\u6d4b\u51fa\u6765\u5e76\u62a5\u9519\u3002<\/p>\n<p>\u62a5\u9519\u4fe1\u606f\u7ed9\u51fa\u51fa\u9519\u7684\u6e90\u6587\u4ef6\u540d\u3001\u884c\u53f7\u3001\u51fd\u6570\u8c03\u7528\u5173\u7cfb\u3001\u5f71\u5b50\u5185\u5b58\u72b6\u6001\u3002\u5176\u4e2d\u5f71\u5b50\u5185\u5b58\u72b6\u6001\u4fe1\u606f\u4e2d\u51fa\u9519\u7684\u90e8\u5206\u7528\u4e2d\u62ec\u53f7\u6807\u8bc6\u51fa\u6765\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<h2><a name=\"t1\"><\/a><a id=\"_53\"><\/a><\/h2>\n<p>\u4e8c. \u5185\u5b58\u6620\u5c04\u4e0e\u63d2\u6869<\/p>\n<p>\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u7a7a\u95f4\u88abASAN\u5212\u5206\u4e3a2\u4e2a\u72ec\u7acb\u7684\u90e8\u5206\uff1a<\/p>\n<ul>\n<li>\u4e3b\u5e94\u7528\u5185\u5b58\u533a (<code>Mem<\/code>): \u666e\u901aAPP\u4ee3\u7801\u5185\u5b58\u4f7f\u7528\u533a\u3002<\/li>\n<li>\u5f71\u5b50\u5185\u5b58\u533a (<code>Shadow<\/code>): \u8be5\u5185\u5b58\u533a\u4ec5<a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\" target=\"_blank\" rel=\"noopener\">ASAN<\/a>\u611f\u77e5\uff0c\u5f71\u5b50\u987e\u540d\u601d\u4e49\u662f\u6307\u8be5\u5185\u5b58\u533a\u4e0e\u4e3b\u5e94\u7528\u5185\u5b58\u533a\u5b58\u5728\u4e00\u79cd\u7c7b\u4f3c\u201c\u5f71\u5b50\u201d\u7684\u5bf9\u5e94\u5173\u7cfb\u3002ASAN\u5728\u5c06\u4e3b\u5185\u5b58\u533a\u7684\u4e00\u4e2a\u5b57\u8282\u6807\u8bb0\u4e3a\u201c\u4e2d\u6bd2\u201d\u72b6\u6001\u65f6\uff0c\u4e5f\u4f1a\u5728\u5bf9\u5e94\u7684\u5f71\u5b50\u5185\u5b58\u533a\u5199\u4e00\u4e2a\u7279\u6b8a\u503c\uff0c\u8be5\u503c\u79f0\u4e3a\u201c\u5f71\u5b50\u503c\u201d\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u5185\u5b58\u533a\u9700\u8981\u7cbe\u5fc3\u5212\u5206\uff0c\u786e\u4fdd\u53ef\u4ee5\u5feb\u901f\u4ece\u4e3b\u5e94\u7528\u5185\u5b58\u533a\u6620\u5c04\u5230\u5f71\u5b50\u5185\u5b58\u533a(<code>MemToShadow<\/code>)\u3002<\/p>\n<p>\u4e3b\u5e94\u7528\u5185\u5b58\u4e0e\u5f71\u5b50\u5185\u5b58Shadow bytes\u6620\u5c04<\/p>\n<p><a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\" target=\"_blank\" rel=\"noopener\">ASAN<\/a>\u5c068\u5b57\u8282\u7684\u4e3b\u5e94\u7528\u533a\u5185\u5b58\u6620\u5c04\u4e3a1\u5b57\u8282\u7684\u5f71\u5b50\u533a\u5185\u5b58\u3002<\/p>\n<p>\u9488\u5bf9\u4efb\u4f558\u5b57\u8282\u5bf9\u9f50\u7684\u4e3b\u5e94\u7528\u533a\u5185\u5b58\uff0c\u603b\u5171\u67099\u79cd\u4e0d\u540c\u7684\u5f71\u5b50\u5185\u5b58\u503c\uff1a<\/p>\n<ul>\n<li>4\u5b57\u4e2d\u7684\u5168\u90e88\u5b57\u8282\u90fd\u672a\u201c\u4e2d\u6bd2\u201d(\u53ef\u8bbf\u95ee\u7684)\uff0c\u5f71\u5b50\u503c\u662f0\u3002<\/li>\n<li>4\u5b57\u4e2d\u7684\u5168\u90e88\u5b57\u8282\u90fd\u201c\u4e2d\u6bd2\u201d(\u4e0d\u53ef\u8bbf\u95ee\u7684)\uff0c\u5f71\u5b50\u503c\u662f\u8d1f\u6570\u3002<\/li>\n<li>\u524d<code>k\u4e2a\u5b57\u8282\u672a\u201c\u4e2d\u6bd2\u201d<\/code>\uff0c\u540e<code>8-k\u5b57\u8282\u201c\u4e2d\u6bd2\u201d\uff0c\u5f71\u5b50\u503c\u662f``k<\/code>\u3002\u8fd9\u4e00\u529f\u80fd\u7684\u8fbe\u6210\u662f\u7531<code>malloc\u51fd\u6570\u603b\u662f\u8fd4\u56de8\u5b57\u8282\u5bf9\u9f50\u7684\u5185\u5b58\u5757\u6765\u4fdd\u8bc1\u7684\uff0c<\/code>\u552f\u4e00\u80fd\u51fa\u73b0\u8be5\u60c5\u51b5\u7684\u573a\u666f\u5c31\u5728\u7533\u8bf7\u5185\u5b58\u533a\u57df\u7684\u5c3e\u90e8\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u7533\u8bf713\u4e2a\u5b57\u8282\uff0c\u5373<code>malloc(13)\uff0c\u8fd9\u6837\u6211\u4eec\u4f1a\u5f97\u5230\u4e00\u4e2a\u5b8c\u6574\u7684\u672a\u201c\u4e2d\u6bd2\u201d\u76844\u5b57\u548c\u524d5\u4e2a\u5b57\u8282\u672a\u201c\u4e2d\u6bd2\u201d\u3001\u540e3\u4e2a\u5b57\u8282\u201c\u4e2d\u6bd2\u201d\u76844\u5b57\u3002<\/code><\/li>\n<\/ul>\n<p><strong>ASAN\u65e5\u5fd7\u683c\u5f0f<\/strong><\/p>\n<p>\u6bcf\u6761\u9519\u8bef\u8bb0\u5f55\u90fd\u662f\u4ee5\u4e00\u4e32&#8221;=&#8221;\u53f7\u5f00\u59cb\u7684\uff0c\u5177\u4f53\u5185\u5bb9\u5305\u542b(\u91cd\u70b9\u5173\u6ce8\u6807\u7ea2\u7684\u5b57\u6bb5)\uff1a<\/p>\n<p>\u9519\u8bef\u8fdb\u7a0b\u53f7\uff1a\u5185\u5b58\u95ee\u9898\u53d1\u751f\u7684<a class=\"hl hl-1\" href=\"https:\/\/so.csdn.net\/so\/search?from=pc_blog_highlight&amp;q=Linux\" target=\"_blank\" rel=\"noopener\">Linux<\/a>\u8fdb\u7a0b\u53f7<\/p>\n<p>\u9519\u8bef\u7c7b\u578b\uff1aglobal-buffer-overflow\/(\u5168\u5c40\u53d8\u91cf\u8d8a\u754c), heap-buffer-overflow \u5806\u5185\u5b58\u8d8a\u754c, stack-buffer-overflow\u6808\u5185\u5b58\u8d8a\u754c, double-free\uff08\u91cd\u590d\u91ca\u653e\u5185\u5b58\uff09 \u5185\u5b58\u8d8a\u754c\u8c03\u7528\u6808\uff1a\u91cd\u590d\u5185\u5b58\u9519\u8bef\u7684\u8c03\u7528\u6808\u4fe1\u606f\uff0c\u5982\u679c\u8981\u663e\u793a\u6587\u4ef6\u540d\u884c\u53f7\uff0c\u9700\u8981\u52a0-g\u9009\u9879 \u4e0a\u6b21\u5185\u5b58\u91ca\u653e\u8c03\u7528\u6808\uff1a\u4e0a\u4e00\u6b21\u91ca\u653e\u5185\u5b58\u7684\u8c03\u7528\u6808\u4fe1\u606f \u5185\u5b58\u7533\u8bf7\u8c03\u7528\u6808\uff1a\u5185\u5b58\u7533\u8bf7\u7684\u8c03\u7528\u6808\u4fe1\u606f<\/p>\n<p>\u8d8a\u754c\u5730\u5740\u8bf4\u660e\uff1a\u5bf9\u51fa\u9519\u65f6\u8bbf\u95ee\u7684\u5185\u5b58\u5730\u5740\u505a\u8fdb\u4e00\u6b65\u8bf4\u660e\uff0c\u4ee5\u4fbf\u66f4\u76f4\u89c2\u7684\u5224\u65ad\u95ee\u9898\u6240\u5728\u5f71\u5b50\u5185\u5b58\u72b6\u6001\u3001\u5f71\u5b50\u5185\u5b58\u9b54\u672f\u5b57\u3001Asan\u5185\u90e8\u4fe1\u606f\uff0c\u5206\u6790\u95ee\u9898\u662f\u53ef\u4e0d\u5173\u6ce8<\/p>\n<p><strong>\u5206\u6790Asan\u62a5\u9519\u65e5\u5fd7<\/strong><\/p>\n<pre class=\"prettyprint\"><code class=\"prism language-bash has-numbering\"><span class=\"token operator\">==<\/span>7829<span class=\"token operator\">==<\/span>ERROR: LeakSanitizer: detected memory leaks\r\n\r\nDirect leak of 7 byte<span class=\"token punctuation\">(<\/span>s<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">in<\/span> 1 object<span class=\"token punctuation\">(<\/span>s<span class=\"token punctuation\">)<\/span> allocated from:\r\n    <span class=\"token comment\">#0 0x42c0c5 in __interceptor_malloc \/usr\/home\/lib\/asan\/asan_malloc_linux.cc:74  -- \u6cc4\u6f0f\u5185\u5b58\u7684\u7533\u8bf7\u8c03\u7528\u6808<\/span>\r\n    <span class=\"token comment\">#1 0x43ef81 in main \/usr\/home\/memory-leak.c:5<\/span>\r\n    <span class=\"token comment\">#2 0x7fef044b876c in __libc_start_main \/build\/\/glibc-2.15\/csu\/libc-start.c:226<\/span>\r\n\r\nSUMMARY: AddressSanitizer: 7 byte<span class=\"token punctuation\">(<\/span>s<span class=\"token punctuation\">)<\/span> leaked <span class=\"token keyword\">in<\/span> 1 allocation<span class=\"token punctuation\">(<\/span>s<span class=\"token punctuation\">)<\/span>.<\/code><\/pre>\n<pre class=\"prettyprint\"><code class=\"prism language-bash has-numbering\"><\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5185\u5b58\u6cc4\u6f0f\u5f88\u660e\u663e\uff0c\u7b2c6\u884c\u4ee3\u7801\u5c06\u4fdd\u5b58\u7533\u8bf7\u5185\u5b58\u7684P\u6307\u9488\u7f6e\u7a7a\uff0c\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u4e86\uff1b\u800c\u751f\u6210\u7684\u65e5\u5fd7\u5185\u5bb9\u4e5f\u633a\u7b80\u5355\uff1a<\/p>\n<p>&#8220;<mark>7829<\/mark>&#8220;\u8868\u793a\u7a0b\u5e8f\u7684\u8fdb\u7a0b\u53f7\uff0c\u540e\u9762\u7684&#8221;ERROR:&#8221;\u8868\u660eASAN\u53d1\u73b0\u4e86\u5185\u5b58\u6cc4\u6f0f\uff0c\u5982\u679c\u6ca1\u6709\u53d1\u73b0\u5185\u5b58\u6cc4\u6f0f\uff0c\u8fd9\u4e9b\u4fe1\u606f\u90fd\u4e0d\u4f1a\u6253\uff0c\u4e5f\u4e0d\u4f1a\u751f\u6210\u76f8\u5173\u65e5\u5fd7\uff1b<\/p>\n<p>\u6362\u4e00\u884c\u7684&#8221;leak of 7 byte(s)&#8221;\u8868\u660e\u5185\u5b58\u6cc4\u6f0f\u4e867\u4e2a\u5b57\u8282\uff0c&#8221;1 object(s)\u201c\u8868\u660e\u6cc4\u6f0f\u4e861\u6b21\uff0c\u800c\u6cc4\u6f0f\u5185\u5b58\u7684\u7533\u8bf7\u8c03\u7528\u6808\u5c31\u5728\u540e\u9762\u6253\u5370\u4e86\uff0c\u5176\u4e2d\u201d\/usr\/home\/memory-leak.c:5&#8243;\u8868\u660e\u5185\u5b58\u7533\u8bf7\u7684\u6587\u4ef6\u540d\u3001\u884c\u53f7\u3002<\/p>\n<h6><a id=\"_109\"><\/a>\u51fd\u6570\u63d2\u6869<\/h6>\n<p>\u53ef\u4ee5\u81ea\u5b9a\u5236\u65b0\u5f00\u53d1\u529f\u80fd\uff0c\u57fa\u4e8e<a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\" target=\"_blank\" rel=\"noopener\">ASAN<\/a>\uff08AddressSanitizer\u7684\u7f29\u5199\uff09\u7684\u6587\u4ef6\u53e5\u67c4\u95ee\u9898\u68c0\u67e5\u529f\u80fd\uff0c \u91c7\u7528LD_PRELOAD\u673a\u5236\u548cdlsym\u63a5\u53e3\uff0c\u63a5\u7ba1libc\u5e93\u7684open\/close\u7b49\u63a5\u53e3\uff0c\u5e76\u8fdb\u884c\u5224\u65ad\u4e0e\u8c03\u7528\u6808\u8bb0\u5f55\u3002\u5c31\u50cfAsan\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684\u8fd0\u884c\u65f6\u5e93\u51fd\u6570\u63a5\u7ba1malloc\/free\uff0cnew\/delete\uff0cmem*\u7b49\u51fd\u6570\u3002<\/p>\n<p><strong>ASAN\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b\u539f\u7406\u5982\u4e0b\uff1a<\/strong><\/p>\n<p>1\u3001ASAN\u4f1a\u63a5\u7ba1\u5185\u5b58\u7533\u8bf7\u63a5\u53e3\uff0c\u5373\u7528\u6237\u7684\u5185\u5b58\u5168\u90fd\u7531ASAN\u6765\u7ba1\u7406\uff1b<\/p>\n<p>2\u3001\u5f53<strong>\u8fdb\u7a0b\u9000\u51fa\u65f6\u89e6\u53d1ASAN\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b<\/strong>\uff0c\u5f00\u53d1\u53ef\u4ee5\u4f7f\u7528\u590d\u4f4d\u5355\u677f\u3001\u91cd\u542f\u8bbe\u5907\u7b49\u4e00\u5207\u53ef\u4ee5\u8ba9\u8fdb\u7a0b\u6b63\u5e38\u9000\u51fa\u7684\u65b9\u6cd5\u6765\u89e6\u53d1ASAN\u8fdb\u884c\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b\uff1b<\/p>\n<p>3\u3001\u5f00\u59cb\u5185\u5b58\u6cc4\u6f0f\u68c0\u67e5\u540e\uff0cASAN\u4f1a\u904d\u5386\u5f53\u524d\u6240\u6709\u5df2\u7ecf\u5206\u914d\u7ed9\u7528\u6237\u4f46\u6ca1\u6709\u91ca\u653e\u7684\u5806\u5185\u5b58\uff0c\u626b\u63cf\u8fd9\u4e9b\u5185\u5b58\u662f\u5426\u88ab\u67d0\u4e2a\u6307\u9488\u5f15\u7528\u7740\uff0c\u8fd9\u4e9b\u6307\u9488\u53ef\u80fd\u662f\u5168\u5c40\u53d8\u91cf\u3001\u5c40\u90e8\u53d8\u91cf\u6216\u8005\u662f\u5806\u5185\u5b58\u91cc\u9762\u7684\u6307\u9488\uff0c\u5982\u679c\u6ca1\u6709\u5219\u8ba4\u4e3a\u662f\u6cc4\u6f0f\u4e86\uff1b\u5982\u679c\u5185\u5b58\u88ab\u5f15\u7528\u7740\uff0c\u6bd4\u5982\u5185\u5b58\u7533\u8bf7\u5b8c\u540e\u653e\u5728V8\u7684Local\u6570\u636e\u533a\u3001\u63d2\u6811\u3001\u63d2\u94fe\u8868\u7b49\uff0c\u662f\u4e0d\u4f1a\u62a5\u6cc4\u6f0f\u7684\uff1b<\/p>\n<p>4\u3001\u5c06\u6240\u6709\u6cc4\u6f0f\u7684\u5185\u5b58\u4fe1\u606f\u6253\u51fa\u6765\uff0c\u5305\u542b\u5185\u5b58\u5927\u5c0f\u548c\u5185\u5b58\u7533\u8bf7\u7684\u8c03\u7528\u6808\u4fe1\u606f\uff1b<\/p>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u65e5\u5fd7\u4e2d\u62a5\u5185\u5b58\u6cc4\u6f0f\u4e86\uff0c<strong>\u5f00\u53d1\u540c\u5b66\u9700\u8981\u5206\u6790\u8be5\u5185\u5b58\u7533\u8bf7\u7684\u6307\u9488\u662f\u5b58\u653e\u5230\u54ea\u513f\u7684\uff0c\u5728\u6d41\u7a0b\u4e2d\u8fd9\u4e2a\u6307\u9488\u662f\u5728\u54ea\u513f\u88ab\u6539\u4e86\uff0c\u4f46\u662f\u6ca1\u6709\u91ca\u653e\u5185\u5b58<\/strong>\u3002<\/p>\n<p>\u8bb2\u4e00\u4e2a\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u7684\u573a\u666f\uff0c\u67d0\u57fa\u7840\u6a21\u5757\u53d1\u73b04\u4e2a\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u90fd\u662f\u5185\u5b58\u7533\u8bf7\u540e\u5b58\u653e\u5230\u5168\u5c40\u53d8\u91cf\u4e2d\uff0c\u5f00\u53d1\u8bf4\u8be5\u5185\u5b58\u4f1a\u4e00\u76f4\u4f7f\u7528\u4e0d\u91ca\u653e\uff0c\u4e0d\u7b97\u6cc4\u6f0f\uff0c\u4f46\u5b9e\u9645\u4e0a\u8be5\u5168\u5c40\u53d8\u91cf\u4f1a\u88ab\u521d\u59cb\u5316\u4e24\u6b21\uff0c\u7b2c\u4e8c\u6b21\u6ca1\u6709\u5224\u65ad\u5168\u5c40\u53d8\u91cf\u662f\u5426\u5df2\u7ecf\u521d\u59cb\u5316\uff0c\u800c\u76f4\u63a5\u8d4b\u6210\u65b0\u7684\u5185\u5b58\u6307\u9488\u503c\uff0c\u5bfc\u81f4\u6cc4\u6f0f\u3002<\/p>\n<p><strong>\u5df2\u77e5ASAN\u5185\u5b58\u6cc4\u6f0f\u8bef\u62a5\u573a\u666f\uff1a<\/strong><\/p>\n<p>1\u3001\u7ed3\u6784\u4f53\u975e4\u5b57\u8282\u5bf9\u9f50\uff1a\u4f8b\u5982\u62a5\u7ed3\u6784\u4f53A\u5185\u5b58\u6cc4\u6f0f\uff0c\u4e14A\u5185\u5b58\u7684\u6307\u9488\u5b58\u653e\u5728\u7ed3\u6784\u4f53B\u4e2d\uff0c\u7531\u4e8eASAN\u626b\u63cf\u5185\u5b58\u65f6\u662f\u63094\u5b57\u8282\u504f\u79fb\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u5982\u679cA\u6307\u9488\u5728\u7ed3\u6784\u4f53B\u4e2d\u7684\u504f\u79fb\u975e4\u7684\u6574\u6570\u500d\uff0cASAN\u5c31\u626b\u4e0d\u5230\uff0c\u51fa\u73b0\u8bef\u62a5\uff08\u4e3b\u5e72\u8981\u6c42\uff1a\u975e4\u5b57\u8282\u5bf9\u9f50\u7684\u7ed3\u6784\u4f53\u9700\u8981\u6574\u6539\uff09\uff1b<\/p>\n<p>2\u3001\u4fe1\u53f7\u6808\u5185\u5b58\uff1a\u8be5\u5185\u5b58\u662f\u5728\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u6267\u884c\u65f6\u505a\u6808\u5185\u5b58\u7528\u7684\uff0c\u5176\u6307\u9488\u4f1a\u4fdd\u5b58\u5230\u5185\u6838\u4e2d\uff0c\u6240\u4ee5ASAN\u626b\u63cf\u4e0d\u5230\uff0c\u4ea7\u751f\u8bef\u62a5\uff1b<\/p>\n<p>3\u3001\u5185\u5b58\u6307\u9488\u504f\u79fb\u540e\u4fdd\u5b58\uff1a\u6709\u5b50\u7cfb\u7edf\u4ee3\u7801\u5b9e\u73b0\u6bd4\u8f83\u7279\u6b8a\uff0c\u5c06\u7533\u8bf7\u7684\u5185\u5b58\u6307\u9488\u505a\u4e00\u4e2a\u5f88\u5927\u7684\u504f\u79fb\uff08\u8d85\u8fc7\u8be5\u5185\u5b58\u7684\u5408\u6cd5\u8303\u56f4\uff09\u64cd\u4f5c\u540e\u4fdd\u5b58\u8d77\u6765\uff0c\u901a\u8fc7\u504f\u79fb\u540e\u7684\u503cASAN\u6839\u672c\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u5185\u5b58\uff0c\u6240\u4ee5\u8bef\u62a5\u6cc4\u6f0f\uff1b<\/p>\n<p>4\u3001\u5b58\u5728ASAN\u672a\u76d1\u63a7\u7684\u5185\u5b58\u63a5\u53e3<\/li>\n<\/ul>\n<p>ASAN\u4f7f\u7528\u8981\u6dfb\u52a0\u7684\u7f16\u8bd1\u9009\u9879<\/p>\n<pre class=\"prettyprint\"><code class=\"has-numbering\">-fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize-recover=all -fno-omit-frame-pointer -fno-stack-protector -fsanitize=leak\r\n\r\nset(CMAKE_C_FLAGS\t\" -m64 -Wno-write-strings -fgnu89-inline -fexceptions  -fno-inline -rdynamic -fsanitize=address -fsanitize-recover=all  -fsanitize=leak\")\r\nset(CMAKE_CXX_FLAGS\t\" -std=c++11 -m64 -Wno-write-strings -fexceptions  -fno-inline -rdynamic -fsanitize=address -fsanitize-recover=all  -fsanitize=leak\")\r\n\r\n-fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize-recover=all -fno-omit-frame-pointer -fno-stack-protector -fsanitize=leak<\/code><\/pre>\n<pre class=\"prettyprint\"><code class=\"has-numbering\"><\/code><\/pre>\n<p>\u66f4\u591a\u5165\u95e8\u8d44\u6599\u53ef\u53c2\u8003<br \/>\nhttps:\/\/bbs.huaweicloud.com\/blogs\/100056<br \/>\nhttps:\/\/www.jianshu.com\/p\/3a2df9b7c353<\/p>\n<\/div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u7248\u6743 C++\/C<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-5633","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5633"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5633\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}