Fix the ELF shared library build targets

lldELF is used by each ELF backend.  lldELF's ELFLinkingContext
 also held a reference to each backend, creating a link-time
 cycle.  This patch moves the backend references to lldDriver.

 Differential Revision: http://reviews.llvm.org/D7119

llvm-svn: 226922
This commit is contained in:
Greg Fitzgerald 2015-01-23 18:52:44 +00:00
parent 69fe98da14
commit 0823ea636e
38 changed files with 139 additions and 162 deletions

View File

@ -0,0 +1,40 @@
//===- lld/ReaderWriter/ELFTargets.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_TARGETS_H
#define LLD_READER_WRITER_ELF_TARGETS_H
#include "ELFLinkingContext.h"
namespace lld {
namespace elf {
#define LLVM_TARGET(TargetName) \
class TargetName##LinkingContext final : public ELFLinkingContext { \
public: \
TargetName##LinkingContext(llvm::Triple); \
};
#include "llvm/Config/Targets.def"
// X86 => X86,X86_64
class X86_64LinkingContext final : public ELFLinkingContext {
public:
X86_64LinkingContext(llvm::Triple);
};
// PowerPC => PPC
class PPCLinkingContext final : public ELFLinkingContext {
public:
PPCLinkingContext(llvm::Triple);
};
} // end namespace elf
} // end namespace lld
#endif

View File

