2013-01-30 06:03:39 +08:00
|
|
|
//===- lib/ReaderWriter/ELF/TargetHandler.h -------------------------------===//
|
2013-01-25 15:39:18 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-01-29 09:00:04 +08:00
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief These interfaces provide target specific hooks to change the linker's
|
|
|
|
/// behaivor.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
#ifndef LLD_READER_WRITER_ELF_TARGET_HANDLER_H
|
|
|
|
#define LLD_READER_WRITER_ELF_TARGET_HANDLER_H
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-01-30 13:25:44 +08:00
|
|
|
#include "Layout.h"
|
|
|
|
|
2013-01-30 03:53:41 +08:00
|
|
|
#include "lld/Core/InputFiles.h"
|
2013-01-25 15:39:18 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
|
|
|
#include "lld/Core/TargetInfo.h"
|
|
|
|
#include "lld/ReaderWriter/ELFTargetInfo.h"
|
2013-01-30 03:53:41 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/Hashing.h"
|
2013-01-30 13:25:44 +08:00
|
|
|
#include "llvm/Support/FileOutputBuffer.h"
|
2013-01-25 15:39:18 +08:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2013-01-30 06:03:39 +08:00
|
|
|
template <class ELFT> class ELFDefinedAtom;
|
2013-02-21 01:38:37 +08:00
|
|
|
template <class ELFT> class ELFReference;
|
2013-01-30 13:25:44 +08:00
|
|
|
class ELFWriter;
|
2013-01-30 06:03:39 +08:00
|
|
|
template <class ELFT> class Header;
|
2013-01-30 03:53:41 +08:00
|
|
|
template <class ELFT> class Section;
|
2013-01-30 06:03:39 +08:00
|
|
|
template <class ELFT> class TargetLayout;
|
2013-01-30 03:53:41 +08:00
|
|
|
|
2013-01-29 09:00:04 +08:00
|
|
|
/// \brief The target registers a set of handlers for overriding target specific
|
|
|
|
/// attributes for a DefinedAtom. The Reader uses this class to query for the
|
2013-03-15 00:09:49 +08:00
|
|
|
/// type of atom and its permissions
|
2013-01-30 06:03:39 +08:00
|
|
|
template <class ELFT> class TargetAtomHandler {
|
2013-01-25 15:39:18 +08:00
|
|
|
public:
|
2013-02-23 01:18:53 +08:00
|
|
|
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
|
2013-01-25 15:39:18 +08:00
|
|
|
typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
|
|
|
|
|
2013-02-23 01:18:53 +08:00
|
|
|
virtual DefinedAtom::ContentType
|
|
|
|
contentType(const ELFDefinedAtom<ELFT> *atom) const {
|
2013-01-25 15:39:18 +08:00
|
|
|
return atom->contentType();
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:18:53 +08:00
|
|
|
virtual DefinedAtom::ContentType
|
|
|
|
contentType(const Elf_Shdr *shdr, const Elf_Sym *sym) const {
|
2013-01-25 15:39:18 +08:00
|
|
|
return DefinedAtom::typeZeroFill;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:38:37 +08:00
|
|
|
virtual DefinedAtom::ContentPermissions
|
|
|
|
contentPermissions(const ELFDefinedAtom<ELFT> *atom) const {
|
2013-01-25 15:39:18 +08:00
|
|
|
return atom->permissions();
|
|
|
|
}
|
2013-02-21 01:38:37 +08:00
|
|
|
|
2013-02-23 01:18:53 +08:00
|
|
|
virtual int64_t getType(const Elf_Sym *sym) const {
|
|
|
|
return llvm::ELF::STT_NOTYPE;
|
|
|
|
}
|
2013-03-19 19:41:16 +08:00
|
|
|
|
|
|
|
virtual ~TargetAtomHandler() {}
|
2013-01-25 15:39:18 +08:00
|
|
|
};
|
|
|
|
|
2013-01-30 13:25:44 +08:00
|
|
|
template <class ELFT> class TargetRelocationHandler {
|
|
|
|
public:
|
2013-02-21 01:38:37 +08:00
|
|
|
virtual ErrorOr<void>
|
2013-06-17 01:14:58 +08:00
|
|
|
applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
|
|
|
|
const lld::AtomLayout &, const Reference &) const = 0;
|
2013-02-21 01:38:37 +08:00
|
|
|
|
|
|
|
virtual int64_t relocAddend(const Reference &)const { return 0; }
|
2013-03-19 19:41:16 +08:00
|
|
|
|
|
|
|
virtual ~TargetRelocationHandler() {}
|
2013-01-30 13:25:44 +08:00
|
|
|
};
|
|
|
|
|
2013-03-15 00:09:49 +08:00
|
|
|
/// \brief An interface to override functions that are provided by the
|
2013-01-25 15:39:18 +08:00
|
|
|
/// the default ELF Layout
|
2013-01-30 06:03:39 +08:00
|
|
|
template <class ELFT> class TargetHandler : public TargetHandlerBase {
|
2013-01-25 15:39:18 +08:00
|
|
|
|
|
|
|
public:
|
2013-01-30 06:03:39 +08:00
|
|
|
TargetHandler(ELFTargetInfo &targetInfo) : _targetInfo(targetInfo) {}
|
2013-01-25 15:39:18 +08:00
|
|
|
|
|
|
|
/// If the target overrides ELF header information, this API would
|
|
|
|
/// return true, so that the target can set all fields specific to
|
|
|
|
/// that target
|
2013-01-30 06:03:39 +08:00
|
|
|
virtual bool doesOverrideHeader() = 0;
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-03-15 00:09:49 +08:00
|
|
|
/// Set the ELF Header information
|
2013-01-30 06:03:39 +08:00
|
|
|
virtual void setHeaderInfo(Header<ELFT> *Header) = 0;
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-03-15 00:09:49 +08:00
|
|
|
/// TargetLayout
|
2013-01-30 06:03:39 +08:00
|
|
|
virtual TargetLayout<ELFT> &targetLayout() = 0;
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
/// TargetAtomHandler
|
|
|
|
virtual TargetAtomHandler<ELFT> &targetAtomHandler() = 0;
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-01-30 13:25:44 +08:00
|
|
|
virtual const TargetRelocationHandler<ELFT> &getRelocationHandler() const = 0;
|
|
|
|
|
2013-01-25 15:39:18 +08:00
|
|
|
/// Create a set of Default target sections that a target might needj
|
|
|
|
virtual void createDefaultSections() = 0;
|
|
|
|
|
|
|
|
/// \brief Add a section to the current Layout
|
|
|
|
virtual void addSection(Section<ELFT> *section) = 0;
|
|
|
|
|
2013-03-15 00:09:49 +08:00
|
|
|
/// \brief add new symbol file
|
2013-01-25 15:39:18 +08:00
|
|
|
virtual void addFiles(InputFiles &) = 0;
|
|
|
|
|
|
|
|
/// \brief Finalize the symbol values
|
|
|
|
virtual void finalizeSymbolValues() = 0;
|
|
|
|
|
|
|
|
/// \brief allocate Commons, some architectures may move small common
|
2013-03-15 00:09:49 +08:00
|
|
|
/// symbols over to small data, this would also be used
|
2013-01-25 15:39:18 +08:00
|
|
|
virtual void allocateCommons() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const ELFTargetInfo &_targetInfo;
|
|
|
|
};
|
2013-01-30 06:03:39 +08:00
|
|
|
} // end namespace elf
|
|
|
|
} // end namespace lld
|
2013-01-25 15:39:18 +08:00
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
#endif
|