diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCContext.cpp | 7 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 63 |
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 53ffc94..2044a93 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -27,6 +27,10 @@ MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0) { MachOUniquingMap = 0; ELFUniquingMap = 0; COFFUniquingMap = 0; + + SecureLogFile = getenv("AS_SECURE_LOG_FILE"); + SecureLog = 0; + SecureLogUsed = false; } MCContext::~MCContext() { @@ -37,6 +41,9 @@ MCContext::~MCContext() { delete (MachOUniqueMapTy*)MachOUniquingMap; delete (ELFUniqueMapTy*)ELFUniquingMap; delete (COFFUniqueMapTy*)COFFUniquingMap; + + // If the stream for the .secure_log_unique directive was created free it. + delete (raw_ostream*)SecureLog; } //===----------------------------------------------------------------------===// diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 4523eab..dea71dd 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -24,6 +24,7 @@ #include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetAsmParser.h" using namespace llvm; @@ -780,6 +781,10 @@ bool AsmParser::ParseStatement() { return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsDump=*/true); if (IDVal == ".load") return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false); + if (IDVal == ".secure_log_unique") + return ParseDirectiveDarwinSecureLogUnique(IDLoc); + if (IDVal == ".secure_log_reset") + return ParseDirectiveDarwinSecureLogReset(IDLoc); // Look up the handler in the handler table, bool(AsmParser::*Handler)(StringRef, SMLoc) = DirectiveMap[IDVal]; @@ -1735,6 +1740,64 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { return false; } +/// ParseDirectiveDarwinSecureLogUnique +/// ::= .secure_log_unique "log message" +bool AsmParser::ParseDirectiveDarwinSecureLogUnique(SMLoc IDLoc) { + std::string LogMessage; + + if (Lexer.isNot(AsmToken::String)) + LogMessage = ""; + else{ + LogMessage = getTok().getString(); + Lex(); + } + + if (Lexer.isNot(AsmToken::EndOfStatement)) + return TokError("unexpected token in '.secure_log_unique' directive"); + + if (getContext().getSecureLogUsed() != false) + return Error(IDLoc, ".secure_log_unique specified multiple times"); + + char *SecureLogFile = getContext().getSecureLogFile(); + if (SecureLogFile == NULL) + return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE " + "environment variable unset."); + + raw_ostream *OS = getContext().getSecureLog(); + if (OS == NULL) { + std::string Err; + OS = new raw_fd_ostream(SecureLogFile, Err, raw_fd_ostream::F_Append); + if (!Err.empty()) { + delete OS; + return Error(IDLoc, Twine("can't open secure log file: ") + + SecureLogFile + " (" + Err + ")"); + } + getContext().setSecureLog(OS); + } + + int CurBuf = SrcMgr.FindBufferContainingLoc(IDLoc); + *OS << SrcMgr.getBufferInfo(CurBuf).Buffer->getBufferIdentifier() << ":" + << SrcMgr.FindLineNumber(IDLoc, CurBuf) << ":" + << LogMessage + "\n"; + + getContext().setSecureLogUsed(true); + + return false; +} + +/// ParseDirectiveDarwinSecureLogReset +/// ::= .secure_log_reset +bool AsmParser::ParseDirectiveDarwinSecureLogReset(SMLoc IDLoc) { + if (Lexer.isNot(AsmToken::EndOfStatement)) + return TokError("unexpected token in '.secure_log_reset' directive"); + + Lex(); + + getContext().setSecureLogUsed(false); + + return false; +} + /// ParseDirectiveIf /// ::= .if expression bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) { |