@ -24,6 +24,13 @@ add_llvm_library(lldDriver
lldMachO
lldPECOFF
lldELF
lldAArch64ELFTarget
lldARMELFTarget
lldHexagonELFTarget
lldMipsELFTarget
lldPPCELFTarget
lldX86ELFTarget
lldX86_64ELFTarget
lldCore
lldNative
lldReaderWriter

View File

@ -15,6 +15,7 @@
#include "lld/Driver/Driver.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "lld/ReaderWriter/ELFTargets.h"
#include "lld/ReaderWriter/LinkerScript.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
@ -314,6 +315,35 @@ void GnuLdDriver::addPlatformSearchDirs(ELFLinkingContext &ctx,
ctx.addSearchPath("=/usr/lib");
}
std::unique_ptr<ELFLinkingContext>
createELFLinkingContext(llvm::Triple triple) {
switch (triple.getArch()) {
case llvm::Triple::x86:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::X86LinkingContext(triple));
case llvm::Triple::x86_64:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::X86_64LinkingContext(triple));
case llvm::Triple::hexagon:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::HexagonLinkingContext(triple));
case llvm::Triple::mipsel:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::MipsLinkingContext(triple));
case llvm::Triple::ppc:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::PPCLinkingContext(triple));
case llvm::Triple::aarch64:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::AArch64LinkingContext(triple));
case llvm::Triple::arm:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::ARMLinkingContext(triple));
default:
return nullptr;
}
}
bool GnuLdDriver::parse(int argc, const char *argv[],
std::unique_ptr<ELFLinkingContext> &context,
raw_ostream &diagnostics) {
@ -349,7 +379,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
if (!applyEmulation(triple, *parsedArgs, diagnostics))
return false;
std::unique_ptr<ELFLinkingContext> ctx(ELFLinkingContext::create(triple));
std::unique_ptr<ELFLinkingContext> ctx(createELFLinkingContext(triple));
if (!ctx) {
diagnostics << "unknown target triple\n";

View File

@ -10,6 +10,7 @@
#define AARCH64_DYNAMIC_LIBRARY_WRITER_H
#include "AArch64LinkingContext.h"
#include "AArch64TargetHandler.h"
#include "DynamicLibraryWriter.h"
namespace lld {

View File

@ -9,9 +9,14 @@
#include "AArch64LinkingContext.h"
#include "AArch64RelocationPass.h"
#include "AArch64TargetHandler.h"
using namespace lld;
elf::AArch64LinkingContext::AArch64LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new AArch64TargetHandler(*this))) {}
void elf::AArch64LinkingContext::addPasses(PassManager &pm) {
auto pass = createAArch64RelocationPass(*this);
if (pass)

View File

@ -10,7 +10,6 @@
#ifndef LLD_READER_WRITER_ELF_AARCH64_AARCH64_LINKING_CONTEXT_H
#define LLD_READER_WRITER_ELF_AARCH64_AARCH64_LINKING_CONTEXT_H
#include "AArch64TargetHandler.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@ -25,9 +24,7 @@ enum {
class AArch64LinkingContext final : public ELFLinkingContext {
public:
AArch64LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new AArch64TargetHandler(*this))) {}
AArch64LinkingContext(llvm::Triple);
void addPasses(PassManager &) override;

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64Target.h -----------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "AArch64LinkingContext.h"

View File

@ -5,5 +5,7 @@ add_llvm_library(lldAArch64ELFTarget
AArch64RelocationPass.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -11,6 +11,7 @@
#include "ExecutableWriter.h"
#include "ARMLinkingContext.h"
#include "ARMTargetHandler.h"
namespace lld {
namespace elf {

View File

@ -9,10 +9,15 @@
#include "ARMLinkingContext.h"
#include "ARMRelocationPass.h"
#include "ARMTargetHandler.h"
using namespace lld;
using namespace lld::elf;
elf::ARMLinkingContext::ARMLinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new ARMTargetHandler(*this))) {}
void elf::ARMLinkingContext::addPasses(PassManager &pm) {
auto pass = createARMRelocationPass(*this);
if (pass)

View File

@ -10,10 +10,7 @@
#ifndef LLD_READER_WRITER_ELF_ARM_ARM_LINKING_CONTEXT_H
#define LLD_READER_WRITER_ELF_ARM_ARM_LINKING_CONTEXT_H
#include "ARMTargetHandler.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@ -22,9 +19,7 @@ namespace elf {
class ARMLinkingContext final : public ELFLinkingContext {
public:
ARMLinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new ARMTargetHandler(*this))) {}
ARMLinkingContext(llvm::Triple);
void addPasses(PassManager &) override;

View File

@ -1,10 +0,0 @@
//===--------- lib/ReaderWriter/ELF/ARM/ARMTarget.h -----------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ARMLinkingContext.h"

View File

@ -5,4 +5,7 @@ add_llvm_library(lldARMELFTarget
ARMRelocationPass.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -4,15 +4,10 @@ add_llvm_library(lldELF
Reader.cpp
Writer.cpp
LINK_LIBS
lldHexagonELFTarget
lldMipsELFTarget
lldPPCELFTarget
lldCore
lldPasses
lldReaderWriter
lldX86ELFTarget
lldX86_64ELFTarget
lldAArch64ELFTarget
lldARMELFTarget
lldYAML
LLVMSupport
)
include_directories(.)

View File

@ -11,8 +11,8 @@
#include "ArrayOrderPass.h"
#include "ELFFile.h"
#include "TargetHandler.h"
#include "Targets.h"
#include "lld/Core/Instrumentation.h"
#include "lld/Core/SharedLibraryFile.h"
#include "lld/Passes/LayoutPass.h"
#include "lld/Passes/RoundTripYAMLPass.h"
#include "llvm/ADT/Triple.h"
@ -56,7 +56,7 @@ public:
ELFLinkingContext::ELFLinkingContext(
llvm::Triple triple, std::unique_ptr<TargetHandlerBase> targetHandler)
: _outputELFType(elf::ET_EXEC), _triple(triple),
: _outputELFType(llvm::ELF::ET_EXEC), _triple(triple),
_targetHandler(std::move(targetHandler)), _baseAddress(0),
_isStaticExecutable(false), _noInhibitExec(false), _exportDynamic(false),
_mergeCommonStrings(false), _runLayoutPass(true),
@ -93,7 +93,7 @@ uint16_t ELFLinkingContext::getOutputMachine() const {
}
StringRef ELFLinkingContext::entrySymbolName() const {
if (_outputELFType == elf::ET_EXEC && _entrySymbolName.empty())
if (_outputELFType == llvm::ELF::ET_EXEC && _entrySymbolName.empty())
return "_start";
return _entrySymbolName;
}
@ -129,35 +129,6 @@ bool ELFLinkingContext::isRelativeReloc(const Reference &) const {
Writer &ELFLinkingContext::writer() const { return *_writer; }
std::unique_ptr<ELFLinkingContext>
ELFLinkingContext::create(llvm::Triple triple) {
switch (triple.getArch()) {
case llvm::Triple::x86:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::X86LinkingContext(triple));
case llvm::Triple::x86_64:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::X86_64LinkingContext(triple));
case llvm::Triple::hexagon:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::HexagonLinkingContext(triple));
case llvm::Triple::mipsel:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::MipsLinkingContext(triple));
case llvm::Triple::ppc:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::PPCLinkingContext(triple));
case llvm::Triple::aarch64:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::AArch64LinkingContext(triple));
case llvm::Triple::arm:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::ARMLinkingContext(triple));
default:
return nullptr;
}
}
static void buildSearchPath(SmallString<128> &path, StringRef dir,
StringRef sysRoot) {
if (!dir.startswith("=/"))

View File

@ -4,5 +4,7 @@ add_llvm_library(lldHexagonELFTarget
HexagonTargetHandler.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h -----------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "HexagonLinkingContext.h"

View File

@ -9,10 +9,7 @@
LLD_LEVEL := ../../..
LIBRARYNAME := lldELF
USEDLIBS = lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
lldX86ELFTarget.a lldX86_64ELFTarget.a lldAArch64ELFTarget.a \
lldARMELFTarget.a \
lldReaderWriter.a lldPasses.a
USEDLIBS = lldPasses.a
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF

View File

@ -7,5 +7,7 @@ add_llvm_library(lldMipsELFTarget
MipsTargetHandler.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/Mips/MipsTarget.h -----------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "MipsLinkingContext.h"

View File

@ -3,5 +3,7 @@ add_llvm_library(lldPPCELFTarget
PPCTargetHandler.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -8,9 +8,14 @@
//===----------------------------------------------------------------------===//
#include "PPCLinkingContext.h"
#include "PPCTargetHandler.h"
#include "lld/Core/LLVM.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorOr.h"
using namespace lld;
elf::PPCLinkingContext::PPCLinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new PPCTargetHandler(*this))) {}

View File

@ -10,7 +10,6 @@
#ifndef LLD_READER_WRITER_ELF_PPC_PPC_LINKING_CONTEXT_H
#define LLD_READER_WRITER_ELF_PPC_PPC_LINKING_CONTEXT_H
#include "PPCTargetHandler.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@ -20,9 +19,7 @@ namespace elf {
class PPCLinkingContext final : public ELFLinkingContext {
public:
PPCLinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new PPCTargetHandler(*this))) {}
PPCLinkingContext(llvm::Triple triple);
/// \brief PPC has no relative relocations defined
bool isRelativeReloc(const Reference &) const override { return false; }

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/PPC/PPCTarget.h -------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PPCLinkingContext.h"

View File

@ -1,21 +0,0 @@
//===- lib/ReaderWriter/ELF/Targets.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_TARGETS_H
#define LLD_READER_WRITER_ELF_TARGETS_H
#include "AArch64/AArch64Target.h"
#include "ARM/ARMTarget.h"
#include "Hexagon/HexagonTarget.h"
#include "Mips/MipsTarget.h"
#include "PPC/PPCTarget.h"
#include "X86/X86Target.h"
#include "X86_64/X86_64Target.h"
#endif

View File

@ -4,5 +4,7 @@ add_llvm_library(lldX86ELFTarget
X86RelocationHandler.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -8,9 +8,13 @@
//===----------------------------------------------------------------------===//
#include "X86LinkingContext.h"
#include "X86TargetHandler.h"
#include "lld/Core/LLVM.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorOr.h"
using namespace lld;
elf::X86LinkingContext::X86LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new X86TargetHandler(*this))) {}

