From d55fc3f151f3167da4aa467cf2ff4038f82e3664 Mon Sep 17 00:00:00 2001 From: Jim Grosbach Date: Tue, 18 Mar 2014 22:09:05 +0000 Subject: Darwin: Add assembler directives to create version-min load commands. Allow object files to be tagged with a version-min load command for iOS or MacOSX. Teach macho-dump to understand the version-min load commands for testcases. rdar://11337778 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204190 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/DarwinAsmParser.cpp | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib/MC/MCParser') diff --git a/lib/MC/MCParser/DarwinAsmParser.cpp b/lib/MC/MCParser/DarwinAsmParser.cpp index 81c2cf021c..dd7eccb237 100644 --- a/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/lib/MC/MCParser/DarwinAsmParser.cpp @@ -163,6 +163,9 @@ public: addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTLV>(".tlv"); addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveIdent>(".ident"); + addDirectiveHandler<&DarwinAsmParser::ParseVersionMin>(".ios_version_min"); + addDirectiveHandler<&DarwinAsmParser::ParseVersionMin>( + ".macosx_version_min"); } bool ParseDirectiveDesc(StringRef, SMLoc); @@ -360,6 +363,7 @@ public: return ParseSectionSwitch("__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS); } + bool ParseVersionMin(StringRef, SMLoc); }; @@ -859,6 +863,50 @@ bool DarwinAsmParser::ParseDirectiveDataRegionEnd(StringRef, SMLoc) { return false; } +/// ParseVersionMin +/// ::= .ios_version_min major,minor[,update] +/// ::= .macosx_version_min major,minor[,update] +bool DarwinAsmParser::ParseVersionMin(StringRef Directive, SMLoc) { + int64_t Major = 0, Minor = 0, Update = 0; + int Kind = StringSwitch(Directive) + .Case(".ios_version_min", MCVM_IOSVersionMin) + .Case(".macosx_version_min", MCVM_OSXVersionMin); + // Get the major version number. + if (getLexer().isNot(AsmToken::Integer)) + return TokError("invalid OS major version number"); + Major = getLexer().getTok().getIntVal(); + if (Major > 65535 || Major <= 0) + return TokError("invalid OS major version number"); + Lex(); + if (getLexer().isNot(AsmToken::Comma)) + return TokError("minor OS version number required, comma expected"); + Lex(); + // Get the minor version number. + if (getLexer().isNot(AsmToken::Integer)) + return TokError("invalid OS minor version number"); + Minor = getLexer().getTok().getIntVal(); + if (Minor > 255 || Minor < 0) + return TokError("invalid OS minor version number"); + Lex(); + // Get the update level, if specified + if (getLexer().isNot(AsmToken::EndOfStatement)) { + if (getLexer().isNot(AsmToken::Comma)) + return TokError("invalid update specifier, comma expected"); + Lex(); + if (getLexer().isNot(AsmToken::Integer)) + return TokError("invalid OS update number"); + Update = getLexer().getTok().getIntVal(); + if (Update > 255 || Update < 0) + return TokError("invalid OS update number"); + Lex(); + } + + // We've parsed a correct version specifier, so send it to the streamer. + getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update); + + return false; +} + namespace llvm { MCAsmParserExtension *createDarwinAsmParser() { -- cgit v1.2.3