From 81e911cd868252e2e788ae1b82fb1ac5b56fd1f6 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 9 Mar 2018 03:13:37 +0000 Subject: [PATCH] Don't treat .symver as a regular alias definition. This patch starts simplifying the handling of .symver. For now it just moves the responsibility for creating an alias down to the streamer. With that the asm streamer can pass a .symver unchanged, which is nice since gas cannot parse "foo@bar = zed". In a followup I hope to move the handling down to the writer so that we don't need special hacks for avoiding breaking names with @@@ on windows. llvm-svn: 327101 --- llvm/include/llvm/MC/MCELFStreamer.h | 2 ++ llvm/lib/MC/MCAsmStreamer.cpp | 12 ++++++++++++ llvm/lib/MC/MCELFStreamer.cpp | 6 ++++++ llvm/lib/MC/MCParser/ELFAsmParser.cpp | 3 --- llvm/lib/Object/RecordStreamer.cpp | 2 ++ llvm/test/MC/ARM/comment.s | 6 +++--- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index c5b66a163c85..4b3e6aa215b8 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -51,6 +51,8 @@ public: unsigned ByteAlignment) override; void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override; + void emitELFSymverDirective(MCSymbol *Alias, + const MCSymbol *Aliasee) override; void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index f254cb50b601..1d7aa5a9067c 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -130,6 +130,9 @@ public: void ChangeSection(MCSection *Section, const MCExpr *Subsection) override; + void emitELFSymverDirective(MCSymbol *Alias, + const MCSymbol *Aliasee) override; + void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override; void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; @@ -414,6 +417,15 @@ void MCAsmStreamer::ChangeSection(MCSection *Section, } } +void MCAsmStreamer::emitELFSymverDirective(MCSymbol *Alias, + const MCSymbol *Aliasee) { + OS << ".symver "; + Aliasee->print(OS, MAI); + OS << ", "; + Alias->print(OS, MAI); + EmitEOL(); +} + void MCAsmStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) { MCStreamer::EmitLabel(Symbol, Loc); diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 366125962a5e..646d0dbded41 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -337,6 +337,12 @@ void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) { cast(Symbol)->setSize(Value); } +void MCELFStreamer::emitELFSymverDirective(MCSymbol *Alias, + const MCSymbol *Aliasee) { + const MCExpr *Value = MCSymbolRefExpr::create(Aliasee, getContext()); + EmitAssignment(Alias, Value); +} + void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size, unsigned ByteAlignment) { auto *Symbol = cast(S); diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 59ffd756b2bb..510c456c7751 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -771,9 +771,6 @@ bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) { MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName); MCSymbol *Sym = getContext().getOrCreateSymbol(Name); - const MCExpr *Value = MCSymbolRefExpr::create(Sym, getContext()); - - getStreamer().EmitAssignment(Alias, Value); getStreamer().emitELFSymverDirective(Alias, Sym); return false; } diff --git a/llvm/lib/Object/RecordStreamer.cpp b/llvm/lib/Object/RecordStreamer.cpp index e94e9cfed394..a9e3a46b5199 100644 --- a/llvm/lib/Object/RecordStreamer.cpp +++ b/llvm/lib/Object/RecordStreamer.cpp @@ -114,5 +114,7 @@ void RecordStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, void RecordStreamer::emitELFSymverDirective(MCSymbol *Alias, const MCSymbol *Aliasee) { + const MCExpr *Value = MCSymbolRefExpr::create(Aliasee, getContext()); + EmitAssignment(Alias, Value); SymverAliasMap[Aliasee].push_back(Alias); } diff --git a/llvm/test/MC/ARM/comment.s b/llvm/test/MC/ARM/comment.s index c24bc1aaa406..7187683a85bd 100644 --- a/llvm/test/MC/ARM/comment.s +++ b/llvm/test/MC/ARM/comment.s @@ -34,9 +34,9 @@ far: @CHECK-NOT: @ @CHECK-LABEL: bar: -@CHECK: bar1@zed = defined1 -@CHECK: bar3@@zed = defined2 -@CHECK: bar5@@@zed = defined3 +@CHECK: .symver defined1, bar1@zed +@CHECK: .symver defined2, bar3@@zed +@CHECK: .symver defined3, bar5@@@zed @ Make sure we did not mess up the parser state and it still lexes @ comments correctly by excluding the @ in normal symbols