This patch enables access checks for global variables in HWASAN.
The algorithm is fairly simple:
For each global variable (GV) we can instrument
- Replace it with one aligned to 1 << kDefaultShadowScale
- Generate tag based on global name: hash_value(GV->getName())
- Replace all uses of pointer to this variable with tagged pointer, i.e:
i64 *@foo -> i64* bitcast (i8* getelementptr (i8, i8* bitcast (i64* @foo to i8*), i64 N) to i64*) where N is a tag shifted by 56 bits
Patch adds calls to __hwasan_register_globals and __hwasan_unregister_globals to tag and untag globals memory.
Everything else is handled HWASAN function pass after that.
This "all globals in one" approach breaks -Wl,-gc-sections, which is rather bad for binary size. You need to do the whole comdat + !associated thing, same as ASan.