Add sanitizer-specific GlobalValue attributes.

Plan is the migrate the global variable metadata for sanitizers, that's
currently carried around generally in the 'llvm.asan.globals' section,
onto the global variable itself.

This patch adds the attribute and plumbs it through the LLVM IR and
bitcode formats, but is a no-op other than that so far.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D126100
This commit is contained in:
Mitch Phillips
2022-06-10 12:24:36 -07:00
parent 0bb317b7bf
commit 8db981d463
12 changed files with 200 additions and 5 deletions

View File

@@ -3441,6 +3441,19 @@ static void inferDSOLocal(GlobalValue *GV) {
GV->setDSOLocal(true);
}
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata(unsigned V) {
GlobalValue::SanitizerMetadata Meta;
if (V & (1 << 0))
Meta.NoAddress = true;
if (V & (1 << 1))
Meta.NoHWAddress = true;
if (V & (1 << 2))
Meta.NoMemtag = true;
if (V & (1 << 3))
Meta.IsDynInit = true;
return Meta;
}
Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) {
// v1: [pointer type, isconst, initid, linkage, alignment, section,
// visibility, threadlocal, unnamed_addr, externally_initialized,
@@ -3544,6 +3557,12 @@ Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) {
if (Record.size() > 15)
NewGV->setPartition(StringRef(Strtab.data() + Record[14], Record[15]));
if (Record.size() > 16 && Record[16] != UINT_MAX) {
llvm::GlobalValue::SanitizerMetadata Meta =
deserializeSanitizerMetadata(Record[16]);
NewGV->setSanitizerMetadata(Meta);
}
return Error::success();
}