Index: lld/trunk/include/lld/ReaderWriter/ELFTargets.h =================================================================== --- lld/trunk/include/lld/ReaderWriter/ELFTargets.h +++ lld/trunk/include/lld/ReaderWriter/ELFTargets.h @@ -26,7 +26,6 @@ LLVM_TARGET(ARM) LLVM_TARGET(Hexagon) LLVM_TARGET(Mips) -LLVM_TARGET(PPC) LLVM_TARGET(X86) LLVM_TARGET(X86_64) Index: lld/trunk/lib/Driver/CMakeLists.txt =================================================================== --- lld/trunk/lib/Driver/CMakeLists.txt +++ lld/trunk/lib/Driver/CMakeLists.txt @@ -28,7 +28,6 @@ lldARMELFTarget lldHexagonELFTarget lldMipsELFTarget - lldPPCELFTarget lldX86ELFTarget lldX86_64ELFTarget lldCore Index: lld/trunk/lib/Driver/GnuLdDriver.cpp =================================================================== --- lld/trunk/lib/Driver/GnuLdDriver.cpp +++ lld/trunk/lib/Driver/GnuLdDriver.cpp @@ -329,7 +329,6 @@ LLVM_TARGET(ARM) LLVM_TARGET(Hexagon) LLVM_TARGET(Mips) - LLVM_TARGET(PPC) LLVM_TARGET(X86) LLVM_TARGET(X86_64) return nullptr; Index: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt +++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt @@ -14,7 +14,6 @@ add_subdirectory(X86) add_subdirectory(X86_64) -add_subdirectory(PPC) add_subdirectory(Mips) add_subdirectory(Hexagon) add_subdirectory(AArch64) Index: lld/trunk/lib/ReaderWriter/ELF/Makefile =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/Makefile +++ lld/trunk/lib/ReaderWriter/ELF/Makefile @@ -14,6 +14,6 @@ CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF # these link against this lib -PARALLEL_DIRS := Hexagon PPC X86 X86_64 Mips AArch64 ARM +PARALLEL_DIRS := Hexagon X86 X86_64 Mips AArch64 ARM include $(LLD_LEVEL)/Makefile Index: lld/trunk/lib/ReaderWriter/ELF/Mips/Makefile =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/Mips/Makefile +++ lld/trunk/lib/ReaderWriter/ELF/Mips/Makefile @@ -1,4 +1,4 @@ -##===- lld/lib/ReaderWriter/ELF/PPC/Makefile ----------*- Makefile -*-===## +##===- lld/lib/ReaderWriter/ELF/Mips/Makefile ----------*- Makefile -*-===## # # The LLVM Compiler Infrastructure # Index: lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt +++ lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt @@ -1,9 +0,0 @@ -add_llvm_library(lldPPCELFTarget - PPCLinkingContext.cpp - PPCTargetHandler.cpp - LINK_LIBS - lldCore - lldELF - LLVMObject - LLVMSupport - ) Index: lld/trunk/lib/ReaderWriter/ELF/PPC/Makefile =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/Makefile +++ lld/trunk/lib/ReaderWriter/ELF/PPC/Makefile @@ -1,15 +0,0 @@ -##===- lld/lib/ReaderWriter/ELF/PPC/Makefile ----------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LLD_LEVEL := ../../../.. -LIBRARYNAME := lldPPCELFTarget -USEDLIBS = lldCore.a -CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF - -include $(LLD_LEVEL)/Makefile Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFFile.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFFile.h +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFFile.h @@ -1,41 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPCELFFile.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_PPC_ELF_FILE_H -#define LLD_READER_WRITER_ELF_PPC_ELF_FILE_H - -#include "ELFReader.h" - -namespace lld { -namespace elf { - -class PPCLinkingContext; - -template class PPCELFFile : public ELFFile { -public: - PPCELFFile(std::unique_ptr mb, bool atomizeStrings) - : ELFFile(std::move(mb), atomizeStrings) {} - - static ErrorOr> - create(std::unique_ptr mb, bool atomizeStrings) { - return std::unique_ptr>( - new PPCELFFile(std::move(mb), atomizeStrings)); - } -}; - -template class PPCDynamicFile : public DynamicFile { -public: - PPCDynamicFile(const PPCLinkingContext &context, StringRef name) - : DynamicFile(context, name) {} -}; - -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_PPC_ELF_FILE_H Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h @@ -1,60 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCELFReader.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_PPC_PPC_ELF_READER_H -#define LLD_READER_WRITER_PPC_PPC_ELF_READER_H - -#include "ELFReader.h" -#include "PPCELFFile.h" - -namespace lld { -namespace elf { - -typedef llvm::object::ELFType PPCELFType; - -struct PPCDynamicFileCreateELFTraits { - typedef llvm::ErrorOr> result_type; - - template - static result_type create(std::unique_ptr mb, - bool useUndefines) { - return lld::elf::PPCDynamicFile::create(std::move(mb), useUndefines); - } -}; - -struct PPCELFFileCreateELFTraits { - typedef llvm::ErrorOr> result_type; - - template - static result_type create(std::unique_ptr mb, - bool atomizeStrings) { - return lld::elf::PPCELFFile::create(std::move(mb), atomizeStrings); - } -}; - -class PPCELFObjectReader - : public ELFObjectReader { -public: - PPCELFObjectReader(bool atomizeStrings) - : ELFObjectReader( - atomizeStrings, llvm::ELF::EM_PPC) {} -}; - -class PPCELFDSOReader - : public ELFDSOReader { -public: - PPCELFDSOReader(bool useUndefines) - : ELFDSOReader( - useUndefines, llvm::ELF::EM_PPC) {} -}; - -} // namespace elf -} // namespace lld - -#endif // LLD_READER_WRITER_PPC_PPC_ELF_READER_H Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h @@ -1,32 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCLinkingContext.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_PPC_PPC_LINKING_CONTEXT_H -#define LLD_READER_WRITER_ELF_PPC_PPC_LINKING_CONTEXT_H - -#include "lld/ReaderWriter/ELFLinkingContext.h" -#include "llvm/Object/ELF.h" -#include "llvm/Support/ELF.h" - -namespace lld { -namespace elf { - -class PPCLinkingContext final : public ELFLinkingContext { -public: - static std::unique_ptr create(llvm::Triple); - PPCLinkingContext(llvm::Triple triple); - - /// \brief PPC has no relative relocations defined - bool isRelativeReloc(const Reference &) const override { return false; } -}; - -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_PPC_PPC_LINKING_CONTEXT_H Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.cpp +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.cpp @@ -1,29 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCLinkingContext.cpp ---------------------===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "PPCLinkingContext.h" -#include "PPCTargetHandler.h" -#include "lld/Core/LLVM.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/Support/ErrorOr.h" - -using namespace lld; - -std::unique_ptr -elf::PPCLinkingContext::create(llvm::Triple triple) { - if (triple.getArch() == llvm::Triple::ppc) - return std::unique_ptr( - new elf::PPCLinkingContext(triple)); - return nullptr; -} - -elf::PPCLinkingContext::PPCLinkingContext(llvm::Triple triple) - : ELFLinkingContext(triple, std::unique_ptr( - new PPCTargetHandler(*this))) {} - Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h @@ -1,67 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCTargetHandler.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_PPC_PPC_TARGET_HANDLER_H -#define LLD_READER_WRITER_ELF_PPC_PPC_TARGET_HANDLER_H - -#include "DefaultTargetHandler.h" -#include "PPCELFReader.h" -#include "TargetLayout.h" - -namespace lld { -namespace elf { -class PPCLinkingContext; - -template class PPCTargetLayout : public TargetLayout { -public: - PPCTargetLayout(PPCLinkingContext &context) : TargetLayout(context) {} -}; - -class PPCTargetRelocationHandler final : public TargetRelocationHandler { -public: - std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, - const lld::AtomLayout &, - const Reference &) const override; -}; - -class PPCTargetHandler final - : public DefaultTargetHandler { -public: - PPCTargetHandler(PPCLinkingContext &context); - - PPCTargetLayout &getTargetLayout() override { - return *(_ppcTargetLayout.get()); - } - - void registerRelocationNames(Registry ®istry) override; - - const PPCTargetRelocationHandler &getRelocationHandler() const override { - return *(_ppcRelocationHandler.get()); - } - - std::unique_ptr getObjReader(bool atomizeStrings) override { - return std::unique_ptr(new PPCELFObjectReader(atomizeStrings)); - } - - std::unique_ptr getDSOReader(bool useShlibUndefines) override { - return std::unique_ptr(new PPCELFDSOReader(useShlibUndefines)); - } - - std::unique_ptr getWriter() override; - -private: - static const Registry::KindStrings kindStrings[]; - PPCLinkingContext &_ppcLinkingContext; - std::unique_ptr> _ppcTargetLayout; - std::unique_ptr _ppcRelocationHandler; -}; -} // end namespace elf -} // end namespace lld - -#endif Index: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp +++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp @@ -1,93 +0,0 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp ----------------------===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "PPCTargetHandler.h" -#include "PPCLinkingContext.h" - -using namespace lld; -using namespace elf; - -using namespace llvm::ELF; - -/// \brief The following relocation routines are derived from the -/// SYSTEM V APPLICATION BINARY INTERFACE: PowerPC Processor Supplement -/// Symbols used: -/// A: Added used to compute the value, r_addend -/// P: Place address of the field being relocated, r_offset -/// S: Value of the symbol whose index resides in the relocation entry. - -/// \brief low24 (S + A - P) >> 2 : Verify -static int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S, - uint64_t A) { - int32_t result = (uint32_t)(((S + A) - P)); - if ((result < 0x1000000) && (result > -0x1000000)) { - result &= ~-(0x1000000); - *reinterpret_cast(location) = result | - (uint32_t)*reinterpret_cast(location); - return 0; - } - return 1; -} - -std::error_code PPCTargetRelocationHandler::applyRelocation( - ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, - const Reference &ref) const { - uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; - uint8_t *location = atomContent + ref.offsetInAtom(); - uint64_t targetVAddress = writer.addressOfAtom(ref.target()); - uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom(); - - if (ref.kindNamespace() != Reference::KindNamespace::ELF) - return std::error_code(); - assert(ref.kindArch() == Reference::KindArch::PowerPC); - switch (ref.kindValue()) { - case R_PPC_REL24: - relocB24PCREL(location, relocVAddress, targetVAddress, ref.addend()); - break; - - default: - return make_unhandled_reloc_error(); - } - - return std::error_code(); -} - -PPCTargetHandler::PPCTargetHandler(PPCLinkingContext &context) - : _ppcLinkingContext(context), - _ppcTargetLayout(new PPCTargetLayout(context)), - _ppcRelocationHandler(new PPCTargetRelocationHandler()) {} - -void PPCTargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::PowerPC, kindStrings); -} - -std::unique_ptr PPCTargetHandler::getWriter() { - switch (_ppcLinkingContext.getOutputELFType()) { - case llvm::ELF::ET_EXEC: - return std::unique_ptr(new elf::ExecutableWriter( - _ppcLinkingContext, *_ppcTargetLayout.get())); - case llvm::ELF::ET_DYN: - return std::unique_ptr(new elf::DynamicLibraryWriter( - _ppcLinkingContext, *_ppcTargetLayout.get())); - case llvm::ELF::ET_REL: - llvm_unreachable("TODO: support -r mode"); - default: - llvm_unreachable("unsupported output type"); - } -} - -#define ELF_RELOC(name, value) LLD_KIND_STRING_ENTRY(name), - -const Registry::KindStrings PPCTargetHandler::kindStrings[] = { -#include "llvm/Support/ELFRelocs/PowerPC.def" - LLD_KIND_STRING_END -}; - -#undef ELF_RELOC Index: lld/trunk/test/elf/ppc.test =================================================================== --- lld/trunk/test/elf/ppc.test +++ lld/trunk/test/elf/ppc.test @@ -1,14 +0,0 @@ -RUN: lld -flavor gnu -target powerpc %p/Inputs/branch-test.ppc %p/Inputs/target-test.ppc -o %t1 --noinhibit-exec -RUN: llvm-readobj -h %t1 | FileCheck -check-prefix=ppc-readobj %s - - -ppc-readobj: ElfHeader { -ppc-readobj: Ident { -ppc-readobj: Class: 32-bit (0x1) -ppc-readobj: DataEncoding: BigEndian (0x2) -ppc-readobj: FileVersion: 1 -ppc-readobj: OS/ABI: SystemV (0x0) -ppc-readobj: ABIVersion: 0 -ppc-readobj: } -ppc-readobj: Type: Executable (0x2) -ppc-readobj: Machine: EM_PPC (0x14) Index: lld/trunk/tools/lld/Makefile =================================================================== --- lld/trunk/tools/lld/Makefile +++ lld/trunk/tools/lld/Makefile @@ -22,7 +22,7 @@ USEDLIBS = lldDriver.a lldConfig.a \ lldELF.a lldMachO.a lldPasses.a lldPECOFF.a lldYAML.a \ lldReaderWriter.a lldCore.a lldNative.a \ - lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \ + lldHexagonELFTarget.a lldMipsELFTarget.a \ lldX86ELFTarget.a lldX86_64ELFTarget.a lldAArch64ELFTarget.a \ lldARMELFTarget.a \ LLVMOption.a