[lld] r234068 - ELF: Define mergeHeaderFlags to ELFLinkingContext.
Rui Ueyama
ruiu at google.com
Fri Apr 3 17:10:14 PDT 2015
Author: ruiu
Date: Fri Apr 3 19:10:14 2015
New Revision: 234068
URL: http://llvm.org/viewvc/llvm-project?rev=234068&view=rev
Log:
ELF: Define mergeHeaderFlags to ELFLinkingContext.
Only MIPS defined the member function, but this feature is not actually
MIPS-specific. Also, the dependency to the MIPS-only member function
prevented us from merging <Arch>ELF{Object,DSO}Reader classes.
This patch moves the feature from MipsLinkingContext to LinkingContext.
Removed:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
Modified:
lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
lld/trunk/lib/Driver/Driver.cpp
lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Fri Apr 3 19:10:14 2015
@@ -306,6 +306,14 @@ public:
bool armTarget1Rel() const { return _armTarget1Rel; }
void setArmTarget1Rel(bool value) { _armTarget1Rel = value; }
+ /// Each time a reader reads a new file, this member function is called
+ /// with the file's ELF magics. This is supposed to "merge" all attributes
+ /// to generate output ELF file magic. This can also reject input files
+ /// if they conflict with previous input files.
+ virtual std::error_code mergeHeaderFlags(uint8_t fileClass, uint64_t flags) {
+ return std::error_code();
+ }
+
protected:
ELFLinkingContext(llvm::Triple triple, std::unique_ptr<TargetHandler> handler)
: _triple(triple), _targetHandler(std::move(handler)) {}
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Fri Apr 3 19:10:14 2015
@@ -104,8 +104,10 @@ bool Driver::link(LinkingContext &contex
// Do core linking.
ScopedTask resolveTask(getDefaultDomain(), "Resolve");
Resolver resolver(context);
- if (!resolver.resolve())
+ if (!resolver.resolve()) {
+ context.getTaskGroup().sync();
return false;
+ }
std::unique_ptr<MutableFile> merged = resolver.resultFile();
resolveTask.end();
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFReader.h?rev=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFReader.h Fri Apr 3 19:10:14 2015
@@ -34,6 +34,10 @@ public:
std::error_code
loadFile(std::unique_ptr<MemoryBuffer> mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
+ const Elf_Ehdr *hdr = elfHeader(*mb);
+ if (auto ec = _ctx.mergeHeaderFlags(hdr->getFileClass(), hdr->e_flags))
+ return ec;
+
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
auto f = createELF<FileT>(llvm::object::getElfArchType(mb->getBuffer()),
Removed: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h?rev=234067&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h (removed)
@@ -1,67 +0,0 @@
-//===- lib/ReaderWriter/ELF/MipsELFReader.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_MIPS_MIPS_ELF_READER_H
-#define LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_READER_H
-
-#include "ELFReader.h"
-#include "MipsELFFile.h"
-#include "MipsELFFlagsMerger.h"
-#include "MipsLinkingContext.h"
-
-namespace lld {
-namespace elf {
-
-template <class ELFT>
-class MipsELFObjectReader
- : public ELFObjectReader<ELFT, MipsLinkingContext, lld::elf::MipsELFFile> {
- typedef ELFObjectReader<ELFT, MipsLinkingContext, lld::elf::MipsELFFile>
- BaseReaderType;
-
-public:
- MipsELFObjectReader(MipsLinkingContext &ctx)
- : BaseReaderType(ctx), _flagMerger(ctx.getELFFlagsMerger()) {}
-
- std::error_code
- loadFile(std::unique_ptr<MemoryBuffer> mb, const Registry ®istry,
- std::vector<std::unique_ptr<File>> &result) const override {
- auto &hdr = *this->elfHeader(*mb);
- if (auto ec = _flagMerger.mergeHeaderFlags(hdr.getFileClass(), hdr.e_flags))
- return ec;
- return BaseReaderType::loadFile(std::move(mb), registry, result);
- }
-
-private:
- MipsELFFlagsMerger &_flagMerger;
-};
-
-template <class ELFT>
-class MipsELFDSOReader : public ELFDSOReader<ELFT, MipsLinkingContext> {
- typedef ELFDSOReader<ELFT, MipsLinkingContext> BaseReaderType;
-
-public:
- MipsELFDSOReader(MipsLinkingContext &ctx)
- : BaseReaderType(ctx), _flagMerger(ctx.getELFFlagsMerger()) {}
-
- std::error_code
- loadFile(std::unique_ptr<MemoryBuffer> mb, const Registry ®istry,
- std::vector<std::unique_ptr<File>> &result) const override {
- auto &hdr = *this->elfHeader(*mb);
- if (auto ec = _flagMerger.mergeHeaderFlags(hdr.getFileClass(), hdr.e_flags))
- return ec;
- return BaseReaderType::loadFile(std::move(mb), registry, result);
- }
-
-private:
- MipsELFFlagsMerger &_flagMerger;
-};
-
-} // namespace elf
-} // namespace lld
-
-#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp?rev=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp Fri Apr 3 19:10:14 2015
@@ -43,12 +43,13 @@ MipsLinkingContext::MipsLinkingContext(l
: ELFLinkingContext(triple, createTarget(triple, *this)),
_flagsMerger(triple.isArch64Bit()) {}
-uint32_t MipsLinkingContext::getMergedELFFlags() const {
- return _flagsMerger.getMergedELFFlags();
+std::error_code MipsLinkingContext::mergeHeaderFlags(uint8_t fileClass,
+ uint64_t flags) {
+ return _flagsMerger.mergeHeaderFlags(fileClass, flags);
}
-MipsELFFlagsMerger &MipsLinkingContext::getELFFlagsMerger() {
- return _flagsMerger;
+uint32_t MipsLinkingContext::getMergedELFFlags() const {
+ return _flagsMerger.getMergedELFFlags();
}
uint64_t MipsLinkingContext::getBaseAddress() const {
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h?rev=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h Fri Apr 3 19:10:14 2015
@@ -46,8 +46,8 @@ public:
static const int machine = llvm::ELF::EM_MIPS;
MipsLinkingContext(llvm::Triple triple);
+ std::error_code mergeHeaderFlags(uint8_t fileClass, uint64_t flags) override;
uint32_t getMergedELFFlags() const;
- MipsELFFlagsMerger &getELFFlagsMerger();
void registerRelocationNames(Registry &r) override;
// ELFLinkingContext
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=234068&r1=234067&r2=234068&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Fri Apr 3 19:10:14 2015
@@ -9,8 +9,9 @@
#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_MIPS_MIPS_TARGET_HANDLER_H
+#include "ELFReader.h"
#include "MipsDynamicLibraryWriter.h"
-#include "MipsELFReader.h"
+#include "MipsELFFile.h"
#include "MipsExecutableWriter.h"
#include "MipsLinkingContext.h"
#include "MipsRelocationHandler.h"
@@ -87,6 +88,10 @@ private:
/// \brief TargetHandler for Mips
template <class ELFT> class MipsTargetHandler final : public TargetHandler {
+ typedef ELFObjectReader<ELFT, MipsLinkingContext, lld::elf::MipsELFFile>
+ ObjReader;
+ typedef ELFDSOReader<ELFT, MipsLinkingContext> DSOReader;
+
public:
MipsTargetHandler(MipsLinkingContext &ctx)
: _ctx(ctx), _targetLayout(new MipsTargetLayout<ELFT>(ctx)),
@@ -94,11 +99,11 @@ public:
createMipsRelocationHandler<ELFT>(ctx, *_targetLayout)) {}
std::unique_ptr<Reader> getObjReader() override {
- return llvm::make_unique<MipsELFObjectReader<ELFT>>(_ctx);
+ return llvm::make_unique<ObjReader>(_ctx);
}
std::unique_ptr<Reader> getDSOReader() override {
- return llvm::make_unique<MipsELFDSOReader<ELFT>>(_ctx);
+ return llvm::make_unique<DSOReader>(_ctx);
}
const TargetRelocationHandler &getRelocationHandler() const override {
More information about the llvm-commits
mailing list