From 8db981d463ee266919907f2554194d05f96f7191 Mon Sep 17 00:00:00 2001 From: Mitch Phillips <31459023+hctim@users.noreply.github.com> Date: Fri, 10 Jun 2022 12:24:36 -0700 Subject: 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 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 9dd2b128..cd253c1 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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 Record) { // v1: [pointer type, isconst, initid, linkage, alignment, section, // visibility, threadlocal, unnamed_addr, externally_initialized, @@ -3544,6 +3557,12 @@ Error BitcodeReader::parseGlobalVarRecord(ArrayRef 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(); } -- cgit v1.1