[lld] r233718 - ELF: Do not use multiple inheritance.
Rui Ueyama
ruiu at google.com
Tue Mar 31 11:10:24 PDT 2015
Author: ruiu
Date: Tue Mar 31 13:10:24 2015
New Revision: 233718
URL: http://llvm.org/viewvc/llvm-project?rev=233718&view=rev
Log:
ELF: Do not use multiple inheritance.
Multiple inheritance is casually used here. Rewriting to not
using multiple inheritance reduces the complexity of the code
and also makes it shorter.
Removed:
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h?rev=233718&r1=233717&r2=233718&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h Tue Mar 31 13:10:24 2015
@@ -19,8 +19,7 @@ namespace elf {
template <typename ELFT> class HexagonTargetLayout;
template <class ELFT>
-class HexagonDynamicLibraryWriter : public DynamicLibraryWriter<ELFT>,
- public HexagonELFWriter<ELFT> {
+class HexagonDynamicLibraryWriter : public DynamicLibraryWriter<ELFT> {
public:
HexagonDynamicLibraryWriter(HexagonLinkingContext &ctx,
HexagonTargetLayout<ELFT> &layout);
@@ -33,7 +32,7 @@ protected:
virtual std::error_code setELFHeader() {
DynamicLibraryWriter<ELFT>::setELFHeader();
- HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader);
+ setHexagonELFHeader(*this->_elfHeader);
return std::error_code();
}
@@ -51,8 +50,7 @@ private:
template <class ELFT>
HexagonDynamicLibraryWriter<ELFT>::HexagonDynamicLibraryWriter(
HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout)
- : DynamicLibraryWriter<ELFT>(ctx, layout),
- HexagonELFWriter<ELFT>(ctx, layout), _ctx(ctx),
+ : DynamicLibraryWriter<ELFT>(ctx, layout), _ctx(ctx),
_hexagonTargetLayout(layout),
_hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(ctx)) {}
@@ -70,7 +68,8 @@ template <class ELFT>
void HexagonDynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() {
// Finalize the atom values that are part of the parent.
DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues();
- HexagonELFWriter<ELFT>::finalizeHexagonRuntimeAtomValues();
+ if (_ctx.isDynamic())
+ finalizeHexagonRuntimeAtomValues(_hexagonTargetLayout);
}
} // namespace elf
Removed: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h?rev=233717&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h (removed)
@@ -1,61 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h -------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef HEXAGON_ELF_WRITERS_H
-#define HEXAGON_ELF_WRITERS_H
-
-#include "HexagonLinkingContext.h"
-#include "OutputELFWriter.h"
-
-namespace lld {
-namespace elf {
-
-template <class ELFT> class HexagonTargetLayout;
-
-template <typename ELFT> class HexagonELFWriter {
-public:
- HexagonELFWriter(HexagonLinkingContext &ctx,
- HexagonTargetLayout<ELFT> &targetLayout)
- : _ctx(ctx), _hexagonTargetLayout(targetLayout) {}
-
-protected:
- bool setELFHeader(ELFHeader<ELFT> &elfHeader) {
- elfHeader.e_ident(llvm::ELF::EI_VERSION, 1);
- elfHeader.e_ident(llvm::ELF::EI_OSABI, 0);
- elfHeader.e_version(1);
- elfHeader.e_flags(0x3);
- return true;
- }
-
- void finalizeHexagonRuntimeAtomValues() {
- if (_ctx.isDynamic()) {
- auto gotAtomIter =
- _hexagonTargetLayout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
- auto gotpltSection = _hexagonTargetLayout.findOutputSection(".got.plt");
- if (gotpltSection)
- (*gotAtomIter)->_virtualAddr = gotpltSection->virtualAddr();
- else
- (*gotAtomIter)->_virtualAddr = 0;
- auto dynamicAtomIter = _hexagonTargetLayout.findAbsoluteAtom("_DYNAMIC");
- auto dynamicSection = _hexagonTargetLayout.findOutputSection(".dynamic");
- if (dynamicSection)
- (*dynamicAtomIter)->_virtualAddr = dynamicSection->virtualAddr();
- else
- (*dynamicAtomIter)->_virtualAddr = 0;
- }
- }
-
-private:
- HexagonLinkingContext &_ctx;
- HexagonTargetLayout<ELFT> &_hexagonTargetLayout;
-};
-
-} // elf
-} // lld
-#endif // HEXAGON_ELF_WRITERS_H
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h?rev=233718&r1=233717&r2=233718&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h Tue Mar 31 13:10:24 2015
@@ -10,7 +10,6 @@
#define HEXAGON_EXECUTABLE_WRITER_H
#include "ExecutableWriter.h"
-#include "HexagonELFWriters.h"
#include "HexagonExecutableAtoms.h"
#include "HexagonLinkingContext.h"
@@ -20,8 +19,7 @@ namespace elf {
template <typename ELFT> class HexagonTargetLayout;
template <class ELFT>
-class HexagonExecutableWriter : public ExecutableWriter<ELFT>,
- public HexagonELFWriter<ELFT> {
+class HexagonExecutableWriter : public ExecutableWriter<ELFT> {
public:
HexagonExecutableWriter(HexagonLinkingContext &ctx,
HexagonTargetLayout<ELFT> &layout);
@@ -34,7 +32,7 @@ protected:
virtual std::error_code setELFHeader() {
ExecutableWriter<ELFT>::setELFHeader();
- HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader);
+ setHexagonELFHeader(*this->_elfHeader);
return std::error_code();
}
@@ -55,8 +53,8 @@ private:
template <class ELFT>
HexagonExecutableWriter<ELFT>::HexagonExecutableWriter(
HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout)
- : ExecutableWriter<ELFT>(ctx, layout), HexagonELFWriter<ELFT>(ctx, layout),
- _ctx(ctx), _hexagonTargetLayout(layout),
+ : ExecutableWriter<ELFT>(ctx, layout), _ctx(ctx),
+ _hexagonTargetLayout(layout),
_hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(ctx)) {}
template <class ELFT>
@@ -76,7 +74,8 @@ void HexagonExecutableWriter<ELFT>::fina
auto sdabaseAtomIter = _hexagonTargetLayout.findAbsoluteAtom("_SDA_BASE_");
(*sdabaseAtomIter)->_virtualAddr =
_hexagonTargetLayout.getSDataSection()->virtualAddr();
- HexagonELFWriter<ELFT>::finalizeHexagonRuntimeAtomValues();
+ if (_ctx.isDynamic())
+ finalizeHexagonRuntimeAtomValues(_hexagonTargetLayout);
}
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h?rev=233718&r1=233717&r2=233718&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h Tue Mar 31 13:10:24 2015
@@ -10,6 +10,7 @@
#ifndef LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_LINKING_CONTEXT_H
#define LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_LINKING_CONTEXT_H
+#include "OutputELFWriter.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@@ -63,6 +64,13 @@ public:
}
};
+template <class ELFT> void setHexagonELFHeader(ELFHeader<ELFT> &elfHeader) {
+ elfHeader.e_ident(llvm::ELF::EI_VERSION, 1);
+ elfHeader.e_ident(llvm::ELF::EI_OSABI, 0);
+ elfHeader.e_version(1);
+ elfHeader.e_flags(0x3);
+}
+
} // elf
} // lld
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=233718&r1=233717&r2=233718&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Tue Mar 31 13:10:24 2015
@@ -135,6 +135,23 @@ private:
std::unique_ptr<HexagonTargetLayout<HexagonELFType>> _hexagonTargetLayout;
std::unique_ptr<HexagonTargetRelocationHandler> _hexagonRelocationHandler;
};
+
+template <class ELFT>
+void finalizeHexagonRuntimeAtomValues(HexagonTargetLayout<ELFT> &layout) {
+ auto gotAtomIter = layout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
+ auto gotpltSection = layout.findOutputSection(".got.plt");
+ if (gotpltSection)
+ (*gotAtomIter)->_virtualAddr = gotpltSection->virtualAddr();
+ else
+ (*gotAtomIter)->_virtualAddr = 0;
+ auto dynamicAtomIter = layout.findAbsoluteAtom("_DYNAMIC");
+ auto dynamicSection = layout.findOutputSection(".dynamic");
+ if (dynamicSection)
+ (*dynamicAtomIter)->_virtualAddr = dynamicSection->virtualAddr();
+ else
+ (*dynamicAtomIter)->_virtualAddr = 0;
+}
+
} // end namespace elf
} // end namespace lld
More information about the llvm-commits
mailing list