<div dir="ltr"><div>Hi Kyle,</div><div><br></div>ASAN inserts redzones (padding) between C/C++ globals in order to detect global buffer overflow. <div>If you are playing tricks with globals -- all bets are off. </div><div>I am not familiar with "linker sets" so can't comment on the specific problem. </div><div>You probably need to make sure that your globals are not instrumented by ASAN (have them in an assembler file, or in a .c file that is not asan-ified)</div><div><br></div><div>--kcc </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 5, 2015 at 10:06 AM, Kyle Manna via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi guys,<div><br>I started playing around with Clang's address sanitizer on a project that uses linker sets to to store an array of structs in a linker section.</div><div><br></div><div>The code runs fine on clang, but when I pass '-fsanitize=address' it breaks.  The spacing between the structs doubles.  Readelf reports an alignment of 32 (vs 8, sizeof(struct) is actually 32 bytes).</div><div><br></div><div><div>Clang's docs warn that "AddressSanitizer is not expected to produce false positives"<br></div><div>(ref: <a href="http://clang.llvm.org/docs/AddressSanitizer.html#issue-suppression" target="_blank">http://clang.llvm.org/docs/AddressSanitizer.html#issue-suppression</a>).  Am I making a bad assumption regarding the layout of linker sections?</div></div><div><br></div><div><div>I have a simple GitHub project that reproduces the problem as well as a travis-ci build that repeats the same result:</div><div>* <a href="https://github.com/kylemanna/cmocka-init" target="_blank">https://github.com/kylemanna/cmocka-init</a><br></div><div>* <a href="https://travis-ci.org/kylemanna/cmocka-init/builds" target="_blank">https://travis-ci.org/kylemanna/cmocka-init/builds</a></div></div><div><br></div><div><br></div><div>With clang -fsanitize=address:</div><div><br></div><div>$ nm -n ./alignment</div><div>...</div><div><div>000000000070ac40 D __start_cmocka_init</div><div>000000000070ac40 D test_Simple_Init</div><div>000000000070ac80 D test_Simple_Life</div><div>000000000070acc0 D test_Test0</div><div>000000000070ad00 D test_Test1</div><div>000000000070ad40 D __stop_cmocka_init</div></div><div><br></div><div>$ readelf -S ./alignment</div><div><div>  [27] cmocka_init       PROGBITS         000000000070ac40  0010ac40</div><div>       0000000000000100  0000000000000000  WA       0     0     32</div></div><div><br></div><div>Note the alignment = 32.</div><div><br></div><div><br></div><div>Without clang -fsanitize=address:</div><div><div><br></div><div><div>$ nm -n ./alignment</div><div>...</div></div><div>0000000000609800 D __start_cmocka_init</div><div>0000000000609800 D test_Simple_Init</div><div>0000000000609820 D test_Simple_Life</div><div>0000000000609840 D test_Test0</div><div>0000000000609860 D test_Test1</div><div>0000000000609880 D __stop_cmocka_init</div></div><div><br>$ readelf -S ./alignment<br></div><div><div>  [25] cmocka_init       PROGBITS         0000000000609800  00009800</div><div>       0000000000000080  0000000000000000  WA       0     0     8</div></div><div><br></div><div>Also, gcc's address sanitizer doesn't appear to do anything.  It ignores intentional issues (i.e. overflow) but also doesn't change the alignment.</div><div><br></div><div><br></div><div>- Kyle</div><div hspace="streak-pt-mark" style="max-height:1px"><img style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aMmJsdWVzY0BnbWFpbC5jb20%3D&type=zerocontent&guid=3e1971ab-c0aa-41a3-bd16-181b171e3a61"><font color="#ffffff" size="1">ᐧ</font></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>