I'll step forward as the person who told Kostya he could use aliases like this. :-)<div><br></div><div>The verifier doesn't forbid it, so I concluded that it was okay. However, looking back at the history it's clear that was a mistake:</div>

<div><br></div>> r70079 | lattner | 2009-04-25 14:23:19 -0700 (Sat, 25 Apr 2009) | 8 lines<br>> <br>> Allow aliasee to be a GEP or bitcast instead of just a bitcast.<br>> The real fix for this whole mess is to require the operand of the<br>

> alias to be a *GlobalValue* (not a general constant, including <br>> constant exprs) but allow the operand and the alias type to be<br><div><div>> unrelated.</div></div><div><br></div><div>So it seems that making an alias to the middle of something else is not actually supported. Sorry.</div>

<div><br></div><div>I have a partial fix. You can replace global @foo with a new @foo.safe of a different type as you do now, then replace all uses of the original GlobalValue with a GEP constant expression. (Well, all uses except GlobalAlias uses.) The problem with this technique is that you'll lose the ability to share those globals by name with external (library) users. That should only be a real problem for ASAN compiled plugins which get dlopen()'d.</div>

<div><br></div><div>Nick</div><div><br><div class="gmail_quote">On 17 June 2011 09:07, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi, <div><br></div><div>In order to find out-of-bound accesses to global objects with AddressSanitizer (<a href="http://code.google.com/p/address-sanitizer/wiki/AddressSanitizer" target="_blank">http://code.google.com/p/address-sanitizer/wiki/AddressSanitizer</a>)</div>



<div>I need to create redzones to the left and to the right of every global variable. </div><div><br></div><div>I tried the following:</div><div>Before: </div><div><div>  @Extern = global [10 x i8] zeroinitializer, align 1</div>


</div><div>After: </div><div><div>  %0 = type { [32 x i8], [10 x i8], [54 x i8] }</div></div><div>  @Extern_asan_redzone = global %0 zeroinitializer, align 1</div><div><div>  @0 = global [10 x i8] zeroinitializer, align 1   << the old variable</div>


<div>  @Extern = alias getelementptr inbounds (%0* @Extern_asan_redzone, i32 0, i32 1)</div></div><div>I.e. I created a global struct @Extern_asan_redzone of 3 elements and an alias @Extern that points to the middle element of this struct. </div>


<div><br></div><div>The compilation passes, but the resulting object looks like this: </div><div><div>  000000000060d150 B Extern</div><div>  000000000060d150 B Extern_asan_redzone</div></div><div>I.e. @Extern points to the beginning of @Extern_asan_redzone instead of middle. </div>


<div><br></div><div>Also, the comment in GlobalAlias.h says: </div><div><div>  /// getAliasedGlobal() - Aliasee can be either global or bitcast of                                                                                                                               </div>


<div>  /// global. This method retrives the global for both aliasee flavours.</div></div><div><br></div><div>So, the question: can I get an alias pointing to the middle of a GlobalVariable? How?</div><div>If not, is there some other way to create a left redzone for a global variable?</div>


<div><br></div><div>Thanks, </div><div><br></div><div>--kcc </div><div><br></div><div><br>
</div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>