View File

@ -10,7 +10,6 @@
#ifndef LLD_READER_WRITER_ELF_X86_TARGETINFO_H
#define LLD_READER_WRITER_ELF_X86_TARGETINFO_H
#include "X86TargetHandler.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@ -19,9 +18,7 @@ namespace lld {
namespace elf {
class X86LinkingContext final : public ELFLinkingContext {
public:
X86LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new X86TargetHandler(*this))) {}
X86LinkingContext(llvm::Triple);
/// \brief X86 has only two relative relocation
/// a) for supporting IFUNC relocs - R_386_IRELATIVE

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/X86/X86Target.h -------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "X86LinkingContext.h"

View File

@ -5,5 +5,7 @@ add_llvm_library(lldX86_64ELFTarget
X86_64RelocationPass.cpp
LINK_LIBS
lldCore
lldELF
LLVMObject
LLVMSupport
)

View File

@ -11,6 +11,7 @@
#include "DynamicLibraryWriter.h"
#include "X86_64LinkingContext.h"
#include "X86_64TargetHandler.h"
namespace lld {
namespace elf {

View File

@ -8,10 +8,15 @@
//===----------------------------------------------------------------------===//
#include "X86_64LinkingContext.h"
#include "X86_64TargetHandler.h"
#include "X86_64RelocationPass.h"
using namespace lld;
elf::X86_64LinkingContext::X86_64LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new X86_64TargetHandler(*this))) {}
void elf::X86_64LinkingContext::addPasses(PassManager &pm) {
auto pass = createX86_64RelocationPass(*this);
if (pass)

View File

@ -10,7 +10,6 @@
#ifndef LLD_READER_WRITER_ELF_X86_64_X86_64_LINKING_CONTEXT_H
#define LLD_READER_WRITER_ELF_X86_64_X86_64_LINKING_CONTEXT_H
#include "X86_64TargetHandler.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
@ -27,9 +26,7 @@ enum {
class X86_64LinkingContext final : public ELFLinkingContext {
public:
X86_64LinkingContext(llvm::Triple triple)
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new X86_64TargetHandler(*this))) {}
X86_64LinkingContext(llvm::Triple);
void addPasses(PassManager &) override;

View File

@ -1,10 +0,0 @@
//===- lib/ReaderWriter/ELF/X86_64/X86_64Target.h -------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "X86_64LinkingContext.h"

View File

@ -16,8 +16,10 @@ add_llvm_library(lldMachO
StubsPass.cpp
WriterMachO.cpp
LINK_LIBS
lldReaderWriter
lldCore
lldPasses
lldYAML
LLVMObject
LLVMSupport
)

View File

@ -9,6 +9,6 @@
LLD_LEVEL := ../../..
LIBRARYNAME := lldMachO
USEDLIBS = lldReaderWriter.a lldCore.a
USEDLIBS = lldCore.a
include $(LLD_LEVEL)/Makefile

View File

@ -10,7 +10,8 @@ add_llvm_library(lldPECOFF
WriterImportLibrary.cpp
WriterPECOFF.cpp
LINK_LIBS
lldReaderWriter
lldCore
lldPasses
LLVMObject
LLVMSupport
)

View File

@ -9,6 +9,6 @@
LLD_LEVEL := ../../..
LIBRARYNAME := lldPECOFF
USEDLIBS = lldReaderWriter.a lldCore.a
USEDLIBS = lldCore.a
include $(LLD_LEVEL)/Makefile