<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 24, 2014 at 5:05 PM, Kevin Enderby <span dir="ltr"><<a href="mailto:enderby@apple.com" target="_blank">enderby@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: enderby<br>
Date: Mon Mar 24 19:05:50 2014<br>
New Revision: 204687<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=204687&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=204687&view=rev</a><br>
Log:<br>
Fix crashes when assembler directives are used that are not<br>
for Mach-O object files by generating an error instead.<br>
<br>
rdar://16335232<br>
<br>
Added:<br>
llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s<br>
Modified:<br>
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=204687&r1=204686&r2=204687&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=204687&r1=204686&r2=204687&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Mon Mar 24 19:05:50 2014<br>
@@ -8297,6 +8297,14 @@ bool ARMAsmParser::parseDirectiveUnreq(S<br>
/// parseDirectiveArch<br>
/// ::= .arch token<br>
bool ARMAsmParser::parseDirectiveArch(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".arch directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br></blockquote><div><br></div><div>Is this really the best way to check if the target is MachO? Why not:</div><div><br></div><div> bool IsMachO =</div><div> getContext().getObjectFileInfo()->getObjectFileType() == MCObjectFileInfo::IsMachO;</div>
<div><br></div><div>Using an assembler property as a MachO indicator seems fragile.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
StringRef Arch = getParser().parseStringToEndOfStatement().trim();<br>
<br>
unsigned ID = StringSwitch<unsigned>(Arch)<br>
@@ -8320,9 +8328,16 @@ bool ARMAsmParser::parseDirectiveArch(SM<br>
/// ::= .eabi_attribute int, int [, "str"]<br>
/// ::= .eabi_attribute Tag_name, int [, "str"]<br>
bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".eabi_attribute directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
int64_t Tag;<br>
SMLoc TagLoc;<br>
-<br>
TagLoc = Parser.getTok().getLoc();<br>
if (Parser.getTok().is(AsmToken::Identifier)) {<br>
StringRef Name = Parser.getTok().getIdentifier();<br>
@@ -8426,6 +8441,14 @@ bool ARMAsmParser::parseDirectiveEabiAtt<br>
/// parseDirectiveCPU<br>
/// ::= .cpu str<br>
bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".cpu directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
StringRef CPU = getParser().parseStringToEndOfStatement().trim();<br>
getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);<br>
return false;<br>
@@ -8434,6 +8457,14 @@ bool ARMAsmParser::parseDirectiveCPU(SML<br>
/// parseDirectiveFPU<br>
/// ::= .fpu str<br>
bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".fpu directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
StringRef FPU = getParser().parseStringToEndOfStatement().trim();<br>
<br>
unsigned ID = StringSwitch<unsigned>(FPU)<br>
@@ -8453,6 +8484,14 @@ bool ARMAsmParser::parseDirectiveFPU(SML<br>
/// parseDirectiveFnStart<br>
/// ::= .fnstart<br>
bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".fnstart directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
if (UC.hasFnStart()) {<br>
Error(L, ".fnstart starts before the end of previous one");<br>
UC.emitFnStartLocNotes();<br>
@@ -8732,6 +8771,14 @@ bool ARMAsmParser::parseDirectiveRegSave<br>
/// ::= .inst.n opcode [, ...]<br>
/// ::= .inst.w opcode [, ...]<br>
bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(Loc, ".inst directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
int Width;<br>
<br>
if (isThumb()) {<br>
@@ -8980,6 +9027,14 @@ bool ARMAsmParser::parseDirectiveUnwindR<br>
/// parseDirectiveTLSDescSeq<br>
/// ::= .tlsdescseq tls-variable<br>
bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".tlsdescseq directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
if (getLexer().isNot(AsmToken::Identifier)) {<br>
TokError("expected variable after '.tlsdescseq' directive");<br>
Parser.eatToEndOfStatement();<br>
@@ -9067,6 +9122,14 @@ bool ARMAsmParser::parseDirectiveMovSP(S<br>
/// parseDirectiveObjectArch<br>
/// ::= .object_arch name<br>
bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {<br>
+ const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();<br>
+ bool isMachO = MAI->hasSubsectionsViaSymbols();<br>
+ if (isMachO) {<br>
+ Error(L, ".object_arch directive not valid for Mach-O");<br>
+ Parser.eatToEndOfStatement();<br>
+ return false;<br>
+ }<br>
+<br>
if (getLexer().isNot(AsmToken::Identifier)) {<br>
Error(getLexer().getLoc(), "unexpected token");<br>
Parser.eatToEndOfStatement();<br>
<br>
Added: llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s?rev=204687&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s?rev=204687&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s (added)<br>
+++ llvm/trunk/test/MC/MachO/ARM/bad-darwin-directives.s Mon Mar 24 19:05:50 2014<br>
@@ -0,0 +1,24 @@<br>
+@ RUN: not llvm-mc -n -triple armv7-apple-darwin10 %s -filetype=obj -o - 2> %t.err > %t<br>
+@ RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s<br>
+@ rdar://16335232<br>
+<br>
+.eabi_attribute 8, 1<br>
+@ CHECK-ERROR: error: .eabi_attribute directive not valid for Mach-O<br>
+<br>
+.cpu<br>
+@ CHECK-ERROR: error: .cpu directive not valid for Mach-O<br>
+<br>
+.fpu neon<br>
+@ CHECK-ERROR: error: .fpu directive not valid for Mach-O<br>
+<br>
+.arch armv7<br>
+@ CHECK-ERROR: error: .arch directive not valid for Mach-O<br>
+<br>
+.fnstart<br>
+@ CHECK-ERROR: error: .fnstart directive not valid for Mach-O<br>
+<br>
+.tlsdescseq<br>
+@ CHECK-ERROR: error: .tlsdescseq directive not valid for Mach-O<br>
+<br>
+.object_arch armv7<br>
+@ CHECK-ERROR: error: .object_arch directive not valid for Mach-O<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org
</div></div>