[LLVMdev] can GlobalAlias point to a middle of a structure?

Kostya Serebryany kcc at google.com
Fri Jun 17 09:07:40 PDT 2011


Hi,

In order to find out-of-bound accesses to global objects with
AddressSanitizer (
http://code.google.com/p/address-sanitizer/wiki/AddressSanitizer)
I need to create redzones to the left and to the right of every global
variable.

I tried the following:
Before:
  @Extern = global [10 x i8] zeroinitializer, align 1
After:
  %0 = type { [32 x i8], [10 x i8], [54 x i8] }
  @Extern_asan_redzone = global %0 zeroinitializer, align 1
  @0 = global [10 x i8] zeroinitializer, align 1   << the old variable
  @Extern = alias getelementptr inbounds (%0* @Extern_asan_redzone, i32 0,
i32 1)
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.

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

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


  /// global. This method retrives the global for both aliasee flavours.

So, the question: can I get an alias pointing to the middle of a
GlobalVariable? How?
If not, is there some other way to create a left redzone for a global
variable?

Thanks,

--kcc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110617/f42e4591/attachment.html>


More information about the llvm-dev mailing list