From 5b75fd9e56def2c63c1e3150e48e28a15c2af8f7 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 3 Mar 2017 21:22:06 +0000 Subject: [PATCH] MC: De-duplicate the object streamer implementations of EmitFileDirective into MCObjectStreamer. NFCI. llvm-svn: 296912 --- llvm/include/llvm/MC/MCELFStreamer.h | 2 -- llvm/include/llvm/MC/MCObjectStreamer.h | 1 + llvm/include/llvm/MC/MCWasmStreamer.h | 2 -- llvm/include/llvm/MC/MCWinCOFFStreamer.h | 1 - llvm/lib/MC/ELFObjectWriter.cpp | 2 ++ llvm/lib/MC/MCELFStreamer.cpp | 7 ------- llvm/lib/MC/MCMachOStreamer.cpp | 7 ------- llvm/lib/MC/MCObjectStreamer.cpp | 4 ++++ llvm/lib/MC/MCWasmStreamer.cpp | 7 ------- llvm/lib/MC/WinCOFFStreamer.cpp | 4 ---- 10 files changed, 7 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 6552b52712ae..ea9ade459e07 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -62,8 +62,6 @@ public: void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc()) override; - void EmitFileDirective(StringRef Filename) override; - void EmitIdent(StringRef IdentString) override; void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override; diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 94e8f177fff7..978a24095267 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -152,6 +152,7 @@ public: SMLoc Loc = SMLoc()) override; void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr, SMLoc Loc = SMLoc()) override; + void EmitFileDirective(StringRef Filename) override; void FinishImpl() override; diff --git a/llvm/include/llvm/MC/MCWasmStreamer.h b/llvm/include/llvm/MC/MCWasmStreamer.h index 64d4fbee4b0e..bdd6f103cd44 100644 --- a/llvm/include/llvm/MC/MCWasmStreamer.h +++ b/llvm/include/llvm/MC/MCWasmStreamer.h @@ -62,8 +62,6 @@ public: void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc()) override; - void EmitFileDirective(StringRef Filename) override; - void EmitIdent(StringRef IdentString) override; void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override; diff --git a/llvm/include/llvm/MC/MCWinCOFFStreamer.h b/llvm/include/llvm/MC/MCWinCOFFStreamer.h index d7e6271de5fc..84e60b85be6a 100644 --- a/llvm/include/llvm/MC/MCWinCOFFStreamer.h +++ b/llvm/include/llvm/MC/MCWinCOFFStreamer.h @@ -60,7 +60,6 @@ public: unsigned ByteAlignment) override; void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; - void EmitFileDirective(StringRef Filename) override; void EmitIdent(StringRef IdentString) override; void EmitWinEHHandlerData() override; void FinishImpl() override; diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index e56c9cb991e3..b84ae5bad1c6 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -902,6 +902,8 @@ void ELFObjectWriter::computeSymbolTable( StrTabBuilder.finalize(); + // File symbols are emitted first and handled separately from normal symbols, + // i.e. a non-STT_FILE symbol with the same name may appear. for (const std::string &Name : FileNames) Writer.writeSymbol(StrTabBuilder.getOffset(Name), ELF::STT_FILE | ELF::STB_LOCAL, 0, 0, ELF::STV_DEFAULT, diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 172440080ea3..0c786b2d0e9e 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -348,13 +348,6 @@ void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment, ValueSize, MaxBytesToEmit); } -// Add a symbol for the file name of this module. They start after the -// null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol -// with the same name may appear. -void MCELFStreamer::EmitFileDirective(StringRef Filename) { - getAssembler().addFileName(Filename); -} - void MCELFStreamer::EmitIdent(StringRef IdentString) { MCSection *Comment = getAssembler().getContext().getELFSection( ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, ""); diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 3ed89c4cccd3..2001e3e3aeaa 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -99,13 +99,6 @@ public: void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment = 0) override; - void EmitFileDirective(StringRef Filename) override { - // FIXME: Just ignore the .file; it isn't important enough to fail the - // entire assembly. - - // report_fatal_error("unsupported directive: '.file'"); - } - void EmitIdent(StringRef IdentString) override { llvm_unreachable("macho doesn't support this directive"); } diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 19269f880a41..2b89407547a4 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -572,6 +572,10 @@ void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size, MCStreamer::emitFill(IntNumValues, Size, Expr); } +void MCObjectStreamer::EmitFileDirective(StringRef Filename) { + getAssembler().addFileName(Filename); +} + void MCObjectStreamer::FinishImpl() { // If we are generating dwarf for assembly source files dump out the sections. if (getContext().getGenDwarfForAssembly()) diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp index 708050b399b2..59b62b8d37c3 100644 --- a/llvm/lib/MC/MCWasmStreamer.cpp +++ b/llvm/lib/MC/MCWasmStreamer.cpp @@ -142,13 +142,6 @@ void MCWasmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, MaxBytesToEmit); } -// Add a symbol for the file name of this module. They start after the -// null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol -// with the same name may appear. -void MCWasmStreamer::EmitFileDirective(StringRef Filename) { - getAssembler().addFileName(Filename); -} - void MCWasmStreamer::EmitIdent(StringRef IdentString) { MCSection *Comment = getAssembler().getContext().getWasmSection( ".comment", 0, 0); diff --git a/llvm/lib/MC/WinCOFFStreamer.cpp b/llvm/lib/MC/WinCOFFStreamer.cpp index 2e75b5f131d5..c26d87f36f83 100644 --- a/llvm/lib/MC/WinCOFFStreamer.cpp +++ b/llvm/lib/MC/WinCOFFStreamer.cpp @@ -278,10 +278,6 @@ void MCWinCOFFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, llvm_unreachable("not implemented"); } -void MCWinCOFFStreamer::EmitFileDirective(StringRef Filename) { - getAssembler().addFileName(Filename); -} - // TODO: Implement this if you want to emit .comment section in COFF obj files. void MCWinCOFFStreamer::EmitIdent(StringRef IdentString) { llvm_unreachable("not implemented");