aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorMitch Phillips <31459023+hctim@users.noreply.github.com>2022-06-10 12:24:36 -0700
committerMitch Phillips <31459023+hctim@users.noreply.github.com>2022-06-10 12:28:18 -0700
commit8db981d463ee266919907f2554194d05f96f7191 (patch)
tree6459225d9ce90dcad0e74fa605ee240d53ec6f4f /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parent0bb317b7bff3d4f70bddd03a1f337c3f2a118943 (diff)
downloadllvm-8db981d463ee266919907f2554194d05f96f7191.zip
llvm-8db981d463ee266919907f2554194d05f96f7191.tar.gz
llvm-8db981d463ee266919907f2554194d05f96f7191.tar.bz2
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
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 4e1729f..691b332 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1223,6 +1223,14 @@ static StringEncoding getStringEncoding(StringRef Str) {
return SE_Fixed7;
}
+static_assert(sizeof(GlobalValue::SanitizerMetadata) <= sizeof(unsigned),
+ "Sanitizer Metadata is too large for naive serialization.");
+static unsigned
+serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
+ return Meta.NoAddress | (Meta.NoHWAddress << 1) |
+ (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3);
+}
+
/// Emit top-level description of module, including target triple, inline asm,
/// descriptors for global variables, and function prototype info.
/// Returns the bit offset to backpatch with the location of the real VST.
@@ -1346,7 +1354,7 @@ void ModuleBitcodeWriter::writeModuleInfo() {
// GLOBALVAR: [strtab offset, strtab size, type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal,
// unnamed_addr, externally_initialized, dllstorageclass,
- // comdat, attributes, DSO_Local]
+ // comdat, attributes, DSO_Local, GlobalSanitizer]
Vals.push_back(addToStrtab(GV.getName()));
Vals.push_back(GV.getName().size());
Vals.push_back(VE.getTypeID(GV.getValueType()));
@@ -1363,7 +1371,7 @@ void ModuleBitcodeWriter::writeModuleInfo() {
GV.isExternallyInitialized() ||
GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass ||
GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
- GV.hasPartition()) {
+ GV.hasPartition() || GV.hasSanitizerMetadata()) {
Vals.push_back(getEncodedVisibility(GV));
Vals.push_back(getEncodedThreadLocalMode(GV));
Vals.push_back(getEncodedUnnamedAddr(GV));
@@ -1377,6 +1385,11 @@ void ModuleBitcodeWriter::writeModuleInfo() {
Vals.push_back(GV.isDSOLocal());
Vals.push_back(addToStrtab(GV.getPartition()));
Vals.push_back(GV.getPartition().size());
+
+ if (GV.hasSanitizerMetadata())
+ Vals.push_back(serializeSanitizerMetadata(GV.getSanitizerMetadata()));
+ else
+ Vals.push_back(UINT_MAX);
} else {
AbbrevToUse = SimpleGVarAbbrev;
}