Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp

Issue 807643002: Don't allow instructions/globals to use alignment > 2**29. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp
diff --git a/lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp b/lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp
index 3f84857feae7e2e8337affef7f6fffabdc09d02b..e3cd46ebbe46af69bd4d87930654d2f2c13276a4 100644
--- a/lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp
+++ b/lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp
@@ -39,6 +39,12 @@ ReportWarningsAsErrors(
cl::desc("Report warnings as errors."),
cl::init(false));
+static cl::opt<bool>
+NoDumpFinalizeRules(
jvoung (off chromium) 2014/12/17 23:36:38 I'm a bit confused about where this is used.
Karl 2014/12/17 23:53:00 One would use this as a command-line argument on a
jvoung (off chromium) 2014/12/18 00:05:40 Hmm but does tool work with non-finalized pexes?
Karl 2014/12/18 16:56:05 You are correct that we require the overall struct
jvoung (off chromium) 2014/12/18 17:10:22 Okay, I see. Yes it's very easy to do a hand-writt
jvoung (off chromium) 2014/12/18 17:18:56 Another way to look at it is the load/store align
Karl 2014/12/18 18:56:19 Renamed to IgnorePNaClABIChecks (cl flag "-ignore-
+ "no-pnacl-dump-finalize-rules",
+ cl::desc("Don't dump finalized-only PNaCl bitcode violations"),
+ cl::init(false));
+
/// Class to handle sign rotations in a human readable form. That is,
/// the sign is in the low bit. The two special cases are:
/// 1) -1 is true for i1.
@@ -942,7 +948,8 @@ public:
// Checks the Alignment for loading/storing a value of type Ty. If
// invalid, generates an appropriate error message.
void VerifyMemoryAccessAlignment(const char *Op, Type *Ty,
- uint64_t Alignment) {
+ unsigned Alignment) {
+ if (NoDumpFinalizeRules) return;
if (!PNaClABIProps::isAllowedAlignment(&DL, Alignment, Ty)) {
if (unsigned Expected = NaClGetExpectedLoadStoreAlignment(DL, Ty)) {
Errors() << Op << ": Illegal alignment for " << *Ty
@@ -2546,6 +2553,11 @@ private:
<< " out of range. Not in [1," << ExpectedNumBbs << "]\n";
}
}
+
+ /// Convert alignment exponent (i.e. power of two (or zero)) to the
+ /// corresponding alignment to use. If alignment is too large, it generates
+ /// an error message and returns 0.
+ unsigned getAlignmentValue(uint64_t Exponent);
};
NaClDisFunctionParser::NaClDisFunctionParser(
@@ -2766,6 +2778,23 @@ const char *NaClDisFunctionParser::GetFcmpPredicate(uint32_t Opcode) {
}
}
+namespace {
+
+static const unsigned MaxAlignmentExponent = 29;
+static_assert(
+ (1u << MaxAlignmentExponent) == Value::MaximumAlignment,
+ "Inconsistency between Value.MaxAlignment and PNaCl alignment limit");
+}
+
+unsigned NaClDisFunctionParser::getAlignmentValue(uint64_t Exponent) {
+ if (Exponent > MaxAlignmentExponent + 1) {
+ Errors() << "Alignment can't be greater than 2**" << MaxAlignmentExponent
+ << ". Found: 2**" << (Exponent - 1) << "\n";
+ return 0;
+ }
+ return (1 << static_cast<unsigned>(Exponent)) >> 1;
+}
+
bool NaClDisFunctionParser::ParseBlock(unsigned BlockID) {
ObjDumpSetRecordBitAddress(GetBlock().GetStartBit());
switch (BlockID) {
@@ -2995,7 +3024,7 @@ void NaClDisFunctionParser::ProcessRecord() {
uint32_t SizeOp = RelativeToAbsId(Values[0]);
Type* SizeType = GetValueType(SizeOp);
BitcodeId SizeId(GetBitcodeId(SizeOp));
- uint64_t Alignment = (1 << Values[1]) >> 1;
+ unsigned Alignment = getAlignmentValue(Values[1]);
if (!PNaClABIProps::isAllocaSizeType(SizeType))
Errors() << PNaClABIProps::ExpectedAllocaSizeType() << "\n";
// TODO(kschimpf) Are there any constraints on alignment?
@@ -3015,7 +3044,7 @@ void NaClDisFunctionParser::ProcessRecord() {
<< Values.size() << "\n";
break;
}
- uint64_t Alignment = (1 << Values[1]) >> 1;
+ unsigned Alignment = getAlignmentValue(Values[1]);
Type *LoadType = GetType(Values[2]);
VerifyScalarOrVectorOp("load", LoadType);
Context->VerifyMemoryAccessAlignment("load", LoadType, Alignment);
@@ -3035,7 +3064,7 @@ void NaClDisFunctionParser::ProcessRecord() {
<< Values.size() << "\n";
break;
}
- uint64_t Alignment = (1 << Values[2]) >> 1;
+ unsigned Alignment = getAlignmentValue(Values[2]);
uint32_t Val = RelativeToAbsId(Values[1]);
Type *ValType = GetValueType(Val);
VerifyScalarOrVectorOp("store", ValType);
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h » ('j') | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698