From 41426aed73eb698a7fb28fd12ae6074e4e7a83c6 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Wed, 26 Aug 2015 05:09:49 +0000 Subject: [PATCH] [MC] Split the layout part of MCAssembler::finish() into its own method. NFC. Split a MCAssembler::layout() method out of MCAssembler::finish(). This allows running the MCSections layout separately from the streaming of the output file. This way if a client wants to use MC to generate section contents, but emit something different than the standard relocatable object files it is possible (llvm-dsymutil is such a client). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246008 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 3 +++ lib/MC/MCAssembler.cpp | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 66b5cb9addb..a00b12b9af1 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -747,6 +747,9 @@ public: /// if not specified it is automatically created from backend. void Finish(); + // Layout all section and prepare them for emission. + void layout(MCAsmLayout &Layout); + // FIXME: This does not belong here. bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; } void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; } diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 09a27fec986..3f419b5b1e4 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -852,14 +852,11 @@ std::pair MCAssembler::handleFixup(const MCAsmLayout &Layout, return std::make_pair(FixedValue, IsPCRel); } -void MCAssembler::Finish() { +void MCAssembler::layout(MCAsmLayout &Layout) { DEBUG_WITH_TYPE("mc-dump", { llvm::errs() << "assembler backend - pre-layout\n--\n"; dump(); }); - // Create the layout object. - MCAsmLayout Layout(*this); - // Create dummy fragments and assign section ordinals. unsigned SectionIndex = 0; for (MCSection &Sec : *this) { @@ -896,8 +893,6 @@ void MCAssembler::Finish() { llvm::errs() << "assembler backend - final-layout\n--\n"; dump(); }); - uint64_t StartOffset = OS.tell(); - // Allow the object writer a chance to perform post-layout binding (for // example, to set the index fields in the symbol data). getWriter().executePostLayoutBinding(*this, Layout); @@ -931,6 +926,14 @@ void MCAssembler::Finish() { } } } +} + +void MCAssembler::Finish() { + // Create the layout object. + MCAsmLayout Layout(*this); + layout(Layout); + + uint64_t StartOffset = OS.tell(); // Write the object file. getWriter().writeObject(*this, Layout); -- 2.34.1