[llvm-commits] [PATCH 3/5] Introduce a helper method to add a section to the end of a layout. This will be used by the ELF ObjectWriter code to add the metadata sections (symbol table, etc) to the end of an object file.

Daniel Dunbar daniel at zuster.org
Mon Aug 2 21:56:44 PDT 2010


Hi Matt,

I'm not sure why this needs to exist in the assembler backend -- why
can't the ELF streamer just create the appropriate sections at the end
of assembly?

 - Daniel

On Mon, Jul 26, 2010 at 1:00 PM, Matt Fleming <matt at console-pimps.org> wrote:
> ---
>  include/llvm/MC/MCAssembler.h |    2 ++
>  lib/MC/MCAssembler.cpp        |   34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 0 deletions(-)
>
> diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h
> index c189a1d..89d83ba 100644
> --- a/include/llvm/MC/MCAssembler.h
> +++ b/include/llvm/MC/MCAssembler.h
> @@ -679,6 +679,8 @@ public:
>   void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout,
>                         MCObjectWriter *OW) const;
>
> +  void AddSectionToTheEnd(MCSectionData &SD, MCAsmLayout &Layout);
> +
>  public:
>   /// Construct a new assembler instance.
>   ///
> diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
> index fe55e51..0444dc2 100644
> --- a/lib/MC/MCAssembler.cpp
> +++ b/lib/MC/MCAssembler.cpp
> @@ -649,6 +649,40 @@ void MCAssembler::WriteSectionData(const MCSectionData *SD,
>   assert(OW->getStream().tell() - Start == Layout.getSectionFileSize(SD));
>  }
>
> +void MCAssembler::AddSectionToTheEnd(MCSectionData &SD, MCAsmLayout &Layout) {
> +  // Create dummy fragments and assign section ordinals.
> +  unsigned SectionIndex = 0;
> +  for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it)
> +    SectionIndex++;
> +
> +  SD.setOrdinal(SectionIndex);
> +
> +  // Assign layout order indices to sections and fragments.
> +  unsigned FragmentIndex = 0;
> +  unsigned i = 0;
> +  for (unsigned e = Layout.getSectionOrder().size(); i != e; ++i) {
> +    MCSectionData *SD = Layout.getSectionOrder()[i];
> +
> +    for (MCSectionData::iterator it2 = SD->begin(),
> +           ie2 = SD->end(); it2 != ie2; ++it2)
> +      FragmentIndex++;
> +  }
> +
> +  SD.setLayoutOrder(i);
> +  for (MCSectionData::iterator it2 = SD.begin(),
> +         ie2 = SD.end(); it2 != ie2; ++it2) {
> +    it2->setLayoutOrder(FragmentIndex++);
> +  }
> +  Layout.getSectionOrder().push_back(&SD);
> +
> +  Layout.LayoutSection(&SD);
> +
> +  // Layout until everything fits.
> +  while (LayoutOnce(Layout))
> +    continue;
> +
> +}
> +
>  void MCAssembler::Finish(MCObjectWriter *Writer) {
>   DEBUG_WITH_TYPE("mc-dump", {
>       llvm::errs() << "assembler backend - pre-layout\n--\n";
> --
> 1.6.4.rc0
>
>




More information about the llvm-commits mailing list