[PATCH] D56672: [HWASAN] Instrument globals

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 17 18:43:06 PST 2019


pcc added a comment.

An alternative idea to ifunc is to compute a tag for each global at compile time and store it in the global's virtual address in the symbol table. Although the tags wouldn't be randomized per run, maybe this would be enough.

You can do this by transforming the globals from:

  @foo = global i32 123

to:

  @foo.data = private global {i32, [12 x i8]} {i32 123, [12 x i8] zeroinitializer}
  @foo = alias inttoptr(add(ptrtoint(@foo.data), 0x4200000000000000))) ; tag is 0x42

To tag the globals at load time, you can create a section of (tagged address, size) pairs. The runtime would tag the range (address, address + size) with the tag (address >> 56). The tagged address could use a 64-bit relative relocation (`R_AARCH64_PREL64` on AArch64 or `R_X86_64_PC64` on x86_64) to avoid needing the section to be dynamically relocated.

One possible downside is that the tagged virtual addresses in the symbol table could confuse tools (e.g. objdump), but we might be able to live with it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56672/new/

https://reviews.llvm.org/D56672





More information about the llvm-commits mailing list