[lld] r234065 - [ELF] Merge Layout and TargetLayout class
Simon Atanasyan
simon at atanasyan.com
Fri Apr 3 16:07:13 PDT 2015
Author: atanasyan
Date: Fri Apr 3 18:07:13 2015
New Revision: 234065
URL: http://llvm.org/viewvc/llvm-project?rev=234065&view=rev
Log:
[ELF] Merge Layout and TargetLayout class
It is enough to have single TargetLayout class.
Removed:
lld/trunk/lib/ReaderWriter/ELF/Layout.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Fri Apr 3 18:07:13 2015
@@ -35,8 +35,9 @@ public:
}
/// \brief Return the section order for a input section
- Layout::SectionOrder getSectionOrder(
- StringRef name, int32_t contentType, int32_t contentPermissions) override {
+ typename TargetLayout<HexagonELFType>::SectionOrder
+ getSectionOrder(StringRef name, int32_t contentType,
+ int32_t contentPermissions) override {
if ((contentType == DefinedAtom::typeDataFast) ||
(contentType == DefinedAtom::typeZeroFillFast))
return ORDER_SDATA;
@@ -61,7 +62,8 @@ public:
AtomSection<HexagonELFType> *
createSection(StringRef name, int32_t contentType,
DefinedAtom::ContentPermissions contentPermissions,
- Layout::SectionOrder sectionOrder) override {
+ typename TargetLayout<HexagonELFType>::SectionOrder
+ sectionOrder) override {
if ((contentType == DefinedAtom::typeDataFast) ||
(contentType == DefinedAtom::typeZeroFillFast))
return _sdataSection;
@@ -70,7 +72,7 @@ public:
}
/// \brief get the segment type for the section thats defined by the target
- Layout::SegmentType
+ typename TargetLayout<HexagonELFType>::SegmentType
getSegmentType(Section<HexagonELFType> *section) const override {
if (section->order() == ORDER_SDATA)
return PT_LOAD;
Removed: lld/trunk/lib/ReaderWriter/ELF/Layout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Layout.h?rev=234064&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Layout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Layout.h (removed)
@@ -1,60 +0,0 @@
-//===- lib/ReaderWriter/ELF/Layout.h --------------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_LAYOUT_H
-#define LLD_READER_WRITER_ELF_LAYOUT_H
-
-#include "lld/Core/DefinedAtom.h"
-#include "lld/ReaderWriter/AtomLayout.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/ErrorOr.h"
-
-namespace lld {
-namespace elf {
-
-/// \brief The Layout is an abstract class for managing the final layout for
-/// the kind of binaries(Shared Libraries / Relocatables / Executables 0
-/// Each architecture (Hexagon, MIPS) would have a concrete
-/// subclass derived from Layout for generating each binary thats
-/// needed by the lld linker
-class Layout {
-public:
- typedef uint32_t SectionOrder;
- typedef uint32_t SegmentType;
- typedef uint32_t Flags;
-
- virtual ~Layout() {}
-
- /// Return the order the section would appear in the output file
- virtual SectionOrder getSectionOrder(StringRef name, int32_t contentType,
- int32_t contentPerm) = 0;
-
- /// \brief Append the Atom to the layout and create appropriate sections.
- /// \returns A reference to the atom layout or an error. The atom layout will
- /// be updated as linking progresses.
- virtual ErrorOr<const lld::AtomLayout *> addAtom(const Atom *atom) = 0;
-
- /// find the Atom in the current layout
- virtual const AtomLayout *findAtomLayoutByName(StringRef name) const = 0;
-
- /// associates a section to a segment
- virtual void assignSectionsToSegments() = 0;
-
- /// associates a virtual address to the segment, section, and the atom
- virtual void assignVirtualAddress() = 0;
-};
-
-} // end namespace elf
-} // end namespace lld
-
-#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Fri Apr 3 18:07:13 2015
@@ -32,9 +32,10 @@ public:
const MipsGOTSection<ELFT> &getGOTSection() const { return *_gotSection; }
const MipsPLTSection<ELFT> &getPLTSection() const { return *_pltSection; }
- AtomSection<ELFT> *createSection(StringRef name, int32_t type,
- DefinedAtom::ContentPermissions permissions,
- Layout::SectionOrder order) override {
+ AtomSection<ELFT> *
+ createSection(StringRef name, int32_t type,
+ DefinedAtom::ContentPermissions permissions,
+ typename TargetLayout<ELFT>::SectionOrder order) override {
if (type == DefinedAtom::typeGOT && name == ".got")
return _gotSection;
if (type == DefinedAtom::typeStub && name == ".plt")
@@ -60,8 +61,9 @@ public:
}
/// \brief Return the section order for a input section
- Layout::SectionOrder getSectionOrder(StringRef name, int32_t contentType,
- int32_t contentPermissions) override {
+ typename TargetLayout<ELFT>::SectionOrder
+ getSectionOrder(StringRef name, int32_t contentType,
+ int32_t contentPermissions) override {
if ((contentType == DefinedAtom::typeStub) && (name.startswith(".text")))
return TargetLayout<ELFT>::ORDER_TEXT;
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Fri Apr 3 18:07:13 2015
@@ -11,12 +11,12 @@
#define LLD_READER_WRITER_ELF_SECTION_CHUNKS_H
#include "Chunk.h"
-#include "Layout.h"
#include "TargetHandler.h"
#include "Writer.h"
#include "lld/Core/DefinedAtom.h"
#include "lld/Core/Parallel.h"
#include "lld/Core/range.h"
+#include "lld/ReaderWriter/AtomLayout.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
@@ -35,6 +35,7 @@ namespace elf {
template <class> class OutputSection;
using namespace llvm::ELF;
template <class ELFT> class Segment;
+template <class ELFT> class TargetLayout;
/// \brief An ELF section.
template <class ELFT> class Section : public Chunk<ELFT> {
@@ -67,7 +68,9 @@ public:
uint32_t getType() const { return _type; }
uint32_t getLink() const { return _link; }
uint32_t getInfo() const { return _info; }
- Layout::SegmentType getSegmentType() const { return _segmentType; }
+ typename TargetLayout<ELFT>::SegmentType getSegmentType() const {
+ return _segmentType;
+ }
/// \brief Return the type of content that the section contains
virtual int getContentType() const override {
@@ -86,7 +89,8 @@ public:
StringRef segmentKindToStr() const;
/// \brief Records the segmentType, that this section belongs to
- void setSegmentType(const Layout::SegmentType segmentType) {
+ void
+ setSegmentType(const typename TargetLayout<ELFT>::SegmentType segmentType) {
this->_segmentType = segmentType;
}
@@ -141,7 +145,7 @@ protected:
/// \brief Is this the first section in the output section.
bool _isFirstSectionInOutputSection = false;
/// \brief the output ELF segment type of this section.
- Layout::SegmentType _segmentType = SHT_NULL;
+ typename TargetLayout<ELFT>::SegmentType _segmentType = SHT_NULL;
/// \brief Input section name.
StringRef _inputSectionName;
/// \brief Output section name.
Modified: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h Fri Apr 3 18:07:13 2015
@@ -11,7 +11,6 @@
#define LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H
#include "Chunk.h"
-#include "Layout.h"
#include "SectionChunks.h"
#include "Writer.h"
#include "lld/Core/range.h"
@@ -97,7 +96,7 @@ public:
typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter;
Segment(const ELFLinkingContext &ctx, StringRef name,
- const Layout::SegmentType type);
+ const typename TargetLayout<ELFT>::SegmentType type);
/// \brief the Order of segments that appear in the output file
enum SegmentOrder {
@@ -180,7 +179,9 @@ public:
int32_t sectionCount() const { return _sections.size(); }
/// \brief, this function returns the type of segment (PT_*)
- Layout::SegmentType segmentType() { return _segmentType; }
+ typename TargetLayout<ELFT>::SegmentType segmentType() {
+ return _segmentType;
+ }
/// \brief return the segment type depending on the content,
/// If the content corresponds to Code, this will return Segment::Code
@@ -251,7 +252,7 @@ protected:
/// \brief Section or some other chunk type.
std::vector<Chunk<ELFT> *> _sections;
std::vector<SegmentSlice<ELFT> *> _segmentSlices;
- Layout::SegmentType _segmentType;
+ typename TargetLayout<ELFT>::SegmentType _segmentType;
uint64_t _flags;
int64_t _atomflags;
llvm::BumpPtrAllocator _segmentAllocate;
@@ -313,7 +314,7 @@ public:
template <class ELFT>
Segment<ELFT>::Segment(const ELFLinkingContext &ctx, StringRef name,
- const Layout::SegmentType type)
+ const typename TargetLayout<ELFT>::SegmentType type)
: Chunk<ELFT>(name, Chunk<ELFT>::Kind::ELFSegment, ctx), _segmentType(type),
_flags(0), _atomflags(0) {
this->_alignment = 0;
Modified: lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h Fri Apr 3 18:07:13 2015
@@ -16,7 +16,6 @@
#ifndef LLD_READER_WRITER_ELF_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_TARGET_HANDLER_H
-#include "Layout.h"
#include "lld/Core/Atom.h"
#include "lld/Core/LLVM.h"
#include "lld/Core/LinkingContext.h"
Modified: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h?rev=234065&r1=234064&r2=234065&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h Fri Apr 3 18:07:13 2015
@@ -13,7 +13,6 @@
#include "Atoms.h"
#include "Chunk.h"
#include "HeaderChunks.h"
-#include "Layout.h"
#include "SectionChunks.h"
#include "SegmentChunks.h"
#include "lld/Core/Instrumentation.h"
@@ -38,9 +37,11 @@ namespace elf {
/// sections and segments in the order determined by the target ELF
/// format. The writer creates a single instance of the TargetLayout
/// class
-template<class ELFT>
-class TargetLayout : public Layout {
+template <class ELFT> class TargetLayout {
public:
+ typedef uint32_t SectionOrder;
+ typedef uint32_t SegmentType;
+ typedef uint32_t Flags;
// The order in which the sections appear in the output file
// If its determined, that the layout needs to change
@@ -166,9 +167,11 @@ public:
TargetLayout(ELFLinkingContext &ctx)
: _ctx(ctx), _linkerScriptSema(ctx.linkerScriptSema()) {}
+ virtual ~TargetLayout() = default;
+
/// \brief Return the section order for a input section
- SectionOrder getSectionOrder(StringRef name, int32_t contentType,
- int32_t contentPermissions) override;
+ virtual SectionOrder getSectionOrder(StringRef name, int32_t contentType,
+ int32_t contentPermissions);
/// \brief Return the name of the input section by decoding the input
/// sectionChoice.
@@ -186,14 +189,17 @@ public:
const DefinedAtom *da);
/// \brief Gets the segment for a output section
- virtual Layout::SegmentType getSegmentType(Section<ELFT> *section) const;
+ virtual typename TargetLayout<ELFT>::SegmentType
+ getSegmentType(Section<ELFT> *section) const;
/// \brief Returns true/false depending on whether the section has a Output
// segment or not
static bool hasOutputSegment(Section<ELFT> *section);
- // Adds an atom to the section
- ErrorOr<const lld::AtomLayout *> addAtom(const Atom *atom) override;
+ /// \brief Append the Atom to the layout and create appropriate sections.
+ /// \returns A reference to the atom layout or an error. The atom layout will
+ /// be updated as linking progresses.
+ virtual ErrorOr<const lld::AtomLayout *> addAtom(const Atom *atom);
/// \brief Find an output Section given a section name.
OutputSection<ELFT> *findOutputSection(StringRef name) {
@@ -228,9 +234,11 @@ public:
StringRef memberPath,
StringRef sectionName);
- void assignSectionsToSegments() override;
+ /// \brief associates a section to a segment
+ virtual void assignSectionsToSegments();
- void assignVirtualAddress() override;
+ /// \brief associates a virtual address to the segment, section, and the atom
+ virtual void assignVirtualAddress();
void assignFileOffsetsForMiscSections();
@@ -249,7 +257,8 @@ public:
si->doPreFlight();
}
- const AtomLayout *findAtomLayoutByName(StringRef name) const override {
+ /// \brief find the Atom in the current layout
+ virtual const AtomLayout *findAtomLayoutByName(StringRef name) const {
for (auto sec : _sections)
if (auto section = dyn_cast<Section<ELFT>>(sec))
if (auto *al = section->findAtomLayoutByName(name))
@@ -352,13 +361,13 @@ protected:
};
template <class ELFT>
-Layout::SectionOrder
+typename TargetLayout<ELFT>::SectionOrder
TargetLayout<ELFT>::getSectionOrder(StringRef name, int32_t contentType,
int32_t contentPermissions) {
switch (contentType) {
case DefinedAtom::typeResolver:
case DefinedAtom::typeCode:
- return llvm::StringSwitch<Layout::SectionOrder>(name)
+ return llvm::StringSwitch<typename TargetLayout<ELFT>::SectionOrder>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
@@ -371,7 +380,7 @@ TargetLayout<ELFT>::getSectionOrder(Stri
case DefinedAtom::typeData:
case DefinedAtom::typeDataFast:
- return llvm::StringSwitch<Layout::SectionOrder>(name)
+ return llvm::StringSwitch<typename TargetLayout<ELFT>::SectionOrder>(name)
.StartsWith(".init_array", ORDER_INIT_ARRAY)
.StartsWith(".fini_array", ORDER_FINI_ARRAY)
.StartsWith(".dynamic", ORDER_DYNAMIC)
@@ -384,7 +393,7 @@ TargetLayout<ELFT>::getSectionOrder(Stri
return ORDER_BSS;
case DefinedAtom::typeGOT:
- return llvm::StringSwitch<Layout::SectionOrder>(name)
+ return llvm::StringSwitch<typename TargetLayout<ELFT>::SectionOrder>(name)
.StartsWith(".got.plt", ORDER_GOT_PLT)
.Default(ORDER_GOT);
@@ -468,7 +477,7 @@ TargetLayout<ELFT>::getOutputSectionName
/// \brief Gets the segment for a output section
template <class ELFT>
-Layout::SegmentType
+typename TargetLayout<ELFT>::SegmentType
TargetLayout<ELFT>::getSegmentType(Section<ELFT> *section) const {
switch (section->order()) {
case ORDER_INTERP:
More information about the llvm-commits
mailing list