[lld] r230574 - [ELF][x86] Detemplatify ELFT. There's only a single valid instantiation.
Rui Ueyama
ruiu at google.com
Wed Feb 25 15:39:28 PST 2015
This is a nice change. Thank you for doing this!
On Wed, Feb 25, 2015 at 3:27 PM, Michael J. Spencer <bigcheesegs at gmail.com>
wrote:
> Author: mspencer
> Date: Wed Feb 25 17:27:13 2015
> New Revision: 230574
>
> URL: http://llvm.org/viewvc/llvm-project?rev=230574&view=rev
> Log:
> [ELF][x86] Detemplatify ELFT. There's only a single valid instantiation.
>
> Added:
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ElfType.h
> Modified:
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.h
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
>
> Modified:
> lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h?rev=230574&r1=230573&r2=230574&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
> (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h Wed
> Feb 25 17:27:13 2015
> @@ -10,28 +10,28 @@
> #define X86_64_DYNAMIC_LIBRARY_WRITER_H
>
> #include "DynamicLibraryWriter.h"
> +#include "X86_64ElfType.h"
> #include "X86_64LinkingContext.h"
> #include "X86_64TargetHandler.h"
>
> namespace lld {
> namespace elf {
>
> -template <class ELFT>
> -class X86_64DynamicLibraryWriter : public DynamicLibraryWriter<ELFT> {
> +class X86_64DynamicLibraryWriter : public
> DynamicLibraryWriter<X86_64ELFType> {
> public:
> X86_64DynamicLibraryWriter(X86_64LinkingContext &context,
> - X86_64TargetLayout<ELFT> &layout);
> + X86_64TargetLayout &layout);
>
> protected:
> // Add any runtime files and their atoms to the output
> virtual bool createImplicitFiles(std::vector<std::unique_ptr<File>> &);
>
> virtual void finalizeDefaultAtomValues() {
> - return DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues();
> + return DynamicLibraryWriter::finalizeDefaultAtomValues();
> }
>
> virtual void addDefaultAtoms() {
> - return DynamicLibraryWriter<ELFT>::addDefaultAtoms();
> + return DynamicLibraryWriter::addDefaultAtoms();
> }
>
> private:
> @@ -43,20 +43,17 @@ private:
>
> std::unique_ptr<GOTFile> _gotFile;
> X86_64LinkingContext &_context;
> - X86_64TargetLayout<ELFT> &_x86_64Layout;
> + X86_64TargetLayout &_x86_64Layout;
> };
>
> -template <class ELFT>
> -X86_64DynamicLibraryWriter<ELFT>::X86_64DynamicLibraryWriter(
> - X86_64LinkingContext &context, X86_64TargetLayout<ELFT> &layout)
> - : DynamicLibraryWriter<ELFT>(context, layout),
> - _gotFile(new GOTFile(context)), _context(context),
> _x86_64Layout(layout) {
> -}
> +X86_64DynamicLibraryWriter::X86_64DynamicLibraryWriter(
> + X86_64LinkingContext &context, X86_64TargetLayout &layout)
> + : DynamicLibraryWriter(context, layout), _gotFile(new
> GOTFile(context)),
> + _context(context), _x86_64Layout(layout) {}
>
> -template <class ELFT>
> -bool X86_64DynamicLibraryWriter<ELFT>::createImplicitFiles(
> +bool X86_64DynamicLibraryWriter::createImplicitFiles(
> std::vector<std::unique_ptr<File>> &result) {
> - DynamicLibraryWriter<ELFT>::createImplicitFiles(result);
> + DynamicLibraryWriter::createImplicitFiles(result);
> _gotFile->addAtom(*new (_gotFile->_alloc)
> GLOBAL_OFFSET_TABLEAtom(*_gotFile));
> _gotFile->addAtom(*new (_gotFile->_alloc) DYNAMICAtom(*_gotFile));
> result.push_back(std::move(_gotFile));
>
> Added: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ElfType.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ElfType.h?rev=230574&view=auto
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ElfType.h (added)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ElfType.h Wed Feb 25
> 17:27:13 2015
> @@ -0,0 +1,21 @@
> +//===- lib/ReaderWriter/ELF/X86_64/X86_64ElfType.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_X86_64_X86_64_ELF_TYPE_H
> +#define LLD_READER_WRITER_ELF_X86_64_X86_64_ELF_TYPE_H
> +
> +#include "llvm/Object/ELF.h"
> +
> +namespace lld {
> +namespace elf {
> +typedef llvm::object::ELFType<llvm::support::little, 2, true>
> X86_64ELFType;
> +}
> +}
> +
> +#endif
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h?rev=230574&r1=230573&r2=230574&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
> (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h Wed Feb
> 25 17:27:13 2015
> @@ -10,27 +10,38 @@
> #define X86_64_EXECUTABLE_WRITER_H
>
> #include "ExecutableWriter.h"
> +#include "X86_64ElfType.h"
> #include "X86_64LinkingContext.h"
>
> namespace lld {
> namespace elf {
>
> -template <class ELFT>
> -class X86_64ExecutableWriter : public ExecutableWriter<ELFT> {
> +class X86_64ExecutableWriter : public ExecutableWriter<X86_64ELFType> {
> public:
> X86_64ExecutableWriter(X86_64LinkingContext &context,
> - X86_64TargetLayout<ELFT> &layout);
> + X86_64TargetLayout &layout)
> + : ExecutableWriter(context, layout), _gotFile(new GOTFile(context)),
> + _context(context) {}
>
> protected:
> // Add any runtime files and their atoms to the output
> - virtual bool createImplicitFiles(std::vector<std::unique_ptr<File>> &);
> + virtual bool
> + createImplicitFiles(std::vector<std::unique_ptr<File>> &result) {
> + ExecutableWriter::createImplicitFiles(result);
> + _gotFile->addAtom(*new (_gotFile->_alloc)
> + GLOBAL_OFFSET_TABLEAtom(*_gotFile));
> + if (_context.isDynamic())
> + _gotFile->addAtom(*new (_gotFile->_alloc) DYNAMICAtom(*_gotFile));
> + result.push_back(std::move(_gotFile));
> + return true;
> + }
>
> virtual void finalizeDefaultAtomValues() {
> - return ExecutableWriter<ELFT>::finalizeDefaultAtomValues();
> + return ExecutableWriter::finalizeDefaultAtomValues();
> }
>
> virtual void addDefaultAtoms() {
> - return ExecutableWriter<ELFT>::addDefaultAtoms();
> + return ExecutableWriter::addDefaultAtoms();
> }
>
> private:
> @@ -42,26 +53,8 @@ private:
>
> std::unique_ptr<GOTFile> _gotFile;
> X86_64LinkingContext &_context;
> - X86_64TargetLayout<ELFT> &_x86_64Layout;
> };
>
> -template <class ELFT>
> -X86_64ExecutableWriter<ELFT>::X86_64ExecutableWriter(
> - X86_64LinkingContext &context, X86_64TargetLayout<ELFT> &layout)
> - : ExecutableWriter<ELFT>(context, layout), _gotFile(new
> GOTFile(context)),
> - _context(context), _x86_64Layout(layout) {}
> -
> -template <class ELFT>
> -bool X86_64ExecutableWriter<ELFT>::createImplicitFiles(
> - std::vector<std::unique_ptr<File>> &result) {
> - ExecutableWriter<ELFT>::createImplicitFiles(result);
> - _gotFile->addAtom(*new (_gotFile->_alloc)
> GLOBAL_OFFSET_TABLEAtom(*_gotFile));
> - if (_context.isDynamic())
> - _gotFile->addAtom(*new (_gotFile->_alloc) DYNAMICAtom(*_gotFile));
> - result.push_back(std::move(_gotFile));
> - return true;
> -}
> -
> } // namespace elf
> } // namespace lld
>
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.h?rev=230574&r1=230573&r2=230574&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.h
> (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.h Wed
> Feb 25 17:27:13 2015
> @@ -16,11 +16,11 @@ namespace lld {
> namespace elf {
> typedef llvm::object::ELFType<llvm::support::little, 2, true>
> X86_64ELFType;
>
> -template <class ELFT> class X86_64TargetLayout;
> +class X86_64TargetLayout;
>
> class X86_64TargetRelocationHandler final : public
> TargetRelocationHandler {
> public:
> - X86_64TargetRelocationHandler(X86_64TargetLayout<X86_64ELFType> &layout)
> + X86_64TargetRelocationHandler(X86_64TargetLayout &layout)
> : _tlsSize(0), _x86_64Layout(layout) {}
>
> std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
> @@ -30,7 +30,7 @@ public:
> private:
> // Cached size of the TLS segment.
> mutable uint64_t _tlsSize;
> - X86_64TargetLayout<X86_64ELFType> &_x86_64Layout;
> + X86_64TargetLayout &_x86_64Layout;
> };
>
> } // end namespace elf
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp?rev=230574&r1=230573&r2=230574&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
> (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp Wed Feb
> 25 17:27:13 2015
> @@ -17,10 +17,9 @@ using namespace lld;
> using namespace elf;
>
> X86_64TargetHandler::X86_64TargetHandler(X86_64LinkingContext &context)
> - : _context(context),
> - _x86_64TargetLayout(new X86_64TargetLayout<X86_64ELFType>(context)),
> - _x86_64RelocationHandler(new X86_64TargetRelocationHandler(
> - *_x86_64TargetLayout.get())) {}
> + : _context(context), _x86_64TargetLayout(new
> X86_64TargetLayout(context)),
> + _x86_64RelocationHandler(
> + new X86_64TargetRelocationHandler(*_x86_64TargetLayout.get()))
> {}
>
> void X86_64TargetHandler::registerRelocationNames(Registry ®istry) {
> registry.addKindTable(Reference::KindNamespace::ELF,
> @@ -30,12 +29,11 @@ void X86_64TargetHandler::registerReloca
> std::unique_ptr<Writer> X86_64TargetHandler::getWriter() {
> switch (this->_context.getOutputELFType()) {
> case llvm::ELF::ET_EXEC:
> - return std::unique_ptr<Writer>(new
> X86_64ExecutableWriter<X86_64ELFType>(
> - _context, *_x86_64TargetLayout.get()));
> + return std::unique_ptr<Writer>(
> + new X86_64ExecutableWriter(_context, *_x86_64TargetLayout.get()));
> case llvm::ELF::ET_DYN:
> return std::unique_ptr<Writer>(
> - new X86_64DynamicLibraryWriter<X86_64ELFType>(
> - _context, *_x86_64TargetLayout.get()));
> + new X86_64DynamicLibraryWriter(_context,
> *_x86_64TargetLayout.get()));
> case llvm::ELF::ET_REL:
> llvm_unreachable("TODO: support -r mode");
> default:
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h?rev=230574&r1=230573&r2=230574&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h Wed Feb 25
> 17:27:13 2015
> @@ -11,6 +11,7 @@
> #define LLD_READER_WRITER_ELF_X86_64_X86_64_TARGET_HANDLER_H
>
> #include "DefaultTargetHandler.h"
> +#include "X86_64LinkingContext.h"
> #include "TargetLayout.h"
> #include "X86_64ELFFile.h"
> #include "X86_64ELFReader.h"
> @@ -19,12 +20,10 @@
>
> namespace lld {
> namespace elf {
> -class X86_64LinkingContext;
> -
> -template <class ELFT> class X86_64TargetLayout : public
> TargetLayout<ELFT> {
> +class X86_64TargetLayout : public TargetLayout<X86_64ELFType> {
> public:
> X86_64TargetLayout(X86_64LinkingContext &context)
> - : TargetLayout<ELFT>(context) {}
> + : TargetLayout(context) {}
> };
>
> class X86_64TargetHandler final
> @@ -32,7 +31,7 @@ class X86_64TargetHandler final
> public:
> X86_64TargetHandler(X86_64LinkingContext &context);
>
> - X86_64TargetLayout<X86_64ELFType> &getTargetLayout() override {
> + X86_64TargetLayout &getTargetLayout() override {
> return *(_x86_64TargetLayout.get());
> }
>
> @@ -55,7 +54,7 @@ public:
> private:
> static const Registry::KindStrings kindStrings[];
> X86_64LinkingContext &_context;
> - std::unique_ptr<X86_64TargetLayout<X86_64ELFType>> _x86_64TargetLayout;
> + std::unique_ptr<X86_64TargetLayout> _x86_64TargetLayout;
> std::unique_ptr<X86_64TargetRelocationHandler> _x86_64RelocationHandler;
> };
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150225/8ca2d4b1/attachment.html>
More information about the llvm-commits
mailing list