//===----------------------------------------------------------------------===//
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
#include "llvm/MC/MCSectionMachO.h"
unsigned TAA = 0, unsigned ImplicitAlign = 0,
unsigned StubSize = 0);
+ SMLoc LastVersionMinDirective;
+
public:
DarwinAsmParser() {}
addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv");
addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident");
+ addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
+ ".watchos_version_min");
+ addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".tvos_version_min");
addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".ios_version_min");
addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
".macosx_version_min");
+
+ LastVersionMinDirective = SMLoc();
}
bool parseDirectiveDesc(StringRef, SMLoc);
// FIXME: Arch specific.
bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS;
getStreamer().SwitchSection(getContext().getMachOSection(
- Segment, Section, TAA, StubSize,
- isText ? SectionKind::getText()
- : SectionKind::getDataRel()));
+ Segment, Section, TAA, StubSize,
+ isText ? SectionKind::getText() : SectionKind::getData()));
// Set the implicit alignment, if any.
//
return TokError("expected identifier in directive");
// Handle the identifier as the key symbol.
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in '.desc' directive");
if (getParser().parseIdentifier(Name))
return TokError("expected identifier in .indirect_symbol directive");
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
// Assembler local symbols don't make any sense here. Complain loudly.
if (Sym->isTemporary())
return TokError("expected identifier in directive");
// Handle the identifier as the key symbol.
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in '.lsym' directive");
if (!ErrorStr.empty())
return Error(Loc, ErrorStr.c_str());
+ // Issue a warning if the target is not powerpc and Section is a *coal* section.
+ Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();
+ Triple::ArchType ArchTy = TT.getArch();
+
+ if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
+ StringRef NonCoalSection = StringSwitch<StringRef>(Section)
+ .Case("__textcoal_nt", "__text")
+ .Case("__const_coal", "__const")
+ .Case("__datacoal_nt", "__data")
+ .Default(Section);
+
+ if (!Section.equals(NonCoalSection)) {
+ StringRef SectionVal(Loc.getPointer());
+ size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
+ SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
+ SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
+ getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
+ SMRange(BLoc, ELoc));
+ getParser().Note(Loc, "change section name to \"" + NonCoalSection +
+ "\"", SMRange(BLoc, ELoc));
+ }
+ }
+
// FIXME: Arch specific.
bool isText = Segment == "__TEXT"; // FIXME: Hack.
getStreamer().SwitchSection(getContext().getMachOSection(
- Segment, Section, TAA, StubSize,
- isText ? SectionKind::getText()
- : SectionKind::getDataRel()));
+ Segment, Section, TAA, StubSize,
+ isText ? SectionKind::getText() : SectionKind::getData()));
return false;
}
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.secure_log_unique' directive");
- if (getContext().getSecureLogUsed() != false)
+ if (getContext().getSecureLogUsed())
return Error(IDLoc, ".secure_log_unique specified multiple times");
// Get the secure log path.
"environment variable unset.");
// Open the secure log file if we haven't already.
- raw_ostream *OS = getContext().getSecureLog();
+ raw_fd_ostream *OS = getContext().getSecureLog();
if (!OS) {
- std::string Err;
- OS = new raw_fd_ostream(SecureLogFile, Err,
- sys::fs::F_Append | sys::fs::F_Text);
- if (!Err.empty()) {
- delete OS;
+ std::error_code EC;
+ auto NewOS = llvm::make_unique<raw_fd_ostream>(
+ SecureLogFile, EC, sys::fs::F_Append | sys::fs::F_Text);
+ if (EC)
return Error(IDLoc, Twine("can't open secure log file: ") +
- SecureLogFile + " (" + Err + ")");
- }
- getContext().setSecureLog(OS);
+ SecureLogFile + " (" + EC.message() + ")");
+ OS = NewOS.get();
+ getContext().setSecureLog(std::move(NewOS));
}
// Write the message.
return TokError("expected identifier in directive");
// Handle the identifier as the key symbol.
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
- MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(IDStr);
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
/// parseVersionMin
/// ::= .ios_version_min major,minor[,update]
/// ::= .macosx_version_min major,minor[,update]
-bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc) {
+bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc) {
int64_t Major = 0, Minor = 0, Update = 0;
int Kind = StringSwitch<int>(Directive)
+ .Case(".watchos_version_min", MCVM_WatchOSVersionMin)
+ .Case(".tvos_version_min", MCVM_TvOSVersionMin)
.Case(".ios_version_min", MCVM_IOSVersionMin)
.Case(".macosx_version_min", MCVM_OSXVersionMin);
// Get the major version number.
Lex();
}
+ const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
+ Triple::OSType ExpectedOS = Triple::UnknownOS;
+ switch ((MCVersionMinType)Kind) {
+ case MCVM_WatchOSVersionMin: ExpectedOS = Triple::WatchOS; break;
+ case MCVM_TvOSVersionMin: ExpectedOS = Triple::TvOS; break;
+ case MCVM_IOSVersionMin: ExpectedOS = Triple::IOS; break;
+ case MCVM_OSXVersionMin: ExpectedOS = Triple::MacOSX; break;
+ }
+ if (T.getOS() != ExpectedOS)
+ Warning(Loc, Directive + " should only be used for " +
+ Triple::getOSTypeName(ExpectedOS) + " targets");
+
+ if (LastVersionMinDirective.isValid()) {
+ Warning(Loc, "overriding previous version_min directive");
+ Note(LastVersionMinDirective, "previous definition is here");
+ }
+ LastVersionMinDirective = Loc;
+
// We've parsed a correct version specifier, so send it to the streamer.
getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update);