From 9b1cbb8f4a26f862c5805322a8581e30372da0e3 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Fri, 16 Nov 2018 09:50:24 +0000 Subject: [PATCH] [MSP430] Add support for .refsym directive Introduces support for '.refsym' assembler directive. From GCC docs (for MSP430): '.refsym' - This directive instructs assembler to add an undefined reference to the symbol following the directive. No relocation is created for this symbol; it will exist purely for pulling in object files from archives. Patch by Kristina Bessonova! Differential Revision: https://reviews.llvm.org/D54618 llvm-svn: 347041 --- lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp | 13 +++++++++++++ test/MC/MSP430/refsym.s | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/MC/MSP430/refsym.s diff --git a/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp b/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp index 51b6918105e..3cc6da2c21a 100644 --- a/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp +++ b/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp @@ -51,6 +51,7 @@ class MSP430AsmParser : public MCTargetAsmParser { SMLoc NameLoc, OperandVector &Operands) override; bool ParseDirective(AsmToken DirectiveID) override; + bool ParseDirectiveRefSym(AsmToken DirectiveID); unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, unsigned Kind) override; @@ -407,6 +408,16 @@ bool MSP430AsmParser::ParseInstruction(ParseInstructionInfo &Info, return false; } +bool MSP430AsmParser::ParseDirectiveRefSym(AsmToken DirectiveID) { + StringRef Name; + if (getParser().parseIdentifier(Name)) + return TokError("expected identifier in directive"); + + MCSymbol *Sym = getContext().getOrCreateSymbol(Name); + getStreamer().EmitSymbolAttribute(Sym, MCSA_Global); + return false; +} + bool MSP430AsmParser::ParseDirective(AsmToken DirectiveID) { StringRef IDVal = DirectiveID.getIdentifier(); if (IDVal.lower() == ".long") { @@ -415,6 +426,8 @@ bool MSP430AsmParser::ParseDirective(AsmToken DirectiveID) { ParseLiteralValues(2, DirectiveID.getLoc()); } else if (IDVal.lower() == ".byte") { ParseLiteralValues(1, DirectiveID.getLoc()); + } else if (IDVal.lower() == ".refsym") { + return ParseDirectiveRefSym(DirectiveID); } return true; } diff --git a/test/MC/MSP430/refsym.s b/test/MC/MSP430/refsym.s new file mode 100644 index 00000000000..684894ca992 --- /dev/null +++ b/test/MC/MSP430/refsym.s @@ -0,0 +1,14 @@ +# RUN: llvm-mc -filetype=obj -triple=msp430 %s | llvm-readobj -t - | FileCheck %s + +foo: + .refsym __hook + +; CHECK: Symbol { +; CHECK: Name: __hook (30) +; CHECK-NEXT: Value: 0x0 +; CHECK-NEXT: Size: 0 +; CHECK-NEXT: Binding: Global (0x1) +; CHECK-NEXT: Type: None (0x0) +; CHECK-NEXT: Other: 0 +; CHECK-NEXT: Section: Undefined (0x0) +; CHECK-NEXT: }