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