Update mclinker for LLVM rebase to r222494.
This corresponds to the following upstream mclinker change:
commit b2f1691276052c4215abf36715d43248d6337cf8
Author: Diana Chen <mysekki@gmail.com>
Date: Tue Nov 25 14:03:29 2014 +0800
option: Allow `-hash-style' can be specified zero or more times
Change-Id: I332546680bb45cf9692adfa2c2d3dcdc84361afc
diff --git a/lib/ADT/GraphLite/Digraph.cpp b/lib/ADT/GraphLite/Digraph.cpp
deleted file mode 100644
index 301f9fa..0000000
--- a/lib/ADT/GraphLite/Digraph.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//===- Digraph.cpp --------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/ADT/GraphLite/Digraph.h>
-
-using namespace mcld::graph;
-
-//===----------------------------------------------------------------------===//
-// Digraph::Arc
-//===----------------------------------------------------------------------===//
-Digraph::Arc::Arc()
-{
-}
-
-bool Digraph::Arc::operator==(const Digraph::Node& pOther) const
-{
- return true;
-}
-
-bool Digraph::Arc::operator!=(const Digraph::Node& pOther) const
-{
- return true;
-}
-
-Digraph::Node Digraph::Arc::source() const
-{
- return Node();
-}
-
-Digraph::Node Digraph::Arc::target() const
-{
- return Node();
-}
-
-Digraph::Arc::Arc(Digraph& pParent)
-{
-}
-
-
-//===----------------------------------------------------------------------===//
-// Digraph
-//===----------------------------------------------------------------------===//
-Digraph::Digraph()
-{
-}
-
-
-Digraph::Node Digraph::addNode()
-{
- return Node();
-}
-
-
-Digraph::Arc
-Digraph::addArc(const Digraph::Node& pSource, const Digraph::Node& pTarget)
-{
- return Arc();
-}
-
-
-void Digraph::erase(const Digraph::Node& pNode)
-{
-}
-
-
-void Digraph::erase(const Digraph::Arc& pArc)
-{
-}
-
-
-void Digraph::clear()
-{
-}
-
-unsigned int Digraph::numOfNodes() const
-{
- return 0;
-}
-
-unsigned int Digraph::numOfArcs() const
-{
- return 0;
-}
diff --git a/lib/ADT/GraphLite/ListDigraph.cpp b/lib/ADT/GraphLite/ListDigraph.cpp
deleted file mode 100644
index fcf957b..0000000
--- a/lib/ADT/GraphLite/ListDigraph.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-//===- ListDigraph.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/ADT/GraphLite/ListDigraph.h>
-
-using namespace mcld::graph;
-
-//===----------------------------------------------------------------------===//
-// ListDigraph::Node
-//===----------------------------------------------------------------------===//
-ListDigraph::Node::Node()
- : prev(NULL), next(NULL), first_in(NULL), first_out(NULL) {
-}
-
-//===----------------------------------------------------------------------===//
-// ListDigraph::Arc
-//===----------------------------------------------------------------------===//
-ListDigraph::Arc::Arc()
- : target(NULL), source(NULL),
- prev_in(NULL), next_in(NULL), prev_out(NULL), next_out(NULL) {
-}
-
-//===----------------------------------------------------------------------===//
-// ListDigraph
-//===----------------------------------------------------------------------===//
-ListDigraph::ListDigraph()
- : m_pNodeHead(NULL), m_pFreeNodeHead(NULL), m_pFreeArcHead(NULL),
- m_NodeList(32), m_ArcList(32) {
-}
-
-
-ListDigraph::Node* ListDigraph::addNode()
-{
- // 1. find an available free node
- Node* result = NULL;
- if (NULL == m_pFreeNodeHead) {
- result = m_NodeList.allocate();
- new (result) Node();
- }
- else {
- result = m_pFreeNodeHead;
- m_pFreeNodeHead = m_pFreeNodeHead->next;
- }
-
- // 2. set up linkages
- result->prev = NULL;
- result->next = m_pNodeHead;
-
- // 3. reset head node
- if (NULL != m_pNodeHead) {
- m_pNodeHead->prev = result;
- }
- m_pNodeHead = result;
-
- return result;
-}
-
-
-ListDigraph::Arc* ListDigraph::addArc(Node& pU, Node& pV)
-{
- // 1. find an available free arc
- Arc* result = NULL;
- if (NULL == m_pFreeArcHead) {
- result = m_ArcList.allocate();
- new (result) Arc();
- }
- else {
- result = m_pFreeArcHead;
- m_pFreeArcHead = m_pFreeArcHead->next_in;
- }
-
- // 2. set up arc
- result->source = &pU;
- result->target = &pV;
-
- // 3. set up fan-out linked list
- result->next_out = pU.first_out;
- if (NULL != pU.first_out) {
- pU.first_out->prev_out = result;
- }
- pU.first_out = result;
-
- // 4. set up fan-in linked list
- result->next_in = pV.first_in;
- if (NULL != pV.first_in) {
- pV.first_in->prev_in = result;
- }
- pV.first_in = result;
-
- return result;
-}
-
-void ListDigraph::erase(ListDigraph::Node& pNode)
-{
- // 1. connect previous node and next node.
- if (NULL != pNode.next) {
- pNode.next->prev = pNode.prev;
- }
-
- if (NULL != pNode.prev) {
- pNode.prev->next = pNode.next;
- }
- else { // pNode.prev is NULL => pNode is the head
- m_pNodeHead = pNode.next;
- }
-
- // 2. remove all fan-in arcs
- Arc* fan_in = pNode.first_in;
- while(NULL != fan_in) {
- Arc* next_in = fan_in->next_in;
- erase(*fan_in);
- fan_in = next_in;
- }
-
- // 3. remove all fan-out arcs
- Arc* fan_out = pNode.first_out;
- while(NULL != fan_out) {
- Arc* next_out = fan_out->next_out;
- erase(*fan_out);
- fan_out = next_out;
- }
-
- // 4. put pNode in the free node list
- pNode.next = m_pFreeNodeHead;
- pNode.prev = NULL;
- if (NULL != m_pFreeNodeHead)
- m_pFreeNodeHead->prev = &pNode;
- m_pFreeNodeHead = &pNode;
-}
-
-
-void ListDigraph::erase(ListDigraph::Arc& pArc)
-{
- // 1. remove from the fan-out list
- if (NULL != pArc.prev_out) {
- pArc.prev_out->next_out = pArc.next_out;
- }
- else { // pArc.prev_out is NULL => pArc is the first_out of the source
- pArc.source->first_out = pArc.next_out;
- }
-
- if (NULL != pArc.next_out) {
- pArc.next_out->prev_out = pArc.prev_out;
- }
-
- // 2. remove from the fan-in list
- if (NULL != pArc.prev_in) {
- pArc.prev_in->next_in = pArc.next_in;
- }
- else {
- pArc.target->first_in = pArc.next_in;
- }
-
- if (NULL != pArc.next_in) {
- pArc.next_in->prev_in = pArc.prev_in;
- }
-
- // 3. put pArc in the free arc list
- // Use fan-in links to chain the free list
- pArc.next_in = m_pFreeArcHead;
- m_pFreeArcHead = &pArc;
-}
-
-
-void ListDigraph::clear()
-{
- m_pNodeHead = NULL;
- m_pFreeNodeHead = NULL;
- m_pFreeArcHead = NULL;
- m_NodeList.clear();
- m_ArcList.clear();
-}
-
diff --git a/lib/ADT/StringEntry.cpp b/lib/ADT/StringEntry.cpp
index e824804..405396e 100644
--- a/lib/ADT/StringEntry.cpp
+++ b/lib/ADT/StringEntry.cpp
@@ -1,4 +1,4 @@
-//===- StringEntry.cpp -----------------------------------------------------===//
+//===- StringEntry.cpp ----------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,44 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/ADT/StringEntry.h>
+#include "mcld/ADT/StringEntry.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// StringEntry<llvm::StringRef>
//===----------------------------------------------------------------------===//
-StringEntry<llvm::StringRef>::StringEntry()
-{
+StringEntry<llvm::StringRef>::StringEntry() {
}
-StringEntry<llvm::StringRef>::StringEntry(const StringEntry::key_type& pKey)
-{
+StringEntry<llvm::StringRef>::StringEntry(const StringEntry::key_type& pKey) {
}
-StringEntry<llvm::StringRef>::StringEntry(const StringEntry<llvm::StringRef>& pCopy)
-{
+StringEntry<llvm::StringRef>::StringEntry(
+ const StringEntry<llvm::StringRef>& pCopy) {
assert("Copy constructor of StringEntry should not be called!");
}
-StringEntry<llvm::StringRef>::~StringEntry()
-{
+StringEntry<llvm::StringRef>::~StringEntry() {
if (!m_Value.empty())
free(const_cast<char*>(m_Value.data()));
}
-void StringEntry<llvm::StringRef>::setValue(llvm::StringRef& pVal)
-{
- char* data = (char*)malloc(pVal.size()+1);
- strcpy(data, pVal.data());
+void StringEntry<llvm::StringRef>::setValue(llvm::StringRef pVal) {
+ char* data = reinterpret_cast<char*>(malloc(pVal.size() + 1));
+ ::memcpy(data, pVal.data(), pVal.size());
m_Value = llvm::StringRef(data, pVal.size());
}
-void StringEntry<llvm::StringRef>::setValue(const char* pVal)
-{
+void StringEntry<llvm::StringRef>::setValue(const char* pVal) {
size_t length = strlen(pVal);
- char* data = (char*)malloc(length+1);
- strcpy(data, pVal);
+ char* data = reinterpret_cast<char*>(malloc(length + 1));
+ ::memcpy(data, pVal, length);
m_Value = llvm::StringRef(data, length);
}
+} // namespace mcld
diff --git a/lib/CodeGen/Android.mk b/lib/CodeGen/Android.mk
deleted file mode 100644
index 9954552..0000000
--- a/lib/CodeGen/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-mcld_codegen_SRC_FILES := \
- MCLDTargetMachine.cpp \
- MCLinker.cpp
-
-# For the host
-# =====================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(mcld_codegen_SRC_FILES)
-LOCAL_MODULE:= libmcldCodeGen
-
-LOCAL_MODULE_TAGS := optional
-
-include $(MCLD_HOST_BUILD_MK)
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# For the device
-# =====================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(mcld_codegen_SRC_FILES)
-LOCAL_MODULE:= libmcldCodeGen
-
-LOCAL_MODULE_TAGS := optional
-
-include $(MCLD_DEVICE_BUILD_MK)
-include $(BUILD_STATIC_LIBRARY)
diff --git a/lib/CodeGen/MCLDTargetMachine.cpp b/lib/CodeGen/MCLDTargetMachine.cpp
deleted file mode 100644
index 7749748..0000000
--- a/lib/CodeGen/MCLDTargetMachine.cpp
+++ /dev/null
@@ -1,382 +0,0 @@
-//===- MCLDTargetMachine.cpp ----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/CodeGen/TargetMachine.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/CodeGen/MCLinker.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/ToolOutputFile.h>
-#include <mcld/Target/TargetLDBackend.h>
-
-#include <llvm/Analysis/Passes.h>
-#include <llvm/CodeGen/AsmPrinter.h>
-#include <llvm/CodeGen/MachineFunctionAnalysis.h>
-#include <llvm/CodeGen/MachineModuleInfo.h>
-#include <llvm/CodeGen/GCStrategy.h>
-#include <llvm/CodeGen/Passes.h>
-#include <llvm/IR/DataLayout.h>
-#include <llvm/IR/IRPrintingPasses.h>
-#include <llvm/IR/Verifier.h>
-#include <llvm/MC/MCAsmInfo.h>
-#include <llvm/MC/MCStreamer.h>
-#include <llvm/MC/MCInstrInfo.h>
-#include <llvm/MC/MCSubtargetInfo.h>
-#include <llvm/MC/MCObjectStreamer.h>
-#include <llvm/MC/MCAssembler.h>
-#include <llvm/MC/MCObjectWriter.h>
-#include <llvm/MC/MCContext.h>
-#include <llvm/PassManager.h>
-#include <llvm/Support/CommandLine.h>
-#include <llvm/Support/Debug.h>
-#include <llvm/Support/TargetRegistry.h>
-#include <llvm/Support/FormattedStream.h>
-#include <llvm/Target/TargetInstrInfo.h>
-#include <llvm/Target/TargetLowering.h>
-#include <llvm/Target/TargetOptions.h>
-#include <llvm/Target/TargetSubtargetInfo.h>
-#include <llvm/Target/TargetLoweringObjectFile.h>
-#include <llvm/Target/TargetRegisterInfo.h>
-#include <llvm/Transforms/Scalar.h>
-
-#include <string>
-
-using namespace mcld;
-using namespace llvm;
-
-//===----------------------------------------------------------------------===//
-/// Arguments
-//===----------------------------------------------------------------------===//
-// Enable or disable FastISel. Both options are needed, because
-// FastISel is enabled by default with -fast, and we wish to be
-// able to enable or disable fast-isel independently from -O0.
-static cl::opt<cl::boolOrDefault>
-ArgEnableFastISelOption("lfast-isel", cl::Hidden,
- cl::desc("Enable the \"fast\" instruction selector"));
-
-static cl::opt<bool>
-ArgShowMCEncoding("lshow-mc-encoding",
- cl::Hidden,
- cl::desc("Show encoding in .s output"));
-
-static cl::opt<bool>
-ArgShowMCInst("lshow-mc-inst",
- cl::Hidden,
- cl::desc("Show instruction structure in .s output"));
-
-static cl::opt<cl::boolOrDefault>
-ArgAsmVerbose("fverbose-asm",
- cl::desc("Put extra commentary information in the \
- generated assembly code to make it more readable."),
- cl::init(cl::BOU_UNSET));
-
-static bool getVerboseAsm(TargetMachine &TM) {
- switch (ArgAsmVerbose) {
- default:
- case cl::BOU_UNSET: return TM.getAsmVerbosityDefault();
- case cl::BOU_TRUE: return true;
- case cl::BOU_FALSE: return false;
- }
-}
-
-
-//===----------------------------------------------------------------------===//
-// MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-mcld::MCLDTargetMachine::MCLDTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : m_TM(pTM),
- m_pLLVMTarget(&pLLVMTarget),
- m_pMCLDTarget(&pMCLDTarget),
- m_Triple(pTriple) {
-}
-
-mcld::MCLDTargetMachine::~MCLDTargetMachine()
-{
- m_pLLVMTarget = NULL;
- m_pMCLDTarget = NULL;
-}
-
-const mcld::Target& mcld::MCLDTargetMachine::getTarget() const
-{
- return *m_pMCLDTarget;
-}
-
-/// Turn exception handling constructs into something the code generators can
-/// handle.
-static void addPassesToHandleExceptions(llvm::TargetMachine *TM,
- llvm::legacy::PassManagerBase &PM) {
- switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
- case llvm::ExceptionHandling::SjLj:
- // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
- // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
- // catch info can get misplaced when a selector ends up more than one block
- // removed from the parent invoke(s). This could happen when a landing
- // pad is shared by multiple invokes and is also a target of a normal
- // edge from elsewhere.
- PM.add(createSjLjEHPreparePass(TM));
- // FALLTHROUGH
- case llvm::ExceptionHandling::DwarfCFI:
- case llvm::ExceptionHandling::ARM:
- case llvm::ExceptionHandling::WinEH:
- PM.add(createDwarfEHPass(TM));
- break;
- case llvm::ExceptionHandling::None:
- PM.add(createLowerInvokePass());
-
- // The lower invoke pass may create unreachable code. Remove it.
- PM.add(createUnreachableBlockEliminationPass());
- break;
- }
-}
-
-
-static llvm::MCContext *
-addPassesToGenerateCode(llvm::LLVMTargetMachine *TM,
- llvm::legacy::PassManagerBase &PM,
- bool DisableVerify)
-{
- // Targets may override createPassConfig to provide a target-specific sublass.
- TargetPassConfig *PassConfig = TM->createPassConfig(PM);
-
- // Set PassConfig options provided by TargetMachine.
- PassConfig->setDisableVerify(DisableVerify);
-
- PM.add(PassConfig);
-
- PassConfig->addIRPasses();
-
- addPassesToHandleExceptions(TM, PM);
-
- PassConfig->addISelPrepare();
-
- // Install a MachineModuleInfo class, which is an immutable pass that holds
- // all the per-module stuff we're generating, including MCContext.
- MachineModuleInfo *MMI =
- new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
- &TM->getTargetLowering()->getObjFileLowering());
- PM.add(MMI);
- MCContext *Context = &MMI->getContext(); // Return the MCContext by-ref.
-
- // Set up a MachineFunction for the rest of CodeGen to work on.
- PM.add(new MachineFunctionAnalysis(*TM));
-
- // Enable FastISel with -fast, but allow that to be overridden.
- if (ArgEnableFastISelOption == cl::BOU_TRUE ||
- (TM->getOptLevel() == CodeGenOpt::None &&
- ArgEnableFastISelOption != cl::BOU_FALSE))
- TM->setFastISel(true);
-
- // Ask the target for an isel.
- if (PassConfig->addInstSelector())
- return NULL;
-
- PassConfig->addMachinePasses();
-
- PassConfig->setInitialized();
-
- return Context;
-
-}
-
-bool
-mcld::MCLDTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase &pPM,
- mcld::ToolOutputFile& pOutput,
- mcld::CodeGenFileType pFileType,
- CodeGenOpt::Level pOptLvl,
- mcld::Module& pModule,
- LinkerConfig& pConfig,
- bool pDisableVerify)
-{
-
- llvm::MCContext* Context =
- addPassesToGenerateCode(static_cast<llvm::LLVMTargetMachine*>(&m_TM),
- pPM, pDisableVerify);
- if (!Context)
- return true;
-
- switch(pFileType) {
- default:
- case mcld::CGFT_NULLFile:
- assert(0 && "fatal: file type is not set!");
- break;
- case CGFT_ASMFile: {
- assert(Context != 0 && "Failed to get MCContext");
-
- if (getTM().Options.MCOptions.MCSaveTempLabels)
- Context->setAllowTemporaryLabels(false);
-
- if (addCompilerPasses(pPM,
- pOutput.formatted_os(),
- Context))
- return true;
- break;
- }
- case CGFT_OBJFile: {
- assert(Context != 0 && "Failed to get MCContext");
-
- if (getTM().Options.MCOptions.MCSaveTempLabels)
- Context->setAllowTemporaryLabels(false);
- if (addAssemblerPasses(pPM,
- pOutput.formatted_os(),
- Context))
- return true;
- break;
- }
- case CGFT_EXEFile: {
- pConfig.setCodeGenType(LinkerConfig::Exec);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_BINARY: {
- pConfig.setCodeGenType(LinkerConfig::Binary);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_DSOFile: {
- pConfig.setCodeGenType(LinkerConfig::DynObj);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_PARTIAL: {
- pConfig.setCodeGenType(LinkerConfig::Object);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- } // switch
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addCompilerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::formatted_raw_ostream &pOutput,
- llvm::MCContext *&Context)
-{
- const MCAsmInfo &MAI = *getTM().getMCAsmInfo();
- const MCInstrInfo &MII = *getTM().getInstrInfo();
- const MCRegisterInfo &MRI = *getTM().getRegisterInfo();
- const MCSubtargetInfo &STI = getTM().getSubtarget<MCSubtargetInfo>();
-
- MCInstPrinter *InstPrinter =
- m_pLLVMTarget->createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
- MII, *Context->getRegisterInfo(), STI);
-
- MCCodeEmitter* MCE = 0;
- MCAsmBackend *MAB = 0;
- if (ArgShowMCEncoding) {
- MCE = m_pLLVMTarget->createMCCodeEmitter(MII, MRI, STI, *Context);
- MAB = m_pLLVMTarget->createMCAsmBackend(MRI, m_Triple,
- getTM().getTargetCPU());
- }
-
-
- // now, we have MCCodeEmitter and MCAsmBackend, we can create AsmStreamer.
- std::unique_ptr<MCStreamer> AsmStreamer(
- m_pLLVMTarget->createAsmStreamer(*Context, pOutput,
- getVerboseAsm(getTM()),
- getTM().Options.MCOptions.MCUseDwarfDirectory,
- InstPrinter,
- MCE, MAB,
- ArgShowMCInst));
-
- llvm::MachineFunctionPass* funcPass =
- m_pLLVMTarget->createAsmPrinter(getTM(), *AsmStreamer.get());
-
- if (funcPass == 0)
- return true;
- // If successful, createAsmPrinter took ownership of AsmStreamer
- AsmStreamer.release();
- pPM.add(funcPass);
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addAssemblerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::raw_ostream &pOutput,
- llvm::MCContext *&Context)
-{
- // MCCodeEmitter
- const MCInstrInfo &MII = *getTM().getInstrInfo();
- const MCRegisterInfo &MRI = *getTM().getRegisterInfo();
- const MCSubtargetInfo &STI = getTM().getSubtarget<MCSubtargetInfo>();
- MCCodeEmitter* MCE =
- m_pLLVMTarget->createMCCodeEmitter(MII, MRI, STI, *Context);
-
- // MCAsmBackend
- MCAsmBackend* MAB =
- m_pLLVMTarget->createMCAsmBackend(MRI, m_Triple, getTM().getTargetCPU());
- if (MCE == 0 || MAB == 0)
- return true;
-
- // now, we have MCCodeEmitter and MCAsmBackend, we can create AsmStreamer.
- std::unique_ptr<MCStreamer> AsmStreamer(m_pLLVMTarget->createMCObjectStreamer(
- m_Triple, *Context, *MAB, pOutput, MCE, STI,
- getTM().Options.MCOptions.MCRelaxAll, getTM().Options.MCOptions.MCNoExecStack));
-
- AsmStreamer.get()->InitSections();
- MachineFunctionPass *funcPass =
- m_pLLVMTarget->createAsmPrinter(getTM(), *AsmStreamer.get());
- if (funcPass == 0)
- return true;
- // If successful, createAsmPrinter took ownership of AsmStreamer
- AsmStreamer.release();
- pPM.add(funcPass);
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addLinkerPasses(llvm::legacy::PassManagerBase &pPM,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- mcld::FileHandle& pFileHandle,
- llvm::MCContext *&Context)
-{
- // set up output's SOName
- if (pConfig.options().soname().empty()) {
- // if the output is a shared object, and the option -soname was not
- // enable, set soname as the output file name. soname must be UTF-8 string.
- pConfig.options().setSOName(pFileHandle.path().filename().native());
- }
-
- // set up output module name
- pModule.setName(pFileHandle.path().filename().native());
-
- MachineFunctionPass* funcPass = m_pMCLDTarget->createMCLinker(m_Triple,
- pConfig,
- pModule,
- pFileHandle);
- if (NULL == funcPass)
- return true;
-
- pPM.add(funcPass);
- return false;
-}
-
diff --git a/lib/CodeGen/MCLinker.cpp b/lib/CodeGen/MCLinker.cpp
deleted file mode 100644
index 471b0af..0000000
--- a/lib/CodeGen/MCLinker.cpp
+++ /dev/null
@@ -1,424 +0,0 @@
-//===- MCLinker.cpp -------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the MCLinker class.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/CodeGen/MCLinker.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/InputTree.h>
-#include <mcld/Linker.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/FileAction.h>
-#include <mcld/MC/CommandAction.h>
-#include <mcld/Object/ObjectLinker.h>
-#include <mcld/Support/CommandLine.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/raw_ostream.h>
-
-#include <llvm/IR/Module.h>
-#include <llvm/Support/CommandLine.h>
-
-#include <algorithm>
-#include <vector>
-#include <string>
-
-using namespace mcld;
-using namespace llvm;
-
-char MCLinker::m_ID = 0;
-
-//===----------------------------------------------------------------------===//
-// Help Functions
-//===----------------------------------------------------------------------===//
-static inline bool CompareAction(const InputAction* X, const InputAction* Y)
-{
- return (X->position() < Y->position());
-}
-
-//===----------------------------------------------------------------------===//
-// Positional Options
-// There are four kinds of positional options:
-// 1. Inputs, object files, such as /tmp/XXXX.o
-// 2. Namespecs, short names of libraries. A namespec may refer to an archive
-// or a shared library. For example, -lm.
-// 3. Attributes of inputs. Attributes describe inputs appears after them.
-// For example, --as-needed and --whole-archive.
-// 4. Groups. A Group is a set of archives. Linkers repeatedly read archives
-// in groups until there is no new undefined symbols.
-// 5. Bitcode. Bitcode is a kind of object files. MCLinker compiles it to
-// object file first, then link it as a object file. (Bitcode is recorded
-// in BitcodeOption, not be read by LLVM Command Line library.)
-//===----------------------------------------------------------------------===//
-// Inputs
-//===----------------------------------------------------------------------===//
-static cl::list<mcld::sys::fs::Path>
-ArgInputObjectFiles(cl::Positional,
- cl::desc("[input object files]"),
- cl::ZeroOrMore);
-
-//===----------------------------------------------------------------------===//
-// Namespecs
-//===----------------------------------------------------------------------===//
-static cl::list<std::string>
-ArgNameSpecList("l",
- cl::ZeroOrMore,
- cl::desc("Add the archive or object file specified by namespec to "
- "the list of files to link."),
- cl::value_desc("namespec"),
- cl::Prefix);
-
-static cl::alias
-ArgNameSpecListAlias("library",
- cl::desc("alias for -l"),
- cl::aliasopt(ArgNameSpecList));
-
-//===----------------------------------------------------------------------===//
-// Attributes
-//===----------------------------------------------------------------------===//
-static cl::list<bool>
-ArgWholeArchiveList("whole-archive",
- cl::ValueDisallowed,
- cl::desc("For each archive mentioned on the command line after "
- "the --whole-archive option, include all object files "
- "in the archive."));
-
-static cl::list<bool>
-ArgNoWholeArchiveList("no-whole-archive",
- cl::ValueDisallowed,
- cl::desc("Turn off the effect of the --whole-archive option for "
- "subsequent archive files."));
-
-static cl::list<bool>
-ArgAsNeededList("as-needed",
- cl::ValueDisallowed,
- cl::desc("This option affects ELF DT_NEEDED tags for dynamic "
- "libraries mentioned on the command line after the "
- "--as-needed option."));
-
-static cl::list<bool>
-ArgNoAsNeededList("no-as-needed",
- cl::ValueDisallowed,
- cl::desc("Turn off the effect of the --as-needed option for "
- "subsequent dynamic libraries"));
-
-static cl::list<bool>
-ArgAddNeededList("add-needed",
- cl::ValueDisallowed,
- cl::desc("--add-needed causes DT_NEEDED tags are always "
- "emitted for those libraries from DT_NEEDED tags. "
- "This is the default behavior."));
-
-static cl::list<bool>
-ArgNoAddNeededList("no-add-needed",
- cl::ValueDisallowed,
- cl::desc("--no-add-needed causes DT_NEEDED tags will never be "
- "emitted for those libraries from DT_NEEDED tags"));
-
-static cl::list<bool>
-ArgBDynamicList("Bdynamic",
- cl::ValueDisallowed,
- cl::desc("Link against dynamic library"));
-
-static cl::alias
-ArgBDynamicListAlias1("dy",
- cl::desc("alias for --Bdynamic"),
- cl::aliasopt(ArgBDynamicList));
-
-static cl::alias
-ArgBDynamicListAlias2("call_shared",
- cl::desc("alias for --Bdynamic"),
- cl::aliasopt(ArgBDynamicList));
-
-static cl::list<bool>
-ArgBStaticList("Bstatic",
- cl::ValueDisallowed,
- cl::desc("Link against static library"));
-
-static cl::alias
-ArgBStaticListAlias1("dn",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-static cl::alias
-ArgBStaticListAlias2("static",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-static cl::alias
-ArgBStaticListAlias3("non_shared",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-//===----------------------------------------------------------------------===//
-// Groups
-//===----------------------------------------------------------------------===//
-static cl::list<bool>
-ArgStartGroupList("start-group",
- cl::ValueDisallowed,
- cl::desc("start to record a group of archives"));
-
-static cl::alias
-ArgStartGroupListAlias("(",
- cl::desc("alias for --start-group"),
- cl::aliasopt(ArgStartGroupList));
-
-static cl::list<bool>
-ArgEndGroupList("end-group",
- cl::ValueDisallowed,
- cl::desc("stop recording a group of archives"));
-
-static cl::alias
-ArgEndGroupListAlias(")",
- cl::desc("alias for --end-group"),
- cl::aliasopt(ArgEndGroupList));
-
-//===----------------------------------------------------------------------===//
-// --defsym
-//===----------------------------------------------------------------------===//
-static cl::list<std::string>
-ArgDefSymList("defsym",
- cl::ZeroOrMore,
- cl::desc("Define a symbol"),
- cl::value_desc("symbol=expression"));
-
-//===----------------------------------------------------------------------===//
-// MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker::MCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : MachineFunctionPass(m_ID),
- m_Config(pConfig),
- m_Module(pModule),
- m_FileHandle(pFileHandle),
- m_pBuilder(NULL),
- m_pLinker(NULL) {
-}
-
-MCLinker::~MCLinker()
-{
- delete m_pLinker;
- delete m_pBuilder;
-}
-
-bool MCLinker::doInitialization(llvm::Module &pM)
-{
- // Now, all input arguments are prepared well, send it into ObjectLinker
- m_pLinker = new Linker();
-
- if (!m_pLinker->emulate(m_Module.getScript(), m_Config))
- return false;
-
- m_pBuilder = new IRBuilder(m_Module, m_Config);
-
- initializeInputTree(*m_pBuilder);
-
- return true;
-}
-
-bool MCLinker::doFinalization(llvm::Module &pM)
-{
- if (!m_pLinker->link(m_Module, *m_pBuilder))
- return true;
-
- if (!m_pLinker->emit(m_Module, m_FileHandle.handler()))
- return true;
-
- return false;
-}
-
-bool MCLinker::runOnMachineFunction(MachineFunction& pF)
-{
- // basically, linkers do nothing during function is generated.
- return false;
-}
-
-void MCLinker::initializeInputTree(IRBuilder& pBuilder)
-{
- if (0 == ArgInputObjectFiles.size() &&
- 0 == ArgNameSpecList.size() &&
- !m_Config.bitcode().hasDefined()) {
- fatal(diag::err_no_inputs);
- return;
- }
-
- size_t num_actions = ArgInputObjectFiles.size() +
- ArgNameSpecList.size() +
- ArgWholeArchiveList.size() +
- ArgNoWholeArchiveList.size() +
- ArgAsNeededList.size() +
- ArgNoAsNeededList.size() +
- ArgAddNeededList.size() +
- ArgNoAddNeededList.size() +
- ArgBDynamicList.size() +
- ArgBStaticList.size() +
- ArgStartGroupList.size() +
- ArgEndGroupList.size() +
- ArgDefSymList.size() +
- 1; // bitcode
- std::vector<InputAction*> actions;
- actions.reserve(num_actions);
-
- // ----- scripts ----- //
- /// -T
- if (!m_Config.options().getScriptList().empty()) {
- GeneralOptions::const_script_iterator ii, ie = m_Config.options().script_end();
- for (ii = m_Config.options().script_begin(); ii != ie; ++ii) {
- actions.push_back(new ScriptAction(0x0,
- *ii,
- ScriptFile::LDScript,
- m_Module.getScript().directories()));
- actions.push_back(new ContextAction(0x0));
- actions.push_back(new MemoryAreaAction(0x0, FileHandle::ReadOnly));
- }
- }
-
- /// --defsym
- cl::list<std::string>::iterator defsym, dsBegin, dsEnd;
- dsBegin = ArgDefSymList.begin();
- dsEnd = ArgDefSymList.end();
- for (defsym = dsBegin; defsym != dsEnd; ++defsym) {
- unsigned int pos = ArgDefSymList.getPosition(defsym - dsBegin);
- actions.push_back(new DefSymAction(pos, *defsym));
- }
-
- // ----- inputs ----- //
- cl::list<mcld::sys::fs::Path>::iterator input, inBegin, inEnd;
- inBegin = ArgInputObjectFiles.begin();
- inEnd = ArgInputObjectFiles.end();
- for (input = inBegin; input != inEnd; ++input) {
- unsigned int pos = ArgInputObjectFiles.getPosition(input - inBegin);
- actions.push_back(new InputFileAction(pos, *input));
- actions.push_back(new ContextAction(pos));
- actions.push_back(new MemoryAreaAction(pos, FileHandle::ReadOnly));
- }
-
- // ----- namespecs ----- //
- cl::list<std::string>::iterator namespec, nsBegin, nsEnd;
- nsBegin = ArgNameSpecList.begin();
- nsEnd = ArgNameSpecList.end();
- for (namespec = nsBegin; namespec != nsEnd; ++namespec) {
- unsigned int pos = ArgNameSpecList.getPosition(namespec - nsBegin);
- actions.push_back(new NamespecAction(pos, *namespec,
- m_Module.getScript().directories()));
- actions.push_back(new ContextAction(pos));
- actions.push_back(new MemoryAreaAction(pos, FileHandle::ReadOnly));
- }
-
- // ----- attributes ----- //
- /// --whole-archive
- cl::list<bool>::iterator attr, attrBegin, attrEnd;
- attrBegin = ArgWholeArchiveList.begin();
- attrEnd = ArgWholeArchiveList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgWholeArchiveList.getPosition(attr - attrBegin);
- actions.push_back(new WholeArchiveAction(pos));
- }
-
- /// --no-whole-archive
- attrBegin = ArgNoWholeArchiveList.begin();
- attrEnd = ArgNoWholeArchiveList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoWholeArchiveList.getPosition(attr - attrBegin);
- actions.push_back(new NoWholeArchiveAction(pos));
- }
-
- /// --as-needed
- attrBegin = ArgAsNeededList.begin();
- attrEnd = ArgAsNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgAsNeededList.getPosition(attr - attrBegin);
- actions.push_back(new AsNeededAction(pos));
- }
-
- /// --no-as-needed
- attrBegin = ArgNoAsNeededList.begin();
- attrEnd = ArgNoAsNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoAsNeededList.getPosition(attr - attrBegin);
- actions.push_back(new NoAsNeededAction(pos));
- }
-
- /// --add--needed
- attrBegin = ArgAddNeededList.begin();
- attrEnd = ArgAddNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgAddNeededList.getPosition(attr - attrBegin);
- actions.push_back(new AddNeededAction(pos));
- }
-
- /// --no-add--needed
- attrBegin = ArgNoAddNeededList.begin();
- attrEnd = ArgNoAddNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoAddNeededList.getPosition(attr - attrBegin);
- actions.push_back(new NoAddNeededAction(pos));
- }
-
- /// --Bdynamic
- attrBegin = ArgBDynamicList.begin();
- attrEnd = ArgBDynamicList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgBDynamicList.getPosition(attr - attrBegin);
- actions.push_back(new BDynamicAction(pos));
- }
-
- /// --Bstatic
- attrBegin = ArgBStaticList.begin();
- attrEnd = ArgBStaticList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgBStaticList.getPosition(attr - attrBegin);
- actions.push_back(new BStaticAction(pos));
- }
-
- // ----- groups ----- //
- /// --start-group
- cl::list<bool>::iterator group, gsBegin, gsEnd;
- gsBegin = ArgStartGroupList.begin();
- gsEnd = ArgStartGroupList.end();
- for (group = gsBegin; group != gsEnd; ++group) {
- unsigned int pos = ArgStartGroupList.getPosition(group - gsBegin);
- actions.push_back(new StartGroupAction(pos));
- }
-
- /// --end-group
- gsBegin = ArgEndGroupList.begin();
- gsEnd = ArgEndGroupList.end();
- for (group = gsBegin; group != gsEnd; ++group) {
- unsigned int pos = ArgEndGroupList.getPosition(group - gsBegin);
- actions.push_back(new EndGroupAction(pos));
- }
-
- // ----- bitcode ----- //
- if (m_Config.bitcode().hasDefined()) {
- actions.push_back(new BitcodeAction(m_Config.bitcode().getPosition(),
- m_Config.bitcode().getPath()));
- }
-
- // stable sort
- std::stable_sort(actions.begin(), actions.end(), CompareAction);
-
- // build up input tree
- std::vector<InputAction*>::iterator action, actionEnd = actions.end();
- for (action = actions.begin(); action != actionEnd; ++action) {
- (*action)->activate(pBuilder.getInputBuilder());
- delete *action;
- }
-
- if (pBuilder.getInputBuilder().isInGroup())
- report_fatal_error("no matched --start-group and --end-group");
-}
-
diff --git a/lib/Core/Android.mk b/lib/Core/Android.mk
index 8036cc5..f75025b 100644
--- a/lib/Core/Android.mk
+++ b/lib/Core/Android.mk
@@ -2,14 +2,13 @@
mcld_core_SRC_FILES := \
AttributeOption.cpp \
- BitcodeOption.cpp \
Environment.cpp \
GeneralOptions.cpp \
- IRBuilder.cpp \
InputTree.cpp \
- LinkerConfig.cpp \
- LinkerScript.cpp \
+ IRBuilder.cpp \
+ LinkerConfig.cpp \
Linker.cpp \
+ LinkerScript.cpp \
Module.cpp \
TargetOptions.cpp
diff --git a/lib/Core/AttributeOption.cpp b/lib/Core/AttributeOption.cpp
index d2a7947..cedfc0f 100644
--- a/lib/Core/AttributeOption.cpp
+++ b/lib/Core/AttributeOption.cpp
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/AttributeOption.h>
+#include "mcld/AttributeOption.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttributeOption
//===----------------------------------------------------------------------===//
-AttributeOption::AttributeOption()
-{
+AttributeOption::AttributeOption() {
}
-AttributeOption::~AttributeOption()
-{
+AttributeOption::~AttributeOption() {
}
+
+} // namespace mcld
diff --git a/lib/Core/BitcodeOption.cpp b/lib/Core/BitcodeOption.cpp
deleted file mode 100644
index 47d6667..0000000
--- a/lib/Core/BitcodeOption.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- BitcodeOption.cpp --------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/BitcodeOption.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// BitcodeOption
-//===----------------------------------------------------------------------===//
-BitcodeOption::BitcodeOption()
- : m_Position(-1) {
-}
-
-BitcodeOption::~BitcodeOption()
-{
-}
-
-bool BitcodeOption::hasDefined() const
-{
- return (m_Position != -1);
-}
diff --git a/lib/Core/Environment.cpp b/lib/Core/Environment.cpp
index 5755fe7..153704b 100644
--- a/lib/Core/Environment.cpp
+++ b/lib/Core/Environment.cpp
@@ -6,11 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Environment.h>
-#include <mcld/Support/TargetSelect.h>
+#include "mcld/Environment.h"
+#include "mcld/Support/TargetSelect.h"
-void mcld::Initialize()
-{
+void mcld::Initialize() {
static bool is_initialized = false;
if (is_initialized)
@@ -23,7 +22,5 @@
is_initialized = true;
}
-void mcld::Finalize()
-{
+void mcld::Finalize() {
}
-
diff --git a/lib/Core/GeneralOptions.cpp b/lib/Core/GeneralOptions.cpp
index f6e86b9..521ffa5 100644
--- a/lib/Core/GeneralOptions.cpp
+++ b/lib/Core/GeneralOptions.cpp
@@ -6,71 +6,69 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/GeneralOptions.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/ZOption.h>
+#include "mcld/GeneralOptions.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/ZOption.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GeneralOptions
//===----------------------------------------------------------------------===//
GeneralOptions::GeneralOptions()
- : m_Verbose(-1),
- m_MaxErrorNum(-1),
- m_MaxWarnNum(-1),
- m_ExecStack(Unknown),
- m_NoUndefined(Unknown),
- m_MulDefs(Unknown),
- m_CommPageSize(0x0),
- m_MaxPageSize(0x0),
- m_bCombReloc(true),
- m_bInitFirst(false),
- m_bInterPose(false),
- m_bLoadFltr(false),
- m_bNoCopyReloc(false),
- m_bNoDefaultLib(false),
- m_bNoDelete(false),
- m_bNoDLOpen(false),
- m_bNoDump(false),
- m_bRelro(false),
- m_bNow(false),
- m_bOrigin(false),
- m_bTrace(false),
- m_Bsymbolic(false),
- m_Bgroup(false),
- m_bPIE(false),
- m_bColor(true),
- m_bCreateEhFrameHdr(false),
- m_bNMagic(false),
- m_bOMagic(false),
- m_bStripDebug(false),
- m_bExportDynamic(false),
- m_bWarnSharedTextrel(false),
- m_bBinaryInput(false),
- m_bDefineCommon(false),
- m_bFatalWarnings(false),
- m_bNewDTags(false),
- m_bNoStdlib(false),
- m_bWarnMismatch(true),
- m_bGCSections(false),
- m_bPrintGCSections(false),
- m_bGenUnwindInfo(true),
- m_bPrintICFSections(false),
- m_ICF(ICF_None),
- m_ICFIterations(0) ,
- m_GPSize(8),
- m_StripSymbols(KeepAllSymbols),
- m_HashStyle(SystemV) {
+ : m_Verbose(-1),
+ m_MaxErrorNum(-1),
+ m_MaxWarnNum(-1),
+ m_ExecStack(Unknown),
+ m_NoUndefined(Unknown),
+ m_MulDefs(Unknown),
+ m_CommPageSize(0x0),
+ m_MaxPageSize(0x0),
+ m_bCombReloc(true),
+ m_bInitFirst(false),
+ m_bInterPose(false),
+ m_bLoadFltr(false),
+ m_bNoCopyReloc(false),
+ m_bNoDefaultLib(false),
+ m_bNoDelete(false),
+ m_bNoDLOpen(false),
+ m_bNoDump(false),
+ m_bRelro(false),
+ m_bNow(false),
+ m_bOrigin(false),
+ m_bTrace(false),
+ m_Bsymbolic(false),
+ m_Bgroup(false),
+ m_bPIE(false),
+ m_bColor(true),
+ m_bCreateEhFrameHdr(false),
+ m_bNMagic(false),
+ m_bOMagic(false),
+ m_bStripDebug(false),
+ m_bExportDynamic(false),
+ m_bWarnSharedTextrel(false),
+ m_bBinaryInput(false),
+ m_bDefineCommon(false),
+ m_bFatalWarnings(false),
+ m_bNewDTags(false),
+ m_bNoStdlib(false),
+ m_bWarnMismatch(true),
+ m_bGCSections(false),
+ m_bPrintGCSections(false),
+ m_bGenUnwindInfo(true),
+ m_bPrintICFSections(false),
+ m_ICF(ICF_None),
+ m_ICFIterations(0),
+ m_GPSize(8),
+ m_StripSymbols(KeepAllSymbols),
+ m_HashStyle(SystemV) {
}
-GeneralOptions::~GeneralOptions()
-{
+GeneralOptions::~GeneralOptions() {
}
-void GeneralOptions::setSOName(const std::string& pName)
-{
+void GeneralOptions::setSOName(const std::string& pName) {
size_t pos = pName.find_last_of(sys::fs::separator);
if (std::string::npos == pos)
m_SOName = pName;
@@ -78,8 +76,7 @@
m_SOName = pName.substr(pos + 1);
}
-void GeneralOptions::addZOption(const ZOption& pOption)
-{
+void GeneralOptions::addZOption(const ZOption& pOption) {
switch (pOption.kind()) {
case ZOption::CombReloc:
m_bCombReloc = true;
@@ -151,8 +148,7 @@
}
}
-bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const
-{
+bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const {
assert(pInput.type() == Input::Archive);
if (m_ExcludeLIBS.empty()) {
@@ -173,3 +169,5 @@
return false;
}
+
+} // namespace mcld
diff --git a/lib/Core/IRBuilder.cpp b/lib/Core/IRBuilder.cpp
index bc44990..252fc43 100644
--- a/lib/Core/IRBuilder.cpp
+++ b/lib/Core/IRBuilder.cpp
@@ -6,28 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/ELF.h>
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/IRBuilder.h"
+
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/ELF.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/StringRef.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Functions
//===----------------------------------------------------------------------===//
-LDFileFormat::Kind GetELFSectionKind(uint32_t pType, const char* pName,
- uint32_t pFlag)
-{
- if (pFlag & mcld::ELF::SHF_EXCLUDE)
+LDFileFormat::Kind GetELFSectionKind(uint32_t pType,
+ const char* pName,
+ uint32_t pFlag) {
+ if (pFlag & llvm::ELF::SHF_EXCLUDE)
return LDFileFormat::Exclude;
if (pFlag & llvm::ELF::SHF_MASKPROC)
@@ -35,11 +39,12 @@
// name rules
llvm::StringRef name(pName);
- if (name.startswith(".debug") ||
- name.startswith(".zdebug") ||
- name.startswith(".line") ||
- name.startswith(".stab"))
+ if (name.startswith(".debug") || name.startswith(".zdebug") ||
+ name.startswith(".line") || name.startswith(".stab")) {
+ if (name.startswith(".debug_str"))
+ return LDFileFormat::DebugString;
return LDFileFormat::Debug;
+ }
if (name.startswith(".comment"))
return LDFileFormat::MetaData;
if (name.startswith(".interp") || name.startswith(".dynamic"))
@@ -56,46 +61,46 @@
return LDFileFormat::LinkOnce;
// type rules
- switch(pType) {
- case llvm::ELF::SHT_NULL:
- return LDFileFormat::Null;
- case llvm::ELF::SHT_INIT_ARRAY:
- case llvm::ELF::SHT_FINI_ARRAY:
- case llvm::ELF::SHT_PREINIT_ARRAY:
- case llvm::ELF::SHT_PROGBITS: {
- if ((pFlag & llvm::ELF::SHF_EXECINSTR) != 0)
- return LDFileFormat::TEXT;
- else
- return LDFileFormat::DATA;
- }
- case llvm::ELF::SHT_SYMTAB:
- case llvm::ELF::SHT_DYNSYM:
- case llvm::ELF::SHT_STRTAB:
- case llvm::ELF::SHT_HASH:
- case llvm::ELF::SHT_DYNAMIC:
- case llvm::ELF::SHT_SYMTAB_SHNDX:
- return LDFileFormat::NamePool;
- case llvm::ELF::SHT_RELA:
- case llvm::ELF::SHT_REL:
- return LDFileFormat::Relocation;
- case llvm::ELF::SHT_NOBITS:
- return LDFileFormat::BSS;
- case llvm::ELF::SHT_NOTE:
- return LDFileFormat::Note;
- case llvm::ELF::SHT_GROUP:
- return LDFileFormat::Group;
- case llvm::ELF::SHT_GNU_versym:
- case llvm::ELF::SHT_GNU_verdef:
- case llvm::ELF::SHT_GNU_verneed:
- return LDFileFormat::Version;
- case llvm::ELF::SHT_SHLIB:
- return LDFileFormat::Target;
- default:
- if ((pType >= llvm::ELF::SHT_LOPROC && pType <= llvm::ELF::SHT_HIPROC) ||
- (pType >= llvm::ELF::SHT_LOOS && pType <= llvm::ELF::SHT_HIOS) ||
- (pType >= llvm::ELF::SHT_LOUSER && pType <= llvm::ELF::SHT_HIUSER))
+ switch (pType) {
+ case llvm::ELF::SHT_NULL:
+ return LDFileFormat::Null;
+ case llvm::ELF::SHT_INIT_ARRAY:
+ case llvm::ELF::SHT_FINI_ARRAY:
+ case llvm::ELF::SHT_PREINIT_ARRAY:
+ case llvm::ELF::SHT_PROGBITS: {
+ if ((pFlag & llvm::ELF::SHF_EXECINSTR) != 0)
+ return LDFileFormat::TEXT;
+ else
+ return LDFileFormat::DATA;
+ }
+ case llvm::ELF::SHT_SYMTAB:
+ case llvm::ELF::SHT_DYNSYM:
+ case llvm::ELF::SHT_STRTAB:
+ case llvm::ELF::SHT_HASH:
+ case llvm::ELF::SHT_DYNAMIC:
+ case llvm::ELF::SHT_SYMTAB_SHNDX:
+ return LDFileFormat::NamePool;
+ case llvm::ELF::SHT_RELA:
+ case llvm::ELF::SHT_REL:
+ return LDFileFormat::Relocation;
+ case llvm::ELF::SHT_NOBITS:
+ return LDFileFormat::BSS;
+ case llvm::ELF::SHT_NOTE:
+ return LDFileFormat::Note;
+ case llvm::ELF::SHT_GROUP:
+ return LDFileFormat::Group;
+ case llvm::ELF::SHT_GNU_versym:
+ case llvm::ELF::SHT_GNU_verdef:
+ case llvm::ELF::SHT_GNU_verneed:
+ return LDFileFormat::Version;
+ case llvm::ELF::SHT_SHLIB:
return LDFileFormat::Target;
- fatal(diag::err_unsupported_section) << pName << pType;
+ default:
+ if ((pType >= llvm::ELF::SHT_LOPROC && pType <= llvm::ELF::SHT_HIPROC) ||
+ (pType >= llvm::ELF::SHT_LOOS && pType <= llvm::ELF::SHT_HIOS) ||
+ (pType >= llvm::ELF::SHT_LOUSER && pType <= llvm::ELF::SHT_HIUSER))
+ return LDFileFormat::Target;
+ fatal(diag::err_unsupported_section) << pName << pType;
}
return LDFileFormat::MetaData;
}
@@ -104,21 +109,20 @@
// IRBuilder
//===----------------------------------------------------------------------===//
IRBuilder::IRBuilder(Module& pModule, const LinkerConfig& pConfig)
- : m_Module(pModule), m_Config(pConfig), m_InputBuilder(pConfig) {
+ : m_Module(pModule), m_Config(pConfig), m_InputBuilder(pConfig) {
m_InputBuilder.setCurrentTree(m_Module.getInputTree());
// FIXME: where to set up Relocation?
Relocation::SetUp(m_Config);
}
-IRBuilder::~IRBuilder()
-{
+IRBuilder::~IRBuilder() {
}
/// CreateInput - To create an input file and append it to the input tree.
Input* IRBuilder::CreateInput(const std::string& pName,
- const sys::fs::Path& pPath, Input::Type pType)
-{
+ const sys::fs::Path& pPath,
+ Input::Type pType) {
if (Input::Unknown == pType)
return ReadInput(pName, pPath);
@@ -132,24 +136,24 @@
}
/// ReadInput - To read an input file and append it to the input tree.
-Input*
-IRBuilder::ReadInput(const std::string& pName, const sys::fs::Path& pPath)
-{
- m_InputBuilder.createNode<InputTree::Positional>(pName, pPath, Input::Unknown);
+Input* IRBuilder::ReadInput(const std::string& pName,
+ const sys::fs::Path& pPath) {
+ m_InputBuilder.createNode<InputTree::Positional>(
+ pName, pPath, Input::Unknown);
Input* input = *m_InputBuilder.getCurrentNode();
if (!input->hasContext())
m_InputBuilder.setContext(*input);
if (!input->hasMemArea())
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(const std::string& pNameSpec)
-{
+Input* IRBuilder::ReadInput(const std::string& pNameSpec) {
const sys::fs::Path* path = NULL;
// find out the real path of the namespec.
if (m_InputBuilder.getConstraint().isSharedSystem()) {
@@ -159,19 +163,17 @@
if (m_InputBuilder.getAttributes().isStatic()) {
// with --static, we must search an archive.
path = m_Module.getScript().directories().find(pNameSpec, Input::Archive);
- }
- else {
+ } else {
// otherwise, with --Bdynamic, we can find either an archive or a
// shared object.
path = m_Module.getScript().directories().find(pNameSpec, Input::DynObj);
}
- }
- else {
+ } else {
// In the system without shared object support, we only look for an archive
path = m_Module.getScript().directories().find(pNameSpec, Input::Archive);
}
- if (NULL == path) {
+ if (path == NULL) {
fatal(diag::err_cannot_find_namespec) << pNameSpec;
return NULL;
}
@@ -183,42 +185,41 @@
m_InputBuilder.setContext(*input);
if (!input->hasMemArea())
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(FileHandle& pFileHandle)
-{
+Input* IRBuilder::ReadInput(FileHandle& pFileHandle) {
m_InputBuilder.createNode<InputTree::Positional>("file handler",
pFileHandle.path());
Input* input = *m_InputBuilder.getCurrentNode();
if (pFileHandle.path().empty()) {
m_InputBuilder.setContext(*input, false);
- m_InputBuilder.setMemory(*input, pFileHandle.handler(), FileHandle::ReadOnly);
- }
- else {
+ } else {
m_InputBuilder.setContext(*input, true);
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
}
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(const std::string& pName, void* pRawMemory, size_t pSize)
-{
- m_InputBuilder.createNode<InputTree::Positional>(pName, "NAN");
+Input* IRBuilder::ReadInput(const std::string& pName,
+ void* pRawMemory,
+ size_t pSize) {
+ m_InputBuilder.createNode<InputTree::Positional>(pName, sys::fs::Path("NAN"));
Input* input = *m_InputBuilder.getCurrentNode();
m_InputBuilder.setContext(*input, false);
m_InputBuilder.setMemory(*input, pRawMemory, pSize);
return input;
}
-bool IRBuilder::StartGroup()
-{
+bool IRBuilder::StartGroup() {
if (m_InputBuilder.isInGroup()) {
fatal(diag::fatal_forbid_nest_group);
return false;
@@ -227,49 +228,40 @@
return true;
}
-bool IRBuilder::EndGroup()
-{
+bool IRBuilder::EndGroup() {
m_InputBuilder.exitGroup();
return true;
}
-void IRBuilder::WholeArchive()
-{
+void IRBuilder::WholeArchive() {
m_InputBuilder.getAttributes().setWholeArchive();
}
-void IRBuilder::NoWholeArchive()
-{
+void IRBuilder::NoWholeArchive() {
m_InputBuilder.getAttributes().unsetWholeArchive();
}
-void IRBuilder::AsNeeded()
-{
+void IRBuilder::AsNeeded() {
m_InputBuilder.getAttributes().setAsNeeded();
}
-void IRBuilder::NoAsNeeded()
-{
+void IRBuilder::NoAsNeeded() {
m_InputBuilder.getAttributes().unsetAsNeeded();
}
-void IRBuilder::CopyDTNeeded()
-{
+void IRBuilder::CopyDTNeeded() {
m_InputBuilder.getAttributes().setAddNeeded();
}
-void IRBuilder::NoCopyDTNeeded()
-{
+void IRBuilder::NoCopyDTNeeded() {
m_InputBuilder.getAttributes().unsetAddNeeded();
}
-void IRBuilder::AgainstShared()
-{
+void IRBuilder::AgainstShared() {
m_InputBuilder.getAttributes().setDynamic();
}
-void IRBuilder::AgainstStatic()
-{
+void IRBuilder::AgainstStatic() {
m_InputBuilder.getAttributes().setStatic();
}
@@ -277,8 +269,7 @@
const std::string& pName,
uint32_t pType,
uint32_t pFlag,
- uint32_t pAlign)
-{
+ uint32_t pAlign) {
// Create section header
LDFileFormat::Kind kind = GetELFSectionKind(pType, pName.c_str(), pFlag);
LDSection* header = LDSection::Create(pName, kind, pType, pFlag);
@@ -290,8 +281,7 @@
}
/// CreateSectionData - To create a section data for given pSection.
-SectionData* IRBuilder::CreateSectionData(LDSection& pSection)
-{
+SectionData* IRBuilder::CreateSectionData(LDSection& pSection) {
assert(!pSection.hasSectionData() && "pSection already has section data.");
SectionData* sect_data = SectionData::Create(pSection);
@@ -300,8 +290,7 @@
}
/// CreateRelocData - To create a relocation data for given pSection.
-RelocData* IRBuilder::CreateRelocData(LDSection &pSection)
-{
+RelocData* IRBuilder::CreateRelocData(LDSection& pSection) {
assert(!pSection.hasRelocData() && "pSection already has relocation data.");
RelocData* reloc_data = RelocData::Create(pSection);
@@ -310,8 +299,7 @@
}
/// CreateEhFrame - To create a eh_frame for given pSection
-EhFrame* IRBuilder::CreateEhFrame(LDSection& pSection)
-{
+EhFrame* IRBuilder::CreateEhFrame(LDSection& pSection) {
assert(!pSection.hasEhFrame() && "pSection already has eh_frame.");
EhFrame* eh_frame = EhFrame::Create(pSection);
@@ -319,16 +307,25 @@
return eh_frame;
}
+/// CreateDebugString - To create a DebugString for given pSection
+DebugString* IRBuilder::CreateDebugString(LDSection& pSection) {
+ assert(!pSection.hasDebugString() && "pSection already has debug_str.");
+
+ DebugString* debug_str = DebugString::Create(pSection);
+ pSection.setDebugString(debug_str);
+ return debug_str;
+}
+
/// CreateBSS - To create a bss section for given pSection
-SectionData* IRBuilder::CreateBSS(LDSection& pSection)
-{
+SectionData* IRBuilder::CreateBSS(LDSection& pSection) {
assert(!pSection.hasSectionData() && "pSection already has section data.");
- assert((pSection.kind() == LDFileFormat::BSS) && "pSection is not a BSS section.");
+ assert((pSection.kind() == LDFileFormat::BSS) &&
+ "pSection is not a BSS section.");
SectionData* sect_data = SectionData::Create(pSection);
pSection.setSectionData(sect_data);
- /* value, valsize, size*/
+ /* value, valsize, size*/
FillFragment* frag = new FillFragment(0x0, 1, pSection.size());
ObjectBuilder::AppendFragment(*frag, *sect_data);
@@ -336,8 +333,9 @@
}
/// CreateRegion - To create a region fragment in the input file.
-Fragment* IRBuilder::CreateRegion(Input& pInput, size_t pOffset, size_t pLength)
-{
+Fragment* IRBuilder::CreateRegion(Input& pInput,
+ size_t pOffset,
+ size_t pLength) {
if (!pInput.hasMemArea()) {
fatal(diag::fatal_cannot_read_input) << pInput.path();
return NULL;
@@ -351,8 +349,7 @@
}
/// CreateRegion - To create a region fragment wrapping the given memory
-Fragment* IRBuilder::CreateRegion(void* pMemory, size_t pLength)
-{
+Fragment* IRBuilder::CreateRegion(void* pMemory, size_t pLength) {
if (0 == pLength)
return new FillFragment(0x0, 0, 0);
@@ -361,42 +358,35 @@
}
/// AppendFragment - To append pFrag to the given SectionData pSD
-uint64_t IRBuilder::AppendFragment(Fragment& pFrag, SectionData& pSD)
-{
- uint64_t size = ObjectBuilder::AppendFragment(pFrag,
- pSD,
- pSD.getSection().align());
+uint64_t IRBuilder::AppendFragment(Fragment& pFrag, SectionData& pSD) {
+ uint64_t size =
+ ObjectBuilder::AppendFragment(pFrag, pSD, pSD.getSection().align());
pSD.getSection().setSize(pSD.getSection().size() + size);
return size;
}
/// AppendRelocation - To append an relocation to the given RelocData pRD.
-void IRBuilder::AppendRelocation(Relocation& pRelocation, RelocData& pRD)
-{
+void IRBuilder::AppendRelocation(Relocation& pRelocation, RelocData& pRD) {
pRD.append(pRelocation);
}
/// AppendEhFrame - To append a fragment to EhFrame.
-uint64_t IRBuilder::AppendEhFrame(Fragment& pFrag, EhFrame& pEhFrame)
-{
- uint64_t size = ObjectBuilder::AppendFragment(pFrag,
- *pEhFrame.getSectionData(),
- pEhFrame.getSection().align());
+uint64_t IRBuilder::AppendEhFrame(Fragment& pFrag, EhFrame& pEhFrame) {
+ uint64_t size = ObjectBuilder::AppendFragment(
+ pFrag, *pEhFrame.getSectionData(), pEhFrame.getSection().align());
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + size);
return size;
}
/// AppendEhFrame - To append a FDE to the given EhFrame pEhFram.
-uint64_t IRBuilder::AppendEhFrame(EhFrame::FDE& pFDE, EhFrame& pEhFrame)
-{
+uint64_t IRBuilder::AppendEhFrame(EhFrame::FDE& pFDE, EhFrame& pEhFrame) {
pEhFrame.addFDE(pFDE);
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + pFDE.size());
return pFDE.size();
}
/// AppendEhFrame - To append a CIE to the given EhFrame pEhFram.
-uint64_t IRBuilder::AppendEhFrame(EhFrame::CIE& pCIE, EhFrame& pEhFrame)
-{
+uint64_t IRBuilder::AppendEhFrame(EhFrame::CIE& pCIE, EhFrame& pEhFrame) {
pEhFrame.addCIE(pCIE);
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + pCIE.size());
return pCIE.size();
@@ -412,8 +402,7 @@
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
LDSection* pSection,
- ResolveInfo::Visibility pVis)
-{
+ ResolveInfo::Visibility pVis) {
// rename symbols
std::string name = pName;
if (!m_Module.getScript().renameMap().empty() &&
@@ -422,7 +411,7 @@
// --wrap and --portable defines the symbol rename map.
const LinkerScript& script = m_Module.getScript();
LinkerScript::SymbolRenameMap::const_iterator renameSym =
- script.renameMap().find(pName);
+ script.renameMap().find(pName);
if (script.renameMap().end() != renameSym)
name = renameSym.getEntry()->value();
}
@@ -436,24 +425,23 @@
switch (pInput.type()) {
case Input::Object: {
-
FragmentRef* frag = NULL;
- if (NULL == pSection ||
- ResolveInfo::Undefined == pDesc ||
- ResolveInfo::Common == pDesc ||
- ResolveInfo::Absolute == pBind ||
- LDFileFormat::Ignore == pSection->kind() ||
- LDFileFormat::Group == pSection->kind())
+ if (pSection == NULL || ResolveInfo::Undefined == pDesc ||
+ ResolveInfo::Common == pDesc || ResolveInfo::Absolute == pBind ||
+ LDFileFormat::Ignore == pSection->kind() ||
+ LDFileFormat::Group == pSection->kind())
frag = FragmentRef::Null();
else
frag = FragmentRef::Create(*pSection, pValue);
- LDSymbol* input_sym = addSymbolFromObject(name, pType, pDesc, pBind, pSize, pValue, frag, pVis);
+ LDSymbol* input_sym = addSymbolFromObject(
+ name, pType, pDesc, pBind, pSize, pValue, frag, pVis);
pInput.context()->addSymbol(input_sym);
return input_sym;
}
case Input::DynObj: {
- return addSymbolFromDynObj(pInput, name, pType, pDesc, pBind, pSize, pValue, pVis);
+ return addSymbolFromDynObj(
+ pInput, name, pType, pDesc, pBind, pSize, pValue, pVis);
}
default: {
return NULL;
@@ -470,38 +458,38 @@
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
// Step 1. calculate a Resolver::Result
// resolved_result is a triple <resolved_info, existent, override>
Resolver::Result resolved_result;
- ResolveInfo old_info; // used for arrange output symbols
+ ResolveInfo old_info; // used for arrange output symbols
if (pBinding == ResolveInfo::Local) {
// if the symbol is a local symbol, create a LDSymbol for input, but do not
// resolve them.
- resolved_result.info = m_Module.getNamePool().createSymbol(pName,
- false,
- pType,
- pDesc,
- pBinding,
- pSize,
- pVisibility);
+ resolved_result.info = m_Module.getNamePool().createSymbol(
+ pName, false, pType, pDesc, pBinding, pSize, pVisibility);
// No matter if there is a symbol with the same name, insert the symbol
// into output symbol table. So, we let the existent false.
- resolved_result.existent = false;
+ resolved_result.existent = false;
resolved_result.overriden = true;
- }
- else {
+ } else {
// if the symbol is not local, insert and resolve it immediately
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc, pBinding,
- pSize, pValue, pVisibility,
- &old_info, resolved_result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ &old_info,
+ resolved_result);
}
// the return ResolveInfo should not NULL
- assert(NULL != resolved_result.info);
+ assert(resolved_result.info != NULL);
/// Step 2. create an input LDSymbol.
// create a LDSymbol for the input file.
@@ -511,16 +499,15 @@
// Step 3. Set up corresponding output LDSymbol
LDSymbol* output_sym = resolved_result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
+ bool has_output_sym = (output_sym != NULL);
if (!resolved_result.existent || !has_output_sym) {
// it is a new symbol, the output_sym should be NULL.
- assert(NULL == output_sym);
+ assert(output_sym == NULL);
if (pType == ResolveInfo::Section) {
// if it is a section symbol, its output LDSymbol is the input LDSymbol.
output_sym = input_sym;
- }
- else {
+ } else {
// if it is a new symbol, create a LDSymbol for the output
output_sym = LDSymbol::Create(*resolved_result.info);
}
@@ -545,16 +532,14 @@
ResolveInfo::Binding pBinding,
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
// We don't need sections of dynamic objects. So we ignore section symbols.
if (pType == ResolveInfo::Section)
return NULL;
// ignore symbols with local binding or that have internal or hidden
// visibility
- if (pBinding == ResolveInfo::Local ||
- pVisibility == ResolveInfo::Internal ||
+ if (pBinding == ResolveInfo::Local || pVisibility == ResolveInfo::Internal ||
pVisibility == ResolveInfo::Hidden)
return NULL;
@@ -566,12 +551,19 @@
// insert symbol and resolve it immediately
// resolved_result is a triple <resolved_info, existent, override>
Resolver::Result resolved_result;
- m_Module.getNamePool().insertSymbol(pName, true, pType, pDesc,
- pBinding, pSize, pValue, pVisibility,
- NULL, resolved_result);
+ m_Module.getNamePool().insertSymbol(pName,
+ true,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ NULL,
+ resolved_result);
// the return ResolveInfo should not NULL
- assert(NULL != resolved_result.info);
+ assert(resolved_result.info != NULL);
if (resolved_result.overriden || !resolved_result.existent)
pInput.setNeeded();
@@ -598,8 +590,7 @@
Relocation::Type pType,
LDSymbol& pSym,
uint32_t pOffset,
- Relocation::Address pAddend)
-{
+ Relocation::Address pAddend) {
FragmentRef* frag_ref = FragmentRef::Create(*pSection.getLink(), pOffset);
Relocation* relocation = Relocation::Create(pType, *frag_ref, pAddend);
@@ -611,26 +602,32 @@
}
/// AddSymbol - define an output symbol and override it immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
LDSymbol* output_sym = NULL;
- if (NULL == info) {
+ if (info == NULL) {
// the symbol is not in the pool, create a new one.
// create a ResolveInfo
Resolver::Result result;
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc,
- pBinding, pSize, pValue, pVisibility,
- NULL, result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ NULL,
+ result);
assert(!result.existent);
// create a output LDSymbol
@@ -641,8 +638,7 @@
m_Module.getSymbolTable().forceLocal(*output_sym);
else
m_Module.getSymbolTable().add(*output_sym);
- }
- else {
+ } else {
// the symbol is already in the pool, override it
ResolveInfo old_info;
old_info.override(*info);
@@ -656,7 +652,7 @@
info->setSize(pSize);
output_sym = info->outSymbol();
- if (NULL != output_sym)
+ if (output_sym != NULL)
m_Module.getSymbolTable().arrange(*output_sym, old_info);
else {
// create a output LDSymbol
@@ -667,7 +663,7 @@
}
}
- if (NULL != output_sym) {
+ if (output_sym != NULL) {
output_sym->setFragmentRef(pFragmentRef);
output_sym->setValue(pValue);
}
@@ -676,20 +672,19 @@
}
/// AddSymbol - define an output symbol and override it immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
- if (NULL == info || !(info->isUndef() || info->isDyn())) {
+ if (info == NULL || !(info->isUndef() || info->isDyn())) {
// only undefined symbol and dynamic symbol can make a reference.
return NULL;
}
@@ -707,12 +702,11 @@
info->setSize(pSize);
LDSymbol* output_sym = info->outSymbol();
- if (NULL != output_sym) {
+ if (output_sym != NULL) {
output_sym->setFragmentRef(pFragmentRef);
output_sym->setValue(pValue);
m_Module.getSymbolTable().arrange(*output_sym, old_info);
- }
- else {
+ } else {
// create a output LDSymbol
output_sym = LDSymbol::Create(*info);
info->setSymPtr(output_sym);
@@ -725,26 +719,32 @@
/// AddSymbol - define an output symbol and resolve it
/// immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
// Result is <info, existent, override>
Resolver::Result result;
ResolveInfo old_info;
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc, pBinding,
- pSize, pValue, pVisibility,
- &old_info, result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ &old_info,
+ result);
LDSymbol* output_sym = result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
+ bool has_output_sym = (output_sym != NULL);
if (!result.existent || !has_output_sym) {
output_sym = LDSymbol::Create(*result.info);
@@ -769,31 +769,25 @@
}
/// defineSymbol - define an output symbol and resolve it immediately.
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
- if (NULL == info || !(info->isUndef() || info->isDyn())) {
+ if (info == NULL || !(info->isUndef() || info->isDyn())) {
// only undefined symbol and dynamic symbol can make a reference.
return NULL;
}
- return AddSymbol<Force, Resolve>(pName,
- pType,
- pDesc,
- pBinding,
- pSize,
- pValue,
- pFragmentRef,
- pVisibility);
+ return AddSymbol<Force, Resolve>(
+ pName, pType, pDesc, pBinding, pSize, pValue, pFragmentRef, pVisibility);
}
+} // namespace mcld
diff --git a/lib/Core/InputTree.cpp b/lib/Core/InputTree.cpp
index 5df91d8..6e65add 100644
--- a/lib/Core/InputTree.cpp
+++ b/lib/Core/InputTree.cpp
@@ -6,27 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/InputTree.h>
+#include "mcld/InputTree.h"
-using namespace mcld;
+namespace mcld {
InputTree::Succeeder InputTree::Afterward;
-InputTree::Includer InputTree::Downward;
+InputTree::Includer InputTree::Downward;
//===----------------------------------------------------------------------===//
// InputTree
//===----------------------------------------------------------------------===//
InputTree& InputTree::merge(TreeIteratorBase pRoot,
const InputTree::Mover& pMover,
- InputTree& pTree)
-{
+ InputTree& pTree) {
if (this == &pTree)
return *this;
if (!pTree.empty()) {
pMover.connect(pRoot, pTree.m_Root.node.right);
- BinaryTreeBase<Input>::m_Root.summon(
- pTree.BinaryTreeBase<Input>::m_Root);
+ BinaryTreeBase<Input>::m_Root.summon(pTree.BinaryTreeBase<Input>::m_Root);
BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
}
@@ -34,8 +32,7 @@
}
InputTree& InputTree::enterGroup(TreeIteratorBase pRoot,
- const InputTree::Mover& pMover)
-{
+ const InputTree::Mover& pMover) {
NodeBase* node = createNode();
pMover.connect(pRoot, node);
return *this;
@@ -43,8 +40,7 @@
InputTree& InputTree::insert(TreeIteratorBase pRoot,
const InputTree::Mover& pMover,
- mcld::Input& pInput)
-{
+ Input& pInput) {
BinaryTree<Input>::node_type* node = createNode();
node->data = &pInput;
pMover.connect(pRoot, node);
@@ -54,33 +50,28 @@
//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
-bool mcld::isGroup(const InputTree::iterator& pos)
-{
+bool isGroup(const InputTree::iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_iterator& pos)
-{
+bool isGroup(const InputTree::const_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::dfs_iterator& pos)
-{
+bool isGroup(const InputTree::dfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_dfs_iterator& pos)
-{
+bool isGroup(const InputTree::const_dfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::bfs_iterator& pos)
-{
+bool isGroup(const InputTree::bfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_bfs_iterator& pos)
-{
+bool isGroup(const InputTree::const_bfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
+} // namespace mcld
diff --git a/lib/Core/Linker.cpp b/lib/Core/Linker.cpp
index c8638a7..b499b80 100644
--- a/lib/Core/Linker.cpp
+++ b/lib/Core/Linker.cpp
@@ -6,46 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Linker.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Module.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/Linker.h"
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/raw_ostream.h>
-
-#include <mcld/Object/ObjectLinker.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/ObjectWriter.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ObjectWriter.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Object/ObjectLinker.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
Linker::Linker()
- : m_pConfig(NULL), m_pIRBuilder(NULL),
- m_pTarget(NULL), m_pBackend(NULL), m_pObjLinker(NULL) {
+ : m_pConfig(NULL),
+ m_pIRBuilder(NULL),
+ m_pTarget(NULL),
+ m_pBackend(NULL),
+ m_pObjLinker(NULL) {
}
-Linker::~Linker()
-{
+Linker::~Linker() {
reset();
}
/// emulate - To set up target-dependent options and default linker script.
/// Follow GNU ld quirks.
-bool Linker::emulate(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool Linker::emulate(LinkerScript& pScript, LinkerConfig& pConfig) {
m_pConfig = &pConfig;
if (!initTarget())
@@ -63,8 +63,7 @@
return true;
}
-bool Linker::link(Module& pModule, IRBuilder& pBuilder)
-{
+bool Linker::link(Module& pModule, IRBuilder& pBuilder) {
if (!normalize(pModule, pBuilder))
return false;
@@ -75,9 +74,8 @@
}
/// normalize - to convert the command line language to the input tree.
-bool Linker::normalize(Module& pModule, IRBuilder& pBuilder)
-{
- assert(NULL != m_pConfig);
+bool Linker::normalize(Module& pModule, IRBuilder& pBuilder) {
+ assert(m_pConfig != NULL);
m_pIRBuilder = &pBuilder;
@@ -107,30 +105,32 @@
if (m_pConfig->options().trace()) {
static int counter = 0;
- mcld::outs() << "** name\ttype\tpath\tsize (" << pModule.getInputTree().size() << ")\n";
- InputTree::const_dfs_iterator input, inEnd = pModule.getInputTree().dfs_end();
- for (input=pModule.getInputTree().dfs_begin(); input!=inEnd; ++input) {
+ mcld::outs() << "** name\ttype\tpath\tsize ("
+ << pModule.getInputTree().size() << ")\n";
+
+ InputTree::const_dfs_iterator input,
+ inEnd = pModule.getInputTree().dfs_end();
+ for (input = pModule.getInputTree().dfs_begin(); input != inEnd; ++input) {
mcld::outs() << counter++ << " * " << (*input)->name();
- switch((*input)->type()) {
- case Input::Archive:
- mcld::outs() << "\tarchive\t(";
- break;
- case Input::Object:
- mcld::outs() << "\tobject\t(";
- break;
- case Input::DynObj:
- mcld::outs() << "\tshared\t(";
- break;
- case Input::Script:
- mcld::outs() << "\tscript\t(";
- break;
- case Input::External:
- mcld::outs() << "\textern\t(";
- break;
- default:
- unreachable(diag::err_cannot_trace_file) << (*input)->type()
- << (*input)->name()
- << (*input)->path();
+ switch ((*input)->type()) {
+ case Input::Archive:
+ mcld::outs() << "\tarchive\t(";
+ break;
+ case Input::Object:
+ mcld::outs() << "\tobject\t(";
+ break;
+ case Input::DynObj:
+ mcld::outs() << "\tshared\t(";
+ break;
+ case Input::Script:
+ mcld::outs() << "\tscript\t(";
+ break;
+ case Input::External:
+ mcld::outs() << "\textern\t(";
+ break;
+ default:
+ unreachable(diag::err_cannot_trace_file)
+ << (*input)->type() << (*input)->name() << (*input)->path();
}
mcld::outs() << (*input)->path() << ")\n";
}
@@ -140,20 +140,19 @@
if (LinkerConfig::DynObj == m_pConfig->codeGenType() ||
m_pConfig->options().isPIE()) {
m_pConfig->setCodePosition(LinkerConfig::Independent);
- }
- else if (pModule.getLibraryList().empty()) {
+ } else if (pModule.getLibraryList().empty()) {
// If the output is dependent on its loaded address, and it does not need
// to call outside functions, then we can treat the output static dependent
// and perform better optimizations.
m_pConfig->setCodePosition(LinkerConfig::StaticDependent);
if (LinkerConfig::Exec == m_pConfig->codeGenType()) {
- // Since the output is static dependent, there should not have any undefined
+ // Since the output is static dependent, there should not have any
+ // undefined
// references in the output module.
m_pConfig->options().setNoUndefined();
}
- }
- else {
+ } else {
m_pConfig->setCodePosition(LinkerConfig::DynamicDependent);
}
@@ -163,9 +162,8 @@
return true;
}
-bool Linker::resolve(Module& pModule)
-{
- assert(NULL != m_pConfig);
+bool Linker::resolve(Module& pModule) {
+ assert(m_pConfig != NULL);
assert(m_pObjLinker != NULL);
// 6. - read all relocation entries from input files
@@ -176,7 +174,6 @@
// To collect all edges in the reference graph.
m_pObjLinker->readRelocations();
-
// 7. - data stripping optimizations
m_pObjLinker->dataStrippingOpt();
@@ -202,14 +199,12 @@
return true;
}
-bool Linker::layout()
-{
- assert(NULL != m_pConfig && NULL != m_pObjLinker);
+bool Linker::layout() {
+ assert(m_pConfig != NULL && m_pObjLinker != NULL);
// 10. - add standard symbols, target-dependent symbols and script symbols
if (!m_pObjLinker->addStandardSymbols() ||
- !m_pObjLinker->addTargetSymbols() ||
- !m_pObjLinker->addScriptSymbols())
+ !m_pObjLinker->addTargetSymbols() || !m_pObjLinker->addScriptSymbols())
return false;
// 11. - scan all relocation entries by output symbols.
@@ -244,8 +239,7 @@
return true;
}
-bool Linker::emit(FileOutputBuffer& pOutput)
-{
+bool Linker::emit(FileOutputBuffer& pOutput) {
// 15. - write out output
m_pObjLinker->emitOutput(pOutput);
@@ -258,57 +252,52 @@
return true;
}
-bool Linker::emit(const Module& pModule, const std::string& pPath)
-{
+bool Linker::emit(const Module& pModule, const std::string& pPath) {
FileHandle file;
- FileHandle::Permission perm;
+ FileHandle::OpenMode open_mode(
+ FileHandle::ReadWrite | FileHandle::Truncate | FileHandle::Create);
+ FileHandle::Permission permission;
switch (m_pConfig->codeGenType()) {
case mcld::LinkerConfig::Unknown:
case mcld::LinkerConfig::Object:
- perm = mcld::FileHandle::Permission(0x644);
+ permission = FileHandle::Permission(0x644);
break;
case mcld::LinkerConfig::DynObj:
case mcld::LinkerConfig::Exec:
case mcld::LinkerConfig::Binary:
- perm = mcld::FileHandle::Permission(0x755);
+ permission = FileHandle::Permission(0x755);
break;
- default: assert(0 && "Unknown file type");
+ default:
+ assert(0 && "Unknown file type");
}
- if (!file.open(pPath,
- FileHandle::ReadWrite | FileHandle::Truncate | FileHandle::Create,
- perm)) {
+ bool result = file.open(sys::fs::Path(pPath), open_mode, permission);
+ if (!result) {
error(diag::err_cannot_open_output_file) << "Linker::emit()" << pPath;
return false;
}
std::unique_ptr<FileOutputBuffer> output;
- FileOutputBuffer::create(file,
- m_pObjLinker->getWriter()->getOutputSize(pModule),
- output);
+ FileOutputBuffer::create(
+ file, m_pObjLinker->getWriter()->getOutputSize(pModule), output);
- bool result = emit(*output.get());
+ result = emit(*output.get());
file.close();
return result;
}
-bool Linker::emit(const Module& pModule, int pFileDescriptor)
-{
+bool Linker::emit(const Module& pModule, int pFileDescriptor) {
FileHandle file;
file.delegate(pFileDescriptor);
std::unique_ptr<FileOutputBuffer> output;
- FileOutputBuffer::create(file,
- m_pObjLinker->getWriter()->getOutputSize(pModule),
- output);
+ FileOutputBuffer::create(
+ file, m_pObjLinker->getWriter()->getOutputSize(pModule), output);
- bool result = emit(*output.get());
-
- return result;
+ return emit(*output.get());
}
-bool Linker::reset()
-{
+bool Linker::reset() {
m_pConfig = NULL;
m_pIRBuilder = NULL;
m_pTarget = NULL;
@@ -332,38 +321,36 @@
return true;
}
-bool Linker::initTarget()
-{
- assert(NULL != m_pConfig);
+bool Linker::initTarget() {
+ assert(m_pConfig != NULL);
std::string error;
llvm::Triple triple(m_pConfig->targets().triple());
- m_pTarget = mcld::TargetRegistry::lookupTarget(m_pConfig->targets().getArch(),
- triple, error);
+ m_pTarget = mcld::TargetRegistry::lookupTarget(
+ m_pConfig->targets().getArch(), triple, error);
m_pConfig->targets().setTriple(triple);
- if (NULL == m_pTarget) {
+ if (m_pTarget == NULL) {
fatal(diag::fatal_cannot_init_target) << triple.str() << error;
return false;
}
return true;
}
-bool Linker::initBackend()
-{
- assert(NULL != m_pTarget);
+bool Linker::initBackend() {
+ assert(m_pTarget != NULL);
m_pBackend = m_pTarget->createLDBackend(*m_pConfig);
- if (NULL == m_pBackend) {
- fatal(diag::fatal_cannot_init_backend) << m_pConfig->targets().triple().str();
+ if (m_pBackend == NULL) {
+ fatal(diag::fatal_cannot_init_backend)
+ << m_pConfig->targets().triple().str();
return false;
}
return true;
}
-bool Linker::initOStream()
-{
- assert(NULL != m_pConfig);
+bool Linker::initOStream() {
+ assert(m_pConfig != NULL);
mcld::outs().setColor(m_pConfig->options().color());
mcld::errs().setColor(m_pConfig->options().color());
@@ -371,9 +358,9 @@
return true;
}
-bool Linker::initEmulator(LinkerScript& pScript)
-{
- assert(NULL != m_pTarget && NULL != m_pConfig);
+bool Linker::initEmulator(LinkerScript& pScript) {
+ assert(m_pTarget != NULL && m_pConfig != NULL);
return m_pTarget->emulate(pScript, *m_pConfig);
}
+} // namespace mcld
diff --git a/lib/Core/LinkerConfig.cpp b/lib/Core/LinkerConfig.cpp
index b40cda5..d252066 100644
--- a/lib/Core/LinkerConfig.cpp
+++ b/lib/Core/LinkerConfig.cpp
@@ -6,47 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerConfig.h>
-#include <mcld/Config/Config.h>
+#include "mcld/LinkerConfig.h"
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/MsgHandling.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LinkerConfig
//===----------------------------------------------------------------------===//
LinkerConfig::LinkerConfig()
- : m_Options(),
- m_Targets(),
- m_Bitcode(),
- m_Attribute(),
- m_CodeGenType(Unknown),
- m_CodePosition(Unset)
-{
+ : m_Options(),
+ m_Targets(),
+ m_Attribute(),
+ m_CodeGenType(Unknown),
+ m_CodePosition(Unset) {
// FIXME: is here the right place to hold this?
InitializeDiagnosticEngine(*this);
}
LinkerConfig::LinkerConfig(const std::string& pTripleString)
- : m_Options(),
- m_Targets(pTripleString),
- m_Bitcode(),
- m_Attribute(),
- m_CodeGenType(Unknown),
- m_CodePosition(Unset)
-{
+ : m_Options(),
+ m_Targets(pTripleString),
+ m_Attribute(),
+ m_CodeGenType(Unknown),
+ m_CodePosition(Unset) {
// FIXME: is here the right place to hold this?
InitializeDiagnosticEngine(*this);
}
-LinkerConfig::~LinkerConfig()
-{
+LinkerConfig::~LinkerConfig() {
// FIXME: is here the right place to hold this?
FinalizeDiagnosticEngine();
}
-const char* LinkerConfig::version()
-{
+const char* LinkerConfig::version() {
return MCLD_VERSION;
}
+
+} // namespace mcld
diff --git a/lib/Core/LinkerScript.cpp b/lib/Core/LinkerScript.cpp
index 2e891e2..7bb26a7 100644
--- a/lib/Core/LinkerScript.cpp
+++ b/lib/Core/LinkerScript.cpp
@@ -6,62 +6,53 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerScript.h>
+#include "mcld/LinkerScript.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LinkerScript
//===----------------------------------------------------------------------===//
-LinkerScript::LinkerScript()
-{
+LinkerScript::LinkerScript() {
}
-LinkerScript::~LinkerScript()
-{
+LinkerScript::~LinkerScript() {
}
-const mcld::sys::fs::Path& LinkerScript::sysroot() const
-{
+const mcld::sys::fs::Path& LinkerScript::sysroot() const {
return m_SearchDirs.sysroot();
}
-void LinkerScript::setSysroot(const mcld::sys::fs::Path &pSysroot)
-{
+void LinkerScript::setSysroot(const mcld::sys::fs::Path& pSysroot) {
m_SearchDirs.setSysRoot(pSysroot);
}
-bool LinkerScript::hasSysroot() const
-{
+bool LinkerScript::hasSysroot() const {
return !sysroot().empty();
}
-const std::string& LinkerScript::entry() const
-{
+const std::string& LinkerScript::entry() const {
return m_Entry;
}
-void LinkerScript::setEntry(const std::string& pEntry)
-{
+void LinkerScript::setEntry(const std::string& pEntry) {
m_Entry = pEntry;
}
-bool LinkerScript::hasEntry() const
-{
+bool LinkerScript::hasEntry() const {
return !m_Entry.empty();
}
-const std::string& LinkerScript::outputFile() const
-{
+const std::string& LinkerScript::outputFile() const {
return m_OutputFile;
}
-void LinkerScript::setOutputFile(const std::string& pOutputFile)
-{
+void LinkerScript::setOutputFile(const std::string& pOutputFile) {
m_OutputFile = pOutputFile;
}
-bool LinkerScript::hasOutputFile() const
-{
+bool LinkerScript::hasOutputFile() const {
return !m_OutputFile.empty();
}
+
+} // namespace mcld
diff --git a/lib/Core/Module.cpp b/lib/Core/Module.cpp
index 0f9a24d..dce8e31 100644
--- a/lib/Core/Module.cpp
+++ b/lib/Core/Module.cpp
@@ -6,38 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Module.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/StaticResolver.h>
+#include "mcld/Module.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/StaticResolver.h"
-using namespace mcld;
+namespace mcld {
-static GCFactory<Module::AliasList, MCLD_SECTIONS_PER_INPUT> gc_aliaslist_factory;
+static GCFactory<Module::AliasList, MCLD_SECTIONS_PER_INPUT>
+ gc_aliaslist_factory;
//===----------------------------------------------------------------------===//
// Module
//===----------------------------------------------------------------------===//
-Module::Module(LinkerScript& pScript)
- : m_Script(pScript), m_NamePool(1024) {
+Module::Module(LinkerScript& pScript) : m_Script(pScript), m_NamePool(1024) {
}
Module::Module(const std::string& pName, LinkerScript& pScript)
- : m_Name(pName), m_Script(pScript), m_NamePool(1024) {
+ : m_Name(pName), m_Script(pScript), m_NamePool(1024) {
}
-Module::~Module()
-{
+Module::~Module() {
}
// Following two functions will be obsolette when we have new section merger.
-LDSection* Module::getSection(const std::string& pName)
-{
+LDSection* Module::getSection(const std::string& pName) {
iterator sect, sectEnd = end();
for (sect = begin(); sect != sectEnd; ++sect) {
if ((*sect)->name() == pName)
@@ -46,8 +44,7 @@
return NULL;
}
-const LDSection* Module::getSection(const std::string& pName) const
-{
+const LDSection* Module::getSection(const std::string& pName) const {
const_iterator sect, sectEnd = end();
for (sect = begin(); sect != sectEnd; ++sect) {
if ((*sect)->name() == pName)
@@ -56,29 +53,26 @@
return NULL;
}
-void Module::CreateAliasList(const ResolveInfo& pSym)
-{
+void Module::CreateAliasList(const ResolveInfo& pSym) {
AliasList* result = gc_aliaslist_factory.allocate();
new (result) AliasList();
m_AliasLists.push_back(result);
result->push_back(&pSym);
}
-void Module::addAlias(const ResolveInfo& pAlias)
-{
- assert(0!=m_AliasLists.size());
- uint32_t last_pos = m_AliasLists.size()-1;
+void Module::addAlias(const ResolveInfo& pAlias) {
+ assert(m_AliasLists.size() != 0);
+ uint32_t last_pos = m_AliasLists.size() - 1;
m_AliasLists[last_pos]->push_back(&pAlias);
}
-Module::AliasList* Module::getAliasList(const ResolveInfo& pSym)
-{
- std::vector<AliasList*>::iterator list_it, list_it_e=m_AliasLists.end();
- for (list_it=m_AliasLists.begin(); list_it!=list_it_e; ++list_it) {
+Module::AliasList* Module::getAliasList(const ResolveInfo& pSym) {
+ std::vector<AliasList*>::iterator list_it, list_it_e = m_AliasLists.end();
+ for (list_it = m_AliasLists.begin(); list_it != list_it_e; ++list_it) {
AliasList& list = **list_it;
- alias_iterator alias_it, alias_it_e=list.end();
- for (alias_it=list.begin(); alias_it!=alias_it_e; ++alias_it) {
- if ( 0==strcmp((*alias_it)->name(), pSym.name()) ) {
+ alias_iterator alias_it, alias_it_e = list.end();
+ for (alias_it = list.begin(); alias_it != alias_it_e; ++alias_it) {
+ if (strcmp((*alias_it)->name(), pSym.name()) == 0) {
return &list;
}
}
@@ -86,3 +80,4 @@
return NULL;
}
+} // namespace mcld
diff --git a/lib/Core/TargetOptions.cpp b/lib/Core/TargetOptions.cpp
index 710899c..57a2eb9 100644
--- a/lib/Core/TargetOptions.cpp
+++ b/lib/Core/TargetOptions.cpp
@@ -6,50 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/TargetOptions.h>
+#include "mcld/TargetOptions.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// TargetOptions
//===----------------------------------------------------------------------===//
-TargetOptions::TargetOptions()
- : m_Endian(Unknown),
- m_BitClass(0) {
+TargetOptions::TargetOptions() : m_Endian(Unknown), m_BitClass(0) {
}
TargetOptions::TargetOptions(const std::string& pTriple)
- : m_Triple(pTriple),
- m_Endian(Unknown),
- m_BitClass(0) {
+ : m_Triple(pTriple), m_Endian(Unknown), m_BitClass(0) {
}
-TargetOptions::~TargetOptions()
-{
+TargetOptions::~TargetOptions() {
}
-void TargetOptions::setTriple(const llvm::Triple& pTriple)
-{
+void TargetOptions::setTriple(const llvm::Triple& pTriple) {
m_Triple = pTriple;
}
-void TargetOptions::setTriple(const std::string& pTriple)
-{
+void TargetOptions::setTriple(const std::string& pTriple) {
m_Triple.setTriple(pTriple);
}
-void TargetOptions::setArch(const std::string& pArchName)
-{
+void TargetOptions::setArch(const std::string& pArchName) {
m_ArchName = pArchName;
}
-void TargetOptions::setTargetCPU(const std::string& pCPU)
-{
+void TargetOptions::setTargetCPU(const std::string& pCPU) {
m_TargetCPU = pCPU;
}
-void TargetOptions::setTargetFeatureString(const std::string& pFS)
-{
+void TargetOptions::setTargetFeatureString(const std::string& pFS) {
m_TargetFS = pFS;
}
+} // namespace mcld
diff --git a/lib/Fragment/AlignFragment.cpp b/lib/Fragment/AlignFragment.cpp
index 7cc1065..de2425f 100644
--- a/lib/Fragment/AlignFragment.cpp
+++ b/lib/Fragment/AlignFragment.cpp
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/AlignFragment.h>
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/MathExtras.h>
-#include <mcld/LD/SectionData.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AlignFragment
@@ -20,15 +20,18 @@
int64_t pValue,
unsigned int pValueSize,
unsigned int pMaxBytesToEmit,
- SectionData *pSD)
- : Fragment(Fragment::Alignment, pSD), m_Alignment(pAlignment),
- m_Value(pValue), m_ValueSize(pValueSize), m_MaxBytesToEmit(pMaxBytesToEmit),
- m_bEmitNops(false) {
+ SectionData* pSD)
+ : Fragment(Fragment::Alignment, pSD),
+ m_Alignment(pAlignment),
+ m_Value(pValue),
+ m_ValueSize(pValueSize),
+ m_MaxBytesToEmit(pMaxBytesToEmit),
+ m_bEmitNops(false) {
}
-size_t AlignFragment::size() const
-{
- assert(hasOffset() && "AlignFragment::size() should not be called before layout.");
+size_t AlignFragment::size() const {
+ assert(hasOffset() &&
+ "AlignFragment::size() should not be called before layout.");
uint64_t size = llvm::OffsetToAlignment(getOffset(), m_Alignment);
if (size > m_MaxBytesToEmit)
return 0;
@@ -36,3 +39,4 @@
return size;
}
+} // namespace mcld
diff --git a/lib/Fragment/FillFragment.cpp b/lib/Fragment/FillFragment.cpp
index 16de4f0..05175e8 100644
--- a/lib/Fragment/FillFragment.cpp
+++ b/lib/Fragment/FillFragment.cpp
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/SectionData.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// FillFragment
@@ -19,9 +19,12 @@
unsigned int pValueSize,
uint64_t pSize,
SectionData* pSD)
- : Fragment(Fragment::Fillment, pSD), m_Value(pValue), m_ValueSize(pValueSize),
- m_Size(pSize) {
+ : Fragment(Fragment::Fillment, pSD),
+ m_Value(pValue),
+ m_ValueSize(pValueSize),
+ m_Size(pSize) {
assert((!m_ValueSize || (m_Size % m_ValueSize) == 0) &&
- "Fill size must be a multiple of the value size!");
+ "Fill size must be a multiple of the value size!");
}
+} // namespace mcld
diff --git a/lib/Fragment/Fragment.cpp b/lib/Fragment/Fragment.cpp
index df66694..f46f264 100644
--- a/lib/Fragment/Fragment.cpp
+++ b/lib/Fragment/Fragment.cpp
@@ -7,39 +7,36 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/LD/SectionData.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Fragment
//===----------------------------------------------------------------------===//
Fragment::Fragment()
- : m_Kind(Type(~0)), m_pParent(NULL), m_Offset(~uint64_t(0)) {
+ : m_Kind(Type(~0)), m_pParent(NULL), m_Offset(~uint64_t(0)) {
}
-Fragment::Fragment(Type pKind, SectionData *pParent)
- : m_Kind(pKind), m_pParent(pParent), m_Offset(~uint64_t(0)) {
- if (NULL != m_pParent)
+Fragment::Fragment(Type pKind, SectionData* pParent)
+ : m_Kind(pKind), m_pParent(pParent), m_Offset(~uint64_t(0)) {
+ if (m_pParent != NULL)
m_pParent->getFragmentList().push_back(this);
}
-Fragment::~Fragment()
-{
+Fragment::~Fragment() {
}
-uint64_t Fragment::getOffset() const
-{
+uint64_t Fragment::getOffset() const {
assert(hasOffset() && "Cannot getOffset() before setting it up.");
return m_Offset;
}
-bool Fragment::hasOffset() const
-{
+bool Fragment::hasOffset() const {
return (m_Offset != ~uint64_t(0));
}
+} // namespace mcld
diff --git a/lib/Fragment/FragmentRef.cpp b/lib/Fragment/FragmentRef.cpp
index a22beca..efe3868 100644
--- a/lib/Fragment/FragmentRef.cpp
+++ b/lib/Fragment/FragmentRef.cpp
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/Fragment/FragmentRef.h"
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Casting.h>
@@ -22,7 +22,7 @@
#include <cassert>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<FragmentRef, MCLD_SECTIONS_PER_INPUT> FragRefFactory;
@@ -33,13 +33,11 @@
//===----------------------------------------------------------------------===//
// FragmentRef
//===----------------------------------------------------------------------===//
-FragmentRef::FragmentRef()
- : m_pFragment(NULL), m_Offset(0) {
+FragmentRef::FragmentRef() : m_pFragment(NULL), m_Offset(0) {
}
-FragmentRef::FragmentRef(Fragment& pFrag,
- FragmentRef::Offset pOffset)
- : m_pFragment(&pFrag), m_Offset(pOffset) {
+FragmentRef::FragmentRef(Fragment& pFrag, FragmentRef::Offset pOffset)
+ : m_pFragment(&pFrag), m_Offset(pOffset) {
}
/// Create - create a fragment reference for a given fragment.
@@ -49,12 +47,11 @@
/// be larger than the section size.
/// @return if the offset is legal, return the fragment reference. Otherwise,
/// return NULL.
-FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset)
-{
+FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset) {
int64_t offset = pOffset;
Fragment* frag = &pFrag;
- while (NULL != frag) {
+ while (frag != NULL) {
offset -= frag->size();
if (offset <= 0)
break;
@@ -67,7 +64,7 @@
offset += frag->size();
}
- if (NULL == frag)
+ if (frag == NULL)
return Null();
FragmentRef* result = g_FragRefFactory->allocate();
@@ -76,8 +73,7 @@
return result;
}
-FragmentRef* FragmentRef::Create(LDSection& pSection, uint64_t pOffset)
-{
+FragmentRef* FragmentRef::Create(LDSection& pSection, uint64_t pOffset) {
SectionData* data = NULL;
switch (pSection.kind()) {
case LDFileFormat::Relocation:
@@ -92,57 +88,54 @@
break;
}
- if (NULL == data || data->empty()) {
+ if (data == NULL || data->empty()) {
return Null();
}
return Create(data->front(), pOffset);
}
-void FragmentRef::Clear()
-{
+void FragmentRef::Clear() {
g_FragRefFactory->clear();
}
-FragmentRef* FragmentRef::Null()
-{
+FragmentRef* FragmentRef::Null() {
return &g_NullFragmentRef;
}
-FragmentRef& FragmentRef::assign(const FragmentRef& pCopy)
-{
+FragmentRef& FragmentRef::assign(const FragmentRef& pCopy) {
m_pFragment = const_cast<Fragment*>(pCopy.m_pFragment);
m_Offset = pCopy.m_Offset;
return *this;
}
-FragmentRef& FragmentRef::assign(Fragment& pFrag, FragmentRef::Offset pOffset)
-{
+FragmentRef& FragmentRef::assign(Fragment& pFrag, FragmentRef::Offset pOffset) {
m_pFragment = &pFrag;
m_Offset = pOffset;
return *this;
}
-void FragmentRef::memcpy(void* pDest, size_t pNBytes, Offset pOffset) const
-{
+void FragmentRef::memcpy(void* pDest, size_t pNBytes, Offset pOffset) const {
// check if the offset is still in a legal range.
- if (NULL == m_pFragment)
+ if (m_pFragment == NULL)
return;
+
unsigned int total_offset = m_Offset + pOffset;
- switch(m_pFragment->getKind()) {
+ switch (m_pFragment->getKind()) {
case Fragment::Region: {
RegionFragment* region_frag = static_cast<RegionFragment*>(m_pFragment);
unsigned int total_length = region_frag->getRegion().size();
- if (total_length < (total_offset+pNBytes))
+ if (total_length < (total_offset + pNBytes))
pNBytes = total_length - total_offset;
- std::memcpy(pDest, region_frag->getRegion().begin() + total_offset, pNBytes);
+ std::memcpy(
+ pDest, region_frag->getRegion().begin() + total_offset, pNBytes);
return;
}
case Fragment::Stub: {
Stub* stub_frag = static_cast<Stub*>(m_pFragment);
unsigned int total_length = stub_frag->size();
- if (total_length < (total_offset+pNBytes))
+ if (total_length < (total_offset + pNBytes))
pNBytes = total_length - total_offset;
std::memcpy(pDest, stub_frag->getContent() + total_offset, pNBytes);
return;
@@ -154,10 +147,11 @@
}
}
-FragmentRef::Offset FragmentRef::getOutputOffset() const
-{
+FragmentRef::Offset FragmentRef::getOutputOffset() const {
Offset result = 0;
- if (NULL != m_pFragment)
+ if (m_pFragment != NULL)
result = m_pFragment->getOffset();
return (result + m_Offset);
}
+
+} // namespace mcld
diff --git a/lib/Fragment/NullFragment.cpp b/lib/Fragment/NullFragment.cpp
index a1d1626..702b3a6 100644
--- a/lib/Fragment/NullFragment.cpp
+++ b/lib/Fragment/NullFragment.cpp
@@ -6,15 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/NullFragment.h>
+#include "mcld/Fragment/NullFragment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// NullFragment
//===----------------------------------------------------------------------===//
-NullFragment::NullFragment(SectionData* pSD)
- : Fragment(Fragment::Null, pSD)
-{
+NullFragment::NullFragment(SectionData* pSD) : Fragment(Fragment::Null, pSD) {
}
+} // namespace mcld
diff --git a/lib/Fragment/RegionFragment.cpp b/lib/Fragment/RegionFragment.cpp
index c8971b8..37945a2 100644
--- a/lib/Fragment/RegionFragment.cpp
+++ b/lib/Fragment/RegionFragment.cpp
@@ -6,23 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/RegionFragment.h>
+#include "mcld/Fragment/RegionFragment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// RegionFragment
//===----------------------------------------------------------------------===//
RegionFragment::RegionFragment(llvm::StringRef pRegion, SectionData* pSD)
- : Fragment(Fragment::Region, pSD), m_Region(pRegion) {
+ : Fragment(Fragment::Region, pSD), m_Region(pRegion) {
}
-RegionFragment::~RegionFragment()
-{
+RegionFragment::~RegionFragment() {
}
-size_t RegionFragment::size() const
-{
+size_t RegionFragment::size() const {
return m_Region.size();
}
+} // namespace mcld
diff --git a/lib/Fragment/Relocation.cpp b/lib/Fragment/Relocation.cpp
index 1537c0c..68c13a0 100644
--- a/lib/Fragment/Relocation.cpp
+++ b/lib/Fragment/Relocation.cpp
@@ -6,18 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/RelocationFactory.h>
+#include "mcld/Fragment/Relocation.h"
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
static llvm::ManagedStatic<RelocationFactory> g_RelocationFactory;
@@ -25,20 +26,17 @@
// Relocation Factory Methods
//===----------------------------------------------------------------------===//
/// Initialize - set up the relocation factory
-void Relocation::SetUp(const LinkerConfig& pConfig)
-{
+void Relocation::SetUp(const LinkerConfig& pConfig) {
g_RelocationFactory->setConfig(pConfig);
}
/// Clear - Clean up the relocation factory
-void Relocation::Clear()
-{
+void Relocation::Clear() {
g_RelocationFactory->clear();
}
/// Create - produce an empty relocation entry
-Relocation* Relocation::Create()
-{
+Relocation* Relocation::Create() {
return g_RelocationFactory->produceEmptyEntry();
}
@@ -46,14 +44,14 @@
/// @param pType [in] the type of the relocation entry
/// @param pFragRef [in] the place to apply the relocation
/// @param pAddend [in] the addend of the relocation entry
-Relocation* Relocation::Create(Type pType, FragmentRef& pFragRef, Address pAddend)
-{
+Relocation* Relocation::Create(Type pType,
+ FragmentRef& pFragRef,
+ Address pAddend) {
return g_RelocationFactory->produce(pType, pFragRef, pAddend);
}
/// Destroy - destroy a relocation entry
-void Relocation::Destroy(Relocation*& pRelocation)
-{
+void Relocation::Destroy(Relocation*& pRelocation) {
g_RelocationFactory->destroy(pRelocation);
pRelocation = NULL;
}
@@ -62,34 +60,30 @@
// Relocation
//===----------------------------------------------------------------------===//
Relocation::Relocation()
- : m_Type(0x0), m_TargetData(0x0), m_pSymInfo(NULL), m_Addend(0x0) {
+ : m_Type(0x0), m_TargetData(0x0), m_pSymInfo(NULL), m_Addend(0x0) {
}
Relocation::Relocation(Relocation::Type pType,
FragmentRef* pTargetRef,
Relocation::Address pAddend,
Relocation::DWord pTargetData)
- : m_Type(pType),
- m_TargetData(pTargetData),
- m_pSymInfo(NULL),
- m_Addend(pAddend)
-{
- if(NULL != pTargetRef)
- m_TargetAddress.assign(*pTargetRef->frag(), pTargetRef->offset()) ;
+ : m_Type(pType),
+ m_TargetData(pTargetData),
+ m_pSymInfo(NULL),
+ m_Addend(pAddend) {
+ if (pTargetRef != NULL)
+ m_TargetAddress.assign(*pTargetRef->frag(), pTargetRef->offset());
}
-Relocation::~Relocation()
-{
+Relocation::~Relocation() {
}
-Relocation::Address Relocation::place() const
-{
+Relocation::Address Relocation::place() const {
Address sect_addr = m_TargetAddress.frag()->getParent()->getSection().addr();
return sect_addr + m_TargetAddress.getOutputOffset();
}
-Relocation::Address Relocation::symValue() const
-{
+Relocation::Address Relocation::symValue() const {
if (m_pSymInfo->type() == ResolveInfo::Section &&
m_pSymInfo->outSymbol()->hasFragRef()) {
const FragmentRef* fragRef = m_pSymInfo->outSymbol()->fragRef();
@@ -99,8 +93,7 @@
return m_pSymInfo->outSymbol()->value();
}
-void Relocation::apply(Relocator& pRelocator)
-{
+void Relocation::apply(Relocator& pRelocator) {
Relocator::Result result = pRelocator.applyRelocation(*this);
switch (result) {
@@ -118,7 +111,7 @@
<< symInfo()->name();
return;
}
- case Relocator::Unsupport: {
+ case Relocator::Unsupported: {
fatal(diag::unsupported_relocation) << type()
<< "mclinker@googlegroups.com";
return;
@@ -127,34 +120,31 @@
fatal(diag::unknown_relocation) << type() << symInfo()->name();
return;
}
- } // end of switch
+ } // end of switch
}
-void Relocation::setType(Type pType)
-{
+void Relocation::setType(Type pType) {
m_Type = pType;
}
-void Relocation::setAddend(Address pAddend)
-{
+void Relocation::setAddend(Address pAddend) {
m_Addend = pAddend;
}
-void Relocation::setSymInfo(ResolveInfo* pSym)
-{
+void Relocation::setSymInfo(ResolveInfo* pSym) {
m_pSymInfo = pSym;
}
-Relocation::Size Relocation::size(Relocator& pRelocator) const
-{
+Relocation::Size Relocation::size(Relocator& pRelocator) const {
return pRelocator.getSize(m_Type);
}
-void Relocation::updateAddend()
-{
+void Relocation::updateAddend() {
// Update value keep in addend if we meet a section symbol
if (m_pSymInfo->type() == ResolveInfo::Section) {
uint32_t offset = m_pSymInfo->outSymbol()->fragRef()->getOutputOffset();
m_Addend += offset;
}
}
+
+} // namespace mcld
diff --git a/lib/Fragment/Stub.cpp b/lib/Fragment/Stub.cpp
index b7122bd..b658ece 100644
--- a/lib/Fragment/Stub.cpp
+++ b/lib/Fragment/Stub.cpp
@@ -6,37 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Fragment/Stub.h"
-#include <mcld/Fragment/Stub.h>
+namespace mcld {
-using namespace mcld;
-
-Stub::Stub()
- : Fragment(Fragment::Stub),
- m_pSymInfo(NULL)
-{
+Stub::Stub() : Fragment(Fragment::Stub), m_pSymInfo(NULL) {
}
-Stub::~Stub()
-{
- for (fixup_iterator fixup= fixup_begin(); fixup != fixup_end(); ++fixup)
- delete(*fixup);
+Stub::~Stub() {
+ for (fixup_iterator fixup = fixup_begin(); fixup != fixup_end(); ++fixup)
+ delete (*fixup);
}
-void Stub::setSymInfo(ResolveInfo* pSymInfo)
-{
+void Stub::setSymInfo(ResolveInfo* pSymInfo) {
m_pSymInfo = pSymInfo;
}
-void Stub::addFixup(DWord pOffset, SWord pAddend, Type pType)
-{
+void Stub::addFixup(DWord pOffset, SWord pAddend, Type pType) {
assert(pOffset < size());
m_FixupList.push_back(new Fixup(pOffset, pAddend, pType));
}
-void Stub::addFixup(const Fixup& pFixup)
-{
+void Stub::addFixup(const Fixup& pFixup) {
assert(pFixup.offset() < size());
m_FixupList.push_back(new Fixup(pFixup));
}
+} // namespace mcld
diff --git a/lib/LD/Archive.cpp b/lib/LD/Archive.cpp
index c555e67..9217519 100644
--- a/lib/LD/Archive.cpp
+++ b/lib/LD/Archive.cpp
@@ -6,87 +6,78 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Archive.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/Input.h>
-#include <llvm/ADT/StringRef.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/Archive.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Support/MsgHandling.h"
-using namespace mcld;
+#include <llvm/ADT/StringRef.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Archive
-const char Archive::MAGIC[] = "!<arch>\n";
-const char Archive::THIN_MAGIC[] = "!<thin>\n";
-const size_t Archive::MAGIC_LEN = sizeof(Archive::MAGIC) - 1;
-const char Archive::SVR4_SYMTAB_NAME[] = "/ ";
-const char Archive::IRIX6_SYMTAB_NAME[]= "/SYM64/ ";
-const char Archive::STRTAB_NAME[] = "// ";
-const char Archive::PAD[] = "\n";
-const char Archive::MEMBER_MAGIC[] = "`\n";
+const char Archive::MAGIC[] = "!<arch>\n";
+const char Archive::THIN_MAGIC[] = "!<thin>\n";
+const size_t Archive::MAGIC_LEN = sizeof(Archive::MAGIC) - 1;
+const char Archive::SVR4_SYMTAB_NAME[] = "/ ";
+const char Archive::IRIX6_SYMTAB_NAME[] = "/SYM64/ ";
+const char Archive::STRTAB_NAME[] = "// ";
+const char Archive::PAD[] = "\n";
+const char Archive::MEMBER_MAGIC[] = "`\n";
Archive::Archive(Input& pInputFile, InputBuilder& pBuilder)
- : m_ArchiveFile(pInputFile),
- m_pInputTree(NULL),
- m_SymbolFactory(32),
- m_Builder(pBuilder)
-{
+ : m_ArchiveFile(pInputFile),
+ m_pInputTree(NULL),
+ m_SymbolFactory(32),
+ m_Builder(pBuilder) {
// FIXME: move creation of input tree out of Archive.
m_pInputTree = new InputTree();
}
-Archive::~Archive()
-{
+Archive::~Archive() {
delete m_pInputTree;
}
/// getARFile - get the Input& of the archive file
-Input& Archive::getARFile()
-{
+Input& Archive::getARFile() {
return m_ArchiveFile;
}
/// getARFile - get the Input& of the archive file
-const Input& Archive::getARFile() const
-{
+const Input& Archive::getARFile() const {
return m_ArchiveFile;
}
/// inputs - get the input tree built from this archive
-InputTree& Archive::inputs()
-{
+InputTree& Archive::inputs() {
return *m_pInputTree;
}
/// inputs - get the input tree built from this archive
-const InputTree& Archive::inputs() const
-{
+const InputTree& Archive::inputs() const {
return *m_pInputTree;
}
/// getObjectMemberMap - get the map that contains the included object files
-Archive::ObjectMemberMapType& Archive::getObjectMemberMap()
-{
+Archive::ObjectMemberMapType& Archive::getObjectMemberMap() {
return m_ObjectMemberMap;
}
/// getObjectMemberMap - get the map that contains the included object files
-const Archive::ObjectMemberMapType& Archive::getObjectMemberMap() const
-{
+const Archive::ObjectMemberMapType& Archive::getObjectMemberMap() const {
return m_ObjectMemberMap;
}
/// numOfObjectMember - return the number of included object files
-size_t Archive::numOfObjectMember() const
-{
+size_t Archive::numOfObjectMember() const {
return m_ObjectMemberMap.numOfEntries();
}
/// addObjectMember - add a object in the object member map
/// @param pFileOffset - file offset in symtab represents a object file
/// @param pIter - the iterator in the input tree built from this archive
-bool Archive::addObjectMember(uint32_t pFileOffset, InputTree::iterator pIter)
-{
+bool Archive::addObjectMember(uint32_t pFileOffset, InputTree::iterator pIter) {
bool exist;
ObjectMemberEntryType* entry = m_ObjectMemberMap.insert(pFileOffset, exist);
if (!exist)
@@ -96,20 +87,17 @@
/// hasObjectMember - check if a object file is included or not
/// @param pFileOffset - file offset in symtab represents a object file
-bool Archive::hasObjectMember(uint32_t pFileOffset) const
-{
+bool Archive::hasObjectMember(uint32_t pFileOffset) const {
return (m_ObjectMemberMap.find(pFileOffset) != m_ObjectMemberMap.end());
}
/// getArchiveMemberMap - get the map that contains the included archive files
-Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap()
-{
+Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() {
return m_ArchiveMemberMap;
}
/// getArchiveMemberMap - get the map that contains the included archive files
-const Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() const
-{
+const Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() const {
return m_ArchiveMemberMap;
}
@@ -121,8 +109,7 @@
/// subtree of this archive member
bool Archive::addArchiveMember(const llvm::StringRef& pName,
InputTree::iterator pLastPos,
- InputTree::Mover* pMove)
-{
+ InputTree::Mover* pMove) {
bool exist;
ArchiveMemberEntryType* entry = m_ArchiveMemberMap.insert(pName, exist);
if (!exist) {
@@ -138,14 +125,13 @@
}
/// hasArchiveMember - check if an archive file is included or not
-bool Archive::hasArchiveMember(const llvm::StringRef& pName) const
-{
+bool Archive::hasArchiveMember(const llvm::StringRef& pName) const {
return (m_ArchiveMemberMap.find(pName) != m_ArchiveMemberMap.end());
}
/// getArchiveMember - get a archive member
-Archive::ArchiveMember* Archive::getArchiveMember(const llvm::StringRef& pName)
-{
+Archive::ArchiveMember* Archive::getArchiveMember(
+ const llvm::StringRef& pName) {
ArchiveMemberMapType::iterator it = m_ArchiveMemberMap.find(pName);
if (it != m_ArchiveMemberMap.end())
return &(it.getEntry()->value());
@@ -153,32 +139,27 @@
}
/// getSymbolTable - get the symtab
-Archive::SymTabType& Archive::getSymbolTable()
-{
+Archive::SymTabType& Archive::getSymbolTable() {
return m_SymTab;
}
/// getSymbolTable - get the symtab
-const Archive::SymTabType& Archive::getSymbolTable() const
-{
+const Archive::SymTabType& Archive::getSymbolTable() const {
return m_SymTab;
}
/// setSymTabSize - set the memory size of symtab
-void Archive::setSymTabSize(size_t pSize)
-{
+void Archive::setSymTabSize(size_t pSize) {
m_SymTabSize = pSize;
}
/// getSymTabSize - get the memory size of symtab
-size_t Archive::getSymTabSize() const
-{
+size_t Archive::getSymTabSize() const {
return m_SymTabSize;
}
/// numOfSymbols - return the number of symbols in symtab
-size_t Archive::numOfSymbols() const
-{
+size_t Archive::numOfSymbols() const {
return m_SymTab.size();
}
@@ -187,57 +168,49 @@
/// @param pFileOffset - file offset in symtab represents a object file
void Archive::addSymbol(const char* pName,
uint32_t pFileOffset,
- enum Archive::Symbol::Status pStatus)
-{
+ enum Archive::Symbol::Status pStatus) {
Symbol* entry = m_SymbolFactory.allocate();
new (entry) Symbol(pName, pFileOffset, pStatus);
m_SymTab.push_back(entry);
}
/// getSymbolName - get the symbol name with the given index
-const std::string& Archive::getSymbolName(size_t pSymIdx) const
-{
+const std::string& Archive::getSymbolName(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->name;
}
/// getObjFileOffset - get the file offset that represent a object file
-uint32_t Archive::getObjFileOffset(size_t pSymIdx) const
-{
+uint32_t Archive::getObjFileOffset(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->fileOffset;
}
/// getSymbolStatus - get the status of a symbol
-enum Archive::Symbol::Status Archive::getSymbolStatus(size_t pSymIdx) const
-{
+enum Archive::Symbol::Status Archive::getSymbolStatus(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->status;
}
/// setSymbolStatus - set the status of a symbol
void Archive::setSymbolStatus(size_t pSymIdx,
- enum Archive::Symbol::Status pStatus)
-{
+ enum Archive::Symbol::Status pStatus) {
assert(pSymIdx < numOfSymbols());
m_SymTab[pSymIdx]->status = pStatus;
}
/// getStrTable - get the extended name table
-std::string& Archive::getStrTable()
-{
+std::string& Archive::getStrTable() {
return m_StrTab;
}
/// getStrTable - get the extended name table
-const std::string& Archive::getStrTable() const
-{
+const std::string& Archive::getStrTable() const {
return m_StrTab;
}
/// hasStrTable()
-bool Archive::hasStrTable() const
-{
+bool Archive::hasStrTable() const {
return (m_StrTab.size() > 0);
}
@@ -252,19 +225,19 @@
bool isThinAR,
const std::string& pName,
const sys::fs::Path& pPath,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
Input* member = NULL;
if (!isThinAR) {
member = m_Builder.createInput(pName, pPath, Input::Unknown, pFileOffset);
assert(member != NULL);
member->setMemArea(pArchiveFile.memArea());
m_Builder.setContext(*member);
- }
- else {
+ } else {
member = m_Builder.createInput(pName, pPath, Input::Unknown);
assert(member != NULL);
- if (!m_Builder.setMemory(*member, FileHandle::ReadOnly)) {
+ if (!m_Builder.setMemory(*member,
+ FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
error(diag::err_cannot_open_input) << member->name() << member->path();
return NULL;
}
@@ -273,3 +246,4 @@
return member;
}
+} // namespace mcld
diff --git a/lib/LD/ArchiveReader.cpp b/lib/LD/ArchiveReader.cpp
index 88957bc..29568c0 100644
--- a/lib/LD/ArchiveReader.cpp
+++ b/lib/LD/ArchiveReader.cpp
@@ -8,14 +8,14 @@
//===----------------------------------------------------------------------===//
#include "mcld/LD/ArchiveReader.h"
-using namespace mcld;
+namespace mcld {
//==========================
// MCELFArchiveReader
-ArchiveReader::ArchiveReader()
-{
+ArchiveReader::ArchiveReader() {
}
-ArchiveReader::~ArchiveReader()
-{
+ArchiveReader::~ArchiveReader() {
}
+
+} // namespace mcld
diff --git a/lib/LD/BSDArchiveReader.cpp b/lib/LD/BSDArchiveReader.cpp
index 57d3a52..00e1ed4 100644
--- a/lib/LD/BSDArchiveReader.cpp
+++ b/lib/LD/BSDArchiveReader.cpp
@@ -6,31 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Input.h>
-#include <mcld/LD/BSDArchiveReader.h>
-#include <mcld/LD/Archive.h>
+#include "mcld/LD/BSDArchiveReader.h"
+#include "mcld/LD/Archive.h"
+#include "mcld/MC/Input.h"
-using namespace mcld;
+namespace mcld {
-BSDArchiveReader::BSDArchiveReader()
-{
+BSDArchiveReader::BSDArchiveReader() {
}
-BSDArchiveReader::~BSDArchiveReader()
-{
+BSDArchiveReader::~BSDArchiveReader() {
}
bool BSDArchiveReader::readArchive(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// TODO
return true;
}
-bool BSDArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool BSDArchiveReader::isMyFormat(Input& pInput, bool& pContinue) const {
pContinue = true;
// TODO
return false;
}
+} // namespace mcld
diff --git a/lib/LD/BinaryReader.cpp b/lib/LD/BinaryReader.cpp
index f5c439f..914c3ca 100644
--- a/lib/LD/BinaryReader.cpp
+++ b/lib/LD/BinaryReader.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BinaryReader.h>
+#include "mcld/LD/BinaryReader.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// BinaryReader
//===----------------------------------------------------------------------===//
-BinaryReader::~BinaryReader()
-{
+BinaryReader::~BinaryReader() {
}
+} // namespace mcld
diff --git a/lib/LD/BranchIsland.cpp b/lib/LD/BranchIsland.cpp
index c6f5b02..0405263 100644
--- a/lib/LD/BranchIsland.cpp
+++ b/lib/LD/BranchIsland.cpp
@@ -6,101 +6,88 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BranchIsland.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/AlignFragment.h>
+#include "mcld/LD/BranchIsland.h"
+
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/ResolveInfo.h"
#include <sstream>
-using namespace mcld;
+namespace mcld {
//==========================
// BranchIsland
-BranchIsland::BranchIsland(Fragment& pEntryFrag,
- size_t pMaxSize,
- size_t pIndex)
- : m_Entry(pEntryFrag),
- m_pExit(pEntryFrag.getNextNode()),
- m_pRear(NULL),
- m_MaxSize(pMaxSize),
- m_Name("island-")
-{
+BranchIsland::BranchIsland(Fragment& pEntryFrag, size_t pMaxSize, size_t pIndex)
+ : m_Entry(pEntryFrag),
+ m_pExit(pEntryFrag.getNextNode()),
+ m_pRear(NULL),
+ m_MaxSize(pMaxSize),
+ m_Name("island-") {
// island name
std::ostringstream index;
index << pIndex;
m_Name.append(index.str());
}
-BranchIsland::~BranchIsland()
-{
+BranchIsland::~BranchIsland() {
}
/// fragment iterators of the island
-SectionData::iterator BranchIsland::begin()
-{
+SectionData::iterator BranchIsland::begin() {
return ++iterator(&m_Entry);
}
-SectionData::const_iterator BranchIsland::begin() const
-{
+SectionData::const_iterator BranchIsland::begin() const {
return ++iterator(&m_Entry);
}
-SectionData::iterator BranchIsland::end()
-{
- if (NULL != m_pExit)
+SectionData::iterator BranchIsland::end() {
+ if (m_pExit != NULL)
return iterator(m_pExit);
return m_Entry.getParent()->end();
}
-SectionData::const_iterator BranchIsland::end() const
-{
- if (NULL != m_pExit)
+SectionData::const_iterator BranchIsland::end() const {
+ if (m_pExit != NULL)
return iterator(m_pExit);
return m_Entry.getParent()->end();
}
-uint64_t BranchIsland::offset() const
-{
+uint64_t BranchIsland::offset() const {
return m_Entry.getOffset() + m_Entry.size();
}
-size_t BranchIsland::size() const
-{
+size_t BranchIsland::size() const {
size_t size = 0x0;
- if (0x0 != numOfStubs()) {
+ if (numOfStubs() != 0x0) {
size = m_pRear->getOffset() + m_pRear->size() -
m_Entry.getNextNode()->getOffset();
}
return size;
}
-size_t BranchIsland::maxSize() const
-{
+size_t BranchIsland::maxSize() const {
return m_MaxSize;
}
-const std::string& BranchIsland::name() const
-{
+const std::string& BranchIsland::name() const {
return m_Name;
}
-size_t BranchIsland::numOfStubs() const
-{
+size_t BranchIsland::numOfStubs() const {
return m_StubMap.numOfEntries();
}
/// findStub - return true if there is a stub built from the given prototype
/// for the given relocation
-Stub* BranchIsland::findStub(const Stub* pPrototype, const Relocation& pReloc)
-{
+Stub* BranchIsland::findStub(const Stub* pPrototype, const Relocation& pReloc) {
Key key(pPrototype, pReloc.symInfo()->outSymbol(), pReloc.addend());
StubMapType::iterator it = m_StubMap.find(key);
if (it != m_StubMap.end()) {
- assert(NULL != it.getEntry()->value());
+ assert(it.getEntry()->value() != NULL);
return it.getEntry()->value();
}
return NULL;
@@ -109,8 +96,7 @@
/// addStub - add a stub into the island
bool BranchIsland::addStub(const Stub* pPrototype,
const Relocation& pReloc,
- Stub& pStub)
-{
+ Stub& pStub) {
bool exist = false;
Key key(pPrototype, pReloc.symInfo()->outSymbol(), pReloc.addend());
StubEntryType* entry = m_StubMap.insert(key, exist);
@@ -121,10 +107,8 @@
// insert alignment fragment
// TODO: check if we can reduce this alignment fragment for some cases
- AlignFragment* align_frag = new AlignFragment(pStub.alignment(),
- 0x0,
- 1u,
- pStub.alignment() - 1);
+ AlignFragment* align_frag =
+ new AlignFragment(pStub.alignment(), 0x0, 1u, pStub.alignment() - 1);
align_frag->setParent(sd);
sd->getFragmentList().insert(end(), align_frag);
align_frag->setOffset(align_frag->getPrevNode()->getOffset() +
@@ -140,9 +124,9 @@
}
/// addRelocation - add a relocation into island
-bool BranchIsland::addRelocation(Relocation& pReloc)
-{
+bool BranchIsland::addRelocation(Relocation& pReloc) {
m_Relocations.push_back(&pReloc);
return true;
}
+} // namespace mcld
diff --git a/lib/LD/BranchIslandFactory.cpp b/lib/LD/BranchIslandFactory.cpp
index 0147e5f..cace800 100644
--- a/lib/LD/BranchIslandFactory.cpp
+++ b/lib/LD/BranchIslandFactory.cpp
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Module.h>
+#include "mcld/LD/BranchIslandFactory.h"
-using namespace mcld;
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// BranchIslandFactory
@@ -25,21 +26,18 @@
BranchIslandFactory::BranchIslandFactory(int64_t pMaxFwdBranchRange,
int64_t pMaxBwdBranchRange,
size_t pMaxIslandSize)
- : GCFactory<BranchIsland, 0>(1u), // magic number
+ : GCFactory<BranchIsland, 0>(1u), // magic number
m_MaxFwdBranchRange(pMaxFwdBranchRange - pMaxIslandSize),
m_MaxBwdBranchRange(pMaxBwdBranchRange + pMaxIslandSize),
- m_MaxIslandSize(pMaxIslandSize)
-{
+ m_MaxIslandSize(pMaxIslandSize) {
}
-BranchIslandFactory::~BranchIslandFactory()
-{
+BranchIslandFactory::~BranchIslandFactory() {
}
/// group - group fragments and create islands when needed
/// @param pSectionData - the SectionData holds fragments need to be grouped
-void BranchIslandFactory::group(Module& pModule)
-{
+void BranchIslandFactory::group(Module& pModule) {
/* FIXME: Currently only support relaxing .text section! */
LDSection* text = pModule.getSection(".text");
if (text != NULL && text->hasSectionData()) {
@@ -64,33 +62,30 @@
/// produce - produce a island for the given fragment
/// @param pFragment - the fragment needs a branch island
-BranchIsland* BranchIslandFactory::produce(Fragment& pFragment)
-{
- BranchIsland *island = allocate();
- new (island) BranchIsland(pFragment, // entry fragment to the island
- m_MaxIslandSize, // the max size of the island
- size() - 1u); // index in the island factory
+BranchIsland* BranchIslandFactory::produce(Fragment& pFragment) {
+ BranchIsland* island = allocate();
+ new (island) BranchIsland(pFragment, // entry fragment to the island
+ m_MaxIslandSize, // the max size of the island
+ size() - 1u); // index in the island factory
return island;
}
/// getIsland - find fwd and bwd islands for the fragment
/// @param pFragment - the fragment needs a branch island
-std::pair<BranchIsland*, BranchIsland*>
-BranchIslandFactory::getIslands(const Fragment& pFragment)
-{
+std::pair<BranchIsland*, BranchIsland*> BranchIslandFactory::getIslands(
+ const Fragment& pFragment) {
BranchIsland* fwd = NULL;
BranchIsland* bwd = NULL;
for (iterator it = begin(), ie = end(), prev = ie; it != ie;
prev = it, ++it) {
if ((pFragment.getOffset() < (*it).offset()) &&
((pFragment.getOffset() + m_MaxFwdBranchRange) >= (*it).offset())) {
-
fwd = &*it;
if (prev != ie) {
int64_t bwd_off = (int64_t)pFragment.getOffset() + m_MaxBwdBranchRange;
if ((pFragment.getOffset() > (*prev).offset()) &&
- (bwd_off <= (int64_t) (*prev).offset())) {
+ (bwd_off <= (int64_t)(*prev).offset())) {
bwd = &*prev;
}
}
@@ -99,3 +94,5 @@
}
return std::make_pair(fwd, bwd);
}
+
+} // namespace mcld
diff --git a/lib/LD/DWARFLineInfo.cpp b/lib/LD/DWARFLineInfo.cpp
index 63c588d..1df686e 100644
--- a/lib/LD/DWARFLineInfo.cpp
+++ b/lib/LD/DWARFLineInfo.cpp
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
-using namespace mcld;
+namespace mcld {
//==========================
// DWARFLineInfo
+} // namespace mcld
diff --git a/lib/LD/DebugString.cpp b/lib/LD/DebugString.cpp
new file mode 100644
index 0000000..3a8f9af
--- /dev/null
+++ b/lib/LD/DebugString.cpp
@@ -0,0 +1,95 @@
+//===- DebugString.cpp ----------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Target/TargetLDBackend.h"
+#include "mcld/LD/Relocator.h"
+
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ManagedStatic.h>
+
+namespace mcld {
+
+// DebugString represents the output .debug_str section, which is at most on
+// in each linking
+static llvm::ManagedStatic<DebugString> g_DebugString;
+
+static inline size_t string_length(const char* pStr) {
+ const char* p = pStr;
+ size_t len = 0;
+ for (; *p != 0; ++p)
+ ++len;
+ return len;
+}
+
+//==========================
+// DebugString
+void DebugString::merge(LDSection& pSection) {
+ // get the fragment contents
+ llvm::StringRef strings;
+ SectionData::iterator it, end = pSection.getSectionData()->end();
+ for (it = pSection.getSectionData()->begin(); it != end; ++it) {
+ if ((*it).getKind() == Fragment::Region) {
+ RegionFragment* frag = llvm::cast<RegionFragment>(&(*it));
+ strings = frag->getRegion().data();
+ }
+ }
+
+ // get the debug strings and add them into merged string table
+ const char* str = strings.data();
+ const char* str_end = str + pSection.size();
+ while (str < str_end) {
+ size_t len = string_length(str);
+ m_StringTable.insertString(llvm::StringRef(str, len));
+ str = str + len + 1;
+ }
+}
+
+size_t DebugString::computeOffsetSize() {
+ size_t size = m_StringTable.finalizeOffset();
+ m_pSection->setSize(size);
+ return size;
+}
+
+void DebugString::applyOffset(Relocation& pReloc, TargetLDBackend& pBackend) {
+ // get the refered string
+ ResolveInfo* info = pReloc.symInfo();
+ // the symbol should point to the first region fragment in the debug
+ // string section, get the input .debut_str region
+ llvm::StringRef d_str;
+ if (info->outSymbol()->fragRef()->frag()->getKind() == Fragment::Region) {
+ RegionFragment* frag =
+ llvm::cast<RegionFragment>(info->outSymbol()->fragRef()->frag());
+ d_str = frag->getRegion();
+ }
+ uint32_t offset = pBackend.getRelocator()->getDebugStringOffset(pReloc);
+ const char* str = d_str.data() + offset;
+
+ // apply the relocation
+ pBackend.getRelocator()->applyDebugStringOffset(pReloc,
+ m_StringTable.getOutputOffset(llvm::StringRef(str, string_length(str))));
+}
+
+void DebugString::emit(MemoryRegion& pRegion) {
+ return m_StringTable.emit(pRegion);
+}
+
+DebugString* DebugString::Create(LDSection& pSection) {
+ g_DebugString->setOutputSection(pSection);
+ return &(*g_DebugString);
+}
+
+} // namespace mcld
diff --git a/lib/LD/Diagnostic.cpp b/lib/LD/Diagnostic.cpp
index 5d57f29..a55a9c1 100644
--- a/lib/LD/Diagnostic.cpp
+++ b/lib/LD/Diagnostic.cpp
@@ -6,29 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Diagnostic.h>
+#include "mcld/LD/Diagnostic.h"
+
#include <llvm/Support/ErrorHandling.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/ADT/Twine.h>
-#include <ctype.h>
+
#include <algorithm>
-using namespace mcld;
+#include <ctype.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Diagnostic
-Diagnostic::Diagnostic(DiagnosticEngine& pEngine)
- : m_Engine(pEngine) {
+Diagnostic::Diagnostic(DiagnosticEngine& pEngine) : m_Engine(pEngine) {
}
-Diagnostic::~Diagnostic()
-{
+Diagnostic::~Diagnostic() {
}
// format - format this diagnostic into string, subsituting the formal
// arguments. The result is appended at on the pOutStr.
-void Diagnostic::format(std::string& pOutStr) const
-{
+void Diagnostic::format(std::string& pOutStr) const {
// we've not implemented DWARF LOC messages yet. So, keep pIsLoC false
llvm::StringRef desc = m_Engine.infoMap().getDescription(getID(), false);
@@ -36,16 +36,16 @@
}
const char* Diagnostic::findMatch(char pVal,
- const char* pBegin, const char* pEnd ) const
-{
+ const char* pBegin,
+ const char* pEnd) const {
unsigned int depth = 0;
for (; pBegin != pEnd; ++pBegin) {
- if (0 == depth && *pBegin == pVal)
+ if (depth == 0 && *pBegin == pVal)
return pBegin;
- if (0 != depth && *pBegin == '}')
+ if (depth != 0 && *pBegin == '}')
--depth;
- if ('%' == *pBegin) {
+ if (*pBegin == '%') {
++pBegin;
if (pBegin == pEnd)
break;
@@ -57,28 +57,27 @@
if (pBegin == pEnd)
break;
- if ('{' == *pBegin)
+ if (*pBegin == '{')
++depth;
}
}
- } // end of for
+ } // end of for
return pEnd;
}
// format - format the given formal string, subsituting the formal
// arguments. The result is appended at on the pOutStr.
-void Diagnostic::format(const char* pBegin, const char* pEnd,
- std::string& pOutStr) const
-{
+void Diagnostic::format(const char* pBegin,
+ const char* pEnd,
+ std::string& pOutStr) const {
const char* cur_char = pBegin;
while (cur_char != pEnd) {
- if ('%' != *cur_char) {
+ if (*cur_char != '%') {
const char* new_end = std::find(cur_char, pEnd, '%');
pOutStr.append(cur_char, new_end);
cur_char = new_end;
continue;
- }
- else if (ispunct(cur_char[1])) {
+ } else if (ispunct(cur_char[1])) {
pOutStr.push_back(cur_char[1]); // %% -> %.
cur_char += 2;
continue;
@@ -98,17 +97,18 @@
modifier_len = cur_char - modifier;
// we get an argument
- if ('{' == *cur_char) {
- ++cur_char; // skip '{'
+ if (*cur_char == '{') {
+ ++cur_char; // skip '{'
cur_char = findMatch('}', cur_char, pEnd);
if (cur_char == pEnd) {
// DIAG's format error
- llvm::report_fatal_error(llvm::Twine("Mismatched {} in the diagnostic: ") +
- llvm::Twine(getID()));
+ llvm::report_fatal_error(
+ llvm::Twine("Mismatched {} in the diagnostic: ") +
+ llvm::Twine(getID()));
}
- ++cur_char; // skip '}'
+ ++cur_char; // skip '}'
}
}
if (!isdigit(*cur_char)) {
@@ -119,30 +119,30 @@
}
unsigned int arg_no = *cur_char - '0';
- ++cur_char; // skip argument number
+ ++cur_char; // skip argument number
DiagnosticEngine::ArgumentKind kind = getArgKind(arg_no);
switch (kind) {
case DiagnosticEngine::ak_std_string: {
- if (0 != modifier_len) {
- llvm::report_fatal_error(llvm::Twine("In diagnostic: ") +
- llvm::Twine(getID()) +
- llvm::Twine(": ") + llvm::Twine(pBegin) +
- llvm::Twine("\nNo modifiers for strings yet\n"));
+ if (modifier_len != 0) {
+ llvm::report_fatal_error(
+ llvm::Twine("In diagnostic: ") + llvm::Twine(getID()) +
+ llvm::Twine(": ") + llvm::Twine(pBegin) +
+ llvm::Twine("\nNo modifiers for strings yet\n"));
}
const std::string& str = getArgStdStr(arg_no);
pOutStr.append(str.begin(), str.end());
break;
}
case DiagnosticEngine::ak_c_string: {
- if (0 != modifier_len) {
- llvm::report_fatal_error(llvm::Twine("In diagnostic: ") +
- llvm::Twine(getID()) +
- llvm::Twine(": ") + llvm::Twine(pBegin) +
- llvm::Twine("\nNo modifiers for strings yet\n"));
+ if (modifier_len != 0) {
+ llvm::report_fatal_error(
+ llvm::Twine("In diagnostic: ") + llvm::Twine(getID()) +
+ llvm::Twine(": ") + llvm::Twine(pBegin) +
+ llvm::Twine("\nNo modifiers for strings yet\n"));
}
const char* str = getArgCStr(arg_no);
- if (NULL == str)
+ if (str == NULL)
str = "(null)";
pOutStr.append(str);
break;
@@ -170,7 +170,8 @@
pOutStr.append("false");
break;
}
- } // end of switch
- } // end of while
+ } // end of switch
+ } // end of while
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticEngine.cpp b/lib/LD/DiagnosticEngine.cpp
index ac51080..ca0f2bd 100644
--- a/lib/LD/DiagnosticEngine.cpp
+++ b/lib/LD/DiagnosticEngine.cpp
@@ -6,26 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticEngine.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-#include <mcld/LD/DiagnosticLineInfo.h>
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/DiagnosticEngine.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/DiagnosticLineInfo.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+#include "mcld/LD/MsgHandler.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// DiagnosticEngine
//===----------------------------------------------------------------------===//
DiagnosticEngine::DiagnosticEngine()
- : m_pConfig(NULL), m_pLineInfo(NULL), m_pPrinter(NULL),
- m_pInfoMap(NULL), m_OwnPrinter(false) {
+ : m_pConfig(NULL),
+ m_pLineInfo(NULL),
+ m_pPrinter(NULL),
+ m_pInfoMap(NULL),
+ m_OwnPrinter(false) {
}
-DiagnosticEngine::~DiagnosticEngine()
-{
+DiagnosticEngine::~DiagnosticEngine() {
if (m_OwnPrinter && m_pPrinter != NULL)
delete m_pPrinter;
@@ -35,40 +38,35 @@
delete m_pLineInfo;
}
-void DiagnosticEngine::reset(const LinkerConfig& pConfig)
-{
+void DiagnosticEngine::reset(const LinkerConfig& pConfig) {
m_pConfig = &pConfig;
delete m_pInfoMap;
m_pInfoMap = new DiagnosticInfos(*m_pConfig);
m_State.reset();
}
-void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo)
-{
+void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo) {
m_pLineInfo = &pLineInfo;
}
void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter,
- bool pShouldOwnPrinter)
-{
- if (m_OwnPrinter && NULL != m_pPrinter)
+ bool pShouldOwnPrinter) {
+ if (m_OwnPrinter && m_pPrinter != NULL)
delete m_pPrinter;
m_pPrinter = &pPrinter;
m_OwnPrinter = pShouldOwnPrinter;
}
// emit - process current diagnostic.
-bool DiagnosticEngine::emit()
-{
- assert(NULL != m_pInfoMap);
+bool DiagnosticEngine::emit() {
+ assert(m_pInfoMap != NULL);
bool emitted = m_pInfoMap->process(*this);
m_State.reset();
return emitted;
}
-MsgHandler
-DiagnosticEngine::report(uint16_t pID, DiagnosticEngine::Severity pSeverity)
-{
+MsgHandler DiagnosticEngine::report(uint16_t pID,
+ DiagnosticEngine::Severity pSeverity) {
m_State.ID = pID;
m_State.severity = pSeverity;
@@ -76,3 +74,4 @@
return result;
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticInfos.cpp b/lib/LD/DiagnosticInfos.cpp
index aed389a..080c318 100644
--- a/lib/LD/DiagnosticInfos.cpp
+++ b/lib/LD/DiagnosticInfos.cpp
@@ -6,83 +6,85 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/LD/DiagnosticInfos.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/LD/Diagnostic.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/Diagnostic.h>
-#include <mcld/LD/DiagnosticInfos.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-
#include <algorithm>
-using namespace mcld;
+namespace mcld {
namespace {
-struct DiagStaticInfo
-{
-public:
+struct DiagStaticInfo {
+ public:
uint16_t ID;
DiagnosticEngine::Severity Severity;
uint16_t DescriptionLen;
const char* DescriptionStr;
-public:
- llvm::StringRef getDescription() const
- { return llvm::StringRef(DescriptionStr, DescriptionLen); }
+ public:
+ llvm::StringRef getDescription() const {
+ return llvm::StringRef(DescriptionStr, DescriptionLen);
+ }
- bool operator<(const DiagStaticInfo& pRHS) const
- { return (ID < pRHS.ID); }
+ bool operator<(const DiagStaticInfo& pRHS) const { return (ID < pRHS.ID); }
};
-} // namespace anonymous
+} // anonymous namespace
static const DiagStaticInfo DiagCommonInfo[] = {
-#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
- { diag::ENUM, CLASS, STR_SIZE(ADDRDESC, uint16_t), ADDRDESC },
-#include "mcld/LD/DiagAttribute.inc"
-#include "mcld/LD/DiagCommonKinds.inc"
-#include "mcld/LD/DiagReaders.inc"
-#include "mcld/LD/DiagSymbolResolutions.inc"
-#include "mcld/LD/DiagRelocations.inc"
-#include "mcld/LD/DiagLayouts.inc"
-#include "mcld/LD/DiagGOTPLT.inc"
-#include "mcld/LD/DiagLDScript.inc"
+#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
+ { diag::ENUM, CLASS, STR_SIZE(ADDRDESC, uint16_t), ADDRDESC } \
+ ,
+#include "mcld/LD/DiagAttribute.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagCommonKinds.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagReaders.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagSymbolResolutions.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagRelocations.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLayouts.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagGOTPLT.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLDScript.inc" // NOLINT [build/include] [4]
#undef DIAG
- { 0, DiagnosticEngine::None, 0, 0}
-};
+ {0, DiagnosticEngine::None, 0, 0}};
static const unsigned int DiagCommonInfoSize =
- sizeof(DiagCommonInfo)/sizeof(DiagCommonInfo[0])-1;
+ sizeof(DiagCommonInfo) / sizeof(DiagCommonInfo[0]) - 1;
static const DiagStaticInfo DiagLoCInfo[] = {
-#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
- { diag::ENUM, CLASS, STR_SIZE(LOCDESC, uint16_t), LOCDESC },
-#include "mcld/LD/DiagAttribute.inc"
-#include "mcld/LD/DiagCommonKinds.inc"
-#include "mcld/LD/DiagReaders.inc"
-#include "mcld/LD/DiagSymbolResolutions.inc"
-#include "mcld/LD/DiagRelocations.inc"
-#include "mcld/LD/DiagLayouts.inc"
-#include "mcld/LD/DiagGOTPLT.inc"
-#include "mcld/LD/DiagLDScript.inc"
+#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
+ { diag::ENUM, CLASS, STR_SIZE(LOCDESC, uint16_t), LOCDESC } \
+ ,
+#include "mcld/LD/DiagAttribute.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagCommonKinds.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagReaders.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagSymbolResolutions.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagRelocations.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLayouts.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagGOTPLT.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLDScript.inc" // NOLINT [build/include] [4]
#undef DIAG
- { 0, DiagnosticEngine::None, 0, 0}
-};
+ {0, DiagnosticEngine::None, 0, 0}};
static const unsigned int DiagLoCInfoSize =
- sizeof(DiagLoCInfo)/sizeof(DiagLoCInfo[0])-1;
+ sizeof(DiagLoCInfo) / sizeof(DiagLoCInfo[0]) - 1;
+static const DiagStaticInfo* getDiagInfo(unsigned int pID,
+ bool pInLoC = false) {
+ const DiagStaticInfo* static_info = (pInLoC) ? DiagLoCInfo : DiagCommonInfo;
+ unsigned int info_size = (pInLoC) ? DiagLoCInfoSize : DiagCommonInfoSize;
-static const DiagStaticInfo* getDiagInfo(unsigned int pID, bool pInLoC = false)
-{
- const DiagStaticInfo* static_info = (pInLoC)?DiagLoCInfo:DiagCommonInfo;
- unsigned int info_size = (pInLoC)?DiagLoCInfoSize:DiagCommonInfoSize;
+ DiagStaticInfo key = {
+ static_cast<uint16_t>(pID), DiagnosticEngine::None, 0, 0};
- DiagStaticInfo key = { static_cast<uint16_t>(pID), DiagnosticEngine::None, 0, 0 };
- const DiagStaticInfo *result = std::lower_bound(static_info, static_info + info_size, key);
+ const DiagStaticInfo* result =
+ std::lower_bound(static_info, static_info + info_size, key);
if (result == (static_info + info_size) || result->ID != pID)
return NULL;
@@ -94,20 +96,18 @@
// DiagnosticInfos
//===----------------------------------------------------------------------===//
DiagnosticInfos::DiagnosticInfos(const LinkerConfig& pConfig)
- : m_Config(pConfig) {
+ : m_Config(pConfig) {
}
-DiagnosticInfos::~DiagnosticInfos()
-{
+DiagnosticInfos::~DiagnosticInfos() {
}
-llvm::StringRef DiagnosticInfos::getDescription(unsigned int pID, bool pInLoC) const
-{
+llvm::StringRef DiagnosticInfos::getDescription(unsigned int pID,
+ bool pInLoC) const {
return getDiagInfo(pID, pInLoC)->getDescription();
}
-bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const
-{
+bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const {
Diagnostic info(pEngine);
unsigned int ID = info.getID();
@@ -127,8 +127,9 @@
case diag::undefined_reference:
case diag::undefined_reference_text: {
// we have not implement --unresolved-symbols=method yet. So far, MCLinker
- // provides the easier --allow-shlib-undefined and --no-undefined (i.e. -z defs)
- switch(m_Config.codeGenType()) {
+ // provides the easier --allow-shlib-undefined and --no-undefined (i.e.
+ // -z defs)
+ switch (m_Config.codeGenType()) {
case LinkerConfig::Object:
if (m_Config.options().isNoUndefined())
severity = DiagnosticEngine::Error;
@@ -154,7 +155,7 @@
}
default:
break;
- } // end of switch
+ } // end of switch
// If --fatal-warnings is turned on, then switch warnings and errors to fatal
if (m_Config.options().isFatalWarnings()) {
@@ -169,3 +170,4 @@
return true;
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticLineInfo.cpp b/lib/LD/DiagnosticLineInfo.cpp
index d3c9190..b1c3a84 100644
--- a/lib/LD/DiagnosticLineInfo.cpp
+++ b/lib/LD/DiagnosticLineInfo.cpp
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticLineInfo.h>
+#include "mcld/LD/DiagnosticLineInfo.h"
-using namespace mcld;
+namespace mcld {
//==========================
// DiagnosticLineInfo
+} // namespace mcld
diff --git a/lib/LD/DiagnosticPrinter.cpp b/lib/LD/DiagnosticPrinter.cpp
index 6eee86a..9978b1e 100644
--- a/lib/LD/DiagnosticPrinter.cpp
+++ b/lib/LD/DiagnosticPrinter.cpp
@@ -6,27 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticPrinter.h>
+#include "mcld/LD/DiagnosticPrinter.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// DiagnosticPrinter
//===----------------------------------------------------------------------===//
-DiagnosticPrinter::DiagnosticPrinter()
- : m_NumErrors(0), m_NumWarnings(0) {
+DiagnosticPrinter::DiagnosticPrinter() : m_NumErrors(0), m_NumWarnings(0) {
}
-DiagnosticPrinter::~DiagnosticPrinter()
-{
+DiagnosticPrinter::~DiagnosticPrinter() {
clear();
}
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
void DiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
- const Diagnostic& pInfo)
-{
+ const Diagnostic& pInfo) {
if (pSeverity == DiagnosticEngine::Warning)
++m_NumWarnings;
@@ -34,3 +31,4 @@
++m_NumErrors;
}
+} // namespace mcld
diff --git a/lib/LD/DynObjReader.cpp b/lib/LD/DynObjReader.cpp
index 552e893..a040cf1 100644
--- a/lib/LD/DynObjReader.cpp
+++ b/lib/LD/DynObjReader.cpp
@@ -7,10 +7,13 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/LD/DynObjReader.h"
-#include "mcld/Target/TargetLDBackend.h"
-#include "mcld/MC/Input.h"
-using namespace mcld;
+#include "mcld/MC/Input.h"
+#include "mcld/Target/TargetLDBackend.h"
+
+namespace mcld {
//==========================
// ObjectReader
+
+} // namespace mcld
diff --git a/lib/LD/ELFBinaryReader.cpp b/lib/LD/ELFBinaryReader.cpp
index c72fa58..5b53d3a 100644
--- a/lib/LD/ELFBinaryReader.cpp
+++ b/lib/LD/ELFBinaryReader.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFBinaryReader.h>
+#include "mcld/LD/ELFBinaryReader.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/Support/ELF.h>
#include <cctype>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFBinaryReader
@@ -25,37 +25,30 @@
/// constructor
ELFBinaryReader::ELFBinaryReader(IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : m_Builder(pBuilder), m_Config(pConfig) {
+ : m_Builder(pBuilder), m_Config(pConfig) {
}
/// destructor
-ELFBinaryReader::~ELFBinaryReader()
-{
+ELFBinaryReader::~ELFBinaryReader() {
}
-bool ELFBinaryReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool ELFBinaryReader::isMyFormat(Input& pInput, bool& pContinue) const {
pContinue = true;
return m_Config.options().isBinaryInput();
}
-bool ELFBinaryReader::readBinary(Input& pInput)
-{
+bool ELFBinaryReader::readBinary(Input& pInput) {
// section: NULL
- m_Builder.CreateELFHeader(pInput,
- "",
- LDFileFormat::Null,
- llvm::ELF::SHT_NULL,
- 0x0);
+ m_Builder.CreateELFHeader(
+ pInput, "", LDFileFormat::Null, llvm::ELF::SHT_NULL, 0x0);
// section: .data
LDSection* data_sect =
- m_Builder.CreateELFHeader(pInput,
- ".data",
- LDFileFormat::DATA,
- llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC,
- 0x1);
-
+ m_Builder.CreateELFHeader(pInput,
+ ".data",
+ LDFileFormat::DATA,
+ llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC,
+ 0x1);
SectionData* data = m_Builder.CreateSectionData(*data_sect);
size_t data_size = pInput.memArea()->size();
@@ -63,11 +56,8 @@
m_Builder.AppendFragment(*frag, *data);
// section: .shstrtab
- m_Builder.CreateELFHeader(pInput,
- ".shstrtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x1);
+ m_Builder.CreateELFHeader(
+ pInput, ".shstrtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x1);
// section: .symtab
m_Builder.CreateELFHeader(pInput,
@@ -89,8 +79,9 @@
// Note: in Win32, the filename is wstring. Is it correct to convert
// filename to std::string?
std::string mangled_name = pInput.path().filename().native();
- for (std::string::iterator it = mangled_name.begin(),
- ie = mangled_name.end(); it != ie; ++it) {
+ for (std::string::iterator it = mangled_name.begin(), ie = mangled_name.end();
+ it != ie;
+ ++it) {
if (isalnum(*it) == 0)
*it = '_';
}
@@ -126,11 +117,10 @@
data_sect);
// section: .strtab
- m_Builder.CreateELFHeader(pInput,
- ".strtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x1);
+ m_Builder.CreateELFHeader(
+ pInput, ".strtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x1);
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFDynObjFileFormat.cpp b/lib/LD/ELFDynObjFileFormat.cpp
index e89f48b..4812091 100644
--- a/lib/LD/ELFDynObjFileFormat.cpp
+++ b/lib/LD/ELFDynObjFileFormat.cpp
@@ -6,86 +6,89 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFDynObjFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LD/ELFDynObjFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
void ELFDynObjFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
- unsigned int pBitClass)
-{
- f_pDynSymTab = pBuilder.CreateSection(".dynsym",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNSYM,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynStrTab = pBuilder.CreateSection(".dynstr",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pInterp = pBuilder.CreateSection(".interp",
- LDFileFormat::Note,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pHashTab = pBuilder.CreateSection(".hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynamic = pBuilder.CreateSection(".dynamic",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNAMIC,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelPlt = pBuilder.CreateSection(".rel.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pGOT = pBuilder.CreateSection(".got",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pPLT = pBuilder.CreateSection(".plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- pBitClass / 8);
- f_pGOTPLT = pBuilder.CreateSection(".got.plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
- LDFileFormat::EhFrameHdr,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_GNU_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
+ unsigned int pBitClass) {
+ f_pDynSymTab = pBuilder.CreateSection(".dynsym",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNSYM,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynStrTab = pBuilder.CreateSection(".dynstr",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_STRTAB,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pInterp = pBuilder.CreateSection(".interp",
+ LDFileFormat::Note,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pHashTab = pBuilder.CreateSection(".hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynamic =
+ pBuilder.CreateSection(".dynamic",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNAMIC,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelPlt = pBuilder.CreateSection(".rel.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pGOT = pBuilder.CreateSection(".got",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pPLT =
+ pBuilder.CreateSection(".plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ pBitClass / 8);
+ f_pGOTPLT =
+ pBuilder.CreateSection(".got.plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
+ LDFileFormat::EhFrameHdr,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_GNU_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
}
+} // namespace mcld
diff --git a/lib/LD/ELFDynObjReader.cpp b/lib/LD/ELFDynObjReader.cpp
index 94eef58..f18d6c6 100644
--- a/lib/LD/ELFDynObjReader.cpp
+++ b/lib/LD/ELFDynObjReader.cpp
@@ -6,14 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFDynObjReader.h>
+#include "mcld/LD/ELFDynObjReader.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
@@ -21,7 +22,7 @@
#include <string>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFDynObjReader
@@ -29,23 +30,19 @@
ELFDynObjReader::ELFDynObjReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : DynObjReader(),
- m_pELFReader(0),
- m_Builder(pBuilder) {
+ : DynObjReader(), m_pELFReader(0), m_Builder(pBuilder) {
if (pConfig.targets().is32Bits() && pConfig.targets().isLittleEndian())
m_pELFReader = new ELFReader<32, true>(pBackend);
else if (pConfig.targets().is64Bits() && pConfig.targets().isLittleEndian())
m_pELFReader = new ELFReader<64, true>(pBackend);
}
-ELFDynObjReader::~ELFDynObjReader()
-{
+ELFDynObjReader::~ELFDynObjReader() {
delete m_pELFReader;
}
/// isMyFormat
-bool ELFDynObjReader::isMyFormat(Input &pInput, bool &pContinue) const
-{
+bool ELFDynObjReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
// Don't warning about the frequently requests.
@@ -54,8 +51,8 @@
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = true;
@@ -76,13 +73,12 @@
}
/// readHeader
-bool ELFDynObjReader::readHeader(Input& pInput)
-{
+bool ELFDynObjReader::readHeader(Input& pInput) {
assert(pInput.hasMemArea());
size_t hdr_size = m_pELFReader->getELFHeaderSize();
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool shdr_result = m_pELFReader->readSectionHeaders(pInput, ELF_hdr);
@@ -94,22 +90,19 @@
}
/// readSymbols
-bool ELFDynObjReader::readSymbols(Input& pInput)
-{
+bool ELFDynObjReader::readSymbols(Input& pInput) {
assert(pInput.hasMemArea());
LDSection* symtab_shdr = pInput.context()->getSection(".dynsym");
- if (NULL == symtab_shdr) {
- note(diag::note_has_no_symtab) << pInput.name()
- << pInput.path()
+ if (symtab_shdr == NULL) {
+ note(diag::note_has_no_symtab) << pInput.name() << pInput.path()
<< ".dynsym";
return true;
}
LDSection* strtab_shdr = symtab_shdr->getLink();
- if (NULL == strtab_shdr) {
- fatal(diag::fatal_cannot_read_strtab) << pInput.name()
- << pInput.path()
+ if (strtab_shdr == NULL) {
+ fatal(diag::fatal_cannot_read_strtab) << pInput.name() << pInput.path()
<< ".dynsym";
return false;
}
@@ -120,8 +113,9 @@
llvm::StringRef strtab_region = pInput.memArea()->request(
pInput.fileOffset() + strtab_shdr->offset(), strtab_shdr->size());
const char* strtab = strtab_region.begin();
- bool result = m_pELFReader->readSymbols(pInput, m_Builder,
- symtab_region, strtab);
+ bool result =
+ m_pELFReader->readSymbols(pInput, m_Builder, symtab_region, strtab);
return result;
}
+} // namespace mcld
diff --git a/lib/LD/ELFExecFileFormat.cpp b/lib/LD/ELFExecFileFormat.cpp
index 6a81f72..3e94295 100644
--- a/lib/LD/ELFExecFileFormat.cpp
+++ b/lib/LD/ELFExecFileFormat.cpp
@@ -6,86 +6,90 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFExecFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LD/ELFExecFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
void ELFExecFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
- unsigned int pBitClass)
-{
+ unsigned int pBitClass) {
// FIXME: make sure ELF executable files has these sections.
- f_pDynSymTab = pBuilder.CreateSection(".dynsym",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNSYM,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynStrTab = pBuilder.CreateSection(".dynstr",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pInterp = pBuilder.CreateSection(".interp",
- LDFileFormat::Note,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pHashTab = pBuilder.CreateSection(".hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynamic = pBuilder.CreateSection(".dynamic",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNAMIC,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelPlt = pBuilder.CreateSection(".rel.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pGOT = pBuilder.CreateSection(".got",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pPLT = pBuilder.CreateSection(".plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- pBitClass / 8);
- f_pGOTPLT = pBuilder.CreateSection(".got.plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
- LDFileFormat::EhFrameHdr,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_GNU_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
+ f_pDynSymTab = pBuilder.CreateSection(".dynsym",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNSYM,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynStrTab = pBuilder.CreateSection(".dynstr",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_STRTAB,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pInterp = pBuilder.CreateSection(".interp",
+ LDFileFormat::Note,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pHashTab = pBuilder.CreateSection(".hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynamic =
+ pBuilder.CreateSection(".dynamic",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNAMIC,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelPlt = pBuilder.CreateSection(".rel.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pGOT = pBuilder.CreateSection(".got",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pPLT =
+ pBuilder.CreateSection(".plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ pBitClass / 8);
+ f_pGOTPLT =
+ pBuilder.CreateSection(".got.plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
+ LDFileFormat::EhFrameHdr,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_GNU_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFFileFormat.cpp b/lib/LD/ELFFileFormat.cpp
index 318e595..0a8d2c8 100644
--- a/lib/LD/ELFFileFormat.cpp
+++ b/lib/LD/ELFFileFormat.cpp
@@ -6,247 +6,232 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
ELFFileFormat::ELFFileFormat()
- : f_pNULLSection(NULL),
- f_pGOT(NULL),
- f_pPLT(NULL),
- f_pRelDyn(NULL),
- f_pRelPlt(NULL),
- f_pRelaDyn(NULL),
- f_pRelaPlt(NULL),
- f_pComment(NULL),
- f_pData1(NULL),
- f_pDebug(NULL),
- f_pDynamic(NULL),
- f_pDynStrTab(NULL),
- f_pDynSymTab(NULL),
- f_pFini(NULL),
- f_pFiniArray(NULL),
- f_pHashTab(NULL),
- f_pInit(NULL),
- f_pInitArray(NULL),
- f_pInterp(NULL),
- f_pLine(NULL),
- f_pNote(NULL),
- f_pPreInitArray(NULL),
- f_pROData1(NULL),
- f_pShStrTab(NULL),
- f_pStrTab(NULL),
- f_pSymTab(NULL),
- f_pTBSS(NULL),
- f_pTData(NULL),
- f_pCtors(NULL),
- f_pDataRelRo(NULL),
- f_pDtors(NULL),
- f_pEhFrame(NULL),
- f_pEhFrameHdr(NULL),
- f_pGCCExceptTable(NULL),
- f_pGNUVersion(NULL),
- f_pGNUVersionD(NULL),
- f_pGNUVersionR(NULL),
- f_pGOTPLT(NULL),
- f_pJCR(NULL),
- f_pNoteABITag(NULL),
- f_pStab(NULL),
- f_pStabStr(NULL),
- f_pStack(NULL),
- f_pStackNote(NULL),
- f_pDataRelRoLocal(NULL),
- f_pGNUHashTab(NULL) {
-
+ : f_pNULLSection(NULL),
+ f_pGOT(NULL),
+ f_pPLT(NULL),
+ f_pRelDyn(NULL),
+ f_pRelPlt(NULL),
+ f_pRelaDyn(NULL),
+ f_pRelaPlt(NULL),
+ f_pComment(NULL),
+ f_pData1(NULL),
+ f_pDebug(NULL),
+ f_pDynamic(NULL),
+ f_pDynStrTab(NULL),
+ f_pDynSymTab(NULL),
+ f_pFini(NULL),
+ f_pFiniArray(NULL),
+ f_pHashTab(NULL),
+ f_pInit(NULL),
+ f_pInitArray(NULL),
+ f_pInterp(NULL),
+ f_pLine(NULL),
+ f_pNote(NULL),
+ f_pPreInitArray(NULL),
+ f_pROData1(NULL),
+ f_pShStrTab(NULL),
+ f_pStrTab(NULL),
+ f_pSymTab(NULL),
+ f_pTBSS(NULL),
+ f_pTData(NULL),
+ f_pCtors(NULL),
+ f_pDataRelRo(NULL),
+ f_pDtors(NULL),
+ f_pEhFrame(NULL),
+ f_pEhFrameHdr(NULL),
+ f_pGCCExceptTable(NULL),
+ f_pGNUVersion(NULL),
+ f_pGNUVersionD(NULL),
+ f_pGNUVersionR(NULL),
+ f_pGOTPLT(NULL),
+ f_pJCR(NULL),
+ f_pNoteABITag(NULL),
+ f_pStab(NULL),
+ f_pStabStr(NULL),
+ f_pStack(NULL),
+ f_pStackNote(NULL),
+ f_pDataRelRoLocal(NULL),
+ f_pGNUHashTab(NULL) {
}
-void ELFFileFormat::initStdSections(ObjectBuilder& pBuilder, unsigned int pBitClass)
-{
- f_pTextSection = pBuilder.CreateSection(".text",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pNULLSection = pBuilder.CreateSection("",
- LDFileFormat::Null,
- llvm::ELF::SHT_NULL,
- 0x0);
+void ELFFileFormat::initStdSections(ObjectBuilder& pBuilder,
+ unsigned int pBitClass) {
+ f_pTextSection =
+ pBuilder.CreateSection(".text",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pNULLSection =
+ pBuilder.CreateSection("", LDFileFormat::Null, llvm::ELF::SHT_NULL, 0x0);
f_pReadOnlySection = pBuilder.CreateSection(".rodata",
LDFileFormat::TEXT,
llvm::ELF::SHT_PROGBITS,
llvm::ELF::SHF_ALLOC,
0x1);
- f_pBSSSection = pBuilder.CreateSection(".bss",
- LDFileFormat::BSS,
- llvm::ELF::SHT_NOBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pComment = pBuilder.CreateSection(".comment",
- LDFileFormat::MetaData,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pDataSection = pBuilder.CreateSection(".data",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pData1 = pBuilder.CreateSection(".data1",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDebug = pBuilder.CreateSection(".debug",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pInit = pBuilder.CreateSection(".init",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pInitArray = pBuilder.CreateSection(".init_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_INIT_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pFini = pBuilder.CreateSection(".fini",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pFiniArray = pBuilder.CreateSection(".fini_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_FINI_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pLine = pBuilder.CreateSection(".line",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pPreInitArray = pBuilder.CreateSection(".preinit_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PREINIT_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
+ f_pBSSSection =
+ pBuilder.CreateSection(".bss",
+ LDFileFormat::BSS,
+ llvm::ELF::SHT_NOBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pComment = pBuilder.CreateSection(
+ ".comment", LDFileFormat::MetaData, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pDataSection =
+ pBuilder.CreateSection(".data",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pData1 = pBuilder.CreateSection(".data1",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDebug = pBuilder.CreateSection(
+ ".debug", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pInit =
+ pBuilder.CreateSection(".init",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pInitArray =
+ pBuilder.CreateSection(".init_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_INIT_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pFini =
+ pBuilder.CreateSection(".fini",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pFiniArray =
+ pBuilder.CreateSection(".fini_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_FINI_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pLine = pBuilder.CreateSection(
+ ".line", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pPreInitArray =
+ pBuilder.CreateSection(".preinit_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PREINIT_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
// the definition of SHF_XXX attributes of rodata in Linux Standard Base
// conflicts with System V standard. We follow System V standard.
- f_pROData1 = pBuilder.CreateSection(".rodata1",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pShStrTab = pBuilder.CreateSection(".shstrtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
+ f_pROData1 = pBuilder.CreateSection(".rodata1",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pShStrTab = pBuilder.CreateSection(
+ ".shstrtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
// In ELF Spec Book I, p1-16. If symbol table and string table are in
// loadable segments, set the attribute to SHF_ALLOC bit. But in the
// real world, this bit always turn off.
- f_pSymTab = pBuilder.CreateSection(".symtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_SYMTAB,
- 0x0,
- pBitClass / 8);
+ f_pSymTab = pBuilder.CreateSection(".symtab",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_SYMTAB,
+ 0x0,
+ pBitClass / 8);
- f_pStrTab = pBuilder.CreateSection(".strtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
- f_pTBSS = pBuilder.CreateSection(".tbss",
- LDFileFormat::BSS,
- llvm::ELF::SHT_NOBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_TLS,
- 0x1);
- f_pTData = pBuilder.CreateSection(".tdata",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_TLS,
- 0x1);
+ f_pStrTab = pBuilder.CreateSection(
+ ".strtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
+ f_pTBSS = pBuilder.CreateSection(
+ ".tbss",
+ LDFileFormat::BSS,
+ llvm::ELF::SHT_NOBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE | llvm::ELF::SHF_TLS,
+ 0x1);
+ f_pTData = pBuilder.CreateSection(
+ ".tdata",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE | llvm::ELF::SHF_TLS,
+ 0x1);
/// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24.
- f_pCtors = pBuilder.CreateSection(".ctors",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDataRelRo = pBuilder.CreateSection(".data.rel.ro",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDtors = pBuilder.CreateSection(".dtors",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pEhFrame = pBuilder.CreateSection(".eh_frame",
- LDFileFormat::EhFrame,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGCCExceptTable = pBuilder.CreateSection(".gcc_except_table",
- LDFileFormat::GCCExceptTable,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUVersion = pBuilder.CreateSection(".gnu.version",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_versym,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pGNUVersionD = pBuilder.CreateSection(".gnu.version_d",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_verdef,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pGNUVersionR = pBuilder.CreateSection(".gnu.version_r",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_verneed,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pJCR = pBuilder.CreateSection(".jcr",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pStab = pBuilder.CreateSection(".stab",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pStabStr = pBuilder.CreateSection(".stabstr",
- LDFileFormat::Debug,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
- f_pStackNote = pBuilder.CreateSection(".note.GNU-stack",
- LDFileFormat::StackNote,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
+ f_pCtors = pBuilder.CreateSection(".ctors",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDataRelRo =
+ pBuilder.CreateSection(".data.rel.ro",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDtors = pBuilder.CreateSection(".dtors",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pEhFrame = pBuilder.CreateSection(".eh_frame",
+ LDFileFormat::EhFrame,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGCCExceptTable = pBuilder.CreateSection(".gcc_except_table",
+ LDFileFormat::GCCExceptTable,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUVersion = pBuilder.CreateSection(".gnu.version",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_versym,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pGNUVersionD = pBuilder.CreateSection(".gnu.version_d",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_verdef,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pGNUVersionR = pBuilder.CreateSection(".gnu.version_r",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_verneed,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pJCR = pBuilder.CreateSection(".jcr",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pStab = pBuilder.CreateSection(
+ ".stab", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pStabStr = pBuilder.CreateSection(
+ ".stabstr", LDFileFormat::Debug, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
+ f_pStackNote = pBuilder.CreateSection(".note.GNU-stack",
+ LDFileFormat::StackNote,
+ llvm::ELF::SHT_PROGBITS,
+ 0x0,
+ 0x1);
/// @ref GCC convention, see http://www.airs.com/blog/archives/189
- f_pDataRelRoLocal = pBuilder.CreateSection(".data.rel.ro.local",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
+ f_pDataRelRoLocal =
+ pBuilder.CreateSection(".data.rel.ro.local",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
/// Initialize format dependent sections. (sections for executable and shared
/// objects)
initObjectFormat(pBuilder, pBitClass);
}
+} // namespace mcld
diff --git a/lib/LD/ELFObjectReader.cpp b/lib/LD/ELFObjectReader.cpp
index a0ece0f..aeefd37 100644
--- a/lib/LD/ELFObjectReader.cpp
+++ b/lib/LD/ELFObjectReader.cpp
@@ -6,17 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFObjectReader.h>
+#include "mcld/LD/ELFObjectReader.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/LD/EhFrameReader.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/EhFrameReader.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
#include <llvm/ADT/Twine.h>
@@ -25,7 +26,7 @@
#include <string>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFObjectReader
@@ -34,17 +35,17 @@
ELFObjectReader::ELFObjectReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : ObjectReader(),
- m_pELFReader(NULL),
- m_pEhFrameReader(NULL),
- m_Builder(pBuilder),
- m_ReadFlag(ParseEhFrame),
- m_Backend(pBackend),
- m_Config(pConfig) {
+ : ObjectReader(),
+ m_pELFReader(NULL),
+ m_pEhFrameReader(NULL),
+ m_Builder(pBuilder),
+ m_ReadFlag(ParseEhFrame),
+ m_Backend(pBackend),
+ m_Config(pConfig) {
if (pConfig.targets().is32Bits() && pConfig.targets().isLittleEndian()) {
m_pELFReader = new ELFReader<32, true>(pBackend);
- }
- else if (pConfig.targets().is64Bits() && pConfig.targets().isLittleEndian()) {
+ } else if (pConfig.targets().is64Bits() &&
+ pConfig.targets().isLittleEndian()) {
m_pELFReader = new ELFReader<64, true>(pBackend);
}
@@ -52,15 +53,13 @@
}
/// destructor
-ELFObjectReader::~ELFObjectReader()
-{
+ELFObjectReader::~ELFObjectReader() {
delete m_pELFReader;
delete m_pEhFrameReader;
}
/// isMyFormat
-bool ELFObjectReader::isMyFormat(Input &pInput, bool &pContinue) const
-{
+bool ELFObjectReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
// Don't warning about the frequently requests.
@@ -69,8 +68,8 @@
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = true;
@@ -91,42 +90,38 @@
}
/// readHeader - read section header and create LDSections.
-bool ELFObjectReader::readHeader(Input& pInput)
-{
+bool ELFObjectReader::readHeader(Input& pInput) {
assert(pInput.hasMemArea());
size_t hdr_size = m_pELFReader->getELFHeaderSize();
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = m_pELFReader->readSectionHeaders(pInput, ELF_hdr);
return result;
}
/// readSections - read all regular sections.
-bool ELFObjectReader::readSections(Input& pInput)
-{
+bool ELFObjectReader::readSections(Input& pInput) {
// handle sections
LDContext::sect_iterator section, sectEnd = pInput.context()->sectEnd();
for (section = pInput.context()->sectBegin(); section != sectEnd; ++section) {
// ignore the section if the LDSection* in input context is NULL
- if (NULL == *section)
- continue;
+ if (*section == NULL)
+ continue;
- switch((*section)->kind()) {
+ switch ((*section)->kind()) {
/** group sections **/
case LDFileFormat::Group: {
- assert(NULL != (*section)->getLink());
- ResolveInfo* signature =
- m_pELFReader->readSignature(pInput,
- *(*section)->getLink(),
- (*section)->getInfo());
+ assert((*section)->getLink() != NULL);
+ ResolveInfo* signature = m_pELFReader->readSignature(
+ pInput, *(*section)->getLink(), (*section)->getInfo());
bool exist = false;
- if (0 == signature->nameSize() &&
+ if (signature->nameSize() == 0 &&
ResolveInfo::Section == signature->type()) {
// if the signature is a section symbol in input object, we use the
// section name as group signature.
@@ -139,14 +134,15 @@
// if this is not the first time we see this group signature, then
// ignore all the members in this group (set Ignore)
llvm::StringRef region = pInput.memArea()->request(
- pInput.fileOffset() + (*section)->offset(), (*section)->size());
+ pInput.fileOffset() + (*section)->offset(), (*section)->size());
const llvm::ELF::Elf32_Word* value =
reinterpret_cast<const llvm::ELF::Elf32_Word*>(region.begin());
size_t size = region.size() / sizeof(llvm::ELF::Elf32_Word);
if (llvm::ELF::GRP_COMDAT == *value) {
for (size_t index = 1; index < size; ++index) {
- pInput.context()->getSection(value[index])->setKind(LDFileFormat::Ignore);
+ pInput.context()->getSection(value[index])->setKind(
+ LDFileFormat::Ignore);
}
}
}
@@ -157,7 +153,8 @@
case LDFileFormat::LinkOnce: {
bool exist = false;
// .gnu.linkonce + "." + type + "." + name
- llvm::StringRef name(llvm::StringRef((*section)->name()).drop_front(14));
+ llvm::StringRef name(
+ llvm::StringRef((*section)->name()).drop_front(14));
signatures().insert(name.split(".").second, exist);
if (!exist) {
if (name.startswith("wi")) {
@@ -185,10 +182,10 @@
}
/** relocation sections **/
case LDFileFormat::Relocation: {
- assert(NULL != (*section)->getLink());
+ assert((*section)->getLink() != NULL);
size_t link_index = (*section)->getLink()->index();
LDSection* link_sect = pInput.context()->getSection(link_index);
- if (NULL == link_sect || LDFileFormat::Ignore == link_sect->kind()) {
+ if (link_sect == NULL || link_sect->kind() == LDFileFormat::Ignore) {
// Relocation sections of group members should also be part of the
// group. Thus, if the associated member sections are ignored, the
// related relocations should be also ignored.
@@ -211,11 +208,11 @@
fatal(diag::err_cannot_read_section) << (*section)->name();
break;
}
- case LDFileFormat::Debug: {
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString: {
if (m_Config.options().stripDebug()) {
(*section)->setKind(LDFileFormat::Ignore);
- }
- else {
+ } else {
SectionData* sd = IRBuilder::CreateSectionData(**section);
if (!m_pELFReader->readRegularSection(pInput, *sd)) {
fatal(diag::err_cannot_read_section) << (*section)->name();
@@ -234,8 +231,7 @@
// .eh_frame.
m_ReadFlag ^= ParseEhFrame;
}
- }
- else {
+ } else {
if (!m_pELFReader->readRegularSection(pInput,
*eh_frame->getSectionData())) {
fatal(diag::err_cannot_read_section) << (*section)->name();
@@ -265,34 +261,30 @@
// warning
case LDFileFormat::EhFrameHdr:
default: {
- warning(diag::warn_illegal_input_section) << (*section)->name()
- << pInput.name()
- << pInput.path();
+ warning(diag::warn_illegal_input_section)
+ << (*section)->name() << pInput.name() << pInput.path();
break;
}
}
- } // end of for all sections
+ } // end of for all sections
return true;
}
/// readSymbols - read symbols from the input relocatable object.
-bool ELFObjectReader::readSymbols(Input& pInput)
-{
+bool ELFObjectReader::readSymbols(Input& pInput) {
assert(pInput.hasMemArea());
LDSection* symtab_shdr = pInput.context()->getSection(".symtab");
- if (NULL == symtab_shdr) {
- note(diag::note_has_no_symtab) << pInput.name()
- << pInput.path()
+ if (symtab_shdr == NULL) {
+ note(diag::note_has_no_symtab) << pInput.name() << pInput.path()
<< ".symtab";
return true;
}
LDSection* strtab_shdr = symtab_shdr->getLink();
- if (NULL == strtab_shdr) {
- fatal(diag::fatal_cannot_read_strtab) << pInput.name()
- << pInput.path()
+ if (strtab_shdr == NULL) {
+ fatal(diag::fatal_cannot_read_strtab) << pInput.name() << pInput.path()
<< ".symtab";
return false;
}
@@ -302,15 +294,12 @@
llvm::StringRef strtab_region = pInput.memArea()->request(
pInput.fileOffset() + strtab_shdr->offset(), strtab_shdr->size());
const char* strtab = strtab_region.begin();
- bool result = m_pELFReader->readSymbols(pInput,
- m_Builder,
- symtab_region,
- strtab);
+ bool result =
+ m_pELFReader->readSymbols(pInput, m_Builder, symtab_region, strtab);
return result;
}
-bool ELFObjectReader::readRelocations(Input& pInput)
-{
+bool ELFObjectReader::readRelocations(Input& pInput) {
assert(pInput.hasMemArea());
MemoryArea* mem = pInput.memArea();
@@ -322,7 +311,8 @@
uint32_t offset = pInput.fileOffset() + (*rs)->offset();
uint32_t size = (*rs)->size();
llvm::StringRef region = mem->request(offset, size);
- IRBuilder::CreateRelocData(**rs); ///< create relocation data for the header
+ IRBuilder::CreateRelocData(
+ **rs); ///< create relocation data for the header
switch ((*rs)->type()) {
case llvm::ELF::SHT_RELA: {
if (!m_pELFReader->readRela(pInput, **rs, region)) {
@@ -336,13 +326,13 @@
}
break;
}
- default: { ///< should not enter
+ default: { ///< should not enter
return false;
}
- } // end of switch
-
- } // end of for all relocation data
+ } // end of switch
+ } // end of for all relocation data
return true;
}
+} // namespace mcld
diff --git a/lib/LD/ELFObjectWriter.cpp b/lib/LD/ELFObjectWriter.cpp
index c90efdf..4d11132 100644
--- a/lib/LD/ELFObjectWriter.cpp
+++ b/lib/LD/ELFObjectWriter.cpp
@@ -6,121 +6,118 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFObjectWriter.h>
+#include "mcld/LD/ELFObjectWriter.h"
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Target/GNUInfo.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Target/GNULDBackend.h"
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
#include <llvm/Support/Errc.h>
#include <llvm/Support/ErrorHandling.h>
-#include <llvm/Support/ELF.h>
-#include <llvm/Support/Casting.h>
-using namespace llvm;
-using namespace llvm::ELF;
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFObjectWriter
//===----------------------------------------------------------------------===//
ELFObjectWriter::ELFObjectWriter(GNULDBackend& pBackend,
const LinkerConfig& pConfig)
- : ObjectWriter(), m_Backend(pBackend), m_Config(pConfig)
-{
+ : ObjectWriter(), m_Backend(pBackend), m_Config(pConfig) {
}
-ELFObjectWriter::~ELFObjectWriter()
-{
+ELFObjectWriter::~ELFObjectWriter() {
}
void ELFObjectWriter::writeSection(Module& pModule,
- FileOutputBuffer& pOutput, LDSection *section)
-{
+ FileOutputBuffer& pOutput,
+ LDSection* section) {
MemoryRegion region;
// Request output region
switch (section->kind()) {
- case LDFileFormat::Note:
- if (section->getSectionData() == NULL)
- return;
+ case LDFileFormat::Note:
+ if (section->getSectionData() == NULL)
+ return;
// Fall through
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Relocation:
- case LDFileFormat::Target:
- case LDFileFormat::Debug:
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::EhFrame: {
- region = pOutput.request(section->offset(), section->size());
- if (region.size() == 0) {
- return;
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Relocation:
+ case LDFileFormat::Target:
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::EhFrame: {
+ region = pOutput.request(section->offset(), section->size());
+ if (region.size() == 0) {
+ return;
+ }
+ break;
}
- break;
- }
- case LDFileFormat::Null:
- case LDFileFormat::NamePool:
- case LDFileFormat::BSS:
- case LDFileFormat::MetaData:
- case LDFileFormat::Version:
- case LDFileFormat::EhFrameHdr:
- case LDFileFormat::StackNote:
- // Ignore these sections
- return;
- default:
- llvm::errs() << "WARNING: unsupported section kind: "
- << section->kind()
- << " of section "
- << section->name()
- << ".\n";
- return;
+ case LDFileFormat::Null:
+ case LDFileFormat::NamePool:
+ case LDFileFormat::BSS:
+ case LDFileFormat::MetaData:
+ case LDFileFormat::Version:
+ case LDFileFormat::EhFrameHdr:
+ case LDFileFormat::StackNote:
+ // Ignore these sections
+ return;
+ default:
+ llvm::errs() << "WARNING: unsupported section kind: " << section->kind()
+ << " of section " << section->name() << ".\n";
+ return;
}
// Write out sections with data
- switch(section->kind()) {
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Debug:
- case LDFileFormat::Note:
- emitSectionData(*section, region);
- break;
- case LDFileFormat::EhFrame:
- emitEhFrame(pModule, *section->getEhFrame(), region);
- break;
- case LDFileFormat::Relocation:
- // sort relocation for the benefit of the dynamic linker.
- target().sortRelocation(*section);
+ switch (section->kind()) {
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Debug:
+ case LDFileFormat::Note:
+ emitSectionData(*section, region);
+ break;
+ case LDFileFormat::EhFrame:
+ emitEhFrame(pModule, *section->getEhFrame(), region);
+ break;
+ case LDFileFormat::Relocation:
+ // sort relocation for the benefit of the dynamic linker.
+ target().sortRelocation(*section);
- emitRelocation(m_Config, *section, region);
- break;
- case LDFileFormat::Target:
- target().emitSectionData(*section, region);
- break;
- default:
- llvm_unreachable("invalid section kind");
+ emitRelocation(m_Config, *section, region);
+ break;
+ case LDFileFormat::Target:
+ target().emitSectionData(*section, region);
+ break;
+ case LDFileFormat::DebugString:
+ section->getDebugString()->emit(region);
+ break;
+ default:
+ llvm_unreachable("invalid section kind");
}
}
std::error_code ELFObjectWriter::writeObject(Module& pModule,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
bool is_dynobj = m_Config.codeGenType() == LinkerConfig::DynObj;
bool is_exec = m_Config.codeGenType() == LinkerConfig::Exec;
bool is_binary = m_Config.codeGenType() == LinkerConfig::Binary;
@@ -171,8 +168,7 @@
emitProgramHeader<32>(pOutput);
emitSectionHeader<32>(pModule, m_Config, pOutput);
- }
- else if (m_Config.targets().is64Bits()) {
+ } else if (m_Config.targets().is64Bits()) {
// Write out ELF header
// Write out section header table
writeELFHeader<64>(m_Config, pModule, pOutput);
@@ -180,17 +176,16 @@
emitProgramHeader<64>(pOutput);
emitSectionHeader<64>(pModule, m_Config, pOutput);
- }
- else
+ } else {
return llvm::make_error_code(llvm::errc::function_not_supported);
+ }
}
return std::error_code();
}
// getOutputSize - count the final output size
-size_t ELFObjectWriter::getOutputSize(const Module& pModule) const
-{
+size_t ELFObjectWriter::getOutputSize(const Module& pModule) const {
if (m_Config.targets().is32Bits()) {
return getLastStartOffset<32>(pModule) +
sizeof(ELFSizeTraits<32>::Shdr) * pModule.size();
@@ -204,66 +199,67 @@
}
// writeELFHeader - emit ElfXX_Ehdr
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::writeELFHeader(const LinkerConfig& pConfig,
const Module& pModule,
- FileOutputBuffer& pOutput) const
-{
+ FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;
typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;
// ELF header must start from 0x0
MemoryRegion region = pOutput.request(0, sizeof(ElfXX_Ehdr));
- ElfXX_Ehdr* header = (ElfXX_Ehdr*)region.begin();
+ ElfXX_Ehdr* header = reinterpret_cast<ElfXX_Ehdr*>(region.begin());
- memcpy(header->e_ident, ElfMagic, EI_MAG3+1);
+ memcpy(header->e_ident, llvm::ELF::ElfMagic, llvm::ELF::EI_MAG3 + 1);
- header->e_ident[EI_CLASS] = (SIZE == 32) ? ELFCLASS32 : ELFCLASS64;
- header->e_ident[EI_DATA] = pConfig.targets().isLittleEndian()?
- ELFDATA2LSB : ELFDATA2MSB;
- header->e_ident[EI_VERSION] = target().getInfo().ELFVersion();
- header->e_ident[EI_OSABI] = target().getInfo().OSABI();
- header->e_ident[EI_ABIVERSION] = target().getInfo().ABIVersion();
+ header->e_ident[llvm::ELF::EI_CLASS] =
+ (SIZE == 32) ? llvm::ELF::ELFCLASS32 : llvm::ELF::ELFCLASS64;
+ header->e_ident[llvm::ELF::EI_DATA] =
+ pConfig.targets().isLittleEndian()
+ ? llvm::ELF::ELFDATA2LSB : llvm::ELF::ELFDATA2MSB;
+ header->e_ident[llvm::ELF::EI_VERSION] = target().getInfo().ELFVersion();
+ header->e_ident[llvm::ELF::EI_OSABI] = target().getInfo().OSABI();
+ header->e_ident[llvm::ELF::EI_ABIVERSION] = target().getInfo().ABIVersion();
// FIXME: add processor-specific and core file types.
- switch(pConfig.codeGenType()) {
+ switch (pConfig.codeGenType()) {
case LinkerConfig::Object:
- header->e_type = ET_REL;
+ header->e_type = llvm::ELF::ET_REL;
break;
case LinkerConfig::DynObj:
- header->e_type = ET_DYN;
+ header->e_type = llvm::ELF::ET_DYN;
break;
case LinkerConfig::Exec:
- header->e_type = ET_EXEC;
+ header->e_type = llvm::ELF::ET_EXEC;
break;
default:
- llvm::errs() << "unspported output file type: " << pConfig.codeGenType() << ".\n";
- header->e_type = ET_NONE;
+ llvm::errs() << "unspported output file type: " << pConfig.codeGenType()
+ << ".\n";
+ header->e_type = llvm::ELF::ET_NONE;
}
- header->e_machine = target().getInfo().machine();
- header->e_version = header->e_ident[EI_VERSION];
- header->e_entry = getEntryPoint(pConfig, pModule);
+ header->e_machine = target().getInfo().machine();
+ header->e_version = header->e_ident[llvm::ELF::EI_VERSION];
+ header->e_entry = getEntryPoint(pConfig, pModule);
if (LinkerConfig::Object != pConfig.codeGenType())
- header->e_phoff = sizeof(ElfXX_Ehdr);
+ header->e_phoff = sizeof(ElfXX_Ehdr);
else
- header->e_phoff = 0x0;
+ header->e_phoff = 0x0;
- header->e_shoff = getLastStartOffset<SIZE>(pModule);
- header->e_flags = target().getInfo().flags();
- header->e_ehsize = sizeof(ElfXX_Ehdr);
+ header->e_shoff = getLastStartOffset<SIZE>(pModule);
+ header->e_flags = target().getInfo().flags();
+ header->e_ehsize = sizeof(ElfXX_Ehdr);
header->e_phentsize = sizeof(ElfXX_Phdr);
- header->e_phnum = target().elfSegmentTable().size();
+ header->e_phnum = target().elfSegmentTable().size();
header->e_shentsize = sizeof(ElfXX_Shdr);
- header->e_shnum = pModule.size();
- header->e_shstrndx = pModule.getSection(".shstrtab")->index();
+ header->e_shnum = pModule.size();
+ header->e_shstrndx = pModule.getSection(".shstrtab")->index();
}
/// getEntryPoint
uint64_t ELFObjectWriter::getEntryPoint(const LinkerConfig& pConfig,
- const Module& pModule) const
-{
+ const Module& pModule) const {
llvm::StringRef entry_name = target().getEntry(pModule);
uint64_t result = 0x0;
@@ -274,24 +270,21 @@
const LDSymbol* entry_symbol = pModule.getNamePool().findSymbol(entry_name);
// found the symbol
- if (NULL != entry_symbol) {
+ if (entry_symbol != NULL) {
if (entry_symbol->desc() != ResolveInfo::Define && issue_warning) {
- llvm::errs() << "WARNING: entry symbol '"
- << entry_symbol->name()
+ llvm::errs() << "WARNING: entry symbol '" << entry_symbol->name()
<< "' exists but is not defined.\n";
}
result = entry_symbol->value();
- }
- // not in the symbol pool
- else {
+ } else {
+ // not in the symbol pool
// We should parse entry as a number.
// @ref GNU ld manual, Options -e. e.g., -e 0x1000.
char* endptr;
result = strtoull(entry_name.data(), &endptr, 0);
if (*endptr != '\0') {
if (issue_warning) {
- llvm::errs() << "cannot find entry symbol '"
- << entry_name.data()
+ llvm::errs() << "cannot find entry symbol '" << entry_name.data()
<< "'.\n";
}
result = 0x0;
@@ -301,35 +294,34 @@
}
// emitSectionHeader - emit ElfXX_Shdr
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitSectionHeader(const Module& pModule,
const LinkerConfig& pConfig,
- FileOutputBuffer& pOutput) const
-{
+ FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;
// emit section header
unsigned int sectNum = pModule.size();
unsigned int header_size = sizeof(ElfXX_Shdr) * sectNum;
- MemoryRegion region = pOutput.request(getLastStartOffset<SIZE>(pModule),
- header_size);
- ElfXX_Shdr* shdr = (ElfXX_Shdr*)region.begin();
+ MemoryRegion region =
+ pOutput.request(getLastStartOffset<SIZE>(pModule), header_size);
+ ElfXX_Shdr* shdr = reinterpret_cast<ElfXX_Shdr*>(region.begin());
// Iterate the SectionTable in LDContext
unsigned int sectIdx = 0;
- unsigned int shstridx = 0; // NULL section has empty name
+ unsigned int shstridx = 0; // NULL section has empty name
for (; sectIdx < sectNum; ++sectIdx) {
- const LDSection *ld_sect = pModule.getSectionTable().at(sectIdx);
- shdr[sectIdx].sh_name = shstridx;
- shdr[sectIdx].sh_type = ld_sect->type();
- shdr[sectIdx].sh_flags = ld_sect->flag();
- shdr[sectIdx].sh_addr = ld_sect->addr();
- shdr[sectIdx].sh_offset = ld_sect->offset();
- shdr[sectIdx].sh_size = ld_sect->size();
+ const LDSection* ld_sect = pModule.getSectionTable().at(sectIdx);
+ shdr[sectIdx].sh_name = shstridx;
+ shdr[sectIdx].sh_type = ld_sect->type();
+ shdr[sectIdx].sh_flags = ld_sect->flag();
+ shdr[sectIdx].sh_addr = ld_sect->addr();
+ shdr[sectIdx].sh_offset = ld_sect->offset();
+ shdr[sectIdx].sh_size = ld_sect->size();
shdr[sectIdx].sh_addralign = ld_sect->align();
- shdr[sectIdx].sh_entsize = getSectEntrySize<SIZE>(*ld_sect);
- shdr[sectIdx].sh_link = getSectLink(*ld_sect, pConfig);
- shdr[sectIdx].sh_info = getSectInfo(*ld_sect);
+ shdr[sectIdx].sh_entsize = getSectEntrySize<SIZE>(*ld_sect);
+ shdr[sectIdx].sh_link = getSectLink(*ld_sect, pConfig);
+ shdr[sectIdx].sh_info = getSectInfo(*ld_sect);
// adjust strshidx
shstridx += ld_sect->name().size() + 1;
@@ -337,9 +329,8 @@
}
// emitProgramHeader - emit ElfXX_Phdr
-template<size_t SIZE>
-void ELFObjectWriter::emitProgramHeader(FileOutputBuffer& pOutput) const
-{
+template <size_t SIZE>
+void ELFObjectWriter::emitProgramHeader(FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;
@@ -348,49 +339,47 @@
start_offset = sizeof(ElfXX_Ehdr);
phdr_size = sizeof(ElfXX_Phdr);
// Program header must start directly after ELF header
- MemoryRegion region = pOutput.request(start_offset,
- target().elfSegmentTable().size() * phdr_size);
+ MemoryRegion region = pOutput.request(
+ start_offset, target().elfSegmentTable().size() * phdr_size);
- ElfXX_Phdr* phdr = (ElfXX_Phdr*)region.begin();
+ ElfXX_Phdr* phdr = reinterpret_cast<ElfXX_Phdr*>(region.begin());
// Iterate the elf segment table in GNULDBackend
size_t index = 0;
ELFSegmentFactory::const_iterator seg = target().elfSegmentTable().begin(),
- segEnd = target().elfSegmentTable().end();
+ segEnd = target().elfSegmentTable().end();
for (; seg != segEnd; ++seg, ++index) {
- phdr[index].p_type = (*seg)->type();
- phdr[index].p_flags = (*seg)->flag();
+ phdr[index].p_type = (*seg)->type();
+ phdr[index].p_flags = (*seg)->flag();
phdr[index].p_offset = (*seg)->offset();
- phdr[index].p_vaddr = (*seg)->vaddr();
- phdr[index].p_paddr = (*seg)->paddr();
+ phdr[index].p_vaddr = (*seg)->vaddr();
+ phdr[index].p_paddr = (*seg)->paddr();
phdr[index].p_filesz = (*seg)->filesz();
- phdr[index].p_memsz = (*seg)->memsz();
- phdr[index].p_align = (*seg)->align();
+ phdr[index].p_memsz = (*seg)->memsz();
+ phdr[index].p_align = (*seg)->align();
}
}
/// emitShStrTab - emit section string table
-void
-ELFObjectWriter::emitShStrTab(const LDSection& pShStrTab,
- const Module& pModule,
- FileOutputBuffer& pOutput)
-{
+void ELFObjectWriter::emitShStrTab(const LDSection& pShStrTab,
+ const Module& pModule,
+ FileOutputBuffer& pOutput) {
// write out data
MemoryRegion region = pOutput.request(pShStrTab.offset(), pShStrTab.size());
- char* data = (char*)region.begin();
+ char* data = reinterpret_cast<char*>(region.begin());
size_t shstrsize = 0;
Module::const_iterator section, sectEnd = pModule.end();
for (section = pModule.begin(); section != sectEnd; ++section) {
- strcpy((char*)(data + shstrsize), (*section)->name().data());
+ ::memcpy(reinterpret_cast<char*>(data + shstrsize),
+ (*section)->name().data(),
+ (*section)->name().size());
shstrsize += (*section)->name().size() + 1;
}
}
/// emitSectionData
-void
-ELFObjectWriter::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+void ELFObjectWriter::emitSectionData(const LDSection& pSection,
+ MemoryRegion& pRegion) const {
const SectionData* sd = NULL;
switch (pSection.kind()) {
case LDFileFormat::Relocation:
@@ -410,21 +399,22 @@
/// emitEhFrame
void ELFObjectWriter::emitEhFrame(Module& pModule,
- EhFrame& pFrame, MemoryRegion& pRegion) const
-{
+ EhFrame& pFrame,
+ MemoryRegion& pRegion) const {
emitSectionData(*pFrame.getSectionData(), pRegion);
// Patch FDE field (offset to CIE)
for (EhFrame::cie_iterator i = pFrame.cie_begin(), e = pFrame.cie_end();
- i != e; ++i) {
+ i != e;
+ ++i) {
EhFrame::CIE& cie = **i;
- for (EhFrame::fde_iterator fi = cie.begin(), fe = cie.end();
- fi != fe; ++fi) {
+ for (EhFrame::fde_iterator fi = cie.begin(), fe = cie.end(); fi != fe;
+ ++fi) {
EhFrame::FDE& fde = **fi;
if (fde.getRecordType() == EhFrame::RECORD_GENERATED) {
// Patch PLT offset
LDSection* plt_sect = pModule.getSection(".plt");
- assert (plt_sect && "We have no plt but have corresponding eh_frame?");
+ assert(plt_sect && "We have no plt but have corresponding eh_frame?");
uint64_t plt_offset = plt_sect->offset();
// FDE entry for PLT is always 32-bit
uint64_t fde_offset = pFrame.getSection().offset() + fde.getOffset() +
@@ -433,34 +423,35 @@
if (plt_offset < fde_offset)
offset = -offset;
memcpy(pRegion.begin() + fde.getOffset() +
- EhFrame::getDataStartOffset<32>(),
- &offset, 4);
+ EhFrame::getDataStartOffset<32>(),
+ &offset,
+ 4);
uint32_t size = plt_sect->size();
memcpy(pRegion.begin() + fde.getOffset() +
- EhFrame::getDataStartOffset<32>() + 4,
- &size, 4);
+ EhFrame::getDataStartOffset<32>() + 4,
+ &size,
+ 4);
}
uint64_t fde_cie_ptr_offset = fde.getOffset() +
EhFrame::getDataStartOffset<32>() -
- /*ID*/4;
+ /*ID*/ 4;
uint64_t cie_start_offset = cie.getOffset();
int32_t offset = fde_cie_ptr_offset - cie_start_offset;
if (fde_cie_ptr_offset < cie_start_offset)
offset = -offset;
memcpy(pRegion.begin() + fde_cie_ptr_offset, &offset, 4);
- } // for loop fde_iterator
- } // for loop cie_iterator
+ } // for loop fde_iterator
+ } // for loop cie_iterator
}
/// emitRelocation
void ELFObjectWriter::emitRelocation(const LinkerConfig& pConfig,
const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
const RelocData* sect_data = pSection.getRelocData();
- assert(NULL != sect_data && "SectionData is NULL in emitRelocation!");
+ assert(sect_data != NULL && "SectionData is NULL in emitRelocation!");
- if (pSection.type() == SHT_REL) {
+ if (pSection.type() == llvm::ELF::SHT_REL) {
if (pConfig.targets().is32Bits())
emitRel<32>(pConfig, *sect_data, pRegion);
else if (pConfig.targets().is64Bits())
@@ -469,7 +460,7 @@
fatal(diag::unsupported_bitclass) << pConfig.targets().triple().str()
<< pConfig.targets().bitclass();
}
- } else if (pSection.type() == SHT_RELA) {
+ } else if (pSection.type() == llvm::ELF::SHT_RELA) {
if (pConfig.targets().is32Bits())
emitRela<32>(pConfig, *sect_data, pRegion);
else if (pConfig.targets().is64Bits())
@@ -482,14 +473,12 @@
llvm::report_fatal_error("unsupported relocation section type!");
}
-
// emitRel - emit ElfXX_Rel
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitRel(const LinkerConfig& pConfig,
const RelocData& pRelocData,
- MemoryRegion& pRegion) const
-{
- typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
+ MemoryRegion& pRegion) const {
+ typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
typedef typename ELFSizeTraits<SIZE>::Addr ElfXX_Addr;
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
@@ -498,40 +487,39 @@
const Relocation* relocation = 0;
const FragmentRef* frag_ref = 0;
- for (RelocData::const_iterator it = pRelocData.begin(),
- ie = pRelocData.end(); it != ie; ++it, ++rel) {
+ for (RelocData::const_iterator it = pRelocData.begin(), ie = pRelocData.end();
+ it != ie;
+ ++it, ++rel) {
ElfXX_Addr r_offset = 0;
ElfXX_Word r_sym = 0;
relocation = &(llvm::cast<Relocation>(*it));
frag_ref = &(relocation->targetRef());
- if(LinkerConfig::DynObj == pConfig.codeGenType() ||
- LinkerConfig::Exec == pConfig.codeGenType()) {
+ if (LinkerConfig::DynObj == pConfig.codeGenType() ||
+ LinkerConfig::Exec == pConfig.codeGenType()) {
r_offset = static_cast<ElfXX_Addr>(
- frag_ref->frag()->getParent()->getSection().addr() +
- frag_ref->getOutputOffset());
- }
- else {
+ frag_ref->frag()->getParent()->getSection().addr() +
+ frag_ref->getOutputOffset());
+ } else {
r_offset = static_cast<ElfXX_Addr>(frag_ref->getOutputOffset());
}
- if( relocation->symInfo() == NULL )
+ if (relocation->symInfo() == NULL)
r_sym = 0;
else
r_sym = static_cast<ElfXX_Word>(
- target().getSymbolIdx(relocation->symInfo()->outSymbol()));
+ target().getSymbolIdx(relocation->symInfo()->outSymbol()));
target().emitRelocation(*rel, relocation->type(), r_sym, r_offset);
}
}
// emitRela - emit ElfXX_Rela
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitRela(const LinkerConfig& pConfig,
const RelocData& pRelocData,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
typedef typename ELFSizeTraits<SIZE>::Rela ElfXX_Rela;
typedef typename ELFSizeTraits<SIZE>::Addr ElfXX_Addr;
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
@@ -541,45 +529,43 @@
const Relocation* relocation = 0;
const FragmentRef* frag_ref = 0;
- for (RelocData::const_iterator it = pRelocData.begin(),
- ie = pRelocData.end(); it != ie; ++it, ++rel) {
+ for (RelocData::const_iterator it = pRelocData.begin(), ie = pRelocData.end();
+ it != ie;
+ ++it, ++rel) {
ElfXX_Addr r_offset = 0;
ElfXX_Word r_sym = 0;
relocation = &(llvm::cast<Relocation>(*it));
frag_ref = &(relocation->targetRef());
- if(LinkerConfig::DynObj == pConfig.codeGenType() ||
- LinkerConfig::Exec == pConfig.codeGenType()) {
+ if (LinkerConfig::DynObj == pConfig.codeGenType() ||
+ LinkerConfig::Exec == pConfig.codeGenType()) {
r_offset = static_cast<ElfXX_Addr>(
- frag_ref->frag()->getParent()->getSection().addr() +
- frag_ref->getOutputOffset());
- }
- else {
+ frag_ref->frag()->getParent()->getSection().addr() +
+ frag_ref->getOutputOffset());
+ } else {
r_offset = static_cast<ElfXX_Addr>(frag_ref->getOutputOffset());
}
- if( relocation->symInfo() == NULL )
+ if (relocation->symInfo() == NULL)
r_sym = 0;
else
r_sym = static_cast<ElfXX_Word>(
- target().getSymbolIdx(relocation->symInfo()->outSymbol()));
+ target().getSymbolIdx(relocation->symInfo()->outSymbol()));
- target().emitRelocation(*rel, relocation->type(),
- r_sym, r_offset, relocation->addend());
+ target().emitRelocation(
+ *rel, relocation->type(), r_sym, r_offset, relocation->addend());
}
}
-
/// getSectEntrySize - compute ElfXX_Shdr::sh_entsize
-template<size_t SIZE>
-uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const
-{
+template <size_t SIZE>
+uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const {
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
- typedef typename ELFSizeTraits<SIZE>::Sym ElfXX_Sym;
- typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
+ typedef typename ELFSizeTraits<SIZE>::Sym ElfXX_Sym;
+ typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
typedef typename ELFSizeTraits<SIZE>::Rela ElfXX_Rela;
- typedef typename ELFSizeTraits<SIZE>::Dyn ElfXX_Dyn;
+ typedef typename ELFSizeTraits<SIZE>::Dyn ElfXX_Dyn;
if (llvm::ELF::SHT_DYNSYM == pSection.type() ||
llvm::ELF::SHT_SYMTAB == pSection.type())
@@ -588,7 +574,7 @@
return sizeof(ElfXX_Rel);
if (llvm::ELF::SHT_RELA == pSection.type())
return sizeof(ElfXX_Rela);
- if (llvm::ELF::SHT_HASH == pSection.type() ||
+ if (llvm::ELF::SHT_HASH == pSection.type() ||
llvm::ELF::SHT_GNU_HASH == pSection.type())
return sizeof(ElfXX_Word);
if (llvm::ELF::SHT_DYNAMIC == pSection.type())
@@ -604,15 +590,14 @@
/// getSectLink - compute ElfXX_Shdr::sh_link
uint64_t ELFObjectWriter::getSectLink(const LDSection& pSection,
- const LinkerConfig& pConfig) const
-{
+ const LinkerConfig& pConfig) const {
if (llvm::ELF::SHT_SYMTAB == pSection.type())
return target().getOutputFormat()->getStrTab().index();
if (llvm::ELF::SHT_DYNSYM == pSection.type())
return target().getOutputFormat()->getDynStrTab().index();
if (llvm::ELF::SHT_DYNAMIC == pSection.type())
return target().getOutputFormat()->getDynStrTab().index();
- if (llvm::ELF::SHT_HASH == pSection.type() ||
+ if (llvm::ELF::SHT_HASH == pSection.type() ||
llvm::ELF::SHT_GNU_HASH == pSection.type())
return target().getOutputFormat()->getDynSymTab().index();
if (llvm::ELF::SHT_REL == pSection.type() ||
@@ -629,8 +614,7 @@
}
/// getSectInfo - compute ElfXX_Shdr::sh_info
-uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const
-{
+uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const {
if (llvm::ELF::SHT_SYMTAB == pSection.type() ||
llvm::ELF::SHT_DYNSYM == pSection.type())
return pSection.getInfo();
@@ -638,7 +622,7 @@
if (llvm::ELF::SHT_REL == pSection.type() ||
llvm::ELF::SHT_RELA == pSection.type()) {
const LDSection* info_link = pSection.getLink();
- if (NULL != info_link)
+ if (info_link != NULL)
return info_link->index();
}
@@ -646,18 +630,16 @@
}
/// getLastStartOffset
-template<>
-uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const
-{
+template <>
+uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const {
const LDSection* lastSect = pModule.back();
assert(lastSect != NULL);
return Align<32>(lastSect->offset() + lastSect->size());
}
/// getLastStartOffset
-template<>
-uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const
-{
+template <>
+uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const {
const LDSection* lastSect = pModule.back();
assert(lastSect != NULL);
return Align<64>(lastSect->offset() + lastSect->size());
@@ -665,15 +647,15 @@
/// emitSectionData
void ELFObjectWriter::emitSectionData(const SectionData& pSD,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
SectionData::const_iterator fragIter, fragEnd = pSD.end();
size_t cur_offset = 0;
for (fragIter = pSD.begin(); fragIter != fragEnd; ++fragIter) {
size_t size = fragIter->size();
- switch(fragIter->getKind()) {
+ switch (fragIter->getKind()) {
case Fragment::Region: {
- const RegionFragment& region_frag = llvm::cast<RegionFragment>(*fragIter);
+ const RegionFragment& region_frag =
+ llvm::cast<RegionFragment>(*fragIter);
const char* from = region_frag.getRegion().begin();
memcpy(pRegion.begin() + cur_offset, from, size);
break;
@@ -684,20 +666,19 @@
uint64_t count = size / align_frag.getValueSize();
switch (align_frag.getValueSize()) {
case 1u:
- std::memset(pRegion.begin() + cur_offset,
- align_frag.getValue(),
- count);
+ std::memset(
+ pRegion.begin() + cur_offset, align_frag.getValue(), count);
break;
default:
- llvm::report_fatal_error("unsupported value size for align fragment emission yet.\n");
+ llvm::report_fatal_error(
+ "unsupported value size for align fragment emission yet.\n");
break;
}
break;
}
case Fragment::Fillment: {
const FillFragment& fill_frag = llvm::cast<FillFragment>(*fragIter);
- if (0 == size ||
- 0 == fill_frag.getValueSize() ||
+ if (0 == size || 0 == fill_frag.getValueSize() ||
0 == fill_frag.size()) {
// ignore virtual fillment
break;
@@ -721,13 +702,16 @@
break;
}
case Fragment::Target:
- llvm::report_fatal_error("Target fragment should not be in a regular section.\n");
+ llvm::report_fatal_error(
+ "Target fragment should not be in a regular section.\n");
break;
default:
- llvm::report_fatal_error("invalid fragment should not be in a regular section.\n");
+ llvm::report_fatal_error(
+ "invalid fragment should not be in a regular section.\n");
break;
}
cur_offset += size;
}
}
+} // namespace mcld
diff --git a/lib/LD/ELFReader.cpp b/lib/LD/ELFReader.cpp
index 119f8a7..526d2ad 100644
--- a/lib/LD/ELFReader.cpp
+++ b/lib/LD/ELFReader.cpp
@@ -6,19 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFReader.h>
+#include "mcld/LD/ELFReader.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Object/ObjectBuilder.h>
-
-#include <cstring>
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
@@ -27,35 +26,33 @@
#include <iostream>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFReader<32, true>
//===----------------------------------------------------------------------===//
/// constructor
-ELFReader<32, true>::ELFReader(GNULDBackend& pBackend)
- : ELFReaderIF(pBackend) {
+ELFReader<32, true>::ELFReader(GNULDBackend& pBackend) : ELFReaderIF(pBackend) {
}
/// destructor
-ELFReader<32, true>::~ELFReader()
-{
+ELFReader<32, true>::~ELFReader() {
}
/// isELF - is this a ELF file
-bool ELFReader<32, true>::isELF(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isELF(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
- if (0 == memcmp(llvm::ELF::ElfMagic, hdr, 4))
+ if (memcmp(llvm::ELF::ElfMagic, hdr, 4) == 0)
return true;
return false;
}
/// readRegularSection - read a regular section and create fragments.
-bool
-ELFReader<32, true>::readRegularSection(Input& pInput, SectionData& pSD) const
-{
+bool ELFReader<32, true>::readRegularSection(Input& pInput,
+ SectionData& pSD) const {
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
@@ -68,18 +65,17 @@
bool ELFReader<32, true>::readSymbols(Input& pInput,
IRBuilder& pBuilder,
llvm::StringRef pRegion,
- const char* pStrTab) const
-{
+ const char* pStrTab) const {
// get number of symbols
- size_t entsize = pRegion.size()/sizeof(llvm::ELF::Elf32_Sym);
+ size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Sym);
const llvm::ELF::Elf32_Sym* symtab =
reinterpret_cast<const llvm::ELF::Elf32_Sym*>(pRegion.begin());
- uint32_t st_name = 0x0;
+ uint32_t st_name = 0x0;
uint32_t st_value = 0x0;
- uint32_t st_size = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_size = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
// skip the first NULL symbol
@@ -87,30 +83,28 @@
/// recording symbols added from DynObj to analyze weak alias
std::vector<AliasInfo> potential_aliases;
- bool is_dyn_obj = (pInput.type()==Input::DynObj);
+ bool is_dyn_obj = (pInput.type() == Input::DynObj);
for (size_t idx = 1; idx < entsize; ++idx) {
- st_info = symtab[idx].st_info;
+ st_info = symtab[idx].st_info;
st_other = symtab[idx].st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = symtab[idx].st_name;
+ st_name = symtab[idx].st_name;
st_value = symtab[idx].st_value;
- st_size = symtab[idx].st_size;
+ st_size = symtab[idx].st_size;
st_shndx = symtab[idx].st_shndx;
- }
- else {
- st_name = mcld::bswap32(symtab[idx].st_name);
+ } else {
+ st_name = mcld::bswap32(symtab[idx].st_name);
st_value = mcld::bswap32(symtab[idx].st_value);
- st_size = mcld::bswap32(symtab[idx].st_size);
+ st_size = mcld::bswap32(symtab[idx].st_size);
st_shndx = mcld::bswap16(symtab[idx].st_shndx);
}
// If the section should not be included, set the st_shndx SHN_UNDEF
// - A section in interrelated groups are not included.
- if (pInput.type() == Input::Object &&
- st_shndx < llvm::ELF::SHN_LORESERVE &&
+ if (pInput.type() == Input::Object && st_shndx < llvm::ELF::SHN_LORESERVE &&
st_shndx != llvm::ELF::SHN_UNDEF) {
- if (NULL == pInput.context()->getSection(st_shndx))
+ if (pInput.context()->getSection(st_shndx) == NULL)
st_shndx = llvm::ELF::SHN_UNDEF;
}
@@ -121,7 +115,8 @@
ResolveInfo::Desc ld_desc = getSymDesc(st_shndx, pInput);
// get ld_binding
- ResolveInfo::Binding ld_binding = getSymBinding((st_info >> 4), st_shndx, st_other);
+ ResolveInfo::Binding ld_binding =
+ getSymBinding((st_info >> 4), st_shndx, st_other);
// get ld_value - ld_value must be section relative.
uint64_t ld_value = getSymValue(st_value, st_shndx, pInput);
@@ -131,17 +126,16 @@
// get section
LDSection* section = NULL;
- if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
section = pInput.context()->getSection(st_shndx);
// get ld_name
std::string ld_name;
if (ResolveInfo::Section == ld_type) {
// Section symbol's st_name is the section index.
- assert(NULL != section && "get a invalid section");
+ assert(section != NULL && "get a invalid section");
ld_name = section->name();
- }
- else {
+ } else {
ld_name = std::string(pStrTab + st_name);
}
@@ -155,20 +149,17 @@
section,
ld_vis);
- if (is_dyn_obj
- && NULL != psym
- && ResolveInfo::Undefined != ld_desc
- && (ResolveInfo::Global == ld_binding ||
- ResolveInfo::Weak == ld_binding)
- && ResolveInfo::Object == ld_type) {
+ if (is_dyn_obj && psym != NULL && ResolveInfo::Undefined != ld_desc &&
+ (ResolveInfo::Global == ld_binding ||
+ ResolveInfo::Weak == ld_binding) &&
+ ResolveInfo::Object == ld_type) {
AliasInfo p;
p.pt_alias = psym;
p.ld_binding = ld_binding;
p.ld_value = ld_value;
potential_aliases.push_back(p);
}
-
- } // end of for loop
+ } // end of for loop
// analyze weak alias
// FIXME: it is better to let IRBuilder handle alias anlysis.
@@ -183,13 +174,13 @@
// then link them as a circular list in Module
std::vector<AliasInfo>::iterator sym_it, sym_e;
sym_e = potential_aliases.end();
- for (sym_it = potential_aliases.begin(); sym_it!=sym_e; ++sym_it) {
- if (ResolveInfo::Weak!=sym_it->ld_binding)
+ for (sym_it = potential_aliases.begin(); sym_it != sym_e; ++sym_it) {
+ if (ResolveInfo::Weak != sym_it->ld_binding)
continue;
Module& pModule = pBuilder.getModule();
- std::vector<AliasInfo>::iterator alias_it = sym_it+1;
- while(alias_it!=sym_e) {
+ std::vector<AliasInfo>::iterator alias_it = sym_it + 1;
+ while (alias_it != sym_e) {
if (sym_it->ld_value != alias_it->ld_value)
break;
@@ -200,7 +191,7 @@
}
sym_it = alias_it - 1;
- }// end of for loop
+ } // end of for loop
}
return true;
@@ -212,42 +203,42 @@
/// ELFReader::readRela - read ELF rela and create Relocation
bool ELFReader<32, true>::readRela(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rela
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Rela);
const llvm::ELF::Elf32_Rela* relaTab =
reinterpret_cast<const llvm::ELF::Elf32_Rela*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint32_t r_offset = 0x0;
- int32_t r_addend = 0;
- if (!target().readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend))
+ int32_t r_addend = 0;
+ if (!target()
+ .readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend)) {
return false;
+ }
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset, r_addend);
- } // end of for
+ } // end of for
return true;
}
/// readRel - read ELF rel and create Relocation
bool ELFReader<32, true>::readRel(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rel
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Rel);
const llvm::ELF::Elf32_Rel* relTab =
reinterpret_cast<const llvm::ELF::Elf32_Rel*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint32_t r_offset = 0x0;
@@ -256,18 +247,17 @@
return false;
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset);
- } // end of for
+ } // end of for
return true;
}
/// isMyEndian - is this ELF file in the same endian to me?
-bool ELFReader<32, true>::isMyEndian(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isMyEndian(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
@@ -275,8 +265,7 @@
}
/// isMyMachine - is this ELF file generated for the same machine.
-bool ELFReader<32, true>::isMyMachine(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isMyMachine(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
@@ -286,8 +275,7 @@
}
/// fileType - return the file type
-Input::Type ELFReader<32, true>::fileType(const void* pELFHeader) const
-{
+Input::Type ELFReader<32, true>::fileType(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
uint32_t type = 0x0;
@@ -296,72 +284,69 @@
else
type = mcld::bswap16(hdr->e_type);
- switch(type) {
- case llvm::ELF::ET_REL:
- return Input::Object;
- case llvm::ELF::ET_EXEC:
- return Input::Exec;
- case llvm::ELF::ET_DYN:
- return Input::DynObj;
- case llvm::ELF::ET_CORE:
- return Input::CoreFile;
- case llvm::ELF::ET_NONE:
- default:
- return Input::Unknown;
+ switch (type) {
+ case llvm::ELF::ET_REL:
+ return Input::Object;
+ case llvm::ELF::ET_EXEC:
+ return Input::Exec;
+ case llvm::ELF::ET_DYN:
+ return Input::DynObj;
+ case llvm::ELF::ET_CORE:
+ return Input::CoreFile;
+ case llvm::ELF::ET_NONE:
+ default:
+ return Input::Unknown;
}
}
/// readSectionHeaders - read ELF section header table and create LDSections
bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
- const void* pELFHeader) const
-{
+ const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* ehdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
- uint32_t shoff = 0x0;
+ uint32_t shoff = 0x0;
uint16_t shentsize = 0x0;
- uint32_t shnum = 0x0;
- uint32_t shstrtab = 0x0;
+ uint32_t shnum = 0x0;
+ uint32_t shstrtab = 0x0;
if (llvm::sys::IsLittleEndianHost) {
- shoff = ehdr->e_shoff;
+ shoff = ehdr->e_shoff;
shentsize = ehdr->e_shentsize;
- shnum = ehdr->e_shnum;
- shstrtab = ehdr->e_shstrndx;
- }
- else {
- shoff = mcld::bswap32(ehdr->e_shoff);
+ shnum = ehdr->e_shnum;
+ shstrtab = ehdr->e_shstrndx;
+ } else {
+ shoff = mcld::bswap32(ehdr->e_shoff);
shentsize = mcld::bswap16(ehdr->e_shentsize);
- shnum = mcld::bswap16(ehdr->e_shnum);
- shstrtab = mcld::bswap16(ehdr->e_shstrndx);
+ shnum = mcld::bswap16(ehdr->e_shnum);
+ shstrtab = mcld::bswap16(ehdr->e_shstrndx);
}
// If the file has no section header table, e_shoff holds zero.
- if (0x0 == shoff)
+ if (shoff == 0x0)
return true;
- const llvm::ELF::Elf32_Shdr *shdr = NULL;
+ const llvm::ELF::Elf32_Shdr* shdr = NULL;
llvm::StringRef shdr_region;
- uint32_t sh_name = 0x0;
- uint32_t sh_type = 0x0;
- uint32_t sh_flags = 0x0;
- uint32_t sh_offset = 0x0;
- uint32_t sh_size = 0x0;
- uint32_t sh_link = 0x0;
- uint32_t sh_info = 0x0;
+ uint32_t sh_name = 0x0;
+ uint32_t sh_type = 0x0;
+ uint32_t sh_flags = 0x0;
+ uint32_t sh_offset = 0x0;
+ uint32_t sh_size = 0x0;
+ uint32_t sh_link = 0x0;
+ uint32_t sh_info = 0x0;
uint32_t sh_addralign = 0x0;
// if shnum and shstrtab overflow, the actual values are in the 1st shdr
if (shnum == llvm::ELF::SHN_UNDEF || shstrtab == llvm::ELF::SHN_XINDEX) {
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shentsize);
shdr = reinterpret_cast<const llvm::ELF::Elf32_Shdr*>(shdr_region.begin());
if (llvm::sys::IsLittleEndianHost) {
sh_size = shdr->sh_size;
sh_link = shdr->sh_link;
- }
- else {
+ } else {
sh_size = mcld::bswap32(shdr->sh_size);
sh_link = mcld::bswap32(shdr->sh_link);
}
@@ -374,8 +359,8 @@
shoff += shentsize;
}
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shnum * shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shnum * shentsize);
const llvm::ELF::Elf32_Shdr* shdrTab =
reinterpret_cast<const llvm::ELF::Elf32_Shdr*>(shdr_region.begin());
@@ -383,15 +368,14 @@
shdr = &shdrTab[shstrtab];
if (llvm::sys::IsLittleEndianHost) {
sh_offset = shdr->sh_offset;
- sh_size = shdr->sh_size;
- }
- else {
+ sh_size = shdr->sh_size;
+ } else {
sh_offset = mcld::bswap32(shdr->sh_offset);
- sh_size = mcld::bswap32(shdr->sh_size);
+ sh_size = mcld::bswap32(shdr->sh_size);
}
- llvm::StringRef sect_name_region = pInput.memArea()->request(
- pInput.fileOffset() + sh_offset, sh_size);
+ llvm::StringRef sect_name_region =
+ pInput.memArea()->request(pInput.fileOffset() + sh_offset, sh_size);
const char* sect_name = sect_name_region.begin();
LinkInfoList link_info_list;
@@ -399,40 +383,36 @@
// create all LDSections, including first NULL section.
for (size_t idx = 0; idx < shnum; ++idx) {
if (llvm::sys::IsLittleEndianHost) {
- sh_name = shdrTab[idx].sh_name;
- sh_type = shdrTab[idx].sh_type;
- sh_flags = shdrTab[idx].sh_flags;
- sh_offset = shdrTab[idx].sh_offset;
- sh_size = shdrTab[idx].sh_size;
- sh_link = shdrTab[idx].sh_link;
- sh_info = shdrTab[idx].sh_info;
+ sh_name = shdrTab[idx].sh_name;
+ sh_type = shdrTab[idx].sh_type;
+ sh_flags = shdrTab[idx].sh_flags;
+ sh_offset = shdrTab[idx].sh_offset;
+ sh_size = shdrTab[idx].sh_size;
+ sh_link = shdrTab[idx].sh_link;
+ sh_info = shdrTab[idx].sh_info;
sh_addralign = shdrTab[idx].sh_addralign;
- }
- else {
- sh_name = mcld::bswap32(shdrTab[idx].sh_name);
- sh_type = mcld::bswap32(shdrTab[idx].sh_type);
- sh_flags = mcld::bswap32(shdrTab[idx].sh_flags);
- sh_offset = mcld::bswap32(shdrTab[idx].sh_offset);
- sh_size = mcld::bswap32(shdrTab[idx].sh_size);
- sh_link = mcld::bswap32(shdrTab[idx].sh_link);
- sh_info = mcld::bswap32(shdrTab[idx].sh_info);
+ } else {
+ sh_name = mcld::bswap32(shdrTab[idx].sh_name);
+ sh_type = mcld::bswap32(shdrTab[idx].sh_type);
+ sh_flags = mcld::bswap32(shdrTab[idx].sh_flags);
+ sh_offset = mcld::bswap32(shdrTab[idx].sh_offset);
+ sh_size = mcld::bswap32(shdrTab[idx].sh_size);
+ sh_link = mcld::bswap32(shdrTab[idx].sh_link);
+ sh_info = mcld::bswap32(shdrTab[idx].sh_info);
sh_addralign = mcld::bswap32(shdrTab[idx].sh_addralign);
}
- LDSection* section = IRBuilder::CreateELFHeader(pInput,
- sect_name+sh_name,
- sh_type,
- sh_flags,
- sh_addralign);
+ LDSection* section = IRBuilder::CreateELFHeader(
+ pInput, sect_name + sh_name, sh_type, sh_flags, sh_addralign);
section->setSize(sh_size);
section->setOffset(sh_offset);
section->setInfo(sh_info);
if (sh_link != 0x0 || sh_info != 0x0) {
- LinkInfo link_info = { section, sh_link, sh_info };
+ LinkInfo link_info = {section, sh_link, sh_info};
link_info_list.push_back(link_info);
}
- } // end of for
+ } // end of for
// set up InfoLink
LinkInfoList::iterator info, infoEnd = link_info_list.end();
@@ -450,31 +430,29 @@
/// This is used to get the signature of a group section.
ResolveInfo* ELFReader<32, true>::readSignature(Input& pInput,
LDSection& pSymTab,
- uint32_t pSymIdx) const
-{
+ uint32_t pSymIdx) const {
LDSection* symtab = &pSymTab;
LDSection* strtab = symtab->getLink();
- assert(NULL != symtab && NULL != strtab);
+ assert(symtab != NULL && strtab != NULL);
uint32_t offset = pInput.fileOffset() + symtab->offset() +
- sizeof(llvm::ELF::Elf32_Sym) * pSymIdx;
+ sizeof(llvm::ELF::Elf32_Sym) * pSymIdx;
llvm::StringRef symbol_region =
pInput.memArea()->request(offset, sizeof(llvm::ELF::Elf32_Sym));
const llvm::ELF::Elf32_Sym* entry =
reinterpret_cast<const llvm::ELF::Elf32_Sym*>(symbol_region.begin());
- uint32_t st_name = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_name = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
- st_info = entry->st_info;
+ st_info = entry->st_info;
st_other = entry->st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = entry->st_name;
+ st_name = entry->st_name;
st_shndx = entry->st_shndx;
- }
- else {
- st_name = mcld::bswap32(entry->st_name);
+ } else {
+ st_name = mcld::bswap32(entry->st_name);
st_shndx = mcld::bswap16(entry->st_shndx);
}
@@ -495,15 +473,14 @@
}
/// readDynamic - read ELF .dynamic in input dynobj
-bool ELFReader<32, true>::readDynamic(Input& pInput) const
-{
+bool ELFReader<32, true>::readDynamic(Input& pInput) const {
assert(pInput.type() == Input::DynObj);
const LDSection* dynamic_sect = pInput.context()->getSection(".dynamic");
- if (NULL == dynamic_sect) {
+ if (dynamic_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynamic";
}
const LDSection* dynstr_sect = dynamic_sect->getLink();
- if (NULL == dynstr_sect) {
+ if (dynstr_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynstr";
}
@@ -520,7 +497,6 @@
size_t numOfEntries = dynamic_sect->size() / sizeof(llvm::ELF::Elf32_Dyn);
for (size_t idx = 0; idx < numOfEntries; ++idx) {
-
llvm::ELF::Elf32_Sword d_tag = 0x0;
llvm::ELF::Elf32_Word d_val = 0x0;
@@ -558,29 +534,25 @@
// ELFReader<64, true>
//===----------------------------------------------------------------------===//
/// constructor
-ELFReader<64, true>::ELFReader(GNULDBackend& pBackend)
- : ELFReaderIF(pBackend) {
+ELFReader<64, true>::ELFReader(GNULDBackend& pBackend) : ELFReaderIF(pBackend) {
}
/// destructor
-ELFReader<64, true>::~ELFReader()
-{
+ELFReader<64, true>::~ELFReader() {
}
/// isELF - is this a ELF file
-bool ELFReader<64, true>::isELF(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isELF(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
- if (0 == memcmp(llvm::ELF::ElfMagic, hdr, 4))
+ if (memcmp(llvm::ELF::ElfMagic, hdr, 4) == 0)
return true;
return false;
}
/// readRegularSection - read a regular section and create fragments.
-bool
-ELFReader<64, true>::readRegularSection(Input& pInput, SectionData& pSD) const
-{
+bool ELFReader<64, true>::readRegularSection(Input& pInput,
+ SectionData& pSD) const {
uint64_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint64_t size = pSD.getSection().size();
@@ -593,18 +565,17 @@
bool ELFReader<64, true>::readSymbols(Input& pInput,
IRBuilder& pBuilder,
llvm::StringRef pRegion,
- const char* pStrTab) const
-{
+ const char* pStrTab) const {
// get number of symbols
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Sym);
const llvm::ELF::Elf64_Sym* symtab =
reinterpret_cast<const llvm::ELF::Elf64_Sym*>(pRegion.begin());
- uint32_t st_name = 0x0;
+ uint32_t st_name = 0x0;
uint64_t st_value = 0x0;
- uint64_t st_size = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint64_t st_size = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
// skip the first NULL symbol
@@ -612,30 +583,28 @@
/// recording symbols added from DynObj to analyze weak alias
std::vector<AliasInfo> potential_aliases;
- bool is_dyn_obj = (pInput.type()==Input::DynObj);
+ bool is_dyn_obj = (pInput.type() == Input::DynObj);
for (size_t idx = 1; idx < entsize; ++idx) {
- st_info = symtab[idx].st_info;
+ st_info = symtab[idx].st_info;
st_other = symtab[idx].st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = symtab[idx].st_name;
+ st_name = symtab[idx].st_name;
st_value = symtab[idx].st_value;
- st_size = symtab[idx].st_size;
+ st_size = symtab[idx].st_size;
st_shndx = symtab[idx].st_shndx;
- }
- else {
- st_name = mcld::bswap32(symtab[idx].st_name);
+ } else {
+ st_name = mcld::bswap32(symtab[idx].st_name);
st_value = mcld::bswap64(symtab[idx].st_value);
- st_size = mcld::bswap64(symtab[idx].st_size);
+ st_size = mcld::bswap64(symtab[idx].st_size);
st_shndx = mcld::bswap16(symtab[idx].st_shndx);
}
// If the section should not be included, set the st_shndx SHN_UNDEF
// - A section in interrelated groups are not included.
- if (pInput.type() == Input::Object &&
- st_shndx < llvm::ELF::SHN_LORESERVE &&
+ if (pInput.type() == Input::Object && st_shndx < llvm::ELF::SHN_LORESERVE &&
st_shndx != llvm::ELF::SHN_UNDEF) {
- if (NULL == pInput.context()->getSection(st_shndx))
+ if (pInput.context()->getSection(st_shndx) == NULL)
st_shndx = llvm::ELF::SHN_UNDEF;
}
@@ -646,7 +615,8 @@
ResolveInfo::Desc ld_desc = getSymDesc(st_shndx, pInput);
// get ld_binding
- ResolveInfo::Binding ld_binding = getSymBinding((st_info >> 4), st_shndx, st_other);
+ ResolveInfo::Binding ld_binding =
+ getSymBinding((st_info >> 4), st_shndx, st_other);
// get ld_value - ld_value must be section relative.
uint64_t ld_value = getSymValue(st_value, st_shndx, pInput);
@@ -656,17 +626,16 @@
// get section
LDSection* section = NULL;
- if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
section = pInput.context()->getSection(st_shndx);
// get ld_name
std::string ld_name;
if (ResolveInfo::Section == ld_type) {
// Section symbol's st_name is the section index.
- assert(NULL != section && "get a invalid section");
+ assert(section != NULL && "get a invalid section");
ld_name = section->name();
- }
- else {
+ } else {
ld_name = std::string(pStrTab + st_name);
}
@@ -680,20 +649,17 @@
section,
ld_vis);
- if (is_dyn_obj
- && NULL != psym
- && ResolveInfo::Undefined != ld_desc
- && (ResolveInfo::Global == ld_binding ||
- ResolveInfo::Weak == ld_binding)
- && ResolveInfo::Object == ld_type ) {
+ if (is_dyn_obj && psym != NULL && ResolveInfo::Undefined != ld_desc &&
+ (ResolveInfo::Global == ld_binding ||
+ ResolveInfo::Weak == ld_binding) &&
+ ResolveInfo::Object == ld_type) {
AliasInfo p;
p.pt_alias = psym;
p.ld_binding = ld_binding;
p.ld_value = ld_value;
potential_aliases.push_back(p);
}
-
- } // end of for loop
+ } // end of for loop
// analyze weak alias here
if (is_dyn_obj) {
@@ -704,13 +670,13 @@
// then link them as a circular list in Module
std::vector<AliasInfo>::iterator sym_it, sym_e;
sym_e = potential_aliases.end();
- for (sym_it = potential_aliases.begin(); sym_it!=sym_e; ++sym_it) {
- if (ResolveInfo::Weak!=sym_it->ld_binding)
+ for (sym_it = potential_aliases.begin(); sym_it != sym_e; ++sym_it) {
+ if (ResolveInfo::Weak != sym_it->ld_binding)
continue;
Module& pModule = pBuilder.getModule();
- std::vector<AliasInfo>::iterator alias_it = sym_it+1;
- while(alias_it!=sym_e) {
+ std::vector<AliasInfo>::iterator alias_it = sym_it + 1;
+ while (alias_it != sym_e) {
if (sym_it->ld_value != alias_it->ld_value)
break;
@@ -721,7 +687,7 @@
}
sym_it = alias_it - 1;
- }// end of for loop
+ } // end of for loop
}
return true;
}
@@ -732,44 +698,42 @@
/// ELFReader::readRela - read ELF rela and create Relocation
bool ELFReader<64, true>::readRela(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rela
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Rela);
const llvm::ELF::Elf64_Rela* relaTab =
reinterpret_cast<const llvm::ELF::Elf64_Rela*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint64_t r_offset = 0x0;
- int64_t r_addend = 0;
- if (!target().readRelocation(relaTab[idx],
- r_type, r_sym, r_offset, r_addend)) {
+ int64_t r_addend = 0;
+ if (!target()
+ .readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend)) {
return false;
}
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset, r_addend);
- } // end of for
+ } // end of for
return true;
}
/// readRel - read ELF rel and create Relocation
bool ELFReader<64, true>::readRel(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rel
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Rel);
const llvm::ELF::Elf64_Rel* relTab =
reinterpret_cast<const llvm::ELF::Elf64_Rel*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint64_t r_offset = 0x0;
@@ -777,18 +741,17 @@
return false;
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset);
- } // end of for
+ } // end of for
return true;
}
/// isMyEndian - is this ELF file in the same endian to me?
-bool ELFReader<64, true>::isMyEndian(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isMyEndian(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
@@ -796,8 +759,7 @@
}
/// isMyMachine - is this ELF file generated for the same machine.
-bool ELFReader<64, true>::isMyMachine(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isMyMachine(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
@@ -807,8 +769,7 @@
}
/// fileType - return the file type
-Input::Type ELFReader<64, true>::fileType(const void* pELFHeader) const
-{
+Input::Type ELFReader<64, true>::fileType(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
uint32_t type = 0x0;
@@ -817,72 +778,69 @@
else
type = mcld::bswap16(hdr->e_type);
- switch(type) {
- case llvm::ELF::ET_REL:
- return Input::Object;
- case llvm::ELF::ET_EXEC:
- return Input::Exec;
- case llvm::ELF::ET_DYN:
- return Input::DynObj;
- case llvm::ELF::ET_CORE:
- return Input::CoreFile;
- case llvm::ELF::ET_NONE:
- default:
- return Input::Unknown;
+ switch (type) {
+ case llvm::ELF::ET_REL:
+ return Input::Object;
+ case llvm::ELF::ET_EXEC:
+ return Input::Exec;
+ case llvm::ELF::ET_DYN:
+ return Input::DynObj;
+ case llvm::ELF::ET_CORE:
+ return Input::CoreFile;
+ case llvm::ELF::ET_NONE:
+ default:
+ return Input::Unknown;
}
}
/// readSectionHeaders - read ELF section header table and create LDSections
bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
- const void* pELFHeader) const
-{
+ const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* ehdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
- uint64_t shoff = 0x0;
+ uint64_t shoff = 0x0;
uint16_t shentsize = 0x0;
- uint32_t shnum = 0x0;
- uint32_t shstrtab = 0x0;
+ uint32_t shnum = 0x0;
+ uint32_t shstrtab = 0x0;
if (llvm::sys::IsLittleEndianHost) {
- shoff = ehdr->e_shoff;
+ shoff = ehdr->e_shoff;
shentsize = ehdr->e_shentsize;
- shnum = ehdr->e_shnum;
- shstrtab = ehdr->e_shstrndx;
- }
- else {
- shoff = mcld::bswap64(ehdr->e_shoff);
+ shnum = ehdr->e_shnum;
+ shstrtab = ehdr->e_shstrndx;
+ } else {
+ shoff = mcld::bswap64(ehdr->e_shoff);
shentsize = mcld::bswap16(ehdr->e_shentsize);
- shnum = mcld::bswap16(ehdr->e_shnum);
- shstrtab = mcld::bswap16(ehdr->e_shstrndx);
+ shnum = mcld::bswap16(ehdr->e_shnum);
+ shstrtab = mcld::bswap16(ehdr->e_shstrndx);
}
// If the file has no section header table, e_shoff holds zero.
- if (0x0 == shoff)
+ if (shoff == 0x0)
return true;
- const llvm::ELF::Elf64_Shdr *shdr = NULL;
+ const llvm::ELF::Elf64_Shdr* shdr = NULL;
llvm::StringRef shdr_region;
- uint32_t sh_name = 0x0;
- uint32_t sh_type = 0x0;
- uint64_t sh_flags = 0x0;
- uint64_t sh_offset = 0x0;
- uint64_t sh_size = 0x0;
- uint32_t sh_link = 0x0;
- uint32_t sh_info = 0x0;
+ uint32_t sh_name = 0x0;
+ uint32_t sh_type = 0x0;
+ uint64_t sh_flags = 0x0;
+ uint64_t sh_offset = 0x0;
+ uint64_t sh_size = 0x0;
+ uint32_t sh_link = 0x0;
+ uint32_t sh_info = 0x0;
uint64_t sh_addralign = 0x0;
// if shnum and shstrtab overflow, the actual values are in the 1st shdr
if (shnum == llvm::ELF::SHN_UNDEF || shstrtab == llvm::ELF::SHN_XINDEX) {
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shentsize);
shdr = reinterpret_cast<const llvm::ELF::Elf64_Shdr*>(shdr_region.begin());
if (llvm::sys::IsLittleEndianHost) {
sh_size = shdr->sh_size;
sh_link = shdr->sh_link;
- }
- else {
+ } else {
sh_size = mcld::bswap64(shdr->sh_size);
sh_link = mcld::bswap32(shdr->sh_link);
}
@@ -895,8 +853,8 @@
shoff += shentsize;
}
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shnum * shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shnum * shentsize);
const llvm::ELF::Elf64_Shdr* shdrTab =
reinterpret_cast<const llvm::ELF::Elf64_Shdr*>(shdr_region.begin());
@@ -904,15 +862,14 @@
shdr = &shdrTab[shstrtab];
if (llvm::sys::IsLittleEndianHost) {
sh_offset = shdr->sh_offset;
- sh_size = shdr->sh_size;
- }
- else {
+ sh_size = shdr->sh_size;
+ } else {
sh_offset = mcld::bswap64(shdr->sh_offset);
- sh_size = mcld::bswap64(shdr->sh_size);
+ sh_size = mcld::bswap64(shdr->sh_size);
}
- llvm::StringRef sect_name_region = pInput.memArea()->request(
- pInput.fileOffset() + sh_offset, sh_size);
+ llvm::StringRef sect_name_region =
+ pInput.memArea()->request(pInput.fileOffset() + sh_offset, sh_size);
const char* sect_name = sect_name_region.begin();
LinkInfoList link_info_list;
@@ -920,40 +877,36 @@
// create all LDSections, including first NULL section.
for (size_t idx = 0; idx < shnum; ++idx) {
if (llvm::sys::IsLittleEndianHost) {
- sh_name = shdrTab[idx].sh_name;
- sh_type = shdrTab[idx].sh_type;
- sh_flags = shdrTab[idx].sh_flags;
- sh_offset = shdrTab[idx].sh_offset;
- sh_size = shdrTab[idx].sh_size;
- sh_link = shdrTab[idx].sh_link;
- sh_info = shdrTab[idx].sh_info;
+ sh_name = shdrTab[idx].sh_name;
+ sh_type = shdrTab[idx].sh_type;
+ sh_flags = shdrTab[idx].sh_flags;
+ sh_offset = shdrTab[idx].sh_offset;
+ sh_size = shdrTab[idx].sh_size;
+ sh_link = shdrTab[idx].sh_link;
+ sh_info = shdrTab[idx].sh_info;
sh_addralign = shdrTab[idx].sh_addralign;
- }
- else {
- sh_name = mcld::bswap32(shdrTab[idx].sh_name);
- sh_type = mcld::bswap32(shdrTab[idx].sh_type);
- sh_flags = mcld::bswap64(shdrTab[idx].sh_flags);
- sh_offset = mcld::bswap64(shdrTab[idx].sh_offset);
- sh_size = mcld::bswap64(shdrTab[idx].sh_size);
- sh_link = mcld::bswap32(shdrTab[idx].sh_link);
- sh_info = mcld::bswap32(shdrTab[idx].sh_info);
+ } else {
+ sh_name = mcld::bswap32(shdrTab[idx].sh_name);
+ sh_type = mcld::bswap32(shdrTab[idx].sh_type);
+ sh_flags = mcld::bswap64(shdrTab[idx].sh_flags);
+ sh_offset = mcld::bswap64(shdrTab[idx].sh_offset);
+ sh_size = mcld::bswap64(shdrTab[idx].sh_size);
+ sh_link = mcld::bswap32(shdrTab[idx].sh_link);
+ sh_info = mcld::bswap32(shdrTab[idx].sh_info);
sh_addralign = mcld::bswap64(shdrTab[idx].sh_addralign);
}
- LDSection* section = IRBuilder::CreateELFHeader(pInput,
- sect_name+sh_name,
- sh_type,
- sh_flags,
- sh_addralign);
+ LDSection* section = IRBuilder::CreateELFHeader(
+ pInput, sect_name + sh_name, sh_type, sh_flags, sh_addralign);
section->setSize(sh_size);
section->setOffset(sh_offset);
section->setInfo(sh_info);
if (sh_link != 0x0 || sh_info != 0x0) {
- LinkInfo link_info = { section, sh_link, sh_info };
+ LinkInfo link_info = {section, sh_link, sh_info};
link_info_list.push_back(link_info);
}
- } // end of for
+ } // end of for
// set up InfoLink
LinkInfoList::iterator info, infoEnd = link_info_list.end();
@@ -971,31 +924,29 @@
/// This is used to get the signature of a group section.
ResolveInfo* ELFReader<64, true>::readSignature(Input& pInput,
LDSection& pSymTab,
- uint32_t pSymIdx) const
-{
+ uint32_t pSymIdx) const {
LDSection* symtab = &pSymTab;
LDSection* strtab = symtab->getLink();
- assert(NULL != symtab && NULL != strtab);
+ assert(symtab != NULL && strtab != NULL);
uint64_t offset = pInput.fileOffset() + symtab->offset() +
- sizeof(llvm::ELF::Elf64_Sym) * pSymIdx;
+ sizeof(llvm::ELF::Elf64_Sym) * pSymIdx;
llvm::StringRef symbol_region =
pInput.memArea()->request(offset, sizeof(llvm::ELF::Elf64_Sym));
const llvm::ELF::Elf64_Sym* entry =
reinterpret_cast<const llvm::ELF::Elf64_Sym*>(symbol_region.begin());
- uint32_t st_name = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_name = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
- st_info = entry->st_info;
+ st_info = entry->st_info;
st_other = entry->st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = entry->st_name;
+ st_name = entry->st_name;
st_shndx = entry->st_shndx;
- }
- else {
- st_name = mcld::bswap32(entry->st_name);
+ } else {
+ st_name = mcld::bswap32(entry->st_name);
st_shndx = mcld::bswap16(entry->st_shndx);
}
@@ -1016,15 +967,14 @@
}
/// readDynamic - read ELF .dynamic in input dynobj
-bool ELFReader<64, true>::readDynamic(Input& pInput) const
-{
+bool ELFReader<64, true>::readDynamic(Input& pInput) const {
assert(pInput.type() == Input::DynObj);
const LDSection* dynamic_sect = pInput.context()->getSection(".dynamic");
- if (NULL == dynamic_sect) {
+ if (dynamic_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynamic";
}
const LDSection* dynstr_sect = dynamic_sect->getLink();
- if (NULL == dynstr_sect) {
+ if (dynstr_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynstr";
}
@@ -1041,7 +991,6 @@
size_t numOfEntries = dynamic_sect->size() / sizeof(llvm::ELF::Elf64_Dyn);
for (size_t idx = 0; idx < numOfEntries; ++idx) {
-
llvm::ELF::Elf64_Sxword d_tag = 0x0;
llvm::ELF::Elf64_Xword d_val = 0x0;
@@ -1074,3 +1023,5 @@
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFReaderIf.cpp b/lib/LD/ELFReaderIf.cpp
index 7d72596..b9d4d32 100644
--- a/lib/LD/ELFReaderIf.cpp
+++ b/lib/LD/ELFReaderIf.cpp
@@ -6,31 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFReaderIf.h>
+#include "mcld/LD/ELFReaderIf.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Target/GNULDBackend.h>
-
-#include <cstring>
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFReaderIF
//===----------------------------------------------------------------------===//
/// getSymType
-ResolveInfo::Type ELFReaderIF::getSymType(uint8_t pInfo, uint16_t pShndx) const
-{
+ResolveInfo::Type ELFReaderIF::getSymType(uint8_t pInfo,
+ uint16_t pShndx) const {
ResolveInfo::Type result = static_cast<ResolveInfo::Type>(pInfo & 0xF);
- if (llvm::ELF::SHN_ABS == pShndx && ResolveInfo::Section == result) {
+ if (pShndx == llvm::ELF::SHN_ABS && result == ResolveInfo::Section) {
// In Mips, __gp_disp is a special section symbol. Its name comes from
// .strtab, not .shstrtab. However, it is unique. Only it is also a ABS
// symbol. So here is a tricky to identify __gp_disp and convert it to
@@ -42,16 +43,15 @@
}
/// getSymDesc
-ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx, const Input& pInput) const
-{
+ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx,
+ const Input& pInput) const {
if (pShndx == llvm::ELF::SHN_UNDEF)
return ResolveInfo::Undefined;
if (pShndx < llvm::ELF::SHN_LORESERVE) {
// an ELF symbol defined in a section which we are not including
// must be treated as an Undefined.
- // @ref Google gold linker: symtab.cc: 1086
- if (NULL == pInput.context()->getSection(pShndx) ||
+ if (pInput.context()->getSection(pShndx) == NULL ||
LDFileFormat::Ignore == pInput.context()->getSection(pShndx)->kind())
return ResolveInfo::Undefined;
return ResolveInfo::Define;
@@ -63,8 +63,7 @@
if (pShndx == llvm::ELF::SHN_COMMON)
return ResolveInfo::Common;
- if (pShndx >= llvm::ELF::SHN_LOPROC &&
- pShndx <= llvm::ELF::SHN_HIPROC)
+ if (pShndx >= llvm::ELF::SHN_LOPROC && pShndx <= llvm::ELF::SHN_HIPROC)
return target().getSymDesc(pShndx);
// FIXME: ELF weak alias should be ResolveInfo::Indirect
@@ -72,80 +71,75 @@
}
/// getSymBinding
-ResolveInfo::Binding
-ELFReaderIF::getSymBinding(uint8_t pBinding, uint16_t pShndx, uint8_t pVis) const
-{
-
+ResolveInfo::Binding ELFReaderIF::getSymBinding(uint8_t pBinding,
+ uint16_t pShndx,
+ uint8_t pVis) const {
// TODO:
// if --just-symbols option is enabled, the symbol must covert to Absolute
- switch(pBinding) {
- case llvm::ELF::STB_LOCAL:
- return ResolveInfo::Local;
- case llvm::ELF::STB_GLOBAL:
- if (pShndx == llvm::ELF::SHN_ABS)
- return ResolveInfo::Absolute;
- return ResolveInfo::Global;
- case llvm::ELF::STB_WEAK:
- return ResolveInfo::Weak;
+ switch (pBinding) {
+ case llvm::ELF::STB_LOCAL:
+ return ResolveInfo::Local;
+ case llvm::ELF::STB_GLOBAL:
+ if (pShndx == llvm::ELF::SHN_ABS)
+ return ResolveInfo::Absolute;
+ return ResolveInfo::Global;
+ case llvm::ELF::STB_WEAK:
+ return ResolveInfo::Weak;
}
return ResolveInfo::NoneBinding;
}
/// getSymFragmentRef
-FragmentRef*
-ELFReaderIF::getSymFragmentRef(Input& pInput,
- uint16_t pShndx,
- uint32_t pOffset) const
-{
-
- if (Input::DynObj == pInput.type())
+FragmentRef* ELFReaderIF::getSymFragmentRef(Input& pInput,
+ uint16_t pShndx,
+ uint32_t pOffset) const {
+ if (pInput.type() == Input::DynObj)
return FragmentRef::Null();
if (pShndx == llvm::ELF::SHN_UNDEF)
return FragmentRef::Null();
- if (pShndx >= llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (pShndx >= llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
return FragmentRef::Null();
LDSection* sect_hdr = pInput.context()->getSection(pShndx);
- if (NULL == sect_hdr)
- unreachable(diag::unreachable_invalid_section_idx) << pShndx
- << pInput.path().native();
+ if (sect_hdr == NULL)
+ unreachable(diag::unreachable_invalid_section_idx)
+ << pShndx << pInput.path().native();
- if (LDFileFormat::Ignore == sect_hdr->kind())
+ if (sect_hdr->kind() == LDFileFormat::Ignore)
return FragmentRef::Null();
- if (LDFileFormat::Group == sect_hdr->kind())
+ if (sect_hdr->kind() == LDFileFormat::Group)
return FragmentRef::Null();
return FragmentRef::Create(*sect_hdr, pOffset);
}
/// getSymVisibility
-ResolveInfo::Visibility
-ELFReaderIF::getSymVisibility(uint8_t pVis) const
-{
+ResolveInfo::Visibility ELFReaderIF::getSymVisibility(uint8_t pVis) const {
return static_cast<ResolveInfo::Visibility>(pVis);
}
/// getSymValue - get the section offset of the symbol.
uint64_t ELFReaderIF::getSymValue(uint64_t pValue,
uint16_t pShndx,
- const Input& pInput) const
-{
- if (Input::Object == pInput.type()) {
+ const Input& pInput) const {
+ if (pInput.type() == Input::Object) {
// In relocatable files, st_value holds alignment constraints for a symbol
// whose section index is SHN_COMMON
if (pShndx == llvm::ELF::SHN_COMMON || pShndx == llvm::ELF::SHN_ABS) {
return pValue;
}
- // In relocatable files, st_value holds a section offset for a defined symbol.
+ // In relocatable files, st_value holds a section offset for a defined
+ // symbol.
// TODO:
- // if --just-symbols option are enabled, convert the value from section offset
+ // if --just-symbols option are enabled, convert the value from section
+ // offset
// to virtual address by adding input section's virtual address.
// The section's virtual address in relocatable files is normally zero, but
// people can use link script to change it.
@@ -157,3 +151,4 @@
return pValue;
}
+} // namespace mcld
diff --git a/lib/LD/ELFSegment.cpp b/lib/LD/ELFSegment.cpp
index 1c09514..da8f5c5 100644
--- a/lib/LD/ELFSegment.cpp
+++ b/lib/LD/ELFSegment.cpp
@@ -6,14 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Config/Config.h>
+#include "mcld/LD/ELFSegment.h"
+
+#include "mcld/Config/Config.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<ELFSegment, MCLD_SEGMENTS_PER_OUTPUT> ELFSegmentFactory;
static llvm::ManagedStatic<ELFSegmentFactory> g_ELFSegmentFactory;
@@ -22,47 +25,41 @@
// ELFSegment
//===----------------------------------------------------------------------===//
ELFSegment::ELFSegment()
- : m_Type(llvm::ELF::PT_NULL),
- m_Flag(llvm::ELF::PF_R),
- m_Offset(0x0),
- m_Vaddr(0x0),
- m_Paddr(0x0),
- m_Filesz(0x0),
- m_Memsz(0x0),
- m_Align(0x0),
- m_MaxSectionAlign(0x0)
-{
+ : m_Type(llvm::ELF::PT_NULL),
+ m_Flag(llvm::ELF::PF_R),
+ m_Offset(0x0),
+ m_Vaddr(0x0),
+ m_Paddr(0x0),
+ m_Filesz(0x0),
+ m_Memsz(0x0),
+ m_Align(0x0),
+ m_MaxSectionAlign(0x0) {
}
ELFSegment::ELFSegment(uint32_t pType, uint32_t pFlag)
- : m_Type(pType),
- m_Flag(pFlag),
- m_Offset(0x0),
- m_Vaddr(0x0),
- m_Paddr(0x0),
- m_Filesz(0x0),
- m_Memsz(0x0),
- m_Align(0x0),
- m_MaxSectionAlign(0x0)
-{
+ : m_Type(pType),
+ m_Flag(pFlag),
+ m_Offset(0x0),
+ m_Vaddr(0x0),
+ m_Paddr(0x0),
+ m_Filesz(0x0),
+ m_Memsz(0x0),
+ m_Align(0x0),
+ m_MaxSectionAlign(0x0) {
}
-ELFSegment::~ELFSegment()
-{
+ELFSegment::~ELFSegment() {
}
-bool ELFSegment::isLoadSegment() const
-{
+bool ELFSegment::isLoadSegment() const {
return type() == llvm::ELF::PT_LOAD;
}
-bool ELFSegment::isDataSegment() const
-{
+bool ELFSegment::isDataSegment() const {
return (type() == llvm::ELF::PT_LOAD) && ((flag() & llvm::ELF::PF_W) != 0x0);
}
-bool ELFSegment::isBssSegment() const
-{
+bool ELFSegment::isBssSegment() const {
if (!isDataSegment())
return false;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
@@ -73,34 +70,31 @@
}
ELFSegment::iterator ELFSegment::insert(ELFSegment::iterator pPos,
- LDSection* pSection)
-{
+ LDSection* pSection) {
return m_SectionList.insert(pPos, pSection);
}
-void ELFSegment::append(LDSection* pSection)
-{
- assert(NULL != pSection);
+void ELFSegment::append(LDSection* pSection) {
+ assert(pSection != NULL);
if (pSection->align() > m_MaxSectionAlign)
m_MaxSectionAlign = pSection->align();
m_SectionList.push_back(pSection);
}
-ELFSegment* ELFSegment::Create(uint32_t pType, uint32_t pFlag)
-{
+ELFSegment* ELFSegment::Create(uint32_t pType, uint32_t pFlag) {
ELFSegment* seg = g_ELFSegmentFactory->allocate();
new (seg) ELFSegment(pType, pFlag);
return seg;
}
-void ELFSegment::Destroy(ELFSegment*& pSegment)
-{
+void ELFSegment::Destroy(ELFSegment*& pSegment) {
g_ELFSegmentFactory->destroy(pSegment);
g_ELFSegmentFactory->deallocate(pSegment);
pSegment = NULL;
}
-void ELFSegment::Clear()
-{
+void ELFSegment::Clear() {
g_ELFSegmentFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFSegmentFactory.cpp b/lib/LD/ELFSegmentFactory.cpp
index 4d06629..de2d175 100644
--- a/lib/LD/ELFSegmentFactory.cpp
+++ b/lib/LD/ELFSegmentFactory.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFSegmentFactory
//===----------------------------------------------------------------------===//
-ELFSegmentFactory::iterator
-ELFSegmentFactory::find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear)
-{
+ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType,
+ uint32_t pFlagSet,
+ uint32_t pFlagClear) {
iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType &&
@@ -29,11 +29,10 @@
return segEnd;
}
-ELFSegmentFactory::const_iterator
-ELFSegmentFactory::find(uint32_t pType,
- uint32_t pFlagSet,
- uint32_t pFlagClear) const
-{
+ELFSegmentFactory::const_iterator ELFSegmentFactory::find(
+ uint32_t pType,
+ uint32_t pFlagSet,
+ uint32_t pFlagClear) const {
const_iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType &&
@@ -45,9 +44,8 @@
return segEnd;
}
-ELFSegmentFactory::iterator
-ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection)
-{
+ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType,
+ const LDSection* pSection) {
iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType) {
@@ -55,15 +53,15 @@
for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
if (*sect == pSection)
return segment;
- } // for each section
+ } // for each section
}
- } // for each segment
+ } // for each segment
return segEnd;
}
-ELFSegmentFactory::const_iterator
-ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection) const
-{
+ELFSegmentFactory::const_iterator ELFSegmentFactory::find(
+ uint32_t pType,
+ const LDSection* pSection) const {
const_iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType) {
@@ -71,19 +69,19 @@
for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
if (*sect == pSection)
return segment;
- } // for each section
+ } // for each section
}
- } // for each segment
+ } // for each segment
return segEnd;
}
-ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag)
-{
+ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag) {
m_Segments.push_back(ELFSegment::Create(pType, pFlag));
return back();
}
-void ELFSegmentFactory::erase(iterator pSegment)
-{
+void ELFSegmentFactory::erase(iterator pSegment) {
m_Segments.erase(pSegment);
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrame.cpp b/lib/LD/EhFrame.cpp
index 5ac3e72..84896d3 100644
--- a/lib/LD/EhFrame.cpp
+++ b/lib/LD/EhFrame.cpp
@@ -6,21 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/EhFrame.h"
+
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<EhFrame, MCLD_SECTIONS_PER_INPUT> EhFrameFactory;
@@ -29,12 +30,10 @@
//===----------------------------------------------------------------------===//
// EhFrame::Record
//===----------------------------------------------------------------------===//
-EhFrame::Record::Record(llvm::StringRef pRegion)
- : RegionFragment(pRegion) {
+EhFrame::Record::Record(llvm::StringRef pRegion) : RegionFragment(pRegion) {
}
-EhFrame::Record::~Record()
-{
+EhFrame::Record::~Record() {
// llvm::iplist will manage and delete the fragments
}
@@ -42,27 +41,27 @@
// EhFrame::CIE
//===----------------------------------------------------------------------===//
EhFrame::CIE::CIE(llvm::StringRef pRegion)
- : EhFrame::Record(pRegion),
- m_FDEEncode(0u), m_Mergeable(false), m_pReloc(0), m_PersonalityOffset(0) {
+ : EhFrame::Record(pRegion),
+ m_FDEEncode(0u),
+ m_Mergeable(false),
+ m_pReloc(0),
+ m_PersonalityOffset(0) {
}
-EhFrame::CIE::~CIE()
-{
+EhFrame::CIE::~CIE() {
}
//===----------------------------------------------------------------------===//
// EhFrame::FDE
//===----------------------------------------------------------------------===//
EhFrame::FDE::FDE(llvm::StringRef pRegion, EhFrame::CIE& pCIE)
- : EhFrame::Record(pRegion), m_pCIE(&pCIE) {
+ : EhFrame::Record(pRegion), m_pCIE(&pCIE) {
}
-EhFrame::FDE::~FDE()
-{
+EhFrame::FDE::~FDE() {
}
-void EhFrame::FDE::setCIE(EhFrame::CIE& pCIE)
-{
+void EhFrame::FDE::setCIE(EhFrame::CIE& pCIE) {
m_pCIE = &pCIE;
m_pCIE->add(*this);
}
@@ -71,74 +70,63 @@
// EhFrame::GeneratedCIE
//===----------------------------------------------------------------------===//
EhFrame::GeneratedCIE::GeneratedCIE(llvm::StringRef pRegion)
- : EhFrame::CIE(pRegion) {
+ : EhFrame::CIE(pRegion) {
}
-EhFrame::GeneratedCIE::~GeneratedCIE()
-{
+EhFrame::GeneratedCIE::~GeneratedCIE() {
}
//===----------------------------------------------------------------------===//
// EhFrame::GeneratedFDE
//===----------------------------------------------------------------------===//
-EhFrame::GeneratedFDE::GeneratedFDE(llvm::StringRef pRegion, CIE &pCIE)
- : EhFrame::FDE(pRegion, pCIE) {
+EhFrame::GeneratedFDE::GeneratedFDE(llvm::StringRef pRegion, CIE& pCIE)
+ : EhFrame::FDE(pRegion, pCIE) {
}
-EhFrame::GeneratedFDE::~GeneratedFDE()
-{
+EhFrame::GeneratedFDE::~GeneratedFDE() {
}
//===----------------------------------------------------------------------===//
// EhFrame
//===----------------------------------------------------------------------===//
-EhFrame::EhFrame()
- : m_pSection(NULL), m_pSectionData(NULL) {
+EhFrame::EhFrame() : m_pSection(NULL), m_pSectionData(NULL) {
}
EhFrame::EhFrame(LDSection& pSection)
- : m_pSection(&pSection),
- m_pSectionData(NULL) {
+ : m_pSection(&pSection), m_pSectionData(NULL) {
m_pSectionData = SectionData::Create(pSection);
}
-EhFrame::~EhFrame()
-{
+EhFrame::~EhFrame() {
}
-EhFrame* EhFrame::Create(LDSection& pSection)
-{
+EhFrame* EhFrame::Create(LDSection& pSection) {
EhFrame* result = g_EhFrameFactory->allocate();
new (result) EhFrame(pSection);
return result;
}
-void EhFrame::Destroy(EhFrame*& pSection)
-{
+void EhFrame::Destroy(EhFrame*& pSection) {
pSection->~EhFrame();
g_EhFrameFactory->deallocate(pSection);
pSection = NULL;
}
-void EhFrame::Clear()
-{
+void EhFrame::Clear() {
g_EhFrameFactory->clear();
}
-const LDSection& EhFrame::getSection() const
-{
- assert(NULL != m_pSection);
+const LDSection& EhFrame::getSection() const {
+ assert(m_pSection != NULL);
return *m_pSection;
}
-LDSection& EhFrame::getSection()
-{
- assert(NULL != m_pSection);
+LDSection& EhFrame::getSection() {
+ assert(m_pSection != NULL);
return *m_pSection;
}
-void EhFrame::addFragment(Fragment& pFrag)
-{
+void EhFrame::addFragment(Fragment& pFrag) {
uint32_t offset = 0;
if (!m_pSectionData->empty())
offset = m_pSectionData->back().getOffset() + m_pSectionData->back().size();
@@ -148,22 +136,19 @@
pFrag.setOffset(offset);
}
-void EhFrame::addCIE(EhFrame::CIE& pCIE, bool pAlsoAddFragment)
-{
+void EhFrame::addCIE(EhFrame::CIE& pCIE, bool pAlsoAddFragment) {
m_CIEs.push_back(&pCIE);
if (pAlsoAddFragment)
addFragment(pCIE);
}
-void EhFrame::addFDE(EhFrame::FDE& pFDE, bool pAlsoAddFragment)
-{
+void EhFrame::addFDE(EhFrame::FDE& pFDE, bool pAlsoAddFragment) {
pFDE.getCIE().add(pFDE);
if (pAlsoAddFragment)
addFragment(pFDE);
}
-size_t EhFrame::numOfFDEs() const
-{
+size_t EhFrame::numOfFDEs() const {
// FDE number only used by .eh_frame_hdr computation, and the number of CIE
// is usually not too many. It is worthy to compromise space by time
size_t size = 0u;
@@ -172,9 +157,8 @@
return size;
}
-EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame)
-{
- assert (this != &pFrame);
+EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame) {
+ assert(this != &pFrame);
if (pFrame.emptyCIEs()) {
// May be a partial linking, or the eh_frame has no data.
// Just append the fragments.
@@ -185,7 +169,9 @@
const LDContext& ctx = *pInput.context();
const LDSection* rel_sec = 0;
for (LDContext::const_sect_iterator ri = ctx.relocSectBegin(),
- re = ctx.relocSectEnd(); ri != re; ++ri) {
+ re = ctx.relocSectEnd();
+ ri != re;
+ ++ri) {
if ((*ri)->getLink() == &pFrame.getSection()) {
rel_sec = *ri;
break;
@@ -221,8 +207,7 @@
return *this;
}
-void EhFrame::setupAttributes(const LDSection* rel_sec)
-{
+void EhFrame::setupAttributes(const LDSection* rel_sec) {
for (cie_iterator i = cie_begin(), e = cie_end(); i != e; ++i) {
CIE* cie = *i;
removeDiscardedFDE(*cie, rel_sec);
@@ -233,16 +218,18 @@
} else {
if (!rel_sec) {
// No relocation to eh_frame section
- assert (cie->getPersonalityName() != "" &&
- "PR name should be a symbol address or offset");
+ assert(cie->getPersonalityName() != "" &&
+ "PR name should be a symbol address or offset");
continue;
}
const RelocData* reloc_data = rel_sec->getRelocData();
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ++ri) {
+ re = reloc_data->end();
+ ri != re;
+ ++ri) {
const Relocation& rel = *ri;
- if (rel.targetRef().getOutputOffset() == cie->getOffset() +
- cie->getPersonalityOffset()) {
+ if (rel.targetRef().getOutputOffset() ==
+ cie->getOffset() + cie->getPersonalityOffset()) {
cie->setMergeable();
cie->setPersonalityName(rel.symInfo()->outSymbol()->name());
cie->setRelocation(rel);
@@ -250,14 +237,13 @@
}
}
- assert (cie->getPersonalityName() != "" &&
- "PR name should be a symbol address or offset");
+ assert(cie->getPersonalityName() != "" &&
+ "PR name should be a symbol address or offset");
}
}
}
-void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
-{
+void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect) {
if (!pRelocSect)
return;
@@ -267,10 +253,12 @@
for (fde_iterator i = pCIE.begin(), e = pCIE.end(); i != e; ++i) {
FDE& fde = **i;
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ++ri) {
+ re = reloc_data->end();
+ ri != re;
+ ++ri) {
const Relocation& rel = *ri;
- if (rel.targetRef().getOutputOffset() == fde.getOffset() +
- getDataStartOffset<32>()) {
+ if (rel.targetRef().getOutputOffset() ==
+ fde.getOffset() + getDataStartOffset<32>()) {
bool has_section = rel.symInfo()->outSymbol()->hasFragRef();
if (!has_section)
// The section was discarded, just ignore this FDE.
@@ -282,7 +270,9 @@
}
for (FDERemoveList::iterator i = to_be_removed_fdes.begin(),
- e = to_be_removed_fdes.end(); i != e; ++i) {
+ e = to_be_removed_fdes.end();
+ i != e;
+ ++i) {
FDE& fde = **i;
fde.getCIE().remove(fde);
@@ -291,7 +281,8 @@
// order, so we can bookkeep the previously found relocation for next use.
// Note: We must ensure FDE order is ordered.
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ) {
+ re = reloc_data->end();
+ ri != re;) {
Relocation& rel = const_cast<Relocation&>(*ri++);
if (rel.targetRef().getOutputOffset() >= fde.getOffset() &&
rel.targetRef().getOutputOffset() < fde.getOffset() + fde.size()) {
@@ -301,9 +292,10 @@
}
}
-void EhFrame::removeAndUpdateCIEForFDE(EhFrame& pInFrame, CIE& pInCIE,
- CIE& pOutCIE, const LDSection* rel_sect)
-{
+void EhFrame::removeAndUpdateCIEForFDE(EhFrame& pInFrame,
+ CIE& pInCIE,
+ CIE& pOutCIE,
+ const LDSection* rel_sect) {
// Make this relocation to be ignored.
Relocation* rel = const_cast<Relocation*>(pInCIE.getRelocation());
if (rel && rel_sect)
@@ -318,8 +310,7 @@
pInCIE.clearFDEs();
}
-void EhFrame::moveInputFragments(EhFrame& pInFrame)
-{
+void EhFrame::moveInputFragments(EhFrame& pInFrame) {
SectionData& in_sd = *pInFrame.getSectionData();
SectionData::FragmentListType& in_frag_list = in_sd.getFragmentList();
SectionData& out_sd = *getSectionData();
@@ -332,9 +323,7 @@
}
}
-void EhFrame::moveInputFragments(EhFrame& pInFrame,
- CIE& pInCIE, CIE* pOutCIE)
-{
+void EhFrame::moveInputFragments(EhFrame& pInFrame, CIE& pInCIE, CIE* pOutCIE) {
SectionData& in_sd = *pInFrame.getSectionData();
SectionData::FragmentListType& in_frag_list = in_sd.getFragmentList();
SectionData& out_sd = *getSectionData();
@@ -354,7 +343,7 @@
}
SectionData::iterator cur_iter(*pOutCIE);
- assert (cur_iter != out_frag_list.end());
+ assert(cur_iter != out_frag_list.end());
for (fde_iterator i = pInCIE.begin(), e = pInCIE.end(); i != e; ++i) {
Fragment* frag = in_frag_list.remove(SectionData::iterator(**i));
cur_iter = out_frag_list.insertAfter(cur_iter, frag);
@@ -362,12 +351,12 @@
}
}
-size_t EhFrame::computeOffsetSize()
-{
+size_t EhFrame::computeOffsetSize() {
size_t offset = 0u;
- SectionData::FragmentListType& frag_list = getSectionData()->getFragmentList();
- for (SectionData::iterator i = frag_list.begin(), e = frag_list.end();
- i != e; ++i) {
+ SectionData::FragmentListType& frag_list =
+ getSectionData()->getFragmentList();
+ for (SectionData::iterator i = frag_list.begin(), e = frag_list.end(); i != e;
+ ++i) {
Fragment& frag = *i;
frag.setOffset(offset);
offset += frag.size();
@@ -376,8 +365,9 @@
return offset;
}
-bool mcld::operator==(const EhFrame::CIE& p1, const EhFrame::CIE& p2)
-{
+bool operator==(const EhFrame::CIE& p1, const EhFrame::CIE& p2) {
return p1.getPersonalityName() == p2.getPersonalityName() &&
p1.getAugmentationData() == p2.getAugmentationData();
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrameHdr.cpp b/lib/LD/EhFrameHdr.cpp
index 74516d1..50e8cad 100644
--- a/lib/LD/EhFrameHdr.cpp
+++ b/lib/LD/EhFrameHdr.cpp
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/EhFrameHdr.h>
+#include "mcld/LD/EhFrameHdr.h"
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/LDSection.h>
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
#include <llvm/Support/Dwarf.h>
#include <llvm/Support/DataTypes.h>
@@ -17,8 +17,7 @@
#include <algorithm>
#include <cstring>
-using namespace mcld;
-using namespace llvm::dwarf;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Function
@@ -27,62 +26,64 @@
typedef std::pair<SizeTraits<32>::Address, SizeTraits<32>::Address> Entry;
-bool EntryCompare(const Entry& pX, const Entry& pY)
-{ return (pX.first < pY.first); }
+bool EntryCompare(const Entry& pX, const Entry& pY) {
+ return (pX.first < pY.first);
+}
-} // bit32 namespace
+} // namespace bit32
//===----------------------------------------------------------------------===//
// Template Specification Functions
//===----------------------------------------------------------------------===//
/// emitOutput<32> - write out eh_frame_hdr
-template<>
-void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput)
-{
- MemoryRegion ehframehdr_region = pOutput.request(m_EhFrameHdr.offset(),
- m_EhFrameHdr.size());
+template <>
+void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput) {
+ MemoryRegion ehframehdr_region =
+ pOutput.request(m_EhFrameHdr.offset(), m_EhFrameHdr.size());
- MemoryRegion ehframe_region = pOutput.request(m_EhFrame.offset(),
- m_EhFrame.size());
+ MemoryRegion ehframe_region =
+ pOutput.request(m_EhFrame.offset(), m_EhFrame.size());
uint8_t* data = ehframehdr_region.begin();
// version
data[0] = 1;
// eh_frame_ptr_enc
- data[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;
+ data[1] = llvm::dwarf::DW_EH_PE_pcrel | llvm::dwarf::DW_EH_PE_sdata4;
// eh_frame_ptr
- uint32_t* eh_frame_ptr = (uint32_t*)(data + 4);
+ uint32_t* eh_frame_ptr = reinterpret_cast<uint32_t*>(data + 4);
*eh_frame_ptr = m_EhFrame.addr() - (m_EhFrameHdr.addr() + 4);
// fde_count
- uint32_t* fde_count = (uint32_t*)(data + 8);
+ uint32_t* fde_count = reinterpret_cast<uint32_t*>(data + 8);
if (m_EhFrame.hasEhFrame())
*fde_count = m_EhFrame.getEhFrame()->numOfFDEs();
else
*fde_count = 0;
- if (0 == *fde_count) {
+ if (*fde_count == 0) {
// fde_count_enc
- data[2] = DW_EH_PE_omit;
+ data[2] = llvm::dwarf::DW_EH_PE_omit;
// table_enc
- data[3] = DW_EH_PE_omit;
- }
- else {
+ data[3] = llvm::dwarf::DW_EH_PE_omit;
+ } else {
// fde_count_enc
- data[2] = DW_EH_PE_udata4;
+ data[2] = llvm::dwarf::DW_EH_PE_udata4;
// table_enc
- data[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4;
+ data[3] = llvm::dwarf::DW_EH_PE_datarel | llvm::dwarf::DW_EH_PE_sdata4;
// prepare the binary search table
typedef std::vector<bit32::Entry> SearchTableType;
SearchTableType search_table;
for (EhFrame::const_cie_iterator i = m_EhFrame.getEhFrame()->cie_begin(),
- e = m_EhFrame.getEhFrame()->cie_end(); i != e; ++i) {
+ e = m_EhFrame.getEhFrame()->cie_end();
+ i != e;
+ ++i) {
EhFrame::CIE& cie = **i;
for (EhFrame::const_fde_iterator fi = cie.begin(), fe = cie.end();
- fi != fe; ++fi) {
+ fi != fe;
+ ++fi) {
EhFrame::FDE& fde = **fi;
SizeTraits<32>::Offset offset;
SizeTraits<32>::Address fde_pc;
@@ -97,7 +98,7 @@
std::sort(search_table.begin(), search_table.end(), bit32::EntryCompare);
// write out the binary search table
- uint32_t* bst = (uint32_t*)(data + 12);
+ uint32_t* bst = reinterpret_cast<uint32_t*>(data + 12);
SearchTableType::const_iterator entry, entry_end = search_table.end();
size_t id = 0;
for (entry = search_table.begin(); entry != entry_end; ++entry) {
@@ -112,11 +113,10 @@
//===----------------------------------------------------------------------===//
EhFrameHdr::EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame)
- : m_EhFrameHdr(pEhFrameHdr), m_EhFrame(pEhFrame) {
+ : m_EhFrameHdr(pEhFrameHdr), m_EhFrame(pEhFrame) {
}
-EhFrameHdr::~EhFrameHdr()
-{
+EhFrameHdr::~EhFrameHdr() {
}
/// @ref lsb core generic 4.1
@@ -130,8 +130,7 @@
/// __________________________ when fde_count > 0
/// <uint32_t, uint32_t>+ : binary search table
/// sizeOutput - base on the fde count to size output
-void EhFrameHdr::sizeOutput()
-{
+void EhFrameHdr::sizeOutput() {
size_t size = 12;
if (m_EhFrame.hasEhFrame())
size += 8 * m_EhFrame.getEhFrame()->numOfFDEs();
@@ -139,27 +138,25 @@
}
/// computePCBegin - return the address of FDE's pc
-/// @ref binutils gold: ehframe.cc:222
uint32_t EhFrameHdr::computePCBegin(const EhFrame::FDE& pFDE,
- const MemoryRegion& pEhFrameRegion)
-{
+ const MemoryRegion& pEhFrameRegion) {
uint8_t fde_encoding = pFDE.getCIE().getFDEEncode();
unsigned int eh_value = fde_encoding & 0x7;
// check the size to read in
if (eh_value == llvm::dwarf::DW_EH_PE_absptr) {
- eh_value = DW_EH_PE_udata4;
+ eh_value = llvm::dwarf::DW_EH_PE_udata4;
}
size_t pc_size = 0x0;
switch (eh_value) {
- case DW_EH_PE_udata2:
+ case llvm::dwarf::DW_EH_PE_udata2:
pc_size = 2;
break;
- case DW_EH_PE_udata4:
+ case llvm::dwarf::DW_EH_PE_udata4:
pc_size = 4;
break;
- case DW_EH_PE_udata8:
+ case llvm::dwarf::DW_EH_PE_udata8:
pc_size = 8;
break;
default:
@@ -168,26 +165,24 @@
}
SizeTraits<32>::Address pc = 0x0;
- const uint8_t* offset = (const uint8_t*) pEhFrameRegion.begin() +
- pFDE.getOffset() +
- EhFrame::getDataStartOffset<32>();
+ const uint8_t* offset = (const uint8_t*)pEhFrameRegion.begin() +
+ pFDE.getOffset() + EhFrame::getDataStartOffset<32>();
std::memcpy(&pc, offset, pc_size);
// adjust the signed value
bool is_signed = (fde_encoding & llvm::dwarf::DW_EH_PE_signed) != 0x0;
- if (DW_EH_PE_udata2 == eh_value && is_signed)
+ if (llvm::dwarf::DW_EH_PE_udata2 == eh_value && is_signed)
pc = (pc ^ 0x8000) - 0x8000;
// handle eh application
- switch (fde_encoding & 0x70)
- {
- case DW_EH_PE_absptr:
+ switch (fde_encoding & 0x70) {
+ case llvm::dwarf::DW_EH_PE_absptr:
break;
- case DW_EH_PE_pcrel:
+ case llvm::dwarf::DW_EH_PE_pcrel:
pc += m_EhFrame.addr() + pFDE.getOffset() +
- EhFrame::getDataStartOffset<32>();
+ EhFrame::getDataStartOffset<32>();
break;
- case DW_EH_PE_datarel:
+ case llvm::dwarf::DW_EH_PE_datarel:
// TODO
break;
default:
@@ -196,3 +191,5 @@
}
return pc;
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrameReader.cpp b/lib/LD/EhFrameReader.cpp
index 49950a0..383c1ee 100644
--- a/lib/LD/EhFrameReader.cpp
+++ b/lib/LD/EhFrameReader.cpp
@@ -6,20 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/EhFrameReader.h>
+#include "mcld/LD/EhFrameReader.h"
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Dwarf.h>
#include <llvm/Support/LEB128.h>
-using namespace mcld;
-using namespace llvm::dwarf;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Functions
@@ -27,12 +26,10 @@
/// skip_LEB128 - skip the first LEB128 encoded value from *pp, update *pp
/// to the next character.
/// @return - false if we ran off the end of the string.
-/// @ref - GNU gold 1.11, ehframe.h, Eh_frame::skip_leb128.
-static bool
-skip_LEB128(EhFrameReader::ConstAddress* pp, EhFrameReader::ConstAddress pend)
-{
+static bool skip_LEB128(EhFrameReader::ConstAddress* pp,
+ EhFrameReader::ConstAddress pend) {
for (EhFrameReader::ConstAddress p = *pp; p < pend; ++p) {
- if (0x0 == (*p & 0x80)) {
+ if ((*p & 0x80) == 0x0) {
*pp = p + 1;
return true;
}
@@ -43,11 +40,10 @@
//===----------------------------------------------------------------------===//
// EhFrameReader
//===----------------------------------------------------------------------===//
-template<> EhFrameReader::Token
-EhFrameReader::scan<true>(ConstAddress pHandler,
- uint64_t pOffset,
- llvm::StringRef pData) const
-{
+template <>
+EhFrameReader::Token EhFrameReader::scan<true>(ConstAddress pHandler,
+ uint64_t pOffset,
+ llvm::StringRef pData) const {
Token result;
result.file_off = pOffset;
@@ -56,7 +52,7 @@
// Length Field
uint32_t length = data[cur_idx++];
- if (0x0 == length) {
+ if (length == 0x0) {
// terminator
result.kind = Terminator;
result.data_off = 4;
@@ -66,23 +62,22 @@
// Extended Field
uint64_t extended = 0x0;
- if (0xFFFFFFFF == length) {
+ if (length == 0xFFFFFFFF) {
extended = data[cur_idx++];
extended <<= 32;
extended |= data[cur_idx++];
result.size = extended + 12;
result.data_off = 16;
// 64-bit obj file still uses 32-bit eh_frame.
- assert (false && "We don't support 64-bit eh_frame.");
- }
- else {
+ assert(false && "We don't support 64-bit eh_frame.");
+ } else {
result.size = length + 4;
result.data_off = 8;
}
// ID Field
uint32_t ID = data[cur_idx++];
- if (0x0 == ID)
+ if (ID == 0x0)
result.kind = CIE;
else
result.kind = FDE;
@@ -90,9 +85,8 @@
return result;
}
-template<>
-bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
-{
+template <>
+bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame) {
// Alphabet:
// {CIE, FDE, CIEt}
//
@@ -112,15 +106,15 @@
// +-----------------------+
// CIEt
const State autometa[NumOfStates][NumOfTokenKinds] = {
- // CIE FDE Term Unknown
- { Q1, Reject, Accept, Reject }, // Q0
- { Q1, Q1, Accept, Reject }, // Q1
+ // CIE FDE Term Unknown
+ {Q1, Reject, Accept, Reject}, // Q0
+ {Q1, Q1, Accept, Reject}, // Q1
};
const Action transition[NumOfStates][NumOfTokenKinds] = {
- /* CIE FDE Term Unknown */
- { addCIE, reject, addTerm, reject}, // Q0
- { addCIE, addFDE, addTerm, reject}, // Q1
+ /* CIE FDE Term Unknown */
+ {addCIE, reject, addTerm, reject}, // Q0
+ {addCIE, addFDE, addTerm, reject}, // Q1
};
LDSection& section = pEhFrame.getSection();
@@ -138,9 +132,9 @@
State cur_state = Q0;
while (Reject != cur_state && Accept != cur_state) {
-
Token token = scan<true>(handler, file_off, sect_reg);
- llvm::StringRef entry = pInput.memArea()->request(token.file_off, token.size);
+ llvm::StringRef entry =
+ pInput.memArea()->request(token.file_off, token.size);
if (!transition[cur_state][token.kind](pEhFrame, entry, token)) {
// fail to scan
@@ -151,14 +145,14 @@
file_off += token.size;
handler += token.size;
- if (handler == sect_reg.end())
+ if (handler == sect_reg.end()) {
cur_state = Accept;
- else if (handler > sect_reg.end()) {
+ } else if (handler > sect_reg.end()) {
cur_state = Reject;
- }
- else
+ } else {
cur_state = autometa[cur_state][token.kind];
- } // end of while
+ }
+ } // end of while
if (Reject == cur_state) {
// fail to parse
@@ -170,8 +164,7 @@
bool EhFrameReader::addCIE(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
// skip Length, Extended Length and CIE ID.
ConstAddress handler = pRegion.begin() + pToken.data_off;
ConstAddress cie_end = pRegion.end();
@@ -180,15 +173,15 @@
// the version should be 1 or 3
uint8_t version = *handler++;
- if (1 != version && 3 != version) {
+ if (version != 1 && version != 3) {
return false;
}
// Set up the Augumentation String
ConstAddress aug_str_front = handler;
- ConstAddress aug_str_back = static_cast<ConstAddress>(
- memchr(aug_str_front, '\0', cie_end - aug_str_front));
- if (NULL == aug_str_back) {
+ ConstAddress aug_str_back = static_cast<ConstAddress>(
+ memchr(aug_str_front, '\0', cie_end - aug_str_front));
+ if (aug_str_back == NULL) {
return false;
}
@@ -212,7 +205,7 @@
llvm::StringRef augment((const char*)aug_str_front);
// we discard this CIE if the augumentation string is '\0'
- if (0 == augment.size()) {
+ if (augment.size() == 0) {
EhFrame::CIE* cie = new EhFrame::CIE(pRegion);
cie->setFDEEncode(llvm::dwarf::DW_EH_PE_absptr);
pEhFrame.addCIE(*cie);
@@ -230,7 +223,7 @@
uint8_t fde_encoding = llvm::dwarf::DW_EH_PE_absptr;
std::string augdata;
std::string pr_ptr_data;
- if ('z' == augment[0]) {
+ if (augment[0] == 'z') {
unsigned offset;
size_t augdata_size = llvm::decodeULEB128((const uint8_t*)handler, &offset);
handler += offset;
@@ -259,7 +252,7 @@
++handler;
// get the length of the second argument
uint32_t per_length = 0;
- if (0x60 == (per_encode & 0x60)) {
+ if ((per_encode & 0x60) == 0x60) {
return false;
}
switch (per_encode & 7) {
@@ -275,14 +268,14 @@
per_length = 8;
break;
case llvm::dwarf::DW_EH_PE_absptr:
- per_length = 4; // pPkg.bitclass / 8;
+ per_length = 4; // pPkg.bitclass / 8;
break;
}
// skip the alignment
if (llvm::dwarf::DW_EH_PE_aligned == (per_encode & 0xf0)) {
uint32_t per_align = handler - cie_end;
per_align += per_length - 1;
- per_align &= ~(per_length -1);
+ per_align &= ~(per_length - 1);
if (static_cast<uint32_t>(cie_end - handler) < per_align) {
return false;
}
@@ -296,7 +289,7 @@
pr_ptr_data = std::string((const char*)handler, per_length);
handler += per_length;
break;
- } // end of case 'P'
+ } // end of case 'P'
// FDE encoding (1 byte)
case 'R': {
@@ -318,9 +311,9 @@
}
default:
return false;
- } // end switch
- } // the rest chars.
- } // first char is 'z'
+ } // end switch
+ } // the rest chars.
+ } // first char is 'z'
// create and push back the CIE entry
EhFrame::CIE* cie = new EhFrame::CIE(pRegion);
@@ -335,15 +328,14 @@
bool EhFrameReader::addFDE(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
if (pToken.data_off == pRegion.size())
return false;
- const int32_t offset = *(const int32_t*) (pRegion.begin() + pToken.data_off
- - 4);
- size_t cie_offset = (size_t) ((int64_t) (pToken.file_off + 4) -
- (int32_t) offset);
+ const int32_t offset =
+ *(const int32_t*)(pRegion.begin() + pToken.data_off - 4);
+ size_t cie_offset =
+ (size_t)((int64_t)(pToken.file_off + 4) - (int32_t)offset);
EhFrame::CIEMap::iterator iter = pEhFrame.getCIEMap().find(cie_offset);
if (iter == pEhFrame.getCIEMap().end())
@@ -357,14 +349,14 @@
bool EhFrameReader::addTerm(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
return true;
}
bool EhFrameReader::reject(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/GNUArchiveReader.cpp b/lib/LD/GNUArchiveReader.cpp
index 4553bfb..f9e4d51 100644
--- a/lib/LD/GNUArchiveReader.cpp
+++ b/lib/LD/GNUArchiveReader.cpp
@@ -6,44 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/GNUArchiveReader.h>
+#include "mcld/LD/GNUArchiveReader.h"
-#include <mcld/Module.h>
-#include <mcld/InputTree.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/ELFObjectReader.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/Path.h>
-#include <mcld/ADT/SizeTraits.h>
+#include "mcld/InputTree.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/ELFObjectReader.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Host.h>
-#include <cstring>
#include <cstdlib>
+#include <cstring>
-using namespace mcld;
+namespace mcld {
GNUArchiveReader::GNUArchiveReader(Module& pModule,
ELFObjectReader& pELFObjectReader)
- : m_Module(pModule),
- m_ELFObjectReader(pELFObjectReader)
-{
+ : m_Module(pModule), m_ELFObjectReader(pELFObjectReader) {
}
-GNUArchiveReader::~GNUArchiveReader()
-{
+GNUArchiveReader::~GNUArchiveReader() {
}
/// isMyFormat
-bool GNUArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool GNUArchiveReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
if (pInput.memArea()->size() < Archive::MAGIC_LEN)
return false;
@@ -53,7 +49,7 @@
const char* str = region.begin();
bool result = false;
- assert(NULL != str);
+ assert(str != NULL);
pContinue = true;
if (isArchive(str) || isThinArchive(str))
result = true;
@@ -62,27 +58,24 @@
}
/// isArchive
-bool GNUArchiveReader::isArchive(const char* pStr) const
-{
- return (0 == memcmp(pStr, Archive::MAGIC, Archive::MAGIC_LEN));
+bool GNUArchiveReader::isArchive(const char* pStr) const {
+ return (memcmp(pStr, Archive::MAGIC, Archive::MAGIC_LEN) == 0);
}
/// isThinArchive
-bool GNUArchiveReader::isThinArchive(const char* pStr) const
-{
- return (0 == memcmp(pStr, Archive::THIN_MAGIC, Archive::MAGIC_LEN));
+bool GNUArchiveReader::isThinArchive(const char* pStr) const {
+ return (memcmp(pStr, Archive::THIN_MAGIC, Archive::MAGIC_LEN) == 0);
}
/// isThinArchive
-bool GNUArchiveReader::isThinArchive(Input& pInput) const
-{
+bool GNUArchiveReader::isThinArchive(Input& pInput) const {
assert(pInput.hasMemArea());
llvm::StringRef region =
pInput.memArea()->request(pInput.fileOffset(), Archive::MAGIC_LEN);
const char* str = region.begin();
bool result = false;
- assert(NULL != str);
+ assert(str != NULL);
if (isThinArchive(str))
result = true;
@@ -90,8 +83,7 @@
}
bool GNUArchiveReader::readArchive(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// bypass the empty archive
if (Archive::MAGIC_LEN == pArchive.getARFile().memArea()->size())
return true;
@@ -101,16 +93,16 @@
// if this is the first time read this archive, setup symtab and strtab
if (pArchive.getSymbolTable().empty()) {
- // read the symtab of the archive
- readSymbolTable(pArchive);
+ // read the symtab of the archive
+ readSymbolTable(pArchive);
- // read the strtab of the archive
- readStringTable(pArchive);
+ // read the strtab of the archive
+ readStringTable(pArchive);
- // add root archive to ArchiveMemberMap
- pArchive.addArchiveMember(pArchive.getARFile().name(),
- pArchive.inputs().root(),
- &InputTree::Downward);
+ // add root archive to ArchiveMemberMap
+ pArchive.addArchiveMember(pArchive.getARFile().name(),
+ pArchive.inputs().root(),
+ &InputTree::Downward);
}
// include the needed members in the archive and build up the input tree
@@ -130,7 +122,7 @@
// check if we should include this defined symbol
Archive::Symbol::Status status =
- shouldIncludeSymbol(pArchive.getSymbolName(idx));
+ shouldIncludeSymbol(pArchive.getSymbolName(idx));
if (Archive::Symbol::Unknown != status)
pArchive.setSymbolStatus(idx, status);
@@ -138,8 +130,8 @@
// include the object member from the given offset
includeMember(pConfig, pArchive, pArchive.getObjFileOffset(idx));
willSymResolved = true;
- } // end of if
- } // end of for
+ } // end of if
+ } // end of for
} while (willSymResolved);
return true;
@@ -158,29 +150,27 @@
Input& pArchiveFile,
uint32_t pFileOffset,
uint32_t& pNestedOffset,
- size_t& pMemberSize)
-{
+ size_t& pMemberSize) {
assert(pArchiveFile.hasMemArea());
- llvm::StringRef header_region =
- pArchiveFile.memArea()->request((pArchiveFile.fileOffset() + pFileOffset),
- sizeof(Archive::MemberHeader));
+ llvm::StringRef header_region = pArchiveFile.memArea()->request(
+ (pArchiveFile.fileOffset() + pFileOffset), sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
pMemberSize = atoi(header->size);
// parse the member name and nested offset if any
std::string member_name;
llvm::StringRef name_field(header->name, sizeof(header->name));
- if ('/' != header->name[0]) {
+ if (header->name[0] != '/') {
// this is an object file in an archive
size_t pos = name_field.find_first_of('/');
member_name.assign(name_field.substr(0, pos).str());
- }
- else {
+ } else {
// this is an object/archive file in a thin archive
size_t begin = 1;
size_t end = name_field.find_first_of(" :");
@@ -188,7 +178,7 @@
// parse the name offset
name_field.substr(begin, end - begin).getAsInteger(10, name_offset);
- if (':' == name_field[end]) {
+ if (name_field[end] == ':') {
// there is a nested offset
begin = end + 1;
end = name_field.find_first_of(' ', begin);
@@ -199,26 +189,26 @@
assert(pArchiveRoot.hasStrTable());
begin = name_offset;
end = pArchiveRoot.getStrTable().find_first_of('\n', begin);
- member_name.assign(pArchiveRoot.getStrTable().substr(begin, end - begin -1));
+ member_name.assign(
+ pArchiveRoot.getStrTable().substr(begin, end - begin - 1));
}
Input* member = NULL;
bool isThinAR = isThinArchive(pArchiveFile);
if (!isThinAR) {
// this is an object file in an archive
- member = pArchiveRoot.getMemberFile(pArchiveFile,
- isThinAR,
- member_name,
- pArchiveFile.path(),
- (pFileOffset +
- sizeof(Archive::MemberHeader)));
- }
- else {
+ member = pArchiveRoot.getMemberFile(
+ pArchiveFile,
+ isThinAR,
+ member_name,
+ pArchiveFile.path(),
+ (pFileOffset + sizeof(Archive::MemberHeader)));
+ } else {
// this is a member in a thin archive
// try to find if this is a archive already in the map first
Archive::ArchiveMember* ar_member =
- pArchiveRoot.getArchiveMember(member_name);
- if (NULL != ar_member) {
+ pArchiveRoot.getArchiveMember(member_name);
+ if (ar_member != NULL) {
return ar_member->file;
}
@@ -226,22 +216,20 @@
// path to the archive containing it.
sys::fs::Path input_path(pArchiveFile.path().parent_path());
if (!input_path.empty())
- input_path.append(member_name);
+ input_path.append(sys::fs::Path(member_name));
else
input_path.assign(member_name);
- member = pArchiveRoot.getMemberFile(pArchiveFile,
- isThinAR,
- member_name,
- input_path);
+ member = pArchiveRoot.getMemberFile(
+ pArchiveFile, isThinAR, member_name, input_path);
}
return member;
}
template <size_t SIZE>
-static void readSymbolTableEntries(Archive& pArchive, llvm::StringRef pMemRegion)
-{
+static void readSymbolTableEntries(Archive& pArchive,
+ llvm::StringRef pMemRegion) {
typedef typename SizeTraits<SIZE>::Offset Offset;
const Offset* data = reinterpret_cast<const Offset*>(pMemRegion.begin());
@@ -269,70 +257,68 @@
}
/// readSymbolTable - read the archive symbol map (armap)
-bool GNUArchiveReader::readSymbolTable(Archive& pArchive)
-{
+bool GNUArchiveReader::readSymbolTable(Archive& pArchive) {
assert(pArchive.getARFile().hasMemArea());
+ MemoryArea* memory_area = pArchive.getARFile().memArea();
- llvm::StringRef header_region =
- pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN),
- sizeof(Archive::MemberHeader));
+ llvm::StringRef header_region = memory_area->request(
+ (pArchive.getARFile().fileOffset() + Archive::MAGIC_LEN),
+ sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
int symtab_size = atoi(header->size);
pArchive.setSymTabSize(symtab_size);
if (!pArchive.getARFile().attribute()->isWholeArchive()) {
- llvm::StringRef symtab_region = pArchive.getARFile().memArea()->request(
- (pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN +
+ llvm::StringRef symtab_region = memory_area->request(
+ (pArchive.getARFile().fileOffset() + Archive::MAGIC_LEN +
sizeof(Archive::MemberHeader)),
symtab_size);
- if (0 == strncmp(header->name, Archive::SVR4_SYMTAB_NAME,
- strlen(Archive::SVR4_SYMTAB_NAME)))
+ if (strncmp(header->name,
+ Archive::SVR4_SYMTAB_NAME,
+ strlen(Archive::SVR4_SYMTAB_NAME)) == 0)
readSymbolTableEntries<32>(pArchive, symtab_region);
- else if (0 == strncmp(header->name, Archive::IRIX6_SYMTAB_NAME,
- strlen(Archive::IRIX6_SYMTAB_NAME)))
+ else if (strncmp(header->name,
+ Archive::IRIX6_SYMTAB_NAME,
+ strlen(Archive::IRIX6_SYMTAB_NAME)) == 0)
readSymbolTableEntries<64>(pArchive, symtab_region);
else
unreachable(diag::err_unsupported_archive);
-
}
return true;
}
/// readStringTable - read the strtab for long file name of the archive
-bool GNUArchiveReader::readStringTable(Archive& pArchive)
-{
- size_t offset = Archive::MAGIC_LEN +
- sizeof(Archive::MemberHeader) +
+bool GNUArchiveReader::readStringTable(Archive& pArchive) {
+ size_t offset = Archive::MAGIC_LEN + sizeof(Archive::MemberHeader) +
pArchive.getSymTabSize();
- if (0x0 != (offset & 1))
+ if ((offset & 1) != 0x0)
++offset;
assert(pArchive.getARFile().hasMemArea());
+ MemoryArea* memory_area = pArchive.getARFile().memArea();
llvm::StringRef header_region =
- pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
- offset),
- sizeof(Archive::MemberHeader));
+ memory_area->request((pArchive.getARFile().fileOffset() + offset),
+ sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
- if (0 == memcmp(header->name, Archive::STRTAB_NAME, sizeof(header->name))) {
+ if (memcmp(header->name, Archive::STRTAB_NAME, sizeof(header->name)) == 0) {
// read the extended name table
int strtab_size = atoi(header->size);
llvm::StringRef strtab_region =
- pArchive.getARFile().memArea()->request(
- (pArchive.getARFile().fileOffset() +
- offset + sizeof(Archive::MemberHeader)),
- strtab_size);
+ memory_area->request((pArchive.getARFile().fileOffset() + offset +
+ sizeof(Archive::MemberHeader)),
+ strtab_size);
const char* strtab = strtab_region.begin();
pArchive.getStrTable().assign(strtab, strtab_size);
}
@@ -341,12 +327,11 @@
/// shouldIncludeStatus - given a sym name from armap and check if including
/// the corresponding archive member, and then return the decision
-enum Archive::Symbol::Status
-GNUArchiveReader::shouldIncludeSymbol(const llvm::StringRef& pSymName) const
-{
+enum Archive::Symbol::Status GNUArchiveReader::shouldIncludeSymbol(
+ const llvm::StringRef& pSymName) const {
// TODO: handle symbol version issue and user defined symbols
const ResolveInfo* info = m_Module.getNamePool().findInfo(pSymName);
- if (NULL != info) {
+ if (info != NULL) {
if (!info->isUndef())
return Archive::Symbol::Exclude;
if (info->isWeak())
@@ -363,8 +348,7 @@
/// @param pFileOffset - file offset of the member header in the archive
size_t GNUArchiveReader::includeMember(const LinkerConfig& pConfig,
Archive& pArchive,
- uint32_t pFileOffset)
-{
+ uint32_t pFileOffset) {
Input* cur_archive = &(pArchive.getARFile());
Input* member = NULL;
uint32_t file_offset = pFileOffset;
@@ -373,24 +357,21 @@
uint32_t nested_offset = 0;
// use the file offset in current archive to find out the member we
// want to include
- member = readMemberHeader(pArchive,
- *cur_archive,
- file_offset,
- nested_offset,
- size);
+ member = readMemberHeader(
+ pArchive, *cur_archive, file_offset, nested_offset, size);
assert(member != NULL);
// bypass if we get an archive that is already in the map
if (Input::Archive == member->type()) {
- cur_archive = member;
- file_offset = nested_offset;
- continue;
+ cur_archive = member;
+ file_offset = nested_offset;
+ continue;
}
// insert a node into the subtree of current archive.
Archive::ArchiveMember* parent =
- pArchive.getArchiveMember(cur_archive->name());
+ pArchive.getArchiveMember(cur_archive->name());
- assert(NULL != parent);
+ assert(parent != NULL);
pArchive.inputs().insert(parent->lastPos, *(parent->move), *member);
// move the iterator to new created node, and also adjust the
@@ -410,20 +391,17 @@
m_ELFObjectReader.readSections(*member);
m_ELFObjectReader.readSymbols(*member);
m_Module.getObjectList().push_back(member);
- }
- else if (doContinue && isMyFormat(*member, doContinue)) {
+ } else if (doContinue && isMyFormat(*member, doContinue)) {
member->setType(Input::Archive);
// when adding a new archive node, set the iterator to archive
// itself, and set the direction to Downward
- pArchive.addArchiveMember(member->name(),
- parent->lastPos,
- &InputTree::Downward);
+ pArchive.addArchiveMember(
+ member->name(), parent->lastPos, &InputTree::Downward);
cur_archive = member;
file_offset = nested_offset;
- }
- else {
- warning(diag::warn_unrecognized_input_file) << member->path()
- << pConfig.targets().triple().str();
+ } else {
+ warning(diag::warn_unrecognized_input_file)
+ << member->path() << pConfig.targets().triple().str();
}
} while (Input::Object != member->type());
return size;
@@ -432,8 +410,7 @@
/// includeAllMembers - include all object members. This is called if
/// --whole-archive is the attribute for this archive file.
bool GNUArchiveReader::includeAllMembers(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// read the symtab of the archive
readSymbolTable(pArchive);
@@ -447,28 +424,27 @@
bool isThinAR = isThinArchive(pArchive.getARFile());
uint32_t begin_offset = pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN +
- sizeof(Archive::MemberHeader) +
+ Archive::MAGIC_LEN + sizeof(Archive::MemberHeader) +
pArchive.getSymTabSize();
if (pArchive.hasStrTable()) {
- if (0x0 != (begin_offset & 1))
+ if ((begin_offset & 1) != 0x0)
++begin_offset;
- begin_offset += sizeof(Archive::MemberHeader) +
- pArchive.getStrTable().size();
+ begin_offset +=
+ sizeof(Archive::MemberHeader) + pArchive.getStrTable().size();
}
uint32_t end_offset = pArchive.getARFile().memArea()->size();
- for (uint32_t offset = begin_offset;
- offset < end_offset;
+ for (uint32_t offset = begin_offset; offset < end_offset;
offset += sizeof(Archive::MemberHeader)) {
-
size_t size = includeMember(pConfig, pArchive, offset);
if (!isThinAR) {
offset += size;
}
- if (0x0 != (offset & 1))
+ if ((offset & 1) != 0x0)
++offset;
}
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/GarbageCollection.cpp b/lib/LD/GarbageCollection.cpp
index 44c9b5a..b36f7ee 100644
--- a/lib/LD/GarbageCollection.cpp
+++ b/lib/LD/GarbageCollection.cpp
@@ -6,34 +6,35 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/GarbageCollection.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/LD/GarbageCollection.h"
+
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Casting.h>
#include <queue>
#if !defined(MCLD_ON_WIN32)
#include <fnmatch.h>
-#define fnmatch0(pattern,string) (fnmatch(pattern,string,0) == 0)
+#define fnmatch0(pattern, string) (fnmatch(pattern, string, 0) == 0)
#else
#include <windows.h>
#include <shlwapi.h>
-#define fnmatch0(pattern,string) (PathMatchSpec(string, pattern) == true)
+#define fnmatch0(pattern, string) (PathMatchSpec(string, pattern) == true)
#endif
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Non-member functions
@@ -41,20 +42,16 @@
// FIXME: these rules should be added into SectionMap, while currently adding to
// SectionMap will cause the output order change in .text section and leads to
// the .ARM.exidx order incorrect. We should sort the .ARM.exidx.
-static const char* pattern_to_keep[] =
-{
- ".text*personality*",
- ".data*personality*",
- ".gnu.linkonce.d*personality*",
- ".sdata*personality*"
-};
+static const char* pattern_to_keep[] = {".text*personality*",
+ ".data*personality*",
+ ".gnu.linkonce.d*personality*",
+ ".sdata*personality*"};
/// shouldKeep - check the section name for the keep sections
-static bool shouldKeep(const std::string& pName)
-{
+static bool shouldKeep(const std::string& pName) {
static const unsigned int pattern_size =
- sizeof(pattern_to_keep) / sizeof(pattern_to_keep[0]);
- for (unsigned int i=0; i < pattern_size; ++i) {
+ sizeof(pattern_to_keep) / sizeof(pattern_to_keep[0]);
+ for (unsigned int i = 0; i < pattern_size; ++i) {
if (fnmatch0(pattern_to_keep[i], pName.c_str()))
return true;
}
@@ -62,8 +59,7 @@
}
/// shouldProcessGC - check if the section kind is handled in GC
-static bool mayProcessGC(const LDSection& pSection)
-{
+static bool mayProcessGC(const LDSection& pSection) {
if (pSection.kind() == LDFileFormat::TEXT ||
pSection.kind() == LDFileFormat::DATA ||
pSection.kind() == LDFileFormat::BSS ||
@@ -75,24 +71,21 @@
//===----------------------------------------------------------------------===//
// GarbageCollection::SectionReachedListMap
//===----------------------------------------------------------------------===//
-void
-GarbageCollection::SectionReachedListMap::addReference(const LDSection& pFrom,
- const LDSection& pTo)
-{
+void GarbageCollection::SectionReachedListMap::addReference(
+ const LDSection& pFrom,
+ const LDSection& pTo) {
m_ReachedSections[&pFrom].insert(&pTo);
}
GarbageCollection::SectionListTy&
GarbageCollection::SectionReachedListMap::getReachedList(
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
return m_ReachedSections[&pSection];
}
GarbageCollection::SectionListTy*
GarbageCollection::SectionReachedListMap::findReachedList(
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ReachedSectionsTy::iterator it = m_ReachedSections.find(&pSection);
if (it == m_ReachedSections.end())
return NULL;
@@ -105,16 +98,13 @@
GarbageCollection::GarbageCollection(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule)
- : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule)
-{
+ : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule) {
}
-GarbageCollection::~GarbageCollection()
-{
+GarbageCollection::~GarbageCollection() {
}
-bool GarbageCollection::run()
-{
+bool GarbageCollection::run() {
// 1. traverse all the relocations to set up the reached sections of each
// section
setUpReachedSections();
@@ -132,8 +122,7 @@
return true;
}
-void GarbageCollection::setUpReachedSections()
-{
+void GarbageCollection::setUpReachedSections() {
// traverse all the input relocations to setup the reached sections
Module::obj_iterator input, inEnd = m_Module.obj_end();
for (input = m_Module.obj_begin(); input != inEnd; ++input) {
@@ -158,12 +147,12 @@
SectionListTy* reached_sects = NULL;
RelocData::iterator reloc_it, rEnd = reloc_sect->getRelocData()->end();
for (reloc_it = reloc_sect->getRelocData()->begin(); reloc_it != rEnd;
- ++reloc_it) {
+ ++reloc_it) {
Relocation* reloc = llvm::cast<Relocation>(reloc_it);
ResolveInfo* sym = reloc->symInfo();
// only the target symbols defined in the input fragments can make the
// reference
- if (NULL == sym)
+ if (sym == NULL)
continue;
if (!sym->isDefine() || !sym->outSymbol()->hasFragRef())
continue;
@@ -171,7 +160,7 @@
// only the target symbols defined in the concerned sections can make
// the reference
const LDSection* target_sect =
- &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*target_sect))
continue;
@@ -189,8 +178,7 @@
}
}
-void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
-{
+void GarbageCollection::getEntrySections(SectionVecTy& pEntry) {
// all the KEEP sections defined in ldscript are entries, traverse all the
// input sections and check the SectionMap to find the KEEP sections
Module::obj_iterator obj, objEnd = m_Module.obj_end();
@@ -204,7 +192,7 @@
continue;
SectionMap::Input* sm_input =
- sect_map.find(input_name, section->name()).second;
+ sect_map.find(input_name, section->name()).second;
if (((sm_input != NULL) && (InputSectDesc::Keep == sm_input->policy())) ||
shouldKeep(section->name()))
pEntry.push_back(section);
@@ -213,19 +201,19 @@
// get the sections those the entry symbols defined in
if (LinkerConfig::Exec == m_Config.codeGenType() ||
- m_Config.options().isPIE()) {
+ m_Config.options().isPIE()) {
// when building executable
// 1. the entry symbol is the entry
LDSymbol* entry_sym =
- m_Module.getNamePool().findSymbol(m_Backend.getEntry(m_Module));
- assert(NULL != entry_sym);
+ m_Module.getNamePool().findSymbol(m_Backend.getEntry(m_Module));
+ assert(entry_sym != NULL);
pEntry.push_back(&entry_sym->fragRef()->frag()->getParent()->getSection());
// 2. the symbols have been seen in dynamice objects are entries
NamePool::syminfo_iterator info_it,
- info_end = m_Module.getNamePool().syminfo_end();
+ info_end = m_Module.getNamePool().syminfo_end();
for (info_it = m_Module.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it) {
+ ++info_it) {
ResolveInfo* info = info_it.getEntry();
if (!info->isDefine() || info->isLocal())
continue;
@@ -234,39 +222,36 @@
continue;
LDSymbol* sym = info->outSymbol();
- if (NULL == sym || !sym->hasFragRef())
+ if (sym == NULL || !sym->hasFragRef())
continue;
// only the target symbols defined in the concerned sections can be
// entries
const LDSection* sect =
- &sym->fragRef()->frag()->getParent()->getSection();
+ &sym->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*sect))
continue;
pEntry.push_back(sect);
}
- }
-
- else {
+ } else {
// when building shared objects, the global define symbols are entries
NamePool::syminfo_iterator info_it,
- info_end = m_Module.getNamePool().syminfo_end();
+ info_end = m_Module.getNamePool().syminfo_end();
for (info_it = m_Module.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it) {
+ ++info_it) {
ResolveInfo* info = info_it.getEntry();
- if (!info->isDefine() ||
- info->isLocal() ||
+ if (!info->isDefine() || info->isLocal() ||
info->shouldForceLocal(m_Config))
continue;
LDSymbol* sym = info->outSymbol();
- if (NULL == sym || !sym->hasFragRef())
+ if (sym == NULL || !sym->hasFragRef())
continue;
// only the target symbols defined in the concerned sections can be
// entries
const LDSection* sect =
- &sym->fragRef()->frag()->getParent()->getSection();
+ &sym->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*sect))
continue;
pEntry.push_back(sect);
@@ -276,7 +261,7 @@
// symbols set by -u should not be garbage collected. Set them entries.
GeneralOptions::const_undef_sym_iterator usym;
GeneralOptions::const_undef_sym_iterator usymEnd =
- m_Config.options().undef_sym_end();
+ m_Config.options().undef_sym_end();
for (usym = m_Config.options().undef_sym_begin(); usym != usymEnd; ++usym) {
LDSymbol* sym = m_Module.getNamePool().findSymbol(*usym);
assert(sym);
@@ -292,8 +277,7 @@
}
}
-void GarbageCollection::findReferencedSections(SectionVecTy& pEntry)
-{
+void GarbageCollection::findReferencedSections(SectionVecTy& pEntry) {
// list of sections waiting to be processed
typedef std::queue<const LDSection*> WorkListTy;
WorkListTy work_list;
@@ -316,8 +300,8 @@
// get the section reached list, if the section do not has one, which
// means no referenced between it and other sections, then skip it
SectionListTy* reach_list =
- m_SectionReachedListMap.findReachedList(*sect);
- if (NULL == reach_list)
+ m_SectionReachedListMap.findReachedList(*sect);
+ if (reach_list == NULL)
continue;
// put the reached sections to work list, skip the one already be in
@@ -331,8 +315,7 @@
}
}
-void GarbageCollection::stripSections()
-{
+void GarbageCollection::stripSections() {
// Traverse all the input Regular and BSS sections, if a section is not found
// in the ReferencedSections, then it should be garbage collected
Module::obj_iterator obj, objEnd = m_Module.obj_end();
@@ -364,3 +347,4 @@
}
}
+} // namespace mcld
diff --git a/lib/LD/GroupReader.cpp b/lib/LD/GroupReader.cpp
index b3e6f9e..87deb33 100644
--- a/lib/LD/GroupReader.cpp
+++ b/lib/LD/GroupReader.cpp
@@ -6,40 +6,38 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Archive.h>
-#include <mcld/LD/ArchiveReader.h>
-#include <mcld/LD/DynObjReader.h>
-#include <mcld/LD/GroupReader.h>
-#include <mcld/LD/ObjectReader.h>
-#include <mcld/LD/BinaryReader.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/GroupReader.h"
-using namespace mcld;
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/BinaryReader.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
GroupReader::GroupReader(Module& pModule,
ObjectReader& pObjectReader,
DynObjReader& pDynObjReader,
ArchiveReader& pArchiveReader,
BinaryReader& pBinaryReader)
- : m_Module(pModule),
- m_ObjectReader(pObjectReader),
- m_DynObjReader(pDynObjReader),
- m_ArchiveReader(pArchiveReader),
- m_BinaryReader(pBinaryReader)
-{
+ : m_Module(pModule),
+ m_ObjectReader(pObjectReader),
+ m_DynObjReader(pDynObjReader),
+ m_ArchiveReader(pArchiveReader),
+ m_BinaryReader(pBinaryReader) {
}
-GroupReader::~GroupReader()
-{
+GroupReader::~GroupReader() {
}
bool GroupReader::readGroup(Module::input_iterator pRoot,
Module::input_iterator pEnd,
InputBuilder& pBuilder,
- const LinkerConfig& pConfig)
-{
+ const LinkerConfig& pConfig) {
// record the number of total objects included in this sub-tree
size_t cur_obj_cnt = 0;
size_t last_obj_cnt = 0;
@@ -83,15 +81,13 @@
// read archive
m_ArchiveReader.readArchive(pConfig, *ar);
cur_obj_cnt += ar->numOfObjectMember();
- }
- // read input as a binary file
- else if (doContinue && m_BinaryReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_BinaryReader.isMyFormat(**input, doContinue)) {
+ // read input as a binary file
(*input)->setType(Input::Object);
m_BinaryReader.readBinary(**input);
m_Module.getObjectList().push_back(*input);
- }
- // is a relocatable object file
- else if (doContinue && m_ObjectReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_ObjectReader.isMyFormat(**input, doContinue)) {
+ // is a relocatable object file
(*input)->setType(Input::Object);
m_ObjectReader.readHeader(**input);
m_ObjectReader.readSections(**input);
@@ -99,17 +95,15 @@
m_Module.getObjectList().push_back(*input);
++cur_obj_cnt;
++non_ar_obj_cnt;
- }
- // is a shared object file
- else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ // is a shared object file
(*input)->setType(Input::DynObj);
m_DynObjReader.readHeader(**input);
m_DynObjReader.readSymbols(**input);
m_Module.getLibraryList().push_back(*input);
- }
- else {
- warning(diag::warn_unrecognized_input_file) << (*input)->path()
- << pConfig.targets().triple().str();
+ } else {
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << pConfig.targets().triple().str();
}
++input;
}
@@ -124,7 +118,7 @@
for (it = ar_list.begin(); it != end; ++it) {
Archive& ar = (*it)->archive;
// if --whole-archive is given to this archive, no need to read it again
- if ( ar.getARFile().attribute()->isWholeArchive())
+ if (ar.getARFile().attribute()->isWholeArchive())
continue;
m_ArchiveReader.readArchive(pConfig, ar);
cur_obj_cnt += ar.numOfObjectMember();
@@ -151,3 +145,4 @@
return true;
}
+} // namespace mcld
diff --git a/lib/LD/IdenticalCodeFolding.cpp b/lib/LD/IdenticalCodeFolding.cpp
index b3ba59d..11e3701 100644
--- a/lib/LD/IdenticalCodeFolding.cpp
+++ b/lib/LD/IdenticalCodeFolding.cpp
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/LD/IdenticalCodeFolding.h"
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/LD/IdenticalCodeFolding.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/GeneralOptions.h>
-#include <mcld/Module.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/GeneralOptions.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Casting.h>
@@ -32,10 +32,10 @@
#include <set>
#include <zlib.h>
-using namespace mcld;
-static bool isSymCtorOrDtor(const ResolveInfo& pSym)
-{
+namespace mcld {
+
+static bool isSymCtorOrDtor(const ResolveInfo& pSym) {
// We can always fold ctors and dtors since accessing function pointer in C++
// is forbidden.
llvm::StringRef name(pSym.name(), pSym.nameSize());
@@ -48,12 +48,10 @@
IdenticalCodeFolding::IdenticalCodeFolding(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule)
- : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule)
-{
+ : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule) {
}
-void IdenticalCodeFolding::foldIdenticalCode()
-{
+void IdenticalCodeFolding::foldIdenticalCode() {
// 1. Find folding candidates.
FoldingCandidates candidate_list;
findCandidates(candidate_list);
@@ -91,8 +89,7 @@
KeptSections::iterator it = m_KeptSections.begin() + kept_index;
LDSection* kept_sect = (*it).first;
Input* kept_obj = (*it).second.first;
- debug(diag::debug_icf_folded_section) << sect->name()
- << obj->name()
+ debug(diag::debug_icf_folded_section) << sect->name() << obj->name()
<< kept_sect->name()
<< kept_obj->name();
}
@@ -110,18 +107,16 @@
LDSection* sect = &(frag_ref->frag()->getParent()->getSection());
if (sect->kind() == LDFileFormat::Folded) {
size_t kept_index = m_KeptSections[sect].second;
- LDSection* kept_sect =
- (*(m_KeptSections.begin() + kept_index)).first;
+ LDSection* kept_sect = (*(m_KeptSections.begin() + kept_index)).first;
frag_ref->assign(kept_sect->getSectionData()->front(),
frag_ref->offset());
}
}
- } // for each symbol
- } // for each folded object
+ } // for each symbol
+ } // for each folded object
}
-void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList)
-{
+void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList) {
Module::obj_iterator obj, objEnd = m_Module.obj_end();
for (obj = m_Module.obj_begin(); obj != objEnd; ++obj) {
std::set<const LDSection*> funcptr_access_set;
@@ -131,7 +126,8 @@
for (sect = (*obj)->context()->sectBegin(); sect != sectEnd; ++sect) {
switch ((*sect)->kind()) {
case LDFileFormat::TEXT: {
- candidate_map.insert(std::make_pair(*sect, (LDSection*)NULL));
+ candidate_map.insert(
+ std::make_pair(*sect, reinterpret_cast<LDSection*>(NULL)));
break;
}
case LDFileFormat::Relocation: {
@@ -150,22 +146,22 @@
&sym->fragRef()->frag()->getParent()->getSection();
if (!isSymCtorOrDtor(*rel->symInfo()) &&
m_Backend.mayHaveUnsafeFunctionPointerAccess(*target) &&
- m_Backend.
- getRelocator()->mayHaveFunctionPointerAccess(*rel)) {
+ m_Backend.getRelocator()
+ ->mayHaveFunctionPointerAccess(*rel)) {
funcptr_access_set.insert(def);
}
}
- } // for each reloc
+ } // for each reloc
}
break;
}
default: {
// skip
- break;;
+ break;
}
- } // end of switch
- } // for each section
+ } // end of switch
+ } // for each section
CandidateMap::iterator candidate, candidateEnd = candidate_map.end();
for (candidate = candidate_map.begin(); candidate != candidateEnd;
@@ -174,25 +170,22 @@
(funcptr_access_set.count(candidate->first) == 0)) {
size_t index = m_KeptSections.size();
m_KeptSections[candidate->first] = ObjectAndId(*obj, index);
- pCandidateList.push_back(FoldingCandidate(candidate->first,
- candidate->second,
- *obj));
+ pCandidateList.push_back(
+ FoldingCandidate(candidate->first, candidate->second, *obj));
}
- } // for each possible candidate
-
- } // for each obj
+ } // for each possible candidate
+ } // for each obj
}
-bool IdenticalCodeFolding::matchCandidates(FoldingCandidates& pCandidateList)
-{
+bool IdenticalCodeFolding::matchCandidates(FoldingCandidates& pCandidateList) {
typedef std::multimap<uint32_t, size_t> ChecksumMap;
ChecksumMap checksum_map;
std::vector<std::string> contents(pCandidateList.size());
bool converged = true;
for (size_t index = 0; index < pCandidateList.size(); ++index) {
- contents[index] = pCandidateList[index].
- getContentWithVariables(m_Backend, m_KeptSections);
+ contents[index] = pCandidateList[index].getContentWithVariables(
+ m_Backend, m_KeptSections);
uint32_t checksum = ::crc32(0xFFFFFFFF,
(const uint8_t*)contents[index].c_str(),
contents[index].length());
@@ -219,8 +212,7 @@
void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
const TargetLDBackend& pBackend,
- const IdenticalCodeFolding::KeptSections& pKeptSections)
-{
+ const IdenticalCodeFolding::KeptSections& pKeptSections) {
// Get the static content from text.
assert(sect != NULL && sect->hasSectionData());
SectionData::const_iterator frag, fragEnd = sect->getSectionData()->end();
@@ -242,10 +234,14 @@
if (reloc_sect != NULL && reloc_sect->hasRelocData()) {
RelocData::iterator rel, relEnd = reloc_sect->getRelocData()->end();
for (rel = reloc_sect->getRelocData()->begin(); rel != relEnd; ++rel) {
- llvm::format_object4<Relocation::Type, Relocation::Address,
- Relocation::Address, Relocation::Address>
- rel_info("%x%llx%llx%llx", rel->type(), rel->symValue(),
- rel->addend(), rel->place());
+ llvm::format_object4<Relocation::Type,
+ Relocation::Address,
+ Relocation::Address,
+ Relocation::Address> rel_info("%x%llx%llx%llx",
+ rel->type(),
+ rel->symValue(),
+ rel->addend(),
+ rel->place());
char rel_str[48];
rel_info.print(rel_str, sizeof(rel_str));
content.append(rel_str);
@@ -259,11 +255,10 @@
}
}
- if (!pBackend.isSymbolPreemptible(*rel->symInfo()) &&
- sym->hasFragRef() &&
+ if (!pBackend.isSymbolPreemptible(*rel->symInfo()) && sym->hasFragRef() &&
(pKeptSections.find(
- &sym->fragRef()->frag()->getParent()->getSection()) !=
- pKeptSections.end())) {
+ &sym->fragRef()->frag()->getParent()->getSection()) !=
+ pKeptSections.end())) {
// Mark this reloc as a variable.
variable_relocs.push_back(rel);
} else {
@@ -271,9 +266,8 @@
if ((sym->binding() == ResolveInfo::Local) ||
(sym->binding() == ResolveInfo::Absolute)) {
// ABS or Local symbols.
- content.append(sym->name())
- .append(obj->name())
- .append(obj->path().native());
+ content.append(sym->name()).append(obj->name()).append(
+ obj->path().native());
} else {
content.append(sym->name());
}
@@ -284,8 +278,7 @@
std::string IdenticalCodeFolding::FoldingCandidate::getContentWithVariables(
const TargetLDBackend& pBackend,
- const IdenticalCodeFolding::KeptSections& pKeptSections)
-{
+ const IdenticalCodeFolding::KeptSections& pKeptSections) {
std::string result(content);
// Compute the variable content from relocs.
std::vector<Relocation*>::const_iterator rel, relEnd = variable_relocs.end();
@@ -302,3 +295,5 @@
return result;
}
+
+} // namespace mcld
diff --git a/lib/LD/LDContext.cpp b/lib/LD/LDContext.cpp
index 8607dfd..ecb8e37 100644
--- a/lib/LD/LDContext.cpp
+++ b/lib/LD/LDContext.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+
#include <llvm/ADT/StringRef.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LDContext
//===----------------------------------------------------------------------===//
-LDContext& LDContext::appendSection(LDSection& pSection)
-{
+LDContext& LDContext::appendSection(LDSection& pSection) {
if (LDFileFormat::Relocation == pSection.kind())
m_RelocSections.push_back(&pSection);
pSection.setIndex(m_SectionTable.size());
@@ -25,42 +25,37 @@
return *this;
}
-LDSection* LDContext::getSection(unsigned int pIdx)
-{
+LDSection* LDContext::getSection(unsigned int pIdx) {
if (pIdx >= m_SectionTable.size())
return NULL;
return m_SectionTable[pIdx];
}
-const LDSection* LDContext::getSection(unsigned int pIdx) const
-{
+const LDSection* LDContext::getSection(unsigned int pIdx) const {
if (pIdx >= m_SectionTable.size())
return NULL;
return m_SectionTable[pIdx];
}
-LDSection* LDContext::getSection(const std::string& pName)
-{
+LDSection* LDContext::getSection(const std::string& pName) {
sect_iterator sect_iter, sect_end = sectEnd();
for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
- if(NULL != *sect_iter && (*sect_iter)->name() == pName)
+ if (*sect_iter != NULL && (*sect_iter)->name() == pName)
return *sect_iter;
}
return NULL;
}
-const LDSection* LDContext::getSection(const std::string& pName) const
-{
+const LDSection* LDContext::getSection(const std::string& pName) const {
const_sect_iterator sect_iter, sect_end = sectEnd();
for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
- if(NULL != *sect_iter && (*sect_iter)->name() == pName)
+ if (*sect_iter != NULL && (*sect_iter)->name() == pName)
return *sect_iter;
}
return NULL;
}
-size_t LDContext::getSectionIdx(const std::string& pName) const
-{
+size_t LDContext::getSectionIdx(const std::string& pName) const {
size_t result = 1;
size_t size = m_SectionTable.size();
for (; result != size; ++result)
@@ -69,23 +64,19 @@
return 0;
}
-LDSymbol* LDContext::getSymbol(unsigned int pIdx)
-{
+LDSymbol* LDContext::getSymbol(unsigned int pIdx) {
if (pIdx >= m_SymTab.size())
return NULL;
return m_SymTab[pIdx];
}
-const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const
-{
+const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const {
if (pIdx >= m_SymTab.size())
return NULL;
return m_SymTab[pIdx];
}
-
-LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName)
-{
+LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) {
size_t sym = 1;
size_t size = m_SymTab.size();
for (; sym < size; ++sym)
@@ -94,8 +85,7 @@
return NULL;
}
-const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const
-{
+const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const {
size_t sym = 1;
size_t size = m_SymTab.size();
for (; sym < size; ++sym)
@@ -103,3 +93,5 @@
return m_SymTab[sym];
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/LD/LDFileFormat.cpp b/lib/LD/LDFileFormat.cpp
index d1f0b80..0393c97 100644
--- a/lib/LD/LDFileFormat.cpp
+++ b/lib/LD/LDFileFormat.cpp
@@ -6,21 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDFileFormat.h>
+#include "mcld/LD/LDFileFormat.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LDFileInfo
//===----------------------------------------------------------------------===//
LDFileFormat::LDFileFormat()
- : f_pTextSection(NULL),
- f_pDataSection(NULL),
- f_pBSSSection(NULL),
- f_pReadOnlySection(NULL) {
+ : f_pTextSection(NULL),
+ f_pDataSection(NULL),
+ f_pBSSSection(NULL),
+ f_pReadOnlySection(NULL) {
}
-LDFileFormat::~LDFileFormat()
-{
+LDFileFormat::~LDFileFormat() {
}
+} // namespace mcld
diff --git a/lib/LD/LDReader.cpp b/lib/LD/LDReader.cpp
index b74fc68..384e24c 100644
--- a/lib/LD/LDReader.cpp
+++ b/lib/LD/LDReader.cpp
@@ -6,9 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDReader.h>
+#include "mcld/LD/LDReader.h"
-using namespace mcld;
+namespace mcld {
//==========================
// LDReader
+
+} // namespace mcld
diff --git a/lib/LD/LDSection.cpp b/lib/LD/LDSection.cpp
index 30daee3..6faedc1 100644
--- a/lib/LD/LDSection.cpp
+++ b/lib/LD/LDSection.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSection.h>
+#include "mcld/LD/LDSection.h"
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<LDSection, MCLD_SECTIONS_PER_INPUT> SectionFactory;
@@ -22,17 +22,17 @@
// LDSection
//===----------------------------------------------------------------------===//
LDSection::LDSection()
- : m_Name(),
- m_Kind(LDFileFormat::Ignore),
- m_Type(0x0),
- m_Flag(0x0),
- m_Size(0),
- m_Offset(~uint64_t(0)),
- m_Addr(0x0),
- m_Align(0),
- m_Info(0),
- m_pLink(NULL),
- m_Index(0) {
+ : m_Name(),
+ m_Kind(LDFileFormat::Ignore),
+ m_Type(0x0),
+ m_Flag(0x0),
+ m_Size(0),
+ m_Offset(~uint64_t(0)),
+ m_Addr(0x0),
+ m_Align(0),
+ m_Info(0),
+ m_pLink(NULL),
+ m_Index(0) {
m_Data.sect_data = NULL;
}
@@ -42,26 +42,24 @@
uint32_t pFlag,
uint64_t pSize,
uint64_t pAddr)
- : m_Name(pName),
- m_Kind(pKind),
- m_Type(pType),
- m_Flag(pFlag),
- m_Size(pSize),
- m_Offset(~uint64_t(0)),
- m_Addr(pAddr),
- m_Align(0),
- m_Info(0),
- m_pLink(NULL),
- m_Index(0) {
+ : m_Name(pName),
+ m_Kind(pKind),
+ m_Type(pType),
+ m_Flag(pFlag),
+ m_Size(pSize),
+ m_Offset(~uint64_t(0)),
+ m_Addr(pAddr),
+ m_Align(0),
+ m_Info(0),
+ m_pLink(NULL),
+ m_Index(0) {
m_Data.sect_data = NULL;
}
-LDSection::~LDSection()
-{
+LDSection::~LDSection() {
}
-bool LDSection::hasOffset() const
-{
+bool LDSection::hasOffset() const {
return (m_Offset != ~uint64_t(0));
}
@@ -70,40 +68,40 @@
uint32_t pType,
uint32_t pFlag,
uint64_t pSize,
- uint64_t pAddr)
-{
+ uint64_t pAddr) {
LDSection* result = g_SectFactory->allocate();
new (result) LDSection(pName, pKind, pType, pFlag, pSize, pAddr);
return result;
}
-void LDSection::Destroy(LDSection*& pSection)
-{
+void LDSection::Destroy(LDSection*& pSection) {
g_SectFactory->destroy(pSection);
g_SectFactory->deallocate(pSection);
pSection = NULL;
}
-void LDSection::Clear()
-{
+void LDSection::Clear() {
g_SectFactory->clear();
}
-bool LDSection::hasSectionData() const
-{
+bool LDSection::hasSectionData() const {
assert(LDFileFormat::Relocation != kind() && LDFileFormat::EhFrame != kind());
- return (NULL != m_Data.sect_data);
+ return (m_Data.sect_data != NULL);
}
-bool LDSection::hasRelocData() const
-{
+bool LDSection::hasRelocData() const {
assert(LDFileFormat::Relocation == kind());
- return (NULL != m_Data.reloc_data);
+ return (m_Data.reloc_data != NULL);
}
-bool LDSection::hasEhFrame() const
-{
+bool LDSection::hasEhFrame() const {
assert(LDFileFormat::EhFrame == kind());
- return (NULL != m_Data.eh_frame);
+ return (m_Data.eh_frame != NULL);
}
+bool LDSection::hasDebugString() const {
+ assert(LDFileFormat::DebugString == kind());
+ return (NULL != m_Data.debug_string);
+}
+
+} // namespace mcld
diff --git a/lib/LD/LDSymbol.cpp b/lib/LD/LDSymbol.cpp
index 9002235..5b389ea 100644
--- a/lib/LD/LDSymbol.cpp
+++ b/lib/LD/LDSymbol.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/LDSymbol.h"
-#include <mcld/Config/Config.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/GCFactory.h>
-
-#include <cstring>
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
typedef GCFactory<LDSymbol, MCLD_SYMBOLS_PER_INPUT> LDSymbolFactory;
@@ -28,52 +28,45 @@
//===----------------------------------------------------------------------===//
// LDSymbol
//===----------------------------------------------------------------------===//
-LDSymbol::LDSymbol()
- : m_pResolveInfo(NULL), m_pFragRef(NULL), m_Value(0) {
+LDSymbol::LDSymbol() : m_pResolveInfo(NULL), m_pFragRef(NULL), m_Value(0) {
}
-LDSymbol::~LDSymbol()
-{
+LDSymbol::~LDSymbol() {
}
LDSymbol::LDSymbol(const LDSymbol& pCopy)
- : m_pResolveInfo(pCopy.m_pResolveInfo),
- m_pFragRef(pCopy.m_pFragRef),
- m_Value(pCopy.m_Value) {
+ : m_pResolveInfo(pCopy.m_pResolveInfo),
+ m_pFragRef(pCopy.m_pFragRef),
+ m_Value(pCopy.m_Value) {
}
-LDSymbol& LDSymbol::operator=(const LDSymbol& pCopy)
-{
+LDSymbol& LDSymbol::operator=(const LDSymbol& pCopy) {
m_pResolveInfo = pCopy.m_pResolveInfo;
m_pFragRef = pCopy.m_pFragRef;
m_Value = pCopy.m_Value;
return (*this);
}
-LDSymbol* LDSymbol::Create(ResolveInfo& pResolveInfo)
-{
+LDSymbol* LDSymbol::Create(ResolveInfo& pResolveInfo) {
LDSymbol* result = g_LDSymbolFactory->allocate();
new (result) LDSymbol();
result->setResolveInfo(pResolveInfo);
return result;
}
-void LDSymbol::Destroy(LDSymbol*& pSymbol)
-{
+void LDSymbol::Destroy(LDSymbol*& pSymbol) {
pSymbol->~LDSymbol();
g_LDSymbolFactory->deallocate(pSymbol);
pSymbol = NULL;
}
-void LDSymbol::Clear()
-{
+void LDSymbol::Clear() {
g_LDSymbolFactory->clear();
}
-LDSymbol* LDSymbol::Null()
-{
+LDSymbol* LDSymbol::Null() {
// lazy initialization
- if (NULL == g_NullSymbol->resolveInfo()) {
+ if (g_NullSymbol->resolveInfo() == NULL) {
g_NullSymbol->setResolveInfo(*ResolveInfo::Null());
g_NullSymbol->setFragmentRef(FragmentRef::Create(*g_NullSymbolFragment, 0));
ResolveInfo::Null()->setSymPtr(&*g_NullSymbol);
@@ -81,23 +74,20 @@
return &*g_NullSymbol;
}
-void LDSymbol::setFragmentRef(FragmentRef* pFragmentRef)
-{
+void LDSymbol::setFragmentRef(FragmentRef* pFragmentRef) {
m_pFragRef = pFragmentRef;
}
-void LDSymbol::setResolveInfo(const ResolveInfo& pInfo)
-{
+void LDSymbol::setResolveInfo(const ResolveInfo& pInfo) {
m_pResolveInfo = const_cast<ResolveInfo*>(&pInfo);
}
-bool LDSymbol::isNull() const
-{
+bool LDSymbol::isNull() const {
return (this == Null());
}
-bool LDSymbol::hasFragRef() const
-{
+bool LDSymbol::hasFragRef() const {
return !m_pFragRef->isNull();
}
+} // namespace mcld
diff --git a/lib/LD/MergedStringTable.cpp b/lib/LD/MergedStringTable.cpp
new file mode 100644
index 0000000..70735cb
--- /dev/null
+++ b/lib/LD/MergedStringTable.cpp
@@ -0,0 +1,42 @@
+//===- MergedStringTable.cpp ----------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/LD/MergedStringTable.h"
+
+namespace mcld {
+
+bool MergedStringTable::insertString(llvm::StringRef pString) {
+ return m_StringMap.insert(std::make_pair(pString, 0)).second;
+}
+
+uint64_t MergedStringTable::finalizeOffset() {
+ // trverse the string table and set the offset
+ string_map_iterator it, end = m_StringMap.end();
+ size_t offset = 0;
+ for (it = m_StringMap.begin(); it != end; ++it) {
+ it->setValue(offset);
+ offset += it->getKey().size() + 1;
+ }
+ return offset;
+}
+
+void MergedStringTable::emit(MemoryRegion& pRegion) {
+ char* ptr = reinterpret_cast<char*>(pRegion.begin());
+ string_map_iterator it, end = m_StringMap.end();
+ for (it = m_StringMap.begin(); it != end; ++it) {
+ ::memcpy(ptr, it->getKey().data(), it->getKey().size());
+ ptr += it->getKey().size() + 1;
+ }
+}
+
+size_t MergedStringTable::getOutputOffset(llvm::StringRef pStr) {
+ assert(m_StringMap.find(pStr) != m_StringMap.end());
+ return m_StringMap[pStr];
+}
+
+} // namespace mcld
diff --git a/lib/LD/MsgHandler.cpp b/lib/LD/MsgHandler.cpp
index 96310a2..0c88565 100644
--- a/lib/LD/MsgHandler.cpp
+++ b/lib/LD/MsgHandler.cpp
@@ -6,47 +6,45 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/LD/DiagnosticEngine.h>
+#include "mcld/LD/MsgHandler.h"
-using namespace mcld;
+#include "mcld/LD/DiagnosticEngine.h"
+
+namespace mcld {
MsgHandler::MsgHandler(DiagnosticEngine& pEngine)
- : m_Engine(pEngine), m_NumArgs(0) {
+ : m_Engine(pEngine), m_NumArgs(0) {
}
-MsgHandler::~MsgHandler()
-{
+MsgHandler::~MsgHandler() {
emit();
}
-bool MsgHandler::emit()
-{
+bool MsgHandler::emit() {
flushCounts();
return m_Engine.emit();
}
-void MsgHandler::addString(llvm::StringRef pStr) const
-{
+void MsgHandler::addString(llvm::StringRef pStr) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = DiagnosticEngine::ak_std_string;
m_Engine.state().ArgumentStrs[m_NumArgs++] = pStr.data();
}
-void MsgHandler::addString(const std::string& pStr) const
-{
+void MsgHandler::addString(const std::string& pStr) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = DiagnosticEngine::ak_std_string;
m_Engine.state().ArgumentStrs[m_NumArgs++] = pStr;
}
-void MsgHandler::addTaggedVal(intptr_t pValue, DiagnosticEngine::ArgumentKind pKind) const
-{
+void MsgHandler::addTaggedVal(intptr_t pValue,
+ DiagnosticEngine::ArgumentKind pKind) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = pKind;
m_Engine.state().ArgumentVals[m_NumArgs++] = pValue;
}
+} // namespace mcld
diff --git a/lib/LD/NamePool.cpp b/lib/LD/NamePool.cpp
index 151b1dd..3eecda4 100644
--- a/lib/LD/NamePool.cpp
+++ b/lib/LD/NamePool.cpp
@@ -6,21 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/raw_ostream.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/StaticResolver.h>
+#include "mcld/LD/NamePool.h"
-using namespace mcld;
+#include "mcld/LD/StaticResolver.h"
+
+#include <llvm/Support/raw_ostream.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// NamePool
//===----------------------------------------------------------------------===//
NamePool::NamePool(NamePool::size_type pSize)
- : m_pResolver(new StaticResolver()), m_Table(pSize) {
+ : m_pResolver(new StaticResolver()), m_Table(pSize) {
}
-NamePool::~NamePool()
-{
+NamePool::~NamePool() {
delete m_pResolver;
FreeInfoSet::iterator info, iEnd = m_FreeInfoSet.end();
@@ -36,8 +37,7 @@
ResolveInfo::Desc pDesc,
ResolveInfo::Binding pBinding,
ResolveInfo::SizeType pSize,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo** result = m_FreeInfoSet.allocate();
(*result) = ResolveInfo::Create(pName);
(*result)->setIsSymbol(true);
@@ -54,16 +54,15 @@
/// @return the pointer of resolved ResolveInfo
/// @return is the symbol existent?
void NamePool::insertSymbol(const llvm::StringRef& pName,
- bool pIsDyn,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- ResolveInfo::Visibility pVisibility,
- ResolveInfo* pOldInfo,
- Resolver::Result& pResult)
-{
+ bool pIsDyn,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ ResolveInfo::Visibility pVisibility,
+ ResolveInfo* pOldInfo,
+ Resolver::Result& pResult) {
// We should check if there is any symbol with the same name existed.
// If it already exists, we should use resolver to decide which symbol
// should be reserved. Otherwise, we insert the symbol and set up its
@@ -73,8 +72,7 @@
ResolveInfo* new_symbol = NULL;
if (exist && old_symbol->isSymbol()) {
new_symbol = m_Table.getEntryFactory().produce(pName);
- }
- else {
+ } else {
exist = false;
new_symbol = old_symbol;
}
@@ -89,12 +87,11 @@
if (!exist) {
// old_symbol is neither existed nor a symbol.
- pResult.info = new_symbol;
- pResult.existent = false;
+ pResult.info = new_symbol;
+ pResult.existent = false;
pResult.overriden = true;
return;
- }
- else if (NULL != pOldInfo) {
+ } else if (pOldInfo != NULL) {
// existent, remember its attribute
pOldInfo->override(*old_symbol);
}
@@ -104,64 +101,57 @@
bool override = false;
unsigned int action = Resolver::LastAction;
if (m_pResolver->resolve(*old_symbol, *new_symbol, override, pValue)) {
- pResult.info = old_symbol;
- pResult.existent = true;
+ pResult.info = old_symbol;
+ pResult.existent = true;
pResult.overriden = override;
- }
- else {
- m_pResolver->resolveAgain(*this, action, *old_symbol, *new_symbol, pResult);
+ } else {
+ m_pResolver->resolveAgain(*this, action, *old_symbol, *new_symbol, pResult);
}
m_Table.getEntryFactory().destroy(new_symbol);
return;
}
-llvm::StringRef NamePool::insertString(const llvm::StringRef& pString)
-{
+llvm::StringRef NamePool::insertString(const llvm::StringRef& pString) {
bool exist = false;
ResolveInfo* resolve_info = m_Table.insert(pString, exist);
return llvm::StringRef(resolve_info->name(), resolve_info->nameSize());
}
-void NamePool::reserve(NamePool::size_type pSize)
-{
+void NamePool::reserve(NamePool::size_type pSize) {
m_Table.rehash(pSize);
}
-NamePool::size_type NamePool::capacity() const
-{
+NamePool::size_type NamePool::capacity() const {
return (m_Table.numOfBuckets() - m_Table.numOfEntries());
}
/// findInfo - find the resolved ResolveInfo
-ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName)
-{
+ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) {
Table::iterator iter = m_Table.find(pName);
return iter.getEntry();
}
/// findInfo - find the resolved ResolveInfo
-const ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) const
-{
+const ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) const {
Table::const_iterator iter = m_Table.find(pName);
return iter.getEntry();
}
/// findSymbol - find the resolved output LDSymbol
-LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName)
-{
+LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) {
ResolveInfo* info = findInfo(pName);
- if (NULL == info)
+ if (info == NULL)
return NULL;
return info->outSymbol();
}
/// findSymbol - find the resolved output LDSymbol
-const LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) const
-{
+const LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) const {
const ResolveInfo* info = findInfo(pName);
- if (NULL == info)
+ if (info == NULL)
return NULL;
return info->outSymbol();
}
+} // namespace mcld
diff --git a/lib/LD/ObjectWriter.cpp b/lib/LD/ObjectWriter.cpp
index 17d04eb..c06a546 100644
--- a/lib/LD/ObjectWriter.cpp
+++ b/lib/LD/ObjectWriter.cpp
@@ -6,17 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ObjectWriter.h>
+#include "mcld/LD/ObjectWriter.h"
-using namespace mcld;
+namespace mcld {
//==========================
// ObjectWriter
-ObjectWriter::ObjectWriter()
-{
+ObjectWriter::ObjectWriter() {
}
-ObjectWriter::~ObjectWriter()
-{
+ObjectWriter::~ObjectWriter() {
}
+} // namespace mcld
diff --git a/lib/LD/RelocData.cpp b/lib/LD/RelocData.cpp
index 8379872..8732bdb 100644
--- a/lib/LD/RelocData.cpp
+++ b/lib/LD/RelocData.cpp
@@ -6,12 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/RelocData.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/RelocData.h"
+
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<RelocData, MCLD_SECTIONS_PER_INPUT> RelocDataFactory;
@@ -20,42 +21,37 @@
//===----------------------------------------------------------------------===//
// RelocData
//===----------------------------------------------------------------------===//
-RelocData::RelocData()
- : m_pSection(NULL) {
+RelocData::RelocData() : m_pSection(NULL) {
}
-RelocData::RelocData(LDSection &pSection)
- : m_pSection(&pSection) {
+RelocData::RelocData(LDSection& pSection) : m_pSection(&pSection) {
}
-RelocData* RelocData::Create(LDSection& pSection)
-{
+RelocData* RelocData::Create(LDSection& pSection) {
RelocData* result = g_RelocDataFactory->allocate();
new (result) RelocData(pSection);
return result;
}
-void RelocData::Destroy(RelocData*& pSection)
-{
+void RelocData::Destroy(RelocData*& pSection) {
pSection->~RelocData();
g_RelocDataFactory->deallocate(pSection);
pSection = NULL;
}
-void RelocData::Clear()
-{
+void RelocData::Clear() {
g_RelocDataFactory->clear();
}
-RelocData& RelocData::append(Relocation& pRelocation)
-{
+RelocData& RelocData::append(Relocation& pRelocation) {
m_Relocations.push_back(&pRelocation);
return *this;
}
-Relocation& RelocData::remove(Relocation& pRelocation)
-{
+Relocation& RelocData::remove(Relocation& pRelocation) {
iterator iter(pRelocation);
Relocation* rel = m_Relocations.remove(iter);
return *rel;
}
+
+} // namespace mcld
diff --git a/lib/LD/RelocationFactory.cpp b/lib/LD/RelocationFactory.cpp
index 08eb347..402c3d6 100644
--- a/lib/LD/RelocationFactory.cpp
+++ b/lib/LD/RelocationFactory.cpp
@@ -6,35 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/RelocationFactory.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Host.h>
-#include <cstring>
#include <cassert>
+#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// RelocationFactory
//===----------------------------------------------------------------------===//
RelocationFactory::RelocationFactory()
- : GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT>(), m_pConfig(NULL) {
+ : GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT>(), m_pConfig(NULL) {
}
-void RelocationFactory::setConfig(const LinkerConfig& pConfig)
-{
+void RelocationFactory::setConfig(const LinkerConfig& pConfig) {
m_pConfig = &pConfig;
}
Relocation* RelocationFactory::produce(RelocationFactory::Type pType,
FragmentRef& pFragRef,
- Address pAddend)
-{
- if (NULL == m_pConfig) {
+ Address pAddend) {
+ if (m_pConfig == NULL) {
fatal(diag::reloc_factory_has_not_config);
return NULL;
}
@@ -65,10 +64,9 @@
<< m_pConfig->targets().bitclass();
return NULL;
}
- } // end of switch
- }
- else {
- pFragRef.memcpy(&target_data, (m_pConfig->targets().bitclass()/8));
+ } // end of switch
+ } else {
+ pFragRef.memcpy(&target_data, (m_pConfig->targets().bitclass() / 8));
}
Relocation* result = allocate();
@@ -76,15 +74,14 @@
return result;
}
-Relocation* RelocationFactory::produceEmptyEntry()
-{
+Relocation* RelocationFactory::produceEmptyEntry() {
Relocation* result = allocate();
new (result) Relocation(0, 0, 0, 0);
return result;
}
-void RelocationFactory::destroy(Relocation* pRelocation)
-{
- /** GCFactory will recycle the relocation **/
+void RelocationFactory::destroy(Relocation* pRelocation) {
+ /** GCFactory will recycle the relocation **/
}
+} // namespace mcld
diff --git a/lib/LD/Relocator.cpp b/lib/LD/Relocator.cpp
index fa3a94f..46fc4c4 100644
--- a/lib/LD/Relocator.cpp
+++ b/lib/LD/Relocator.cpp
@@ -6,31 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Module.h>
+#include "mcld/LD/Relocator.h"
+
+#include "mcld/Module.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <sstream>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Relocator
//===----------------------------------------------------------------------===//
-Relocator::~Relocator()
-{
+Relocator::~Relocator() {
}
void Relocator::partialScanRelocation(Relocation& pReloc,
- Module& pModule,
- const LDSection& pSection)
-{
+ Module& pModule) {
// if we meet a section symbol
if (pReloc.symInfo()->type() == ResolveInfo::Section) {
LDSymbol* input_sym = pReloc.symInfo()->outSymbol();
@@ -43,9 +42,9 @@
// 2. get output section symbol
// get the output LDSection which the symbol defined in
const LDSection& out_sect =
- input_sym->fragRef()->frag()->getParent()->getSection();
+ input_sym->fragRef()->frag()->getParent()->getSection();
ResolveInfo* sym_info =
- pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
+ pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
// set relocation target symbol to the output section symbol's resolveInfo
pReloc.setSymInfo(sym_info);
}
@@ -53,11 +52,11 @@
void Relocator::issueUndefRef(Relocation& pReloc,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
FragmentRef::Offset undef_sym_pos = pReloc.targetRef().offset();
std::string sect_name(pSection.name());
- sect_name = sect_name.substr(sect_name.find('.', /*pos=*/1)); // Drop .rel(a) prefix
+ // Drop .rel(a) prefix
+ sect_name = sect_name.substr(sect_name.find('.', /*pos=*/1));
std::string reloc_sym(pReloc.symInfo()->name());
reloc_sym = demangleName(reloc_sym);
@@ -68,9 +67,7 @@
if (sect_name.substr(0, 5) != ".text") {
// Function name is only valid for text section
- fatal(diag::undefined_reference) << reloc_sym
- << pInput.path()
- << sect_name
+ fatal(diag::undefined_reference) << reloc_sym << pInput.path() << sect_name
<< undef_sym_pos_hex;
return;
}
@@ -78,7 +75,9 @@
std::string caller_file_name;
std::string caller_func_name;
for (LDContext::sym_iterator i = pInput.context()->symTabBegin(),
- e = pInput.context()->symTabEnd(); i != e; ++i) {
+ e = pInput.context()->symTabEnd();
+ i != e;
+ ++i) {
LDSymbol& sym = **i;
if (sym.resolveInfo()->type() == ResolveInfo::File)
caller_file_name = sym.resolveInfo()->name();
@@ -93,8 +92,8 @@
caller_func_name = demangleName(caller_func_name);
- fatal(diag::undefined_reference_text) << reloc_sym
- << pInput.path()
- << caller_file_name
- << caller_func_name;
+ fatal(diag::undefined_reference_text) << reloc_sym << pInput.path()
+ << caller_file_name << caller_func_name;
}
+
+} // namespace mcld
diff --git a/lib/LD/ResolveInfo.cpp b/lib/LD/ResolveInfo.cpp
index ca26d63..b152044 100644
--- a/lib/LD/ResolveInfo.cpp
+++ b/lib/LD/ResolveInfo.cpp
@@ -6,15 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/ResolveInfo.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
+
#include <cstdlib>
#include <cstring>
-using namespace mcld;
+namespace mcld {
/// g_NullResolveInfo - a pointer to Null ResolveInfo.
static ResolveInfo* g_NullResolveInfo = NULL;
@@ -22,34 +25,27 @@
//===----------------------------------------------------------------------===//
// ResolveInfo
//===----------------------------------------------------------------------===//
-ResolveInfo::ResolveInfo()
- : m_Size(0), m_BitField(0) {
+ResolveInfo::ResolveInfo() : m_Size(0), m_BitField(0) {
m_Ptr.sym_ptr = 0;
}
-ResolveInfo::~ResolveInfo()
-{
+ResolveInfo::~ResolveInfo() {
}
-void ResolveInfo::override(const ResolveInfo& pFrom)
-{
+void ResolveInfo::override(const ResolveInfo& pFrom) {
m_Size = pFrom.m_Size;
overrideAttributes(pFrom);
overrideVisibility(pFrom);
}
-void ResolveInfo::overrideAttributes(const ResolveInfo& pFrom)
-{
- m_BitField &= ~RESOLVE_MASK;
- m_BitField |= (pFrom.m_BitField & RESOLVE_MASK);
+void ResolveInfo::overrideAttributes(const ResolveInfo& pFrom) {
+ m_BitField &= ~RESOLVE_MASK | VISIBILITY_MASK;
+ m_BitField |= (pFrom.m_BitField & (RESOLVE_MASK & ~VISIBILITY_MASK));
}
/// overrideVisibility - override the visibility
/// always use the most strict visibility
-void ResolveInfo::overrideVisibility(const ResolveInfo& pFrom)
-{
- // Reference: Google gold linker: resolve.cc
- //
+void ResolveInfo::overrideVisibility(const ResolveInfo& pFrom) {
// The rule for combining visibility is that we always choose the
// most constrained visibility. In order of increasing constraint,
// visibility goes PROTECTED, HIDDEN, INTERNAL. This is the reverse
@@ -65,51 +61,44 @@
Visibility from_vis = pFrom.visibility();
Visibility cur_vis = visibility();
- if (0 != from_vis ) {
- if (0 == cur_vis)
+ if (from_vis != 0) {
+ if (cur_vis == 0)
setVisibility(from_vis);
else if (cur_vis > from_vis)
setVisibility(from_vis);
}
}
-void ResolveInfo::setRegular()
-{
+void ResolveInfo::setRegular() {
m_BitField &= (~dynamic_flag);
}
-void ResolveInfo::setDynamic()
-{
+void ResolveInfo::setDynamic() {
m_BitField |= dynamic_flag;
}
-void ResolveInfo::setSource(bool pIsDyn)
-{
+void ResolveInfo::setSource(bool pIsDyn) {
if (pIsDyn)
m_BitField |= dynamic_flag;
else
m_BitField &= (~dynamic_flag);
}
-void ResolveInfo::setInDyn()
-{
+void ResolveInfo::setInDyn() {
m_BitField |= indyn_flag;
}
-void ResolveInfo::setType(uint32_t pType)
-{
+void ResolveInfo::setType(uint32_t pType) {
m_BitField &= ~TYPE_MASK;
m_BitField |= ((pType << TYPE_OFFSET) & TYPE_MASK);
}
-void ResolveInfo::setDesc(uint32_t pDesc)
-{
+void ResolveInfo::setDesc(uint32_t pDesc) {
m_BitField &= ~DESC_MASK;
m_BitField |= ((pDesc << DESC_OFFSET) & DESC_MASK);
}
-void ResolveInfo::setBinding(uint32_t pBinding)
-{
+void ResolveInfo::setBinding(uint32_t pBinding) {
m_BitField &= ~BINDING_MASK;
if (pBinding == Local || pBinding == Absolute)
m_BitField |= local_flag;
@@ -117,112 +106,92 @@
m_BitField |= weak_flag;
}
-void ResolveInfo::setReserved(uint32_t pReserved)
-{
+void ResolveInfo::setReserved(uint32_t pReserved) {
m_BitField &= ~RESERVED_MASK;
m_BitField |= ((pReserved << RESERVED_OFFSET) & RESERVED_MASK);
}
-void ResolveInfo::setOther(uint32_t pOther)
-{
+void ResolveInfo::setOther(uint32_t pOther) {
setVisibility(static_cast<ResolveInfo::Visibility>(pOther & 0x3));
}
-void ResolveInfo::setVisibility(ResolveInfo::Visibility pVisibility)
-{
+void ResolveInfo::setVisibility(ResolveInfo::Visibility pVisibility) {
m_BitField &= ~VISIBILITY_MASK;
m_BitField |= pVisibility << VISIBILITY_OFFSET;
}
-void ResolveInfo::setIsSymbol(bool pIsSymbol)
-{
+void ResolveInfo::setIsSymbol(bool pIsSymbol) {
if (pIsSymbol)
m_BitField |= symbol_flag;
else
m_BitField &= ~symbol_flag;
}
-bool ResolveInfo::isNull() const
-{
+bool ResolveInfo::isNull() const {
return (this == Null());
}
-bool ResolveInfo::isDyn() const
-{
+bool ResolveInfo::isDyn() const {
return (dynamic_flag == (m_BitField & DYN_MASK));
}
-bool ResolveInfo::isUndef() const
-{
+bool ResolveInfo::isUndef() const {
return (undefine_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isDefine() const
-{
+bool ResolveInfo::isDefine() const {
return (define_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isCommon() const
-{
+bool ResolveInfo::isCommon() const {
return (common_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isIndirect() const
-{
+bool ResolveInfo::isIndirect() const {
return (indirect_flag == (m_BitField & DESC_MASK));
}
// isGlobal - [L,W] == [0, 0]
-bool ResolveInfo::isGlobal() const
-{
+bool ResolveInfo::isGlobal() const {
return (global_flag == (m_BitField & BINDING_MASK));
}
// isWeak - [L,W] == [0, 1]
-bool ResolveInfo::isWeak() const
-{
+bool ResolveInfo::isWeak() const {
return (weak_flag == (m_BitField & BINDING_MASK));
}
// isLocal - [L,W] == [1, 0]
-bool ResolveInfo::isLocal() const
-{
+bool ResolveInfo::isLocal() const {
return (local_flag == (m_BitField & BINDING_MASK));
}
// isAbsolute - [L,W] == [1, 1]
-bool ResolveInfo::isAbsolute() const
-{
+bool ResolveInfo::isAbsolute() const {
return (absolute_flag == (m_BitField & BINDING_MASK));
}
-bool ResolveInfo::isSymbol() const
-{
+bool ResolveInfo::isSymbol() const {
return (symbol_flag == (m_BitField & SYMBOL_MASK));
}
-bool ResolveInfo::isString() const
-{
+bool ResolveInfo::isString() const {
return (string_flag == (m_BitField & SYMBOL_MASK));
}
-bool ResolveInfo::isInDyn() const
-{
+bool ResolveInfo::isInDyn() const {
return (indyn_flag == (m_BitField & IN_DYN_MASK));
}
-uint32_t ResolveInfo::type() const
-{
+uint32_t ResolveInfo::type() const {
return (m_BitField & TYPE_MASK) >> TYPE_OFFSET;
}
-uint32_t ResolveInfo::desc() const
-{
+uint32_t ResolveInfo::desc() const {
return (m_BitField & DESC_MASK) >> DESC_OFFSET;
}
-uint32_t ResolveInfo::binding() const
-{
+uint32_t ResolveInfo::binding() const {
if (m_BitField & LOCAL_MASK) {
if (m_BitField & GLOBAL_MASK) {
return ResolveInfo::Absolute;
@@ -232,26 +201,23 @@
return m_BitField & GLOBAL_MASK;
}
-uint32_t ResolveInfo::reserved() const
-{
+uint32_t ResolveInfo::reserved() const {
return (m_BitField & RESERVED_MASK) >> RESERVED_OFFSET;
}
-ResolveInfo::Visibility ResolveInfo::visibility() const
-{
- return static_cast<ResolveInfo::Visibility>((m_BitField & VISIBILITY_MASK) >> VISIBILITY_OFFSET);
+ResolveInfo::Visibility ResolveInfo::visibility() const {
+ return static_cast<ResolveInfo::Visibility>((m_BitField & VISIBILITY_MASK) >>
+ VISIBILITY_OFFSET);
}
-bool ResolveInfo::compare(const ResolveInfo::key_type& pKey)
-{
+bool ResolveInfo::compare(const ResolveInfo::key_type& pKey) {
size_t length = nameSize();
if (length != pKey.size())
return false;
- return (0 == std::memcmp(m_Name, pKey.data(), length));
+ return (std::memcmp(m_Name, pKey.data(), length) == 0);
}
-bool ResolveInfo::shouldForceLocal(const LinkerConfig& pConfig)
-{
+bool ResolveInfo::shouldForceLocal(const LinkerConfig& pConfig) {
// forced local symbol matches all rules:
// 1. We are not doing incremental linking.
// 2. The symbol is with Hidden or Internal visibility.
@@ -260,22 +226,20 @@
if (LinkerConfig::Object != pConfig.codeGenType() &&
(visibility() == ResolveInfo::Hidden ||
visibility() == ResolveInfo::Internal) &&
- (isGlobal() || isWeak()) &&
- (isDefine() || isCommon()))
+ (isGlobal() || isWeak()) && (isDefine() || isCommon()))
return true;
return false;
}
//===----------------------------------------------------------------------===//
// ResolveInfo Factory Methods
//===----------------------------------------------------------------------===//
-ResolveInfo* ResolveInfo::Create(const ResolveInfo::key_type& pKey)
-{
- ResolveInfo* info = static_cast<ResolveInfo*>(
- malloc(sizeof(ResolveInfo)+pKey.size()+1));
- if (NULL == info)
+ResolveInfo* ResolveInfo::Create(const ResolveInfo::key_type& pKey) {
+ ResolveInfo* info =
+ static_cast<ResolveInfo*>(malloc(sizeof(ResolveInfo) + pKey.size() + 1));
+ if (info == NULL)
return NULL;
- new (info) ResolveInfo(); // call constructor at the `result` address.
+ new (info) ResolveInfo(); // call constructor at the `result` address.
std::memcpy(info->m_Name, pKey.data(), pKey.size());
info->m_Name[pKey.size()] = '\0';
info->m_BitField &= ~ResolveInfo::RESOLVE_MASK;
@@ -283,12 +247,11 @@
return info;
}
-void ResolveInfo::Destroy(ResolveInfo*& pInfo)
-{
+void ResolveInfo::Destroy(ResolveInfo*& pInfo) {
if (pInfo->isNull())
return;
- if (NULL != pInfo) {
+ if (pInfo != NULL) {
pInfo->~ResolveInfo();
free(pInfo);
}
@@ -296,11 +259,10 @@
pInfo = NULL;
}
-ResolveInfo* ResolveInfo::Null()
-{
- if (NULL == g_NullResolveInfo) {
- g_NullResolveInfo = static_cast<ResolveInfo*>(
- malloc(sizeof(ResolveInfo) + 1));
+ResolveInfo* ResolveInfo::Null() {
+ if (g_NullResolveInfo == NULL) {
+ g_NullResolveInfo =
+ static_cast<ResolveInfo*>(malloc(sizeof(ResolveInfo) + 1));
new (g_NullResolveInfo) ResolveInfo();
g_NullResolveInfo->m_Name[0] = '\0';
g_NullResolveInfo->m_BitField = 0x0;
@@ -309,4 +271,4 @@
return g_NullResolveInfo;
}
-
+} // namespace mcld
diff --git a/lib/LD/Resolver.cpp b/lib/LD/Resolver.cpp
index aa39b13..1824d92 100644
--- a/lib/LD/Resolver.cpp
+++ b/lib/LD/Resolver.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Resolver.h>
+#include "mcld/LD/Resolver.h"
-using namespace mcld;
+namespace mcld {
//==========================
// Resolver
-Resolver::~Resolver()
-{
+Resolver::~Resolver() {
}
+} // namespace mcld
diff --git a/lib/LD/SectionData.cpp b/lib/LD/SectionData.cpp
index bb73724..6f669b7 100644
--- a/lib/LD/SectionData.cpp
+++ b/lib/LD/SectionData.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/SectionData.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<SectionData, MCLD_SECTIONS_PER_INPUT> SectDataFactory;
@@ -22,30 +22,26 @@
//===----------------------------------------------------------------------===//
// SectionData
//===----------------------------------------------------------------------===//
-SectionData::SectionData()
- : m_pSection(NULL) {
+SectionData::SectionData() : m_pSection(NULL) {
}
-SectionData::SectionData(LDSection &pSection)
- : m_pSection(&pSection) {
+SectionData::SectionData(LDSection& pSection) : m_pSection(&pSection) {
}
-SectionData* SectionData::Create(LDSection& pSection)
-{
+SectionData* SectionData::Create(LDSection& pSection) {
SectionData* result = g_SectDataFactory->allocate();
new (result) SectionData(pSection);
return result;
}
-void SectionData::Destroy(SectionData*& pSection)
-{
+void SectionData::Destroy(SectionData*& pSection) {
pSection->~SectionData();
g_SectDataFactory->deallocate(pSection);
pSection = NULL;
}
-void SectionData::Clear()
-{
+void SectionData::Clear() {
g_SectDataFactory->clear();
}
+} // namespace mcld
diff --git a/lib/LD/SectionSymbolSet.cpp b/lib/LD/SectionSymbolSet.cpp
index 07157cb..0d2555c 100644
--- a/lib/LD/SectionSymbolSet.cpp
+++ b/lib/LD/SectionSymbolSet.cpp
@@ -6,36 +6,33 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/SectionSymbolSet.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/LD/LDFileFormat.h>
+#include "mcld/LD/SectionSymbolSet.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// SectionSymbolSet
//===----------------------------------------------------------------------===//
-SectionSymbolSet::SectionSymbolSet()
-{
+SectionSymbolSet::SectionSymbolSet() {
m_pSectionSymbolMap = new SectHashTableType(16);
}
-SectionSymbolSet::~SectionSymbolSet()
-{
+SectionSymbolSet::~SectionSymbolSet() {
delete m_pSectionSymbolMap;
}
-bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool)
-{
+bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool) {
// create the resolveInfo for this section symbol
llvm::StringRef sym_name = llvm::StringRef(pOutSect.name());
ResolveInfo* sym_info = pNamePool.createSymbol(sym_name,
@@ -43,7 +40,7 @@
ResolveInfo::Section,
ResolveInfo::Define,
ResolveInfo::Local,
- 0x0, // size
+ 0x0, // size
ResolveInfo::Default);
// create the output section symbol and set its fragRef to the first fragment
@@ -54,7 +51,7 @@
// insert the symbol to the Section to Symbol hash map
bool exist = false;
SectHashTableType::entry_type* entry =
- m_pSectionSymbolMap->insert(&pOutSect, exist);
+ m_pSectionSymbolMap->insert(&pOutSect, exist);
assert(!exist);
entry->setValue(sym);
@@ -62,13 +59,13 @@
}
bool SectionSymbolSet::finalize(LDSection& pOutSect,
- SymbolTable& pSymTab, bool relocatable)
-{
+ SymbolTable& pSymTab,
+ bool relocatable) {
if (!relocatable && pOutSect.size() == 0)
- return true;
+ return true;
LDSymbol* sym = get(pOutSect);
- assert(NULL != sym);
+ assert(sym != NULL);
SectionData* data = NULL;
switch (pOutSect.kind()) {
case LDFileFormat::Relocation:
@@ -76,8 +73,8 @@
return true;
case LDFileFormat::EhFrame:
- if (EhFrame *ehframe = pOutSect.getEhFrame())
- data = ehframe->getSectionData();
+ if (EhFrame* ehframe = pOutSect.getEhFrame())
+ data = ehframe->getSectionData();
break;
default:
@@ -96,15 +93,14 @@
return true;
}
-LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect)
-{
+LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) {
SectHashTableType::iterator entry = m_pSectionSymbolMap->find(&pOutSect);
return entry.getEntry()->value();
}
-const LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) const
-{
+const LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) const {
SectHashTableType::iterator entry = m_pSectionSymbolMap->find(&pOutSect);
return entry.getEntry()->value();
}
+} // namespace mcld
diff --git a/lib/LD/StaticResolver.cpp b/lib/LD/StaticResolver.cpp
index 3dad005..1dd9747 100644
--- a/lib/LD/StaticResolver.cpp
+++ b/lib/LD/StaticResolver.cpp
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/StaticResolver.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/StaticResolver.h"
-using namespace mcld;
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
//==========================
// StaticResolver
-StaticResolver::~StaticResolver()
-{
+StaticResolver::~StaticResolver() {
}
bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
const ResolveInfo& __restrict__ pNew,
- bool &pOverride, LDSymbol::ValueType pValue) const
-{
-
+ bool& pOverride,
+ LDSymbol::ValueType pValue) const {
/* The state table itself.
* The first index is a link_row and the second index is a bfd_link_hash_type.
*
* Cs -> all rest kind of common (d_C, wd_C)
* Is -> all kind of indirect
*/
- static const enum LinkAction link_action[LAST_ORD][LAST_ORD] =
- {
- /* new\old U w_U d_U wd_U D w_D d_D wd_D C w_C, Cs, Is */
- /* U */ {NOACT, UND, UND, UND, NOACT, NOACT, DUND, DUND, NOACT, NOACT, NOACT, REFC },
- /* w_U */ {NOACT, NOACT, NOACT, WEAK, NOACT, NOACT, DUNDW, DUNDW, NOACT, NOACT, NOACT, REFC },
- /* d_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* wd_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* D */ {DEF, DEF, DEF, DEF, MDEF, DEF, DEF, DEF, CDEF, CDEF, CDEF, MDEF },
- /* w_D */ {DEFW, DEFW, DEFW, DEFW, NOACT, NOACT, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT},
- /* d_D */ {MDEFD, MDEFD, DEFD, DEFD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, MDEF },
- /* wd_D */ {MDEFWD, MDEFWD, DEFWD, DEFWD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT},
- /* C */ {COM, COM, COM, COM, CREF, COM, COM, COM, MBIG, COM, BIG, REFC },
- /* w_C */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* Cs */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, MBIG, MBIG, MBIG, REFC },
- /* Is */ {IND, IND, IND, IND, MDEF, IND, IND, IND, CIND, CIND, CIND, MIND }
+ static const enum LinkAction link_action[LAST_ORD][LAST_ORD] = {
+ /* new\old U w_U d_U wd_U D w_D d_D wd_D C w_C, Cs, Is */ // NOLINT
+ /* U */ {NOACT, UND, UND, UND, NOACT, NOACT, DUND, DUND, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* w_U */ {NOACT, NOACT, NOACT, WEAK, NOACT, NOACT, DUNDW, DUNDW, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* d_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* wd_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* D */ {DEF, DEF, DEF, DEF, MDEF, DEF, DEF, DEF, CDEF, CDEF, CDEF, MDEF }, // NOLINT
+ /* w_D */ {DEFW, DEFW, DEFW, DEFW, NOACT, NOACT, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT}, // NOLINT
+ /* d_D */ {MDEFD, MDEFD, DEFD, DEFD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, MDEF }, // NOLINT
+ /* wd_D */ {MDEFWD, MDEFWD, DEFWD, DEFWD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT}, // NOLINT
+ /* C */ {COM, COM, COM, COM, CREF, COM, COM, COM, MBIG, COM, BIG, REFC }, // NOLINT
+ /* w_C */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* Cs */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, MBIG, MBIG, MBIG, REFC }, // NOLINT
+ /* Is */ {IND, IND, IND, IND, MDEF, IND, IND, IND, CIND, CIND, CIND, MIND } // NOLINT
};
// Special cases:
@@ -57,7 +55,7 @@
// * When a undefined symbol meets a dynamic defined symbol or a weak
// undefined symbol meets a dynamic defined symbol, should override.
// * When a common symbol meets a weak common symbol, adjust the size of
- // common symbol (ref: Google gold linker: resolve.cc)
+ // common symbol.
unsigned int row = getOrdinate(pNew);
unsigned int col = getOrdinate(pOld);
@@ -70,31 +68,30 @@
cycle = false;
action = link_action[row][col];
- switch(action) {
- case FAIL: { /* abort. */
- fatal(diag::fail_sym_resolution)
- << __FILE__ << __LINE__
- << "mclinker@googlegroups.com";
+ switch (action) {
+ case FAIL: { /* abort. */
+ fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
+ << "mclinker@googlegroups.com";
return false;
}
- case NOACT: { /* no action. */
+ case NOACT: { /* no action. */
pOverride = false;
old->overrideVisibility(pNew);
break;
}
- case UND: /* override by symbol undefined symbol. */
- case WEAK: /* override by symbol weak undefined. */
- case DEF: /* override by symbol defined. */
- case DEFW: /* override by symbol weak defined. */
- case DEFD: /* override by symbol dynamic defined. */
- case DEFWD: /* override by symbol dynamic weak defined. */
- case COM: { /* override by symbol common defined. */
+ case UND: /* override by symbol undefined symbol. */
+ case WEAK: /* override by symbol weak undefined. */
+ case DEF: /* override by symbol defined. */
+ case DEFW: /* override by symbol weak defined. */
+ case DEFD: /* override by symbol dynamic defined. */
+ case DEFWD: /* override by symbol dynamic weak defined. */
+ case COM: { /* override by symbol common defined. */
pOverride = true;
old->override(pNew);
break;
}
- case MDEFD: /* mark symbol dynamic defined. */
- case MDEFWD: { /* mark symbol dynamic weak defined. */
+ case MDEFD: /* mark symbol dynamic defined. */
+ case MDEFWD: { /* mark symbol dynamic weak defined. */
uint32_t binding = old->binding();
old->override(pNew);
old->setBinding(binding);
@@ -109,23 +106,24 @@
pOverride = false;
break;
}
- case CREF: { /* Possibly warn about common reference to defined symbol. */
+ case CREF: { /* Possibly warn about common reference to defined symbol. */
// A common symbol does not override a definition.
ignore(diag::comm_refer_to_define) << old->name();
pOverride = false;
break;
}
- case CDEF: { /* redefine existing common symbol. */
+ case CDEF: { /* redefine existing common symbol. */
// We've seen a common symbol and now we see a definition. The
// definition overrides.
//
- // NOTE: m_Mesg uses 'name' instead of `name' for being compatible to GNU ld.
+ // NOTE: m_Mesg uses 'name' instead of `name' for being compatible to
+ // GNU ld.
ignore(diag::redefine_common) << old->name();
old->override(pNew);
pOverride = true;
break;
}
- case BIG: { /* override by symbol common using largest size. */
+ case BIG: { /* override by symbol common using largest size. */
if (old->size() < pNew.size())
old->setSize(pNew.size());
old->overrideAttributes(pNew);
@@ -133,26 +131,27 @@
pOverride = true;
break;
}
- case MBIG: { /* mark common symbol by larger size. */
+ case MBIG: { /* mark common symbol by larger size. */
if (old->size() < pNew.size())
old->setSize(pNew.size());
old->overrideVisibility(pNew);
pOverride = false;
break;
}
- case CIND: { /* mark indirect symbol from existing common symbol. */
- ignore(diag::indirect_refer_to_common) << old->name();
+ case CIND: { /* mark indirect symbol from existing common symbol. */
+ ignore(diag::indirect_refer_to_common) << old->name();
}
/* Fall through */
- case IND: { /* override by indirect symbol. */
- if (NULL == pNew.link()) {
+ case IND: { /* override by indirect symbol. */
+ if (pNew.link() == NULL) {
fatal(diag::indirect_refer_to_inexist) << pNew.name();
break;
}
/** Should detect the loop of indirect symbol during file reading **/
// if (pNew.link()->isIndirect() && pNew.link()->link() == &pNew) {
- // m_Mesg = "indirect symbol `"+pNew.name()+"' to `"+pNew.link()->name()+"' is a loop.";
+ // m_Mesg = "indirect symbol `"+pNew.name()+"' to
+ // `"+pNew.link()->name()+"' is a loop.";
// return Resolver::Abort;
//}
@@ -161,7 +160,7 @@
pOverride = true;
break;
}
- case MIND: { /* multiple indirect symbols. */
+ case MIND: { /* multiple indirect symbols. */
// it is OK if they both point to the same symbol
if (old->link() == pNew.link()) {
pOverride = false;
@@ -169,9 +168,9 @@
}
}
/* Fall through */
- case MDEF: { /* multiple definition error. */
- if (pOld.isDefine() && pNew.isDefine() &&
- pOld.isAbsolute() && pNew.isAbsolute() &&
+ case MDEF: { /* multiple definition error. */
+ if (pOld.isDefine() && pNew.isDefine() && pOld.isAbsolute() &&
+ pNew.isAbsolute() &&
(pOld.desc() == pNew.desc() || pOld.desc() == ResolveInfo::NoType ||
pNew.desc() == ResolveInfo::NoType)) {
if (pOld.outSymbol()->value() == pValue) {
@@ -180,8 +179,7 @@
break;
} else {
error(diag::multiple_absolute_definitions)
- << demangleName(pNew.name())
- << pOld.outSymbol()->value()
+ << demangleName(pNew.name()) << pOld.outSymbol()->value()
<< pValue;
break;
}
@@ -190,8 +188,8 @@
error(diag::multiple_definitions) << demangleName(pNew.name());
break;
}
- case REFC: { /* Mark indirect symbol referenced and then CYCLE. */
- if (NULL == old->link()) {
+ case REFC: { /* Mark indirect symbol referenced and then CYCLE. */
+ if (old->link() == NULL) {
fatal(diag::indirect_refer_to_inexist) << old->name();
break;
}
@@ -202,11 +200,13 @@
break;
}
default: {
- error(diag::undefined_situation) << action << old->name() << pNew.name();
+ error(diag::undefined_situation) << action << old->name()
+ << pNew.name();
return false;
}
- } // end of the big switch (action)
- } while(cycle);
+ } // end of the big switch (action)
+ } while (cycle);
return true;
}
+} // namespace mcld
diff --git a/lib/LD/StubFactory.cpp b/lib/LD/StubFactory.cpp
index 52c372c..75de0cf 100644
--- a/lib/LD/StubFactory.cpp
+++ b/lib/LD/StubFactory.cpp
@@ -6,32 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/StubFactory.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/BranchIsland.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/LD/StubFactory.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIsland.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
#include <string>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// StubFactory
//===----------------------------------------------------------------------===//
-StubFactory::~StubFactory()
-{
+StubFactory::~StubFactory() {
for (StubPoolType::iterator it = m_StubPool.begin(), ie = m_StubPool.end();
- it != ie; ++it)
- delete(*it);
+ it != ie;
+ ++it)
+ delete (*it);
}
/// addPrototype - register a stub prototype
-void StubFactory::addPrototype(Stub* pPrototype)
-{
+void StubFactory::addPrototype(Stub* pPrototype) {
m_StubPool.push_back(pPrototype);
}
@@ -39,8 +39,7 @@
Stub* StubFactory::create(Relocation& pReloc,
uint64_t pTargetSymValue,
IRBuilder& pBuilder,
- BranchIslandFactory& pBRIslandFactory)
-{
+ BranchIslandFactory& pBRIslandFactory) {
// find if there is a prototype stub for the input relocation
Stub* stub = NULL;
Stub* prototype = findPrototype(pReloc, pReloc.place(), pTargetSymValue);
@@ -87,16 +86,18 @@
ResolveInfo::Function,
ResolveInfo::Define,
ResolveInfo::Local,
- stub->size(), // size
- stub->initSymValue(), // value
+ stub->size(), // size
+ stub->initSymValue(), // value
FragmentRef::Create(*stub, stub->initSymValue()),
ResolveInfo::Default);
stub->setSymInfo(symbol->resolveInfo());
- // add relocations of this stub (i.e., set the branch target of the stub)
+ // add relocations of this stub (i.e., set the branch target of the
+ // stub)
for (Stub::fixup_iterator it = stub->fixup_begin(),
- ie = stub->fixup_end(); it != ie; ++it) {
-
+ ie = stub->fixup_end();
+ it != ie;
+ ++it) {
Relocation* reloc =
Relocation::Create((*it)->type(),
*(FragmentRef::Create(*stub, (*it)->offset())),
@@ -120,12 +121,14 @@
/// relocation
Stub* StubFactory::findPrototype(const Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue)
-{
+ uint64_t pTargetSymValue) {
for (StubPoolType::iterator it = m_StubPool.begin(), ie = m_StubPool.end();
- it != ie; ++it) {
+ it != ie;
+ ++it) {
if ((*it)->isMyDuty(pReloc, pSource, pTargetSymValue))
return (*it);
}
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/LD/TextDiagnosticPrinter.cpp b/lib/LD/TextDiagnosticPrinter.cpp
index 9fcabea..5b1d488 100644
--- a/lib/LD/TextDiagnosticPrinter.cpp
+++ b/lib/LD/TextDiagnosticPrinter.cpp
@@ -6,38 +6,45 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/TextDiagnosticPrinter.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/TextDiagnosticPrinter.h"
+
+#include "mcld/LinkerConfig.h"
+
#include <llvm/Support/Signals.h>
+
#include <string>
-using namespace mcld;
+namespace mcld {
-static const enum llvm::raw_ostream::Colors UnreachableColor = llvm::raw_ostream::RED;
-static const enum llvm::raw_ostream::Colors FatalColor = llvm::raw_ostream::YELLOW;
-static const enum llvm::raw_ostream::Colors ErrorColor = llvm::raw_ostream::RED;
-static const enum llvm::raw_ostream::Colors WarningColor = llvm::raw_ostream::MAGENTA;
-static const enum llvm::raw_ostream::Colors DebugColor = llvm::raw_ostream::CYAN;
-static const enum llvm::raw_ostream::Colors NoteColor = llvm::raw_ostream::GREEN;
-static const enum llvm::raw_ostream::Colors IgnoreColor = llvm::raw_ostream::BLUE;
+static const enum llvm::raw_ostream::Colors UnreachableColor =
+ llvm::raw_ostream::RED;
+static const enum llvm::raw_ostream::Colors FatalColor =
+ llvm::raw_ostream::YELLOW;
+static const enum llvm::raw_ostream::Colors ErrorColor = llvm::raw_ostream::RED;
+static const enum llvm::raw_ostream::Colors WarningColor =
+ llvm::raw_ostream::MAGENTA;
+static const enum llvm::raw_ostream::Colors DebugColor =
+ llvm::raw_ostream::CYAN;
+static const enum llvm::raw_ostream::Colors NoteColor =
+ llvm::raw_ostream::GREEN;
+static const enum llvm::raw_ostream::Colors IgnoreColor =
+ llvm::raw_ostream::BLUE;
//===----------------------------------------------------------------------===//
// TextDiagnosticPrinter
TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream& pOStream,
const LinkerConfig& pConfig)
- : m_OStream(pOStream), m_Config(pConfig), m_pInput(NULL) {
+ : m_OStream(pOStream), m_Config(pConfig), m_pInput(NULL) {
}
-TextDiagnosticPrinter::~TextDiagnosticPrinter()
-{
+TextDiagnosticPrinter::~TextDiagnosticPrinter() {
}
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
-void
-TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
- const Diagnostic& pInfo)
-{
+void TextDiagnosticPrinter::handleDiagnostic(
+ DiagnosticEngine::Severity pSeverity,
+ const Diagnostic& pInfo) {
DiagnosticPrinter::handleDiagnostic(pSeverity, pInfo);
std::string out_string;
@@ -74,7 +81,7 @@
}
case DiagnosticEngine::Debug: {
// show debug message only if verbose >= 0
- if (0 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 0) {
m_OStream.changeColor(DebugColor, true);
m_OStream << "Debug: ";
m_OStream.resetColor();
@@ -84,7 +91,7 @@
}
case DiagnosticEngine::Note: {
// show ignored message only if verbose >= 1
- if (1 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 1) {
m_OStream.changeColor(NoteColor, true);
m_OStream << "Note: ";
m_OStream.resetColor();
@@ -94,7 +101,7 @@
}
case DiagnosticEngine::Ignore: {
// show ignored message only if verbose >= 2
- if (2 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 2) {
m_OStream.changeColor(IgnoreColor, true);
m_OStream << "Ignore: ";
m_OStream.resetColor();
@@ -116,8 +123,10 @@
}
/** fall through **/
case DiagnosticEngine::Fatal: {
- // If we reached here, we are failing ungracefully. Run the interrupt handlers
- // to make sure any special cleanups get done, in particular that we remove
+ // If we reached here, we are failing ungracefully. Run the interrupt
+ // handlers
+ // to make sure any special cleanups get done, in particular that we
+ // remove
// files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
exit(1);
@@ -142,7 +151,8 @@
(getNumWarnings() > static_cast<unsigned>(warning_limit))) {
m_OStream << "\n\n";
m_OStream.changeColor(llvm::raw_ostream::YELLOW);
- m_OStream << "too many warning messages (>" << warning_limit << ")...\n";
+ m_OStream << "too many warning messages (>" << warning_limit
+ << ")...\n";
m_OStream.resetColor();
llvm::sys::RunInterruptHandlers();
exit(1);
@@ -153,12 +163,13 @@
}
}
-void TextDiagnosticPrinter::beginInput(const Input& pInput, const LinkerConfig& pConfig)
-{
+void TextDiagnosticPrinter::beginInput(const Input& pInput,
+ const LinkerConfig& pConfig) {
m_pInput = &pInput;
}
-void TextDiagnosticPrinter::endInput()
-{
+void TextDiagnosticPrinter::endInput() {
m_pInput = NULL;
}
+
+} // namespace mcld
diff --git a/lib/MC/Attribute.cpp b/lib/MC/Attribute.cpp
index 64782db..859689d 100644
--- a/lib/MC/Attribute.cpp
+++ b/lib/MC/Attribute.cpp
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/AttributeSet.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/MC/Attribute.h"
-using namespace mcld;
+#include "mcld/MC/AttributeSet.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttrConstraint
//===----------------------------------------------------------------------===//
-bool AttrConstraint::isLegal(const Attribute& pAttr) const
-{
+bool AttrConstraint::isLegal(const Attribute& pAttr) const {
if (!isWholeArchive() && pAttr.isWholeArchive()) {
error(diag::err_unsupported_whole_archive);
return false;
@@ -51,47 +51,41 @@
AttributeProxy::AttributeProxy(AttributeSet& pParent,
const Attribute& pBase,
const AttrConstraint& pConstraint)
- : m_AttrPool(pParent), m_pBase(&pBase), m_Constraint(pConstraint) {
+ : m_AttrPool(pParent), m_pBase(&pBase), m_Constraint(pConstraint) {
}
-AttributeProxy::~AttributeProxy()
-{
+AttributeProxy::~AttributeProxy() {
}
-bool AttributeProxy::isWholeArchive() const
-{
+bool AttributeProxy::isWholeArchive() const {
if (m_Constraint.isWholeArchive())
return m_pBase->isWholeArchive();
else
return false;
}
-bool AttributeProxy::isAsNeeded() const
-{
+bool AttributeProxy::isAsNeeded() const {
if (m_Constraint.isAsNeeded())
return m_pBase->isAsNeeded();
else
return false;
}
-bool AttributeProxy::isAddNeeded() const
-{
+bool AttributeProxy::isAddNeeded() const {
if (m_Constraint.isAddNeeded())
return m_pBase->isAddNeeded();
else
return false;
}
-bool AttributeProxy::isStatic() const
-{
+bool AttributeProxy::isStatic() const {
if (m_Constraint.isSharedSystem())
return m_pBase->isStatic();
else
return true;
}
-bool AttributeProxy::isDynamic() const
-{
+bool AttributeProxy::isDynamic() const {
if (m_Constraint.isSharedSystem())
return m_pBase->isDynamic();
else
@@ -99,79 +93,69 @@
}
static inline void ReplaceOrRecord(AttributeSet& pParent,
- const Attribute *&pBase,
- Attribute *&pCopy)
-{
- Attribute *result = pParent.exists(*pCopy);
- if (NULL == result) { // can not find
+ const Attribute*& pBase,
+ Attribute*& pCopy) {
+ Attribute* result = pParent.exists(*pCopy);
+ if (result == NULL) { // can not find
pParent.record(*pCopy);
pBase = pCopy;
- }
- else { // find
+ } else { // find
delete pCopy;
pBase = result;
}
}
-void AttributeProxy::setWholeArchive()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setWholeArchive() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setWholeArchive();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetWholeArchive()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetWholeArchive() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetWholeArchive();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setAsNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setAsNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setAsNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetAsNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetAsNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetAsNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setAddNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setAddNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setAddNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetAddNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetAddNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetAddNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setStatic()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setStatic() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setStatic();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setDynamic()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setDynamic() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setDynamic();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-AttributeProxy& AttributeProxy::assign(Attribute* pBase)
-{
+AttributeProxy& AttributeProxy::assign(Attribute* pBase) {
m_pBase = pBase;
return *this;
}
+} // namespace mcld
diff --git a/lib/MC/AttributeSet.cpp b/lib/MC/AttributeSet.cpp
index e657207..96dc77f 100644
--- a/lib/MC/AttributeSet.cpp
+++ b/lib/MC/AttributeSet.cpp
@@ -6,39 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/AttributeSet.h>
+#include "mcld/MC/AttributeSet.h"
+
+#include "mcld/MC/Attribute.h"
+
#include <cstddef>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttributeSet
//===----------------------------------------------------------------------===//
AttributeSet::AttributeSet(unsigned int pNum, const Attribute& pPredefined)
- : m_AttrSet(), m_Predefined(pPredefined) {
+ : m_AttrSet(), m_Predefined(pPredefined) {
m_AttrSet.reserve(pNum);
}
-AttributeSet::~AttributeSet()
-{
+AttributeSet::~AttributeSet() {
iterator cur = m_AttrSet.begin();
iterator aEnd = m_AttrSet.end();
- while(cur != aEnd) {
+ while (cur != aEnd) {
delete (*cur);
++cur;
}
}
-Attribute* AttributeSet::exists(const Attribute& pAttr) const
-{
+Attribute* AttributeSet::exists(const Attribute& pAttr) const {
if (m_Predefined == pAttr)
return const_cast<Attribute*>(&m_Predefined);
const_iterator cur = m_AttrSet.begin();
const_iterator aEnd = m_AttrSet.end();
- while(cur != aEnd) {
+ while (cur != aEnd) {
if (*(*cur) == pAttr) {
return *cur;
}
@@ -47,8 +47,8 @@
return NULL;
}
-void AttributeSet::record(mcld::Attribute &pAttr)
-{
+void AttributeSet::record(mcld::Attribute& pAttr) {
m_AttrSet.push_back(&pAttr);
}
+} // namespace mcld
diff --git a/lib/MC/CommandAction.cpp b/lib/MC/CommandAction.cpp
index bae5fbf..4439d7e 100644
--- a/lib/MC/CommandAction.cpp
+++ b/lib/MC/CommandAction.cpp
@@ -6,15 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/CommandAction.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/SearchDirs.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/MC/CommandAction.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/MC/SearchDirs.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/FileSystem.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Derived Positional Option
@@ -22,12 +23,16 @@
// InputFileAction
//===----------------------------------------------------------------------===//
InputFileAction::InputFileAction(unsigned int pPosition,
- const sys::fs::Path &pPath)
- : InputAction(pPosition), m_Path(pPath) {
+ const sys::fs::Path& pPath)
+ : InputAction(pPosition), m_Path(pPath) {
}
-bool InputFileAction::activate(InputBuilder& pBuilder) const
-{
+InputFileAction::InputFileAction(unsigned int pPosition,
+ const char* pPath)
+ : InputAction(pPosition), m_Path(pPath) {
+}
+
+bool InputFileAction::activate(InputBuilder& pBuilder) const {
pBuilder.createNode<InputTree::Positional>(path().stem().native(), path());
return true;
}
@@ -36,13 +41,12 @@
// NamespecAction
//===----------------------------------------------------------------------===//
NamespecAction::NamespecAction(unsigned int pPosition,
- const std::string &pNamespec,
+ const std::string& pNamespec,
const SearchDirs& pSearchDirs)
- : InputAction(pPosition), m_Namespec(pNamespec), m_SearchDirs(pSearchDirs) {
+ : InputAction(pPosition), m_Namespec(pNamespec), m_SearchDirs(pSearchDirs) {
}
-bool NamespecAction::activate(InputBuilder& pBuilder) const
-{
+bool NamespecAction::activate(InputBuilder& pBuilder) const {
const sys::fs::Path* path = NULL;
// find out the real path of the namespec.
if (pBuilder.getConstraint().isSharedSystem()) {
@@ -52,19 +56,17 @@
if (pBuilder.getAttributes().isStatic()) {
// with --static, we must search an archive.
path = m_SearchDirs.find(namespec(), Input::Archive);
- }
- else {
+ } else {
// otherwise, with --Bdynamic, we can find either an archive or a
// shared object.
path = m_SearchDirs.find(namespec(), Input::DynObj);
}
- }
- else {
+ } else {
// In the system without shared object support, we only look for an archive
path = m_SearchDirs.find(namespec(), Input::Archive);
}
- if (NULL == path) {
+ if (path == NULL) {
fatal(diag::err_cannot_find_namespec) << namespec();
return false;
}
@@ -76,13 +78,13 @@
//===----------------------------------------------------------------------===//
// BitcodeAction
//===----------------------------------------------------------------------===//
-BitcodeAction::BitcodeAction(unsigned int pPosition, const sys::fs::Path &pPath)
- : InputAction(pPosition), m_Path(pPath) {
+BitcodeAction::BitcodeAction(unsigned int pPosition, const sys::fs::Path& pPath)
+ : InputAction(pPosition), m_Path(pPath) {
}
-bool BitcodeAction::activate(InputBuilder& pBuilder) const
-{
- pBuilder.createNode<InputTree::Positional>("bitcode", path(), Input::External);
+bool BitcodeAction::activate(InputBuilder& pBuilder) const {
+ pBuilder.createNode<InputTree::Positional>(
+ "bitcode", path(), Input::External);
return true;
}
@@ -90,11 +92,10 @@
// StartGroupAction
//===----------------------------------------------------------------------===//
StartGroupAction::StartGroupAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool StartGroupAction::activate(InputBuilder& pBuilder) const
-{
+bool StartGroupAction::activate(InputBuilder& pBuilder) const {
if (pBuilder.isInGroup()) {
fatal(diag::fatal_forbid_nest_group);
return false;
@@ -107,11 +108,10 @@
// EndGroupAction
//===----------------------------------------------------------------------===//
EndGroupAction::EndGroupAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool EndGroupAction::activate(InputBuilder& pBuilder) const
-{
+bool EndGroupAction::activate(InputBuilder& pBuilder) const {
pBuilder.exitGroup();
return true;
}
@@ -120,11 +120,10 @@
// WholeArchiveAction
//===----------------------------------------------------------------------===//
WholeArchiveAction::WholeArchiveAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool WholeArchiveAction::activate(InputBuilder& pBuilder) const
-{
+bool WholeArchiveAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setWholeArchive();
return true;
}
@@ -133,11 +132,10 @@
// NoWholeArchiveAction
//===----------------------------------------------------------------------===//
NoWholeArchiveAction::NoWholeArchiveAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const
-{
+bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetWholeArchive();
return true;
}
@@ -146,11 +144,10 @@
// AsNeededAction
//===----------------------------------------------------------------------===//
AsNeededAction::AsNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool AsNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool AsNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setAsNeeded();
return true;
}
@@ -159,11 +156,10 @@
// NoAsNeededAction
//===----------------------------------------------------------------------===//
NoAsNeededAction::NoAsNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoAsNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool NoAsNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetAsNeeded();
return true;
}
@@ -172,11 +168,10 @@
// AddNeededAction
//===----------------------------------------------------------------------===//
AddNeededAction::AddNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool AddNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool AddNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setAddNeeded();
return true;
}
@@ -185,11 +180,10 @@
// NoAddNeededAction
//===----------------------------------------------------------------------===//
NoAddNeededAction::NoAddNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoAddNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool NoAddNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetAddNeeded();
return true;
}
@@ -198,11 +192,10 @@
// BDynamicAction
//===----------------------------------------------------------------------===//
BDynamicAction::BDynamicAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool BDynamicAction::activate(InputBuilder& pBuilder) const
-{
+bool BDynamicAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setDynamic();
return true;
}
@@ -210,12 +203,10 @@
//===----------------------------------------------------------------------===//
// BStaticAction
//===----------------------------------------------------------------------===//
-BStaticAction::BStaticAction(unsigned int pPosition)
- : InputAction(pPosition) {
+BStaticAction::BStaticAction(unsigned int pPosition) : InputAction(pPosition) {
}
-bool BStaticAction::activate(InputBuilder& pBuilder) const
-{
+bool BStaticAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setStatic();
return true;
}
@@ -224,12 +215,11 @@
// DefSymAction
//===----------------------------------------------------------------------===//
DefSymAction::DefSymAction(unsigned int pPosition, std::string& pAssignment)
- : InputAction(pPosition), m_Assignment(pAssignment) {
+ : InputAction(pPosition), m_Assignment(pAssignment) {
}
-bool DefSymAction::activate(InputBuilder& pBuilder) const
-{
- pBuilder.createNode<InputTree::Positional>("defsym", "NAN");
+bool DefSymAction::activate(InputBuilder& pBuilder) const {
+ pBuilder.createNode<InputTree::Positional>("defsym", sys::fs::Path("NAN"));
Input* input = *pBuilder.getCurrentNode();
pBuilder.setContext(*input, false);
@@ -245,31 +235,33 @@
const std::string& pFileName,
ScriptFile::Kind pKind,
const SearchDirs& pSearchDirs)
- : InputAction(pPosition),
- m_FileName(pFileName),
- m_Kind(pKind),
- m_SearchDirs(pSearchDirs) {
+ : InputAction(pPosition),
+ m_FileName(pFileName),
+ m_Kind(pKind),
+ m_SearchDirs(pSearchDirs) {
}
-bool ScriptAction::activate(InputBuilder& pBuilder) const
-{
+bool ScriptAction::activate(InputBuilder& pBuilder) const {
sys::fs::Path path(m_FileName);
if (!exists(path)) {
const sys::fs::Path* res = m_SearchDirs.find(m_FileName, Input::Script);
if (res == NULL) {
switch (m_Kind) {
- case ScriptFile::LDScript:
- fatal(diag::err_cannot_find_scriptfile) << "linker script" << m_FileName;
- break;
- case ScriptFile::VersionScript:
- fatal(diag::err_cannot_find_scriptfile) << "version script" << m_FileName;
- break;
- case ScriptFile::DynamicList:
- fatal(diag::err_cannot_find_scriptfile) << "dynamic list" << m_FileName;
- break;
- default:
- break;
+ case ScriptFile::LDScript:
+ fatal(diag::err_cannot_find_scriptfile) << "linker script"
+ << m_FileName;
+ break;
+ case ScriptFile::VersionScript:
+ fatal(diag::err_cannot_find_scriptfile) << "version script"
+ << m_FileName;
+ break;
+ case ScriptFile::DynamicList:
+ fatal(diag::err_cannot_find_scriptfile) << "dynamic list"
+ << m_FileName;
+ break;
+ default:
+ break;
}
return false;
}
@@ -280,3 +272,5 @@
return true;
}
+
+} // namespace mcld
diff --git a/lib/MC/ContextFactory.cpp b/lib/MC/ContextFactory.cpp
index 5b698c7..fe0489c 100644
--- a/lib/MC/ContextFactory.cpp
+++ b/lib/MC/ContextFactory.cpp
@@ -6,26 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDContext.h>
-#include <mcld/MC/ContextFactory.h>
+#include "mcld/MC/ContextFactory.h"
-using namespace mcld;
+#include "mcld/LD/LDContext.h"
+
+namespace mcld {
//===---------------------------------------------------------------------===//
// LDContextFactory
ContextFactory::ContextFactory(size_t pNum)
- : UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>(pNum)
-{
+ : UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>(pNum) {
}
-ContextFactory::~ContextFactory()
-{
+ContextFactory::~ContextFactory() {
}
-LDContext* ContextFactory::produce(const sys::fs::Path& pPath)
-{
+LDContext* ContextFactory::produce(const sys::fs::Path& pPath) {
LDContext* result = find(pPath);
- if (0 == result) {
+ if (result == NULL) {
result = UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>::allocate();
new (result) LDContext();
f_KeyMap.insert(std::make_pair(pPath, result));
@@ -33,10 +31,14 @@
return result;
}
-LDContext* ContextFactory::produce()
-{
+LDContext* ContextFactory::produce(const char* pPath) {
+ return produce(sys::fs::Path(pPath));
+}
+
+LDContext* ContextFactory::produce() {
LDContext* result = allocate();
new (result) LDContext();
return result;
}
+} // namespace mcld
diff --git a/lib/MC/FileAction.cpp b/lib/MC/FileAction.cpp
index 0de60ee..f4e68df 100644
--- a/lib/MC/FileAction.cpp
+++ b/lib/MC/FileAction.cpp
@@ -6,31 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/FileAction.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/InputBuilder.h>
+#include "mcld/MC/FileAction.h"
-using namespace mcld;
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ContextAction
//===----------------------------------------------------------------------===//
-ContextAction::ContextAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ContextAction::ContextAction(unsigned int pPosition) : InputAction(pPosition) {
}
-bool ContextAction::activate(InputBuilder& pBuilder) const
-{
+bool ContextAction::activate(InputBuilder& pBuilder) const {
Input* input = *pBuilder.getCurrentNode();
if (input->hasContext())
return false;
// already got type - for example, bitcode
- if (input->type() == Input::Script ||
- input->type() == Input::Object ||
- input->type() == Input::DynObj ||
- input->type() == Input::Archive)
+ if (input->type() == Input::Script || input->type() == Input::Object ||
+ input->type() == Input::DynObj || input->type() == Input::Archive)
return false;
return pBuilder.setContext(*input);
@@ -40,25 +37,23 @@
// MemoryAreaAction
//===----------------------------------------------------------------------===//
MemoryAreaAction::MemoryAreaAction(unsigned int pPosition,
- FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
- : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
+ FileHandle::OpenModeEnum pMode,
+ FileHandle::PermissionEnum pPerm)
+ : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
}
-bool MemoryAreaAction::activate(InputBuilder& pBuilder) const
-{
+bool MemoryAreaAction::activate(InputBuilder& pBuilder) const {
Input* input = *pBuilder.getCurrentNode();
if (input->hasMemArea())
return false;
// already got type - for example, bitcode
- if (input->type() == Input::Script ||
- input->type() == Input::Object ||
- input->type() == Input::DynObj ||
- input->type() == Input::Archive)
+ if (input->type() == Input::Script || input->type() == Input::Object ||
+ input->type() == Input::DynObj || input->type() == Input::Archive)
return false;
return pBuilder.setMemory(*input, m_Mode, m_Permission);
}
+} // namespace mcld
diff --git a/lib/MC/Input.cpp b/lib/MC/Input.cpp
index 26234fc..e19f667 100644
--- a/lib/MC/Input.cpp
+++ b/lib/MC/Input.cpp
@@ -6,73 +6,74 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Input.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/LD/LDContext.h>
+#include "mcld/MC/Input.h"
-using namespace mcld;
+#include "mcld/MC/Attribute.h"
+#include "mcld/LD/LDContext.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// mcld::Input
//===----------------------------------------------------------------------===//
Input::Input(llvm::StringRef pName)
- : m_Type(Unknown),
- m_Name(pName.data()),
- m_Path(),
- m_pAttr(NULL),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(0),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ : m_Type(Unknown),
+ m_Name(pName.data()),
+ m_Path(),
+ m_pAttr(NULL),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(0),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName, const AttributeProxy& pProxy)
- : m_Type(Unknown),
- m_Name(pName.data()),
- m_Path(),
- m_pAttr(const_cast<Attribute*>(pProxy.attr())),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(0),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ : m_Type(Unknown),
+ m_Name(pName.data()),
+ m_Path(),
+ m_pAttr(const_cast<Attribute*>(pProxy.attr())),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(0),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName,
- const sys::fs::Path& pPath,
- unsigned int pType,
- off_t pFileOffset)
- : m_Type(pType),
- m_Name(pName.data()),
- m_Path(pPath),
- m_pAttr(NULL),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(pFileOffset),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ const sys::fs::Path& pPath,
+ unsigned int pType,
+ off_t pFileOffset)
+ : m_Type(pType),
+ m_Name(pName.data()),
+ m_Path(pPath),
+ m_pAttr(NULL),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(pFileOffset),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName,
- const sys::fs::Path& pPath,
- const AttributeProxy& pProxy,
- unsigned int pType,
- off_t pFileOffset)
- : m_Type(pType),
- m_Name(pName.data()),
- m_Path(pPath),
- m_pAttr(const_cast<Attribute*>(pProxy.attr())),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(pFileOffset),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ const sys::fs::Path& pPath,
+ const AttributeProxy& pProxy,
+ unsigned int pType,
+ off_t pFileOffset)
+ : m_Type(pType),
+ m_Name(pName.data()),
+ m_Path(pPath),
+ m_pAttr(const_cast<Attribute*>(pProxy.attr())),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(pFileOffset),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
-Input::~Input()
-{
+Input::~Input() {
// Attribute is deleted by AttributeFactory
// MemoryArea is deleted by MemoryAreaFactory
}
+} // namespace mcld
diff --git a/lib/MC/InputAction.cpp b/lib/MC/InputAction.cpp
index f9078c6..7fdb93a 100644
--- a/lib/MC/InputAction.cpp
+++ b/lib/MC/InputAction.cpp
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputAction.h>
+#include "mcld/MC/InputAction.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Base Positional Option
//===----------------------------------------------------------------------===//
-InputAction::InputAction(unsigned int pPosition)
- : m_Position(pPosition) {
+InputAction::InputAction(unsigned int pPosition) : m_Position(pPosition) {
}
-InputAction::~InputAction()
-{
+InputAction::~InputAction() {
}
+} // namespace mcld
diff --git a/lib/MC/InputBuilder.cpp b/lib/MC/InputBuilder.cpp
index 842c476..e20403f 100644
--- a/lib/MC/InputBuilder.cpp
+++ b/lib/MC/InputBuilder.cpp
@@ -6,25 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputBuilder.h>
+#include "mcld/MC/InputBuilder.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/Config/Config.h>
-#include <mcld/Support/Path.h>
-#include <mcld/MC/InputFactory.h>
-#include <mcld/MC/ContextFactory.h>
-#include <mcld/Support/MemoryAreaFactory.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/Config/Config.h"
+#include "mcld/MC/ContextFactory.h"
+#include "mcld/MC/InputFactory.h"
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/Path.h"
-using namespace mcld;
+namespace mcld {
InputBuilder::InputBuilder(const LinkerConfig& pConfig)
- : m_Config(pConfig),
- m_pCurrentTree(NULL), m_pMove(NULL), m_Root(),
- m_bOwnFactory(true) {
-
- m_pInputFactory = new InputFactory(MCLD_NUM_OF_INPUTS, pConfig);
- m_pContextFactory = new ContextFactory(MCLD_NUM_OF_INPUTS);
- m_pMemFactory = new MemoryAreaFactory(MCLD_NUM_OF_INPUTS);
+ : m_Config(pConfig),
+ m_pCurrentTree(NULL),
+ m_pMove(NULL),
+ m_Root(),
+ m_bOwnFactory(true) {
+ m_pInputFactory = new InputFactory(MCLD_NUM_OF_INPUTS, pConfig);
+ m_pContextFactory = new ContextFactory(MCLD_NUM_OF_INPUTS);
+ m_pMemFactory = new MemoryAreaFactory(MCLD_NUM_OF_INPUTS);
}
InputBuilder::InputBuilder(const LinkerConfig& pConfig,
@@ -32,17 +33,17 @@
ContextFactory& pContextFactory,
MemoryAreaFactory& pMemoryFactory,
bool pDelegate)
- : m_Config(pConfig),
- m_pInputFactory(&pInputFactory),
- m_pMemFactory(&pMemoryFactory),
- m_pContextFactory(&pContextFactory),
- m_pCurrentTree(NULL), m_pMove(NULL), m_Root(),
- m_bOwnFactory(pDelegate) {
-
+ : m_Config(pConfig),
+ m_pInputFactory(&pInputFactory),
+ m_pMemFactory(&pMemoryFactory),
+ m_pContextFactory(&pContextFactory),
+ m_pCurrentTree(NULL),
+ m_pMove(NULL),
+ m_Root(),
+ m_bOwnFactory(pDelegate) {
}
-InputBuilder::~InputBuilder()
-{
+InputBuilder::~InputBuilder() {
if (m_bOwnFactory) {
delete m_pInputFactory;
delete m_pContextFactory;
@@ -53,14 +54,12 @@
Input* InputBuilder::createInput(const std::string& pName,
const sys::fs::Path& pPath,
unsigned int pType,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
return m_pInputFactory->produce(pName, pPath, pType, pFileOffset);
}
-InputTree& InputBuilder::enterGroup()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::enterGroup() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
m_pCurrentTree->enterGroup(m_Root, *m_pMove);
m_pMove->move(m_Root);
@@ -70,9 +69,8 @@
return *m_pCurrentTree;
}
-InputTree& InputBuilder::exitGroup()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::exitGroup() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
m_Root = m_ReturnStack.top();
m_ReturnStack.pop();
@@ -81,42 +79,36 @@
return *m_pCurrentTree;
}
-bool InputBuilder::isInGroup() const
-{
+bool InputBuilder::isInGroup() const {
return !m_ReturnStack.empty();
}
-const InputTree& InputBuilder::getCurrentTree() const
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+const InputTree& InputBuilder::getCurrentTree() const {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
return *m_pCurrentTree;
}
-InputTree& InputBuilder::getCurrentTree()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::getCurrentTree() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
return *m_pCurrentTree;
}
-void InputBuilder::setCurrentTree(InputTree& pInputTree)
-{
+void InputBuilder::setCurrentTree(InputTree& pInputTree) {
m_pCurrentTree = &pInputTree;
m_Root = m_pCurrentTree->root();
m_pMove = &InputTree::Downward;
}
-bool InputBuilder::setContext(Input& pInput, bool pCheck)
-{
+bool InputBuilder::setContext(Input& pInput, bool pCheck) {
// The object files in an archive have common path. Every object files in an
// archive needs a individual context. We identify the object files in an
// archive by its file offset. Their file offsets are not zero.
LDContext* context = NULL;
- if (0 != pInput.fileOffset() || !pCheck) {
+ if (pInput.fileOffset() != 0 || !pCheck) {
// pInput is an object in an archive file. Produce a new context in this
// case.
context = m_pContextFactory->produce();
- }
- else {
+ } else {
// Using pInput.path() to avoid from creating context for identical file
// twice.
context = m_pContextFactory->produce(pInput.path());
@@ -128,32 +120,28 @@
bool InputBuilder::setMemory(Input& pInput,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
- MemoryArea *memory = m_pMemFactory->produce(pInput.path(), pMode, pPerm);
+ FileHandle::Permission pPerm) {
+ MemoryArea* memory = m_pMemFactory->produce(pInput.path(), pMode, pPerm);
pInput.setMemArea(memory);
return true;
}
-bool InputBuilder::setMemory(Input& pInput, void* pMemBuffer, size_t pSize)
-{
- MemoryArea *memory = m_pMemFactory->produce(pMemBuffer, pSize);
+bool InputBuilder::setMemory(Input& pInput, void* pMemBuffer, size_t pSize) {
+ MemoryArea* memory = m_pMemFactory->produce(pMemBuffer, pSize);
pInput.setMemArea(memory);
return true;
}
-const AttrConstraint& InputBuilder::getConstraint() const
-{
+const AttrConstraint& InputBuilder::getConstraint() const {
return m_Config.attribute().constraint();
}
-const AttributeProxy& InputBuilder::getAttributes() const
-{
+const AttributeProxy& InputBuilder::getAttributes() const {
return m_pInputFactory->attr();
}
-AttributeProxy& InputBuilder::getAttributes()
-{
+AttributeProxy& InputBuilder::getAttributes() {
return m_pInputFactory->attr();
}
+} // namespace mcld
diff --git a/lib/MC/InputFactory.cpp b/lib/MC/InputFactory.cpp
index b0b7aaa..32d1913 100644
--- a/lib/MC/InputFactory.cpp
+++ b/lib/MC/InputFactory.cpp
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/AttributeSet.h>
-#include <mcld/AttributeOption.h>
+#include "mcld/MC/InputFactory.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+#include "mcld/AttributeOption.h"
+#include "mcld/MC/AttributeSet.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputFactory
//===----------------------------------------------------------------------===//
InputFactory::InputFactory(size_t pNum, const LinkerConfig& pConfig)
- : GCFactory<Input,0>(pNum) {
-
+ : GCFactory<Input, 0>(pNum) {
m_pAttrSet = new AttributeSet(16, pConfig.attribute().predefined());
m_pLast = new AttributeProxy(*m_pAttrSet,
pConfig.attribute().predefined(),
pConfig.attribute().constraint());
}
-InputFactory::~InputFactory()
-{
+InputFactory::~InputFactory() {
delete m_pAttrSet;
delete m_pLast;
}
@@ -34,10 +33,19 @@
Input* InputFactory::produce(llvm::StringRef pName,
const sys::fs::Path& pPath,
unsigned int pType,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
Input* result = Alloc::allocate();
new (result) Input(pName, pPath, *m_pLast, pType, pFileOffset);
return result;
}
+Input* InputFactory::produce(llvm::StringRef pName,
+ const char* pPath,
+ unsigned int pType,
+ off_t pFileOffset) {
+ Input* result = Alloc::allocate();
+ new (result) Input(pName, sys::fs::Path(pPath), *m_pLast, pType, pFileOffset);
+ return result;
+}
+
+} // namespace mcld
diff --git a/lib/MC/MCLDDirectory.cpp b/lib/MC/MCLDDirectory.cpp
index a15e744..5d281d5 100644
--- a/lib/MC/MCLDDirectory.cpp
+++ b/lib/MC/MCLDDirectory.cpp
@@ -6,99 +6,93 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/MCLDDirectory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/MC/MCLDDirectory.h"
+#include "mcld/Support/FileSystem.h"
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MCLDDirectory
//===----------------------------------------------------------------------===//
-MCLDDirectory::MCLDDirectory()
- : Directory(), m_Name(), m_bInSysroot(false) {
+MCLDDirectory::MCLDDirectory() : Directory(), m_Name(), m_bInSysroot(false) {
}
-MCLDDirectory::MCLDDirectory(const char* pName)
- : Directory(), m_Name(pName) {
+MCLDDirectory::MCLDDirectory(const char* pName) : Directory(), m_Name(pName) {
Directory::m_Path.assign(pName);
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
-MCLDDirectory::MCLDDirectory(const std::string &pName)
- : Directory(), m_Name(pName) {
+MCLDDirectory::MCLDDirectory(const std::string& pName)
+ : Directory(), m_Name(pName) {
Directory::m_Path.assign(pName);
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
MCLDDirectory::MCLDDirectory(llvm::StringRef pName)
- : Directory(), m_Name(pName.data(), pName.size()) {
+ : Directory(), m_Name(pName.data(), pName.size()) {
Directory::m_Path.assign(pName.str());
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
-MCLDDirectory &MCLDDirectory::assign(llvm::StringRef pName)
-{
+MCLDDirectory& MCLDDirectory::assign(llvm::StringRef pName) {
m_Name.assign(pName.data(), pName.size());
Directory::m_Path.assign(pName.str());
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
- Directory::m_FileStatus = FileStatus();
- Directory::m_SymLinkStatus = FileStatus();
+ sys::fs::detail::open_dir(*this);
+ Directory::m_FileStatus = sys::fs::FileStatus();
+ Directory::m_SymLinkStatus = sys::fs::FileStatus();
Directory::m_Cache.clear();
Directory::m_Handler = 0;
return (*this);
}
-MCLDDirectory::~MCLDDirectory()
-{
+MCLDDirectory::~MCLDDirectory() {
}
-bool MCLDDirectory::isInSysroot() const
-{
+bool MCLDDirectory::isInSysroot() const {
return m_bInSysroot;
}
-void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot)
-{
+void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot) {
if (m_bInSysroot) {
std::string old_path = Directory::m_Path.native();
Directory::m_Path.native() = pSysroot.native();
Directory::m_Path.m_append_separator_if_needed();
Directory::m_Path.native() += old_path;
- detail::canonicalize(Directory::m_Path.native());
- detail::open_dir(*this);
+ sys::fs::detail::canonicalize(Directory::m_Path.native());
+ sys::fs::detail::open_dir(*this);
}
}
+} // namespace mcld
diff --git a/lib/MC/SearchDirs.cpp b/lib/MC/SearchDirs.cpp
index 1950f96..07c02b6 100644
--- a/lib/MC/SearchDirs.cpp
+++ b/lib/MC/SearchDirs.cpp
@@ -6,17 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/SearchDirs.h>
-#include <mcld/MC/MCLDDirectory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/MC/SearchDirs.h"
-using namespace mcld;
+#include "mcld/MC/MCLDDirectory.h"
+#include "mcld/Support/FileSystem.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Non-member functions
//===----------------------------------------------------------------------===//
-static inline void SpecToFilename(const std::string& pSpec, std::string& pFile)
-{
+static inline void SpecToFilename(const std::string& pSpec,
+ std::string& pFile) {
pFile = "lib";
pFile += pSpec;
}
@@ -24,30 +25,26 @@
//===----------------------------------------------------------------------===//
// SearchDirs
//===----------------------------------------------------------------------===//
-SearchDirs::SearchDirs()
-{
+SearchDirs::SearchDirs() {
// a magic number 8, no why.
// please prove it or change it
m_DirList.reserve(8);
}
-SearchDirs::SearchDirs(const sys::fs::Path& pSysRoot)
- : m_SysRoot(pSysRoot) {
+SearchDirs::SearchDirs(const sys::fs::Path& pSysRoot) : m_SysRoot(pSysRoot) {
// a magic number 8, no why.
// please prove it or change it
m_DirList.reserve(8);
}
-SearchDirs::~SearchDirs()
-{
+SearchDirs::~SearchDirs() {
iterator dir, dirEnd = end();
- for (dir = begin(); dir!=dirEnd; ++dir) {
+ for (dir = begin(); dir != dirEnd; ++dir) {
delete (*dir);
}
}
-bool SearchDirs::insert(const std::string& pPath)
-{
+bool SearchDirs::insert(const std::string& pPath) {
MCLDDirectory* dir = new MCLDDirectory(pPath);
if (dir->isInSysroot())
dir->setSysroot(m_SysRoot);
@@ -55,43 +52,38 @@
if (exists(dir->path()) && is_directory(dir->path())) {
m_DirList.push_back(dir);
return true;
- }
- else {
+ } else {
delete dir;
return false;
}
return true;
}
-bool SearchDirs::insert(const char* pPath)
-{
+bool SearchDirs::insert(const char* pPath) {
return insert(std::string(pPath));
}
-bool SearchDirs::insert(const sys::fs::Path& pPath)
-{
+bool SearchDirs::insert(const sys::fs::Path& pPath) {
return insert(pPath.native());
}
-mcld::sys::fs::Path*
-SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType)
-{
- assert(Input::DynObj == pType ||
- Input::Archive == pType ||
- Input::Script == pType);
+mcld::sys::fs::Path* SearchDirs::find(const std::string& pNamespec,
+ mcld::Input::Type pType) {
+ assert(Input::DynObj == pType || Input::Archive == pType ||
+ Input::Script == pType);
std::string file;
- switch(pType) {
- case Input::Script:
- file.assign(pNamespec);
- break;
- case Input::DynObj:
- case Input::Archive :
- SpecToFilename(pNamespec, file);
- break;
- default:
- break;
- } // end of switch
+ switch (pType) {
+ case Input::Script:
+ file.assign(pNamespec);
+ break;
+ case Input::DynObj:
+ case Input::Archive:
+ SpecToFilename(pNamespec, file);
+ break;
+ default:
+ break;
+ } // end of switch
// for all MCLDDirectorys
DirList::iterator mcld_dir, mcld_dir_end = m_DirList.end();
@@ -100,65 +92,63 @@
MCLDDirectory::iterator entry = (*mcld_dir)->begin();
MCLDDirectory::iterator enEnd = (*mcld_dir)->end();
- switch(pType) {
- case Input::Script: {
- while (entry != enEnd) {
- if (file == entry.path()->filename())
- return entry.path();
- ++entry;
+ switch (pType) {
+ case Input::Script: {
+ while (entry != enEnd) {
+ if (file == entry.path()->filename().native())
+ return entry.path();
+ ++entry;
+ }
+ break;
}
- break;
- }
- case Input::DynObj: {
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() ) {
- if (mcld::sys::fs::detail::shared_library_extension ==
+ case Input::DynObj: {
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native()) {
+ if (mcld::sys::fs::detail::shared_library_extension ==
entry.path()->extension().native()) {
+ return entry.path();
+ }
+ }
+ ++entry;
+ }
+ }
+ /** Fall through **/
+ case Input::Archive: {
+ entry = (*mcld_dir)->begin();
+ enEnd = (*mcld_dir)->end();
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native() &&
+ mcld::sys::fs::detail::static_library_extension ==
+ entry.path()->extension().native()) {
return entry.path();
}
+ ++entry;
}
- ++entry;
}
- }
- /** Fall through **/
- case Input::Archive : {
- entry = (*mcld_dir)->begin();
- enEnd = (*mcld_dir)->end();
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() &&
- mcld::sys::fs::detail::static_library_extension ==
- entry.path()->extension().native()) {
- return entry.path();
- }
- ++entry;
- }
- }
- default:
- break;
- } // end of switch
- } // end of for
+ default:
+ break;
+ } // end of switch
+ } // end of for
return NULL;
}
-const mcld::sys::fs::Path*
-SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType) const
-{
- assert(Input::DynObj == pType ||
- Input::Archive == pType ||
- Input::Script == pType);
+const mcld::sys::fs::Path* SearchDirs::find(const std::string& pNamespec,
+ mcld::Input::Type pType) const {
+ assert(Input::DynObj == pType || Input::Archive == pType ||
+ Input::Script == pType);
std::string file;
- switch(pType) {
- case Input::Script:
- file.assign(pNamespec);
- break;
- case Input::DynObj:
- case Input::Archive :
- SpecToFilename(pNamespec, file);
- break;
- default:
- break;
- } // end of switch
+ switch (pType) {
+ case Input::Script:
+ file.assign(pNamespec);
+ break;
+ case Input::DynObj:
+ case Input::Archive:
+ SpecToFilename(pNamespec, file);
+ break;
+ default:
+ break;
+ } // end of switch
// for all MCLDDirectorys
DirList::const_iterator mcld_dir, mcld_dir_end = m_DirList.end();
@@ -167,42 +157,44 @@
MCLDDirectory::iterator entry = (*mcld_dir)->begin();
MCLDDirectory::iterator enEnd = (*mcld_dir)->end();
- switch(pType) {
- case Input::Script: {
- while (entry != enEnd) {
- if (file == entry.path()->filename())
- return entry.path();
- ++entry;
+ switch (pType) {
+ case Input::Script: {
+ while (entry != enEnd) {
+ if (file == entry.path()->filename().native())
+ return entry.path();
+ ++entry;
+ }
+ break;
}
- break;
- }
- case Input::DynObj: {
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() ) {
- if (mcld::sys::fs::detail::shared_library_extension ==
+ case Input::DynObj: {
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native()) {
+ if (mcld::sys::fs::detail::shared_library_extension ==
entry.path()->extension().native()) {
+ return entry.path();
+ }
+ }
+ ++entry;
+ }
+ }
+ /** Fall through **/
+ case Input::Archive: {
+ entry = (*mcld_dir)->begin();
+ enEnd = (*mcld_dir)->end();
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native() &&
+ mcld::sys::fs::detail::static_library_extension ==
+ entry.path()->extension().native()) {
return entry.path();
}
+ ++entry;
}
- ++entry;
}
- }
- /** Fall through **/
- case Input::Archive : {
- entry = (*mcld_dir)->begin();
- enEnd = (*mcld_dir)->end();
- while ( entry!=enEnd ) {
- if (file == entry.path()->stem().native() &&
- mcld::sys::fs::detail::static_library_extension ==
- entry.path()->extension().native()) {
- return entry.path();
- }
- ++entry;
- }
- }
- default:
- break;
- } // end of switch
- } // end of for
+ default:
+ break;
+ } // end of switch
+ } // end of for
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/MC/SymbolCategory.cpp b/lib/MC/SymbolCategory.cpp
index 3bd3df6..71a5bfd 100644
--- a/lib/MC/SymbolCategory.cpp
+++ b/lib/MC/SymbolCategory.cpp
@@ -6,26 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/SymbolCategory.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ResolveInfo.h>
+#include "mcld/MC/SymbolCategory.h"
+
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <algorithm>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Category
-SymbolCategory::Category::Type
-SymbolCategory::Category::categorize(const ResolveInfo& pInfo)
-{
+SymbolCategory::Category::Type SymbolCategory::Category::categorize(
+ const ResolveInfo& pInfo) {
if (ResolveInfo::File == pInfo.type())
return Category::File;
if (ResolveInfo::Local == pInfo.binding())
return Category::Local;
if (ResolveInfo::Common == pInfo.desc())
return Category::Common;
- if (ResolveInfo::Default == pInfo.visibility() ||
+ if (ResolveInfo::Default == pInfo.visibility() ||
ResolveInfo::Protected == pInfo.visibility())
return Category::Dynamic;
return Category::Regular;
@@ -33,50 +34,46 @@
//===----------------------------------------------------------------------===//
// SymbolCategory
-SymbolCategory::SymbolCategory()
-{
- m_pFile = new Category(Category::File);
- m_pLocal = new Category(Category::Local);
+SymbolCategory::SymbolCategory() {
+ m_pFile = new Category(Category::File);
+ m_pLocal = new Category(Category::Local);
m_pLocalDyn = new Category(Category::LocalDyn);
- m_pCommon = new Category(Category::Common);
- m_pDynamic = new Category(Category::Dynamic);
- m_pRegular = new Category(Category::Regular);
+ m_pCommon = new Category(Category::Common);
+ m_pDynamic = new Category(Category::Dynamic);
+ m_pRegular = new Category(Category::Regular);
- m_pFile->next = m_pLocal;
- m_pLocal->next = m_pLocalDyn;
+ m_pFile->next = m_pLocal;
+ m_pLocal->next = m_pLocalDyn;
m_pLocalDyn->next = m_pCommon;
- m_pCommon->next = m_pDynamic;
- m_pDynamic->next = m_pRegular;
+ m_pCommon->next = m_pDynamic;
+ m_pDynamic->next = m_pRegular;
- m_pRegular->prev = m_pDynamic;
- m_pDynamic->prev = m_pCommon;
- m_pCommon->prev = m_pLocalDyn;
+ m_pRegular->prev = m_pDynamic;
+ m_pDynamic->prev = m_pCommon;
+ m_pCommon->prev = m_pLocalDyn;
m_pLocalDyn->prev = m_pLocal;
- m_pLocal->prev = m_pFile;
+ m_pLocal->prev = m_pFile;
}
-SymbolCategory::~SymbolCategory()
-{
+SymbolCategory::~SymbolCategory() {
Category* current = m_pFile;
- while (NULL != current) {
+ while (current != NULL) {
Category* tmp = current;
current = current->next;
delete tmp;
}
}
-SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol, Category::Type pTarget)
-{
+SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol, Category::Type pTarget) {
Category* current = m_pRegular;
m_OutputSymbols.push_back(&pSymbol);
// use non-stable bubble sort to arrange the order of symbols.
- while (NULL != current) {
+ while (current != NULL) {
if (current->type == pTarget) {
current->end++;
break;
- }
- else {
+ } else {
if (!current->empty()) {
std::swap(m_OutputSymbols[current->begin],
m_OutputSymbols[current->end]);
@@ -89,23 +86,20 @@
return *this;
}
-SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol)
-{
- assert(NULL != pSymbol.resolveInfo());
+SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol) {
+ assert(pSymbol.resolveInfo() != NULL);
return add(pSymbol, Category::categorize(*pSymbol.resolveInfo()));
}
-SymbolCategory& SymbolCategory::forceLocal(LDSymbol& pSymbol)
-{
+SymbolCategory& SymbolCategory::forceLocal(LDSymbol& pSymbol) {
return add(pSymbol, Category::Local);
}
SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
Category::Type pSource,
- Category::Type pTarget)
-{
+ Category::Type pTarget) {
int distance = pTarget - pSource;
- if (0 == distance) {
+ if (distance == 0) {
// in the same category, do not need to re-arrange
return *this;
}
@@ -113,13 +107,13 @@
// source and target are not in the same category
// find the category of source
Category* current = m_pFile;
- while(NULL != current) {
+ while (current != NULL) {
if (pSource == current->type)
break;
current = current->next;
}
- assert(NULL != current);
+ assert(current != NULL);
size_t pos = 0;
if (!current->empty()) {
// find the position of source
@@ -158,8 +152,7 @@
do {
if (current->type == pTarget) {
break;
- }
- else {
+ } else {
assert(!current->isLast() && "target category is wrong.");
rear = current->end - 1;
std::swap(m_OutputSymbols[pos], m_OutputSymbols[rear]);
@@ -168,20 +161,18 @@
current->end--;
}
current = current->next;
- } while(NULL != current);
+ } while (current != NULL);
return *this;
- } // downward
+ } // downward
// The distance is negative. It means we should bubble sort upward.
if (distance < 0) {
-
// upward
do {
if (current->type == pTarget) {
break;
- }
- else {
+ } else {
assert(!current->isFirst() && "target category is wrong.");
std::swap(m_OutputSymbols[current->begin], m_OutputSymbols[pos]);
pos = current->begin;
@@ -189,282 +180,238 @@
current->prev->end++;
}
current = current->prev;
- } while(NULL != current);
+ } while (current != NULL);
return *this;
- } // upward
+ } // upward
return *this;
}
SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
- const ResolveInfo& pSourceInfo)
-{
- assert(NULL != pSymbol.resolveInfo());
+ const ResolveInfo& pSourceInfo) {
+ assert(pSymbol.resolveInfo() != NULL);
return arrange(pSymbol,
Category::categorize(pSourceInfo),
Category::categorize(*pSymbol.resolveInfo()));
}
-SymbolCategory& SymbolCategory::changeCommonsToGlobal()
-{
+SymbolCategory& SymbolCategory::changeCommonsToGlobal() {
// Change Common to Dynamic/Regular
while (!emptyCommons()) {
size_t pos = m_pCommon->end - 1;
switch (Category::categorize(*(m_OutputSymbols[pos]->resolveInfo()))) {
- case Category::Dynamic:
- m_pCommon->end--;
- m_pDynamic->begin--;
- break;
- case Category::Regular:
- std::swap(m_OutputSymbols[pos], m_OutputSymbols[m_pDynamic->end - 1]);
- m_pCommon->end--;
- m_pDynamic->begin--;
- m_pDynamic->end--;
- m_pRegular->begin--;
- break;
- default:
- assert(0);
- break;
+ case Category::Dynamic:
+ m_pCommon->end--;
+ m_pDynamic->begin--;
+ break;
+ case Category::Regular:
+ std::swap(m_OutputSymbols[pos], m_OutputSymbols[m_pDynamic->end - 1]);
+ m_pCommon->end--;
+ m_pDynamic->begin--;
+ m_pDynamic->end--;
+ m_pRegular->begin--;
+ break;
+ default:
+ assert(0);
+ break;
}
}
return *this;
}
-SymbolCategory& SymbolCategory::changeToDynamic(LDSymbol& pSymbol)
-{
- assert(NULL != pSymbol.resolveInfo());
+SymbolCategory& SymbolCategory::changeToDynamic(LDSymbol& pSymbol) {
+ assert(pSymbol.resolveInfo() != NULL);
return arrange(pSymbol,
Category::categorize(*pSymbol.resolveInfo()),
Category::LocalDyn);
}
-size_t SymbolCategory::numOfSymbols() const
-{
+size_t SymbolCategory::numOfSymbols() const {
return m_OutputSymbols.size();
}
-size_t SymbolCategory::numOfFiles() const
-{
+size_t SymbolCategory::numOfFiles() const {
return m_pFile->size();
}
-size_t SymbolCategory::numOfLocals() const
-{
+size_t SymbolCategory::numOfLocals() const {
return m_pLocal->size();
}
-size_t SymbolCategory::numOfLocalDyns() const
-{
+size_t SymbolCategory::numOfLocalDyns() const {
return m_pLocalDyn->size();
}
-size_t SymbolCategory::numOfCommons() const
-{
+size_t SymbolCategory::numOfCommons() const {
return m_pCommon->size();
}
-size_t SymbolCategory::numOfDynamics() const
-{
+size_t SymbolCategory::numOfDynamics() const {
return m_pDynamic->size();
}
-size_t SymbolCategory::numOfRegulars() const
-{
+size_t SymbolCategory::numOfRegulars() const {
return m_pRegular->size();
}
-bool SymbolCategory::empty() const
-{
+bool SymbolCategory::empty() const {
return m_OutputSymbols.empty();
}
-bool SymbolCategory::emptyFiles() const
-{
+bool SymbolCategory::emptyFiles() const {
return m_pFile->empty();
}
-bool SymbolCategory::emptyLocals() const
-{
+bool SymbolCategory::emptyLocals() const {
return m_pLocal->empty();
}
-bool SymbolCategory::emptyLocalDyns() const
-{
+bool SymbolCategory::emptyLocalDyns() const {
return m_pLocalDyn->empty();
}
-bool SymbolCategory::emptyCommons() const
-{
+bool SymbolCategory::emptyCommons() const {
return m_pCommon->empty();
}
-bool SymbolCategory::emptyDynamics() const
-{
+bool SymbolCategory::emptyDynamics() const {
return m_pDynamic->empty();
}
-bool SymbolCategory::emptyRegulars() const
-{
+bool SymbolCategory::emptyRegulars() const {
return m_pRegular->empty();
}
-SymbolCategory::iterator SymbolCategory::begin()
-{
+SymbolCategory::iterator SymbolCategory::begin() {
return m_OutputSymbols.begin();
}
-SymbolCategory::iterator SymbolCategory::end()
-{
+SymbolCategory::iterator SymbolCategory::end() {
return m_OutputSymbols.end();
}
-SymbolCategory::const_iterator SymbolCategory::begin() const
-{
+SymbolCategory::const_iterator SymbolCategory::begin() const {
return m_OutputSymbols.begin();
}
-SymbolCategory::const_iterator SymbolCategory::end() const
-{
+SymbolCategory::const_iterator SymbolCategory::end() const {
return m_OutputSymbols.end();
}
-SymbolCategory::iterator SymbolCategory::fileBegin()
-{
+SymbolCategory::iterator SymbolCategory::fileBegin() {
return m_OutputSymbols.begin();
}
-SymbolCategory::iterator SymbolCategory::fileEnd()
-{
+SymbolCategory::iterator SymbolCategory::fileEnd() {
iterator iter = fileBegin();
iter += m_pFile->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::fileBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::fileBegin() const {
return m_OutputSymbols.begin();
}
-SymbolCategory::const_iterator SymbolCategory::fileEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::fileEnd() const {
const_iterator iter = fileBegin();
iter += m_pFile->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::localBegin()
-{
+SymbolCategory::iterator SymbolCategory::localBegin() {
return fileEnd();
}
-SymbolCategory::iterator SymbolCategory::localEnd()
-{
+SymbolCategory::iterator SymbolCategory::localEnd() {
iterator iter = localBegin();
iter += m_pLocal->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::localBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::localBegin() const {
return fileEnd();
}
-SymbolCategory::const_iterator SymbolCategory::localEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::localEnd() const {
const_iterator iter = localBegin();
iter += m_pLocal->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::localDynBegin()
-{
+SymbolCategory::iterator SymbolCategory::localDynBegin() {
return localEnd();
}
-SymbolCategory::iterator SymbolCategory::localDynEnd()
-{
+SymbolCategory::iterator SymbolCategory::localDynEnd() {
iterator iter = localDynBegin();
iter += m_pLocalDyn->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::localDynBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::localDynBegin() const {
return localEnd();
}
-SymbolCategory::const_iterator SymbolCategory::localDynEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::localDynEnd() const {
const_iterator iter = localDynBegin();
iter += m_pLocalDyn->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::commonBegin()
-{
+SymbolCategory::iterator SymbolCategory::commonBegin() {
return localDynEnd();
}
-SymbolCategory::iterator SymbolCategory::commonEnd()
-{
+SymbolCategory::iterator SymbolCategory::commonEnd() {
iterator iter = commonBegin();
iter += m_pCommon->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::commonBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::commonBegin() const {
return localDynEnd();
}
-SymbolCategory::const_iterator SymbolCategory::commonEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::commonEnd() const {
const_iterator iter = commonBegin();
iter += m_pCommon->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::dynamicBegin()
-{
+SymbolCategory::iterator SymbolCategory::dynamicBegin() {
return commonEnd();
}
-SymbolCategory::iterator SymbolCategory::dynamicEnd()
-{
+SymbolCategory::iterator SymbolCategory::dynamicEnd() {
iterator iter = dynamicBegin();
iter += m_pDynamic->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::dynamicBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::dynamicBegin() const {
return commonEnd();
}
-SymbolCategory::const_iterator SymbolCategory::dynamicEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::dynamicEnd() const {
const_iterator iter = dynamicBegin();
iter += m_pDynamic->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::regularBegin()
-{
- return commonEnd();
+SymbolCategory::iterator SymbolCategory::regularBegin() {
+ return dynamicEnd();
}
-SymbolCategory::iterator SymbolCategory::regularEnd()
-{
+SymbolCategory::iterator SymbolCategory::regularEnd() {
return m_OutputSymbols.end();
}
-SymbolCategory::const_iterator SymbolCategory::regularBegin() const
-{
- return commonEnd();
+SymbolCategory::const_iterator SymbolCategory::regularBegin() const {
+ return dynamicEnd();
}
-SymbolCategory::const_iterator SymbolCategory::regularEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::regularEnd() const {
return m_OutputSymbols.end();
}
+} // namespace mcld
diff --git a/lib/MC/ZOption.cpp b/lib/MC/ZOption.cpp
index 8b11765..c955967 100644
--- a/lib/MC/ZOption.cpp
+++ b/lib/MC/ZOption.cpp
@@ -6,14 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/ZOption.h>
+#include "mcld/MC/ZOption.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ZOption
//===----------------------------------------------------------------------===//
-ZOption::ZOption()
- : m_Kind(Unknown), m_PageSize(0x0) {
+ZOption::ZOption() : ZOption(Unknown) {
}
+ZOption::ZOption(Kind pKind) : ZOption(pKind, 0x0) {
+}
+
+ZOption::ZOption(Kind pKind, uint64_t pPageSize)
+ : m_Kind(pKind), m_PageSize(pPageSize) {
+}
+
+} // namespace mcld
diff --git a/lib/Object/ObjectBuilder.cpp b/lib/Object/ObjectBuilder.cpp
index 5543f46..8bbbda1 100644
--- a/lib/Object/ObjectBuilder.cpp
+++ b/lib/Object/ObjectBuilder.cpp
@@ -6,28 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/Object/ObjectBuilder.h"
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Fragment/FillFragment.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/SectionMap.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ObjectBuilder
//===----------------------------------------------------------------------===//
-ObjectBuilder::ObjectBuilder(Module& pTheModule)
- : m_Module(pTheModule) {
+ObjectBuilder::ObjectBuilder(Module& pTheModule) : m_Module(pTheModule) {
}
/// CreateSection - create an output section.
@@ -35,16 +35,15 @@
LDFileFormat::Kind pKind,
uint32_t pType,
uint32_t pFlag,
- uint32_t pAlign)
-{
+ uint32_t pAlign) {
// try to get one from output LDSection
SectionMap::const_mapping pair =
- m_Module.getScript().sectionMap().find("*", pName);
+ m_Module.getScript().sectionMap().find("*", pName);
std::string output_name = (pair.first == NULL) ? pName : pair.first->name();
LDSection* output_sect = m_Module.getSection(output_name);
- if (NULL == output_sect) {
+ if (output_sect == NULL) {
output_sect = LDSection::Create(pName, pKind, pType, pFlag);
output_sect->setAlign(pAlign);
m_Module.getSectionTable().push_back(output_sect);
@@ -54,22 +53,20 @@
/// MergeSection - merge the pInput section to the pOutput section
LDSection* ObjectBuilder::MergeSection(const Input& pInputFile,
- LDSection& pInputSection)
-{
- SectionMap::mapping pair =
- m_Module.getScript().sectionMap().find(pInputFile.path().native(),
- pInputSection.name());
+ LDSection& pInputSection) {
+ SectionMap::mapping pair = m_Module.getScript().sectionMap().find(
+ pInputFile.path().native(), pInputSection.name());
if (pair.first != NULL && pair.first->isDiscard()) {
pInputSection.setKind(LDFileFormat::Ignore);
return NULL;
}
- std::string output_name = (pair.first == NULL) ?
- pInputSection.name() : pair.first->name();
+ std::string output_name =
+ (pair.first == NULL) ? pInputSection.name() : pair.first->name();
LDSection* target = m_Module.getSection(output_name);
- if (NULL == target) {
+ if (target == NULL) {
target = LDSection::Create(output_name,
pInputSection.kind(),
pInputSection.type(),
@@ -90,6 +87,17 @@
UpdateSectionAlign(*target, pInputSection);
return target;
}
+ case LDFileFormat::DebugString: {
+ DebugString* debug_str = NULL;
+ if (target->hasDebugString())
+ debug_str = target->getDebugString();
+ else
+ debug_str = IRBuilder::CreateDebugString(*target);
+
+ debug_str->merge(pInputSection);
+ UpdateSectionAlign(*target, pInputSection);
+ return target;
+ }
default: {
if (!target->hasSectionData())
IRBuilder::CreateSectionData(*target);
@@ -98,6 +106,11 @@
if (pair.first != NULL) {
assert(pair.second != NULL);
data = pair.second->getSection()->getSectionData();
+
+ // force input alignment from ldscript if any
+ if (pair.first->prolog().hasSubAlign()) {
+ pInputSection.setAlign(pair.second->getSection()->align());
+ }
} else {
// orphan section
data = target->getSectionData();
@@ -114,19 +127,18 @@
}
/// MoveSectionData - move the fragments of pTO section data to pTo
-bool ObjectBuilder::MoveSectionData(SectionData& pFrom, SectionData& pTo)
-{
+bool ObjectBuilder::MoveSectionData(SectionData& pFrom, SectionData& pTo) {
assert(&pFrom != &pTo && "Cannot move section data to itself!");
uint64_t offset = pTo.getSection().size();
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
align->setOffset(offset);
align->setParent(&pTo);
pTo.getFragmentList().push_back(align);
@@ -151,16 +163,14 @@
}
/// UpdateSectionAlign - update alignment for input section
-void ObjectBuilder::UpdateSectionAlign(LDSection& pTo, const LDSection& pFrom)
-{
+void ObjectBuilder::UpdateSectionAlign(LDSection& pTo, const LDSection& pFrom) {
if (pFrom.align() > pTo.align())
pTo.setAlign(pFrom.align());
}
/// UpdateSectionAlign - update alignment for input section
void ObjectBuilder::UpdateSectionAlign(LDSection& pSection,
- uint32_t pAlignConstraint)
-{
+ uint32_t pAlignConstraint) {
if (pSection.align() < pAlignConstraint)
pSection.setAlign(pAlignConstraint);
}
@@ -168,8 +178,7 @@
/// AppendFragment - To append pFrag to the given SectionData pSD.
uint64_t ObjectBuilder::AppendFragment(Fragment& pFrag,
SectionData& pSD,
- uint32_t pAlignConstraint)
-{
+ uint32_t pAlignConstraint) {
// get initial offset.
uint64_t offset = 0;
if (!pSD.empty())
@@ -178,11 +187,10 @@
AlignFragment* align = NULL;
if (pAlignConstraint > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pAlignConstraint, // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pAlignConstraint - 1 // max bytes to emit
- );
+ align = new AlignFragment(/*alignment*/pAlignConstraint,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/pAlignConstraint - 1);
align->setOffset(offset);
align->setParent(&pSD);
pSD.getFragmentList().push_back(align);
@@ -199,9 +207,10 @@
NullFragment* null = new NullFragment(&pSD);
null->setOffset(offset);
- if (NULL != align)
+ if (align != NULL)
return align->size() + pFrag.size();
else
return pFrag.size();
}
+} // namespace mcld
diff --git a/lib/Object/ObjectLinker.cpp b/lib/Object/ObjectLinker.cpp
index dfc7f37..f32ebfc 100644
--- a/lib/Object/ObjectLinker.cpp
+++ b/lib/Object/ObjectLinker.cpp
@@ -6,68 +6,68 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/ObjectLinker.h>
+#include "mcld/Object/ObjectLinker.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
-#include <mcld/InputTree.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/Archive.h>
-#include <mcld/LD/ArchiveReader.h>
-#include <mcld/LD/ObjectReader.h>
-#include <mcld/LD/DynObjReader.h>
-#include <mcld/LD/GroupReader.h>
-#include <mcld/LD/BinaryReader.h>
-#include <mcld/LD/GarbageCollection.h>
-#include <mcld/LD/IdenticalCodeFolding.h>
-#include <mcld/LD/ObjectWriter.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Support/RealPath.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/InputTree.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/BinaryReader.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/GarbageCollection.h"
+#include "mcld/LD/GroupReader.h"
+#include "mcld/LD/IdenticalCodeFolding.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/LD/ObjectWriter.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Script/ScriptReader.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/RealPath.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Casting.h>
#include <llvm/Support/Host.h>
+
#include <system_error>
-using namespace llvm;
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ObjectLinker
//===----------------------------------------------------------------------===//
ObjectLinker::ObjectLinker(const LinkerConfig& pConfig,
TargetLDBackend& pLDBackend)
- : m_Config(pConfig),
- m_pModule(NULL),
- m_pBuilder(NULL),
- m_LDBackend(pLDBackend),
- m_pObjectReader(NULL),
- m_pDynObjReader(NULL),
- m_pArchiveReader(NULL),
- m_pGroupReader(NULL),
- m_pBinaryReader(NULL),
- m_pScriptReader(NULL),
- m_pWriter(NULL) {
+ : m_Config(pConfig),
+ m_pModule(NULL),
+ m_pBuilder(NULL),
+ m_LDBackend(pLDBackend),
+ m_pObjectReader(NULL),
+ m_pDynObjReader(NULL),
+ m_pArchiveReader(NULL),
+ m_pGroupReader(NULL),
+ m_pBinaryReader(NULL),
+ m_pScriptReader(NULL),
+ m_pWriter(NULL) {
}
-ObjectLinker::~ObjectLinker()
-{
+ObjectLinker::~ObjectLinker() {
delete m_pObjectReader;
delete m_pDynObjReader;
delete m_pArchiveReader;
@@ -77,20 +77,23 @@
delete m_pWriter;
}
-bool ObjectLinker::initialize(Module& pModule, IRBuilder& pBuilder)
-{
+bool ObjectLinker::initialize(Module& pModule, IRBuilder& pBuilder) {
m_pModule = &pModule;
m_pBuilder = &pBuilder;
// initialize the readers and writers
- m_pObjectReader = m_LDBackend.createObjectReader(*m_pBuilder);
+ m_pObjectReader = m_LDBackend.createObjectReader(*m_pBuilder);
m_pArchiveReader = m_LDBackend.createArchiveReader(*m_pModule);
- m_pDynObjReader = m_LDBackend.createDynObjReader(*m_pBuilder);
- m_pBinaryReader = m_LDBackend.createBinaryReader(*m_pBuilder);
- m_pGroupReader = new GroupReader(*m_pModule, *m_pObjectReader,
- *m_pDynObjReader, *m_pArchiveReader, *m_pBinaryReader);
- m_pScriptReader = new ScriptReader(*m_pGroupReader);
- m_pWriter = m_LDBackend.createWriter();
+ m_pDynObjReader = m_LDBackend.createDynObjReader(*m_pBuilder);
+ m_pBinaryReader = m_LDBackend.createBinaryReader(*m_pBuilder);
+ m_pGroupReader = new GroupReader(*m_pModule,
+ *m_pObjectReader,
+ *m_pDynObjReader,
+ *m_pArchiveReader,
+ *m_pBinaryReader);
+ m_pScriptReader = new ScriptReader(
+ *m_pObjectReader, *m_pArchiveReader, *m_pDynObjReader, *m_pGroupReader);
+ m_pWriter = m_LDBackend.createWriter();
// initialize Relocator
m_LDBackend.initRelocator();
@@ -99,8 +102,7 @@
}
/// initStdSections - initialize standard sections
-bool ObjectLinker::initStdSections()
-{
+bool ObjectLinker::initStdSections() {
ObjectBuilder builder(*m_pModule);
// initialize standard sections
@@ -113,30 +115,27 @@
return true;
}
-void ObjectLinker::addUndefinedSymbols()
-{
+void ObjectLinker::addUndefinedSymbols() {
// Add the symbol set by -u as an undefind global symbol into symbol pool
GeneralOptions::const_undef_sym_iterator usym;
GeneralOptions::const_undef_sym_iterator usymEnd =
- m_Config.options().undef_sym_end();
+ m_Config.options().undef_sym_end();
for (usym = m_Config.options().undef_sym_begin(); usym != usymEnd; ++usym) {
Resolver::Result result;
- m_pModule->getNamePool().insertSymbol(*usym, // name
- false, // isDyn
+ m_pModule->getNamePool().insertSymbol(*usym, // name
+ false, // isDyn
ResolveInfo::NoType,
ResolveInfo::Undefined,
ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
+ 0x0, // size
+ 0x0, // value
ResolveInfo::Default,
NULL,
result);
LDSymbol* output_sym = result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
-
// create the output symbol if it dose not have one
- if (!result.existent || !has_output_sym) {
+ if (!result.existent || (output_sym != NULL)) {
output_sym = LDSymbol::Create(*result.info);
result.info->setSymPtr(output_sym);
output_sym->setFragmentRef(FragmentRef::Null());
@@ -144,15 +143,14 @@
}
}
-void ObjectLinker::normalize()
-{
+void ObjectLinker::normalize() {
// ----- set up inputs ----- //
Module::input_iterator input, inEnd = m_pModule->input_end();
- for (input = m_pModule->input_begin(); input!=inEnd; ++input) {
+ for (input = m_pModule->input_begin(); input != inEnd; ++input) {
// is a group node
if (isGroup(input)) {
- getGroupReader()->readGroup(input, inEnd, m_pBuilder->getInputBuilder(),
- m_Config);
+ getGroupReader()->readGroup(
+ input, inEnd, m_pBuilder->getInputBuilder(), m_Config);
continue;
}
@@ -179,58 +177,56 @@
(*input)->setType(Input::Object);
getBinaryReader()->readBinary(**input);
m_pModule->getObjectList().push_back(*input);
- }
- // is a relocatable object file
- else if (doContinue && getObjectReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getObjectReader()->isMyFormat(**input, doContinue)) {
+ // is a relocatable object file
(*input)->setType(Input::Object);
getObjectReader()->readHeader(**input);
getObjectReader()->readSections(**input);
getObjectReader()->readSymbols(**input);
m_pModule->getObjectList().push_back(*input);
- }
- // is a shared object file
- else if (doContinue && getDynObjReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getDynObjReader()->isMyFormat(**input, doContinue)) {
+ // is a shared object file
(*input)->setType(Input::DynObj);
getDynObjReader()->readHeader(**input);
getDynObjReader()->readSymbols(**input);
m_pModule->getLibraryList().push_back(*input);
- }
- // is an archive
- else if (doContinue && getArchiveReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getArchiveReader()->isMyFormat(**input, doContinue)) {
+ // is an archive
(*input)->setType(Input::Archive);
if (m_Config.options().isInExcludeLIBS(**input)) {
(*input)->setNoExport();
}
Archive archive(**input, m_pBuilder->getInputBuilder());
getArchiveReader()->readArchive(m_Config, archive);
- if(archive.numOfObjectMember() > 0) {
+ if (archive.numOfObjectMember() > 0) {
m_pModule->getInputTree().merge<InputTree::Inclusive>(input,
archive.inputs());
}
- }
- // try to parse input as a linker script
- else if (doContinue && getScriptReader()->isMyFormat(**input, doContinue)) {
- ScriptFile script(ScriptFile::LDScript, **input,
- m_pBuilder->getInputBuilder());
+ } else if (doContinue &&
+ getScriptReader()->isMyFormat(**input, doContinue)) {
+ // try to parse input as a linker script
+ ScriptFile script(
+ ScriptFile::LDScript, **input, m_pBuilder->getInputBuilder());
if (getScriptReader()->readScript(m_Config, script)) {
(*input)->setType(Input::Script);
script.activate(*m_pModule);
if (script.inputs().size() > 0) {
- m_pModule->getInputTree().merge<InputTree::Inclusive>(input,
- script.inputs());
+ m_pModule->getInputTree().merge<InputTree::Inclusive>(
+ input, script.inputs());
}
}
- }
- else {
+ } else {
if (m_Config.options().warnMismatch())
- warning(diag::warn_unrecognized_input_file) << (*input)->path()
- << m_Config.targets().triple().str();
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << m_Config.targets().triple().str();
}
- } // end of for
+ } // end of for
}
-bool ObjectLinker::linkable() const
-{
+bool ObjectLinker::linkable() const {
// check we have input and output files
if (m_pModule->getInputTree().empty()) {
error(diag::err_no_inputs);
@@ -240,9 +236,9 @@
// can not mix -static with shared objects
Module::const_lib_iterator lib, libEnd = m_pModule->lib_end();
for (lib = m_pModule->lib_begin(); lib != libEnd; ++lib) {
- if((*lib)->attribute()->isStatic()) {
- error(diag::err_mixed_shared_static_objects)
- << (*lib)->name() << (*lib)->path();
+ if ((*lib)->attribute()->isStatic()) {
+ error(diag::err_mixed_shared_static_objects) << (*lib)->name()
+ << (*lib)->path();
return false;
}
}
@@ -265,8 +261,11 @@
return true;
}
-void ObjectLinker::dataStrippingOpt()
-{
+void ObjectLinker::dataStrippingOpt() {
+ if (m_Config.codeGenType() == LinkerConfig::Object) {
+ return;
+ }
+
// Garbege collection
if (m_Config.options().GCSections()) {
GarbageCollection GC(m_Config, m_LDBackend, *m_pModule);
@@ -284,12 +283,12 @@
/// readRelocations - read all relocation entries
///
/// All symbols should be read and resolved before this function.
-bool ObjectLinker::readRelocations()
-{
+bool ObjectLinker::readRelocations() {
// Bitcode is read by the other path. This function reads relocation sections
// in object files.
- mcld::InputTree::bfs_iterator input, inEnd = m_pModule->getInputTree().bfs_end();
- for (input=m_pModule->getInputTree().bfs_begin(); input!=inEnd; ++input) {
+ mcld::InputTree::bfs_iterator input,
+ inEnd = m_pModule->getInputTree().bfs_end();
+ for (input = m_pModule->getInputTree().bfs_begin(); input != inEnd; ++input) {
if ((*input)->type() == Input::Object && (*input)->hasMemArea()) {
if (!getObjectReader()->readRelocations(**input))
return false;
@@ -300,8 +299,39 @@
}
/// mergeSections - put allinput sections into output sections
-bool ObjectLinker::mergeSections()
-{
+bool ObjectLinker::mergeSections() {
+ // Set up input/output from ldscript requirement if any
+ {
+ RpnEvaluator evaluator(*m_pModule, m_LDBackend);
+ SectionMap::iterator out, outBegin, outEnd;
+ outBegin = m_pModule->getScript().sectionMap().begin();
+ outEnd = m_pModule->getScript().sectionMap().end();
+ for (out = outBegin; out != outEnd; ++out) {
+ uint64_t out_align = 0x0, in_align = 0x0;
+ LDSection* out_sect = (*out)->getSection();
+ SectionMap::Output::iterator in, inBegin, inEnd;
+ inBegin = (*out)->begin();
+ inEnd = (*out)->end();
+
+ // force input alignment from ldscript if any
+ if ((*out)->prolog().hasSubAlign()) {
+ evaluator.eval((*out)->prolog().subAlign(), in_align);
+ }
+
+ for (in = inBegin; in != inEnd; ++in) {
+ LDSection* in_sect = (*in)->getSection();
+ if ((*out)->prolog().hasSubAlign())
+ in_sect->setAlign(in_align);
+ } // for each input section description
+
+ // force output alignment from ldscript if any
+ if ((*out)->prolog().hasAlign()) {
+ evaluator.eval((*out)->prolog().align(), out_align);
+ out_sect->setAlign(out_align);
+ }
+ } // for each output section description
+ }
+
ObjectBuilder builder(*m_pModule);
Module::obj_iterator obj, objEnd = m_pModule->obj_end();
for (obj = m_pModule->obj_begin(); obj != objEnd; ++obj) {
@@ -317,15 +347,14 @@
case LDFileFormat::StackNote:
// skip
continue;
- case LDFileFormat::Relocation: {
+ case LDFileFormat::Relocation:
if (!(*sect)->hasRelocData())
- continue; // skip
+ continue; // skip
if ((*sect)->getLink()->kind() == LDFileFormat::Ignore ||
(*sect)->getLink()->kind() == LDFileFormat::Folded)
(*sect)->setKind(LDFileFormat::Ignore);
break;
- }
case LDFileFormat::Target:
if (!m_LDBackend.mergeSection(*m_pModule, **obj, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
@@ -335,10 +364,10 @@
break;
case LDFileFormat::EhFrame: {
if (!(*sect)->hasEhFrame())
- continue; // skip
+ continue; // skip
LDSection* out_sect = NULL;
- if (NULL != (out_sect = builder.MergeSection(**obj, **sect))) {
+ if ((out_sect = builder.MergeSection(**obj, **sect)) != NULL) {
if (!m_LDBackend.updateSectionFlags(*out_sect, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
<< (*obj)->name();
@@ -347,12 +376,17 @@
}
break;
}
+ case LDFileFormat::DebugString: {
+ // FIXME: disable debug string merge when doing partial link.
+ if (LinkerConfig::Object == m_Config.codeGenType())
+ (*sect)->setKind(LDFileFormat::Debug);
+ } // Fall through
default: {
if (!(*sect)->hasSectionData())
- continue; // skip
+ continue; // skip
LDSection* out_sect = NULL;
- if (NULL != (out_sect = builder.MergeSection(**obj, **sect))) {
+ if ((out_sect = builder.MergeSection(**obj, **sect)) != NULL) {
if (!m_LDBackend.updateSectionFlags(*out_sect, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
<< (*obj)->name();
@@ -361,69 +395,72 @@
}
break;
}
- } // end of switch
- } // for each section
- } // for each obj
+ } // end of switch
+ } // for each section
+ } // for each obj
- RpnEvaluator evaluator(*m_pModule, m_LDBackend);
- SectionMap::iterator out, outBegin, outEnd;
- outBegin = m_pModule->getScript().sectionMap().begin();
- outEnd = m_pModule->getScript().sectionMap().end();
- for (out = outBegin; out != outEnd; ++out) {
- uint64_t out_align = 0x0, in_align = 0x0;
- LDSection* out_sect = (*out)->getSection();
- SectionMap::Output::iterator in, inBegin, inEnd;
- inBegin = (*out)->begin();
- inEnd = (*out)->end();
+ {
+ SectionMap::iterator out, outBegin, outEnd;
+ outBegin = m_pModule->getScript().sectionMap().begin();
+ outEnd = m_pModule->getScript().sectionMap().end();
+ for (out = outBegin; out != outEnd; ++out) {
+ LDSection* out_sect = (*out)->getSection();
+ SectionMap::Output::iterator in, inBegin, inEnd;
+ inBegin = (*out)->begin();
+ inEnd = (*out)->end();
- // force input alignment from ldscript if any
- if ((*out)->prolog().hasSubAlign()) {
- evaluator.eval((*out)->prolog().subAlign(), in_align);
- }
+ for (in = inBegin; in != inEnd; ++in) {
+ LDSection* in_sect = (*in)->getSection();
+ if (builder.MoveSectionData(*in_sect->getSectionData(),
+ *out_sect->getSectionData())) {
+ builder.UpdateSectionAlign(*out_sect, *in_sect);
+ m_LDBackend.updateSectionFlags(*out_sect, *in_sect);
+ }
+ } // for each input section description
- for (in = inBegin; in != inEnd; ++in) {
- LDSection* in_sect = (*in)->getSection();
- if ((*out)->prolog().hasSubAlign())
- in_sect->setAlign(in_align);
-
- if (builder.MoveSectionData(*in_sect->getSectionData(),
- *out_sect->getSectionData())) {
- builder.UpdateSectionAlign(*out_sect, *in_sect);
- m_LDBackend.updateSectionFlags(*out_sect, *in_sect);
+ if ((*out)->hasContent()) {
+ LDSection* target = m_pModule->getSection((*out)->name());
+ assert(target != NULL && target->hasSectionData());
+ if (builder.MoveSectionData(*out_sect->getSectionData(),
+ *target->getSectionData())) {
+ builder.UpdateSectionAlign(*target, *out_sect);
+ m_LDBackend.updateSectionFlags(*target, *out_sect);
+ }
}
- } // for each input section description
-
- // force output alignment from ldscript if any
- if ((*out)->prolog().hasAlign()) {
- evaluator.eval((*out)->prolog().align(), out_align);
- out_sect->setAlign(out_align);
- }
-
- if ((*out)->hasContent()) {
- LDSection* target = m_pModule->getSection((*out)->name());
- assert(target != NULL && target->hasSectionData());
- if (builder.MoveSectionData(*out_sect->getSectionData(),
- *target->getSectionData())) {
- builder.UpdateSectionAlign(*target, *out_sect);
- m_LDBackend.updateSectionFlags(*target, *out_sect);
- }
- }
- } // for each output section description
+ } // for each output section description
+ }
return true;
}
-void ObjectLinker::addSymbolToOutput(ResolveInfo& pInfo, Module& pModule)
-{
+void ObjectLinker::addSymbolToOutput(ResolveInfo& pInfo, Module& pModule) {
// section symbols will be defined by linker later, we should not add section
// symbols to output here
- if (ResolveInfo::Section == pInfo.type() || NULL == pInfo.outSymbol())
+ if (ResolveInfo::Section == pInfo.type() || pInfo.outSymbol() == NULL)
return;
// if the symbols defined in the Ignore sections (e.g. discared by GC), then
// not to put them to output
- if (pInfo.outSymbol()->hasFragRef() && LDFileFormat::Ignore ==
- pInfo.outSymbol()->fragRef()->frag()->getParent()->getSection().kind())
+ // make sure that symbols defined in .debug_str won't add into output
+ // symbol table. Since these symbols has fragRef to input fragments, which
+ // will refer to input LDSection and has bad result when emitting their
+ // section index. However, .debug_str actually does not need symobl in
+ // shrad/executable objects, so it's fine to do so.
+ if (pInfo.outSymbol()->hasFragRef() &&
+ (LDFileFormat::Ignore ==
+ pInfo.outSymbol()
+ ->fragRef()
+ ->frag()
+ ->getParent()
+ ->getSection()
+ .kind() ||
+ LDFileFormat::DebugString ==
+ pInfo.outSymbol()
+ ->fragRef()
+ ->frag()
+ ->getParent()
+ ->getSection()
+ .kind()))
return;
if (pInfo.shouldForceLocal(m_Config))
@@ -432,31 +469,27 @@
pModule.getSymbolTable().add(*pInfo.outSymbol());
}
-void ObjectLinker::addSymbolsToOutput(Module& pModule)
-{
+void ObjectLinker::addSymbolsToOutput(Module& pModule) {
// Traverse all the free ResolveInfo and add the output symobols to output
NamePool::freeinfo_iterator free_it,
- free_end = pModule.getNamePool().freeinfo_end();
+ free_end = pModule.getNamePool().freeinfo_end();
for (free_it = pModule.getNamePool().freeinfo_begin(); free_it != free_end;
- ++free_it)
+ ++free_it)
addSymbolToOutput(**free_it, pModule);
-
// Traverse all the resolveInfo and add the output symbol to output
NamePool::syminfo_iterator info_it,
- info_end = pModule.getNamePool().syminfo_end();
+ info_end = pModule.getNamePool().syminfo_end();
for (info_it = pModule.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it)
+ ++info_it)
addSymbolToOutput(*info_it.getEntry(), pModule);
}
-
/// addStandardSymbols - shared object and executable files need some
/// standard symbols
/// @return if there are some input symbols with the same name to the
/// standard symbols, return false
-bool ObjectLinker::addStandardSymbols()
-{
+bool ObjectLinker::addStandardSymbols() {
// create and add section symbols for each output section
Module::iterator iter, iterEnd = m_pModule->end();
for (iter = m_pModule->begin(); iter != iterEnd; ++iter) {
@@ -470,25 +503,23 @@
/// target-dependent symbols
/// @return if there are some input symbols with the same name to the
/// target symbols, return false
-bool ObjectLinker::addTargetSymbols()
-{
+bool ObjectLinker::addTargetSymbols() {
m_LDBackend.initTargetSymbols(*m_pBuilder, *m_pModule);
return true;
}
/// addScriptSymbols - define symbols from the command line option or linker
/// scripts.
-bool ObjectLinker::addScriptSymbols()
-{
+bool ObjectLinker::addScriptSymbols() {
LinkerScript& script = m_pModule->getScript();
LinkerScript::Assignments::iterator it, ie = script.assignments().end();
// go through the entire symbol assignments
for (it = script.assignments().begin(); it != ie; ++it) {
LDSymbol* symbol = NULL;
assert((*it).second.symbol().type() == Operand::SYMBOL);
- const llvm::StringRef symName = (*it).second.symbol().name();
- ResolveInfo::Type type = ResolveInfo::NoType;
- ResolveInfo::Visibility vis = ResolveInfo::Default;
+ const llvm::StringRef symName = (*it).second.symbol().name();
+ ResolveInfo::Type type = ResolveInfo::NoType;
+ ResolveInfo::Visibility vis = ResolveInfo::Default;
size_t size = 0;
ResolveInfo* old_info = m_pModule->getNamePool().findInfo(symName);
// if the symbol does not exist, we can set type to NOTYPE
@@ -504,36 +535,35 @@
// FIXME: bfd linker would change the binding instead, but currently
// ABS is also a kind of Binding in ResolveInfo.
switch ((*it).second.type()) {
- case Assignment::HIDDEN:
- vis = ResolveInfo::Hidden;
+ case Assignment::HIDDEN:
+ vis = ResolveInfo::Hidden;
// Fall through
- case Assignment::DEFAULT:
- symbol =
- m_pBuilder->AddSymbol<IRBuilder::Force,
- IRBuilder::Unresolve>(symName,
- type,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- size,
- 0x0,
- FragmentRef::Null(),
- vis);
- break;
- case Assignment::PROVIDE_HIDDEN:
- vis = ResolveInfo::Hidden;
+ case Assignment::DEFAULT:
+ symbol = m_pBuilder->AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
+ symName,
+ type,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ size,
+ 0x0,
+ FragmentRef::Null(),
+ vis);
+ break;
+ case Assignment::PROVIDE_HIDDEN:
+ vis = ResolveInfo::Hidden;
// Fall through
- case Assignment::PROVIDE:
- symbol =
- m_pBuilder->AddSymbol<IRBuilder::AsReferred,
- IRBuilder::Unresolve>(symName,
- type,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- size,
- 0x0,
- FragmentRef::Null(),
- vis);
- break;
+ case Assignment::PROVIDE:
+ symbol =
+ m_pBuilder->AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ symName,
+ type,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ size,
+ 0x0,
+ FragmentRef::Null(),
+ vis);
+ break;
}
// Set symbol of this assignment.
(*it).first = symbol;
@@ -541,8 +571,7 @@
return true;
}
-bool ObjectLinker::scanRelocations()
-{
+bool ObjectLinker::scanRelocations() {
// apply all relocations of all inputs
Module::obj_iterator input, inEnd = m_pModule->obj_end();
for (input = m_pModule->obj_begin(); input != inEnd; ++input) {
@@ -565,25 +594,25 @@
if (!info->outSymbol()->hasFragRef() &&
ResolveInfo::Section == info->type() &&
ResolveInfo::Undefined == info->desc())
- continue;
+ continue;
// scan relocation
- if (LinkerConfig::Object != m_Config.codeGenType())
+ if (LinkerConfig::Object != m_Config.codeGenType()) {
m_LDBackend.getRelocator()->scanRelocation(
- *relocation, *m_pBuilder, *m_pModule, **rs, **input);
- else
+ *relocation, *m_pBuilder, *m_pModule, **rs, **input);
+ } else {
m_LDBackend.getRelocator()->partialScanRelocation(
- *relocation, *m_pModule, **rs);
- } // for all relocations
- } // for all relocation section
+ *relocation, *m_pModule);
+ }
+ } // for all relocations
+ } // for all relocation section
m_LDBackend.getRelocator()->finalizeScan(**input);
- } // for all inputs
+ } // for all inputs
return true;
}
/// initStubs - initialize stub-related stuff.
-bool ObjectLinker::initStubs()
-{
+bool ObjectLinker::initStubs() {
// initialize BranchIslandFactory
m_LDBackend.initBRIslandFactory();
@@ -597,8 +626,7 @@
/// allocateCommonSymobols - allocate fragments for common symbols to the
/// corresponding sections
-bool ObjectLinker::allocateCommonSymbols()
-{
+bool ObjectLinker::allocateCommonSymbols() {
if (LinkerConfig::Object != m_Config.codeGenType() ||
m_Config.options().isDefineCommon())
return m_LDBackend.allocateCommonSymbols(*m_pModule);
@@ -606,13 +634,13 @@
}
/// prelayout - help backend to do some modification before layout
-bool ObjectLinker::prelayout()
-{
+bool ObjectLinker::prelayout() {
// finalize the section symbols, set their fragment reference and push them
// into output symbol table
Module::iterator sect, sEnd = m_pModule->end();
for (sect = m_pModule->begin(); sect != sEnd; ++sect) {
- m_pModule->getSectionSymbolSet().finalize(**sect,
+ m_pModule->getSectionSymbolSet().finalize(
+ **sect,
m_pModule->getSymbolTable(),
m_Config.codeGenType() == LinkerConfig::Object);
}
@@ -622,15 +650,15 @@
/// check program interpreter - computer the name size of the runtime dyld
if (!m_Config.isCodeStatic() &&
(LinkerConfig::Exec == m_Config.codeGenType() ||
- m_Config.options().isPIE() ||
- m_Config.options().hasDyld()))
+ m_Config.options().isPIE() || m_Config.options().hasDyld()))
m_LDBackend.sizeInterp();
/// measure NamePools - compute the size of name pool sections
/// In ELF, will compute the size of.symtab, .strtab, .dynsym, .dynstr,
/// .hash and .shstrtab sections.
///
- /// dump all symbols and strings from ObjectLinker and build the format-dependent
+ /// dump all symbols and strings from ObjectLinker and build the
+ /// format-dependent
/// hash table.
/// @note sizeNamePools replies on LinkerConfig::CodePosition. Must determine
/// code position model before calling GNULDBackend::sizeNamePools()
@@ -642,6 +670,16 @@
eh_frame_sect->getEhFrame()->computeOffsetSize();
m_LDBackend.createAndSizeEhFrameHdr(*m_pModule);
+ // size debug string table and set up the debug string offset
+ // we set the .debug_str size here so that there won't be a section symbol for
+ // .debug_str. While actually it doesn't matter that .debug_str has section
+ // symbol or not.
+ // FIXME: disable debug string merge when doing partial link.
+ if (LinkerConfig::Object != m_Config.codeGenType()) {
+ LDSection* debug_str_sect = m_pModule->getSection(".debug_str");
+ if (debug_str_sect && debug_str_sect->hasDebugString())
+ debug_str_sect->getDebugString()->computeOffsetSize();
+ }
return true;
}
@@ -650,27 +688,24 @@
/// Because we do not support instruction relaxing in this early version,
/// if there is a branch can not jump to its target, we return false
/// directly
-bool ObjectLinker::layout()
-{
+bool ObjectLinker::layout() {
m_LDBackend.layout(*m_pModule);
return true;
}
/// prelayout - help backend to do some modification after layout
-bool ObjectLinker::postlayout()
-{
+bool ObjectLinker::postlayout() {
m_LDBackend.postLayout(*m_pModule, *m_pBuilder);
return true;
}
/// finalizeSymbolValue - finalize the resolved symbol value.
-/// Before relocate(), after layout(), ObjectLinker should correct value of all
+/// Before relocate(), after layout(), ObjectLinker should correct value of
+/// all
/// symbol.
-bool ObjectLinker::finalizeSymbolValue()
-{
+bool ObjectLinker::finalizeSymbolValue() {
Module::sym_iterator symbol, symEnd = m_pModule->sym_end();
for (symbol = m_pModule->sym_begin(); symbol != symEnd; ++symbol) {
-
if ((*symbol)->resolveInfo()->isAbsolute() ||
(*symbol)->resolveInfo()->type() == ResolveInfo::File) {
// absolute symbols should just use its value directly (i.e., the result
@@ -688,9 +723,9 @@
// relocatable object file, the section's virtual address becomes zero.
// And the symbol's value become section relative offset.
uint64_t value = (*symbol)->fragRef()->getOutputOffset();
- assert(NULL != (*symbol)->fragRef()->frag());
+ assert((*symbol)->fragRef()->frag() != NULL);
uint64_t addr =
- (*symbol)->fragRef()->frag()->getParent()->getSection().addr();
+ (*symbol)->fragRef()->frag()->getParent()->getSection().addr();
(*symbol)->setValue(value + addr);
continue;
}
@@ -714,7 +749,7 @@
break;
symbol->setValue(assignment.symbol().value());
- } // for each script symbol assignment
+ } // for each script symbol assignment
bool assertionsPassed = true;
LinkerScript::Assertions::iterator assert, assertEnd;
@@ -724,7 +759,7 @@
evaluator.eval((*assert).getRpnExpr(), res);
if (res == 0x0)
fatal(diag::err_assert_failed) << (*assert).message();
- } // for each assertion in ldscript
+ } // for each assertion in ldscript
return finalized && scriptSymsFinalized && assertionsPassed;
}
@@ -734,12 +769,13 @@
/// Create relocation section, asking TargetLDBackend to
/// read the relocation information into RelocationEntry
/// and push_back into the relocation section
-bool ObjectLinker::relocation()
-{
+bool ObjectLinker::relocation() {
// when producing relocatables, no need to apply relocation
if (LinkerConfig::Object == m_Config.codeGenType())
return true;
+ LDSection* debug_str_sect = m_pModule->getSection(".debug_str");
+
// apply all relocations of all inputs
Module::obj_iterator input, inEnd = m_pModule->obj_end();
for (input = m_pModule->obj_begin(); input != inEnd; ++input) {
@@ -764,11 +800,24 @@
ResolveInfo::Undefined == info->desc())
continue;
+ // apply the relocation aginst symbol on DebugString
+ if (info->outSymbol()->hasFragRef() &&
+ info->outSymbol()->fragRef()->frag()->getKind()
+ == Fragment::Region &&
+ info->outSymbol()->fragRef()->frag()->getParent()->getSection()
+ .kind() == LDFileFormat::DebugString) {
+ assert(debug_str_sect != NULL);
+ assert(debug_str_sect->hasDebugString());
+ debug_str_sect->getDebugString()->applyOffset(*relocation,
+ m_LDBackend);
+ continue;
+ }
+
relocation->apply(*m_LDBackend.getRelocator());
- } // for all relocations
- } // for all relocation section
+ } // for all relocations
+ } // for all relocation section
m_LDBackend.getRelocator()->finalizeApply(**input);
- } // for all inputs
+ } // for all inputs
// apply relocations created by relaxation
BranchIslandFactory* br_factory = m_LDBackend.getBRIslandFactory();
@@ -779,19 +828,17 @@
for (iter = island.reloc_begin(); iter != iterEnd; ++iter)
(*iter)->apply(*m_LDBackend.getRelocator());
}
+
return true;
}
/// emitOutput - emit the output file.
-bool ObjectLinker::emitOutput(FileOutputBuffer& pOutput)
-{
+bool ObjectLinker::emitOutput(FileOutputBuffer& pOutput) {
return std::error_code() == getWriter()->writeObject(*m_pModule, pOutput);
}
-
/// postProcessing - do modification after all processes
-bool ObjectLinker::postProcessing(FileOutputBuffer& pOutput)
-{
+bool ObjectLinker::postProcessing(FileOutputBuffer& pOutput) {
if (LinkerConfig::Object != m_Config.codeGenType())
normalSyncRelocationResult(pOutput);
else
@@ -804,8 +851,7 @@
return true;
}
-void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput)
-{
+void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput) {
uint8_t* data = pOutput.getBufferStart();
// sync all relocations of all inputs
@@ -837,12 +883,12 @@
// we want is the value of the other relocation result. For example,
// in .exidx, there are usually an R_ARM_NONE and R_ARM_PREL31 apply to
// the same place
- if (0x0 == relocation->type())
+ if (relocation->type() == 0x0)
continue;
writeRelocationResult(*relocation, data);
- } // for all relocations
- } // for all relocation section
- } // for all inputs
+ } // for all relocations
+ } // for all relocation section
+ } // for all inputs
// sync relocations created by relaxation
BranchIslandFactory* br_factory = m_LDBackend.getBRIslandFactory();
@@ -857,8 +903,7 @@
}
}
-void ObjectLinker::partialSyncRelocationResult(FileOutputBuffer& pOutput)
-{
+void ObjectLinker::partialSyncRelocationResult(FileOutputBuffer& pOutput) {
uint8_t* data = pOutput.getBufferStart();
// traverse outputs' LDSection to get RelocData
@@ -878,51 +923,52 @@
// we want is the value of the other relocation result. For example,
// in .exidx, there are usually an R_ARM_NONE and R_ARM_PREL31 apply to
// the same place
- if (0x0 == reloc->type())
+ if (reloc->type() == 0x0)
continue;
writeRelocationResult(*reloc, data);
}
}
}
-void ObjectLinker::writeRelocationResult(Relocation& pReloc, uint8_t* pOutput)
-{
+void ObjectLinker::writeRelocationResult(Relocation& pReloc, uint8_t* pOutput) {
// get output file offset
size_t out_offset =
- pReloc.targetRef().frag()->getParent()->getSection().offset() +
- pReloc.targetRef().getOutputOffset();
+ pReloc.targetRef().frag()->getParent()->getSection().offset() +
+ pReloc.targetRef().getOutputOffset();
uint8_t* target_addr = pOutput + out_offset;
// byte swapping if target and host has different endian, and then write back
- if(llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian()) {
- uint64_t tmp_data = 0;
+ if (llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian()) {
+ uint64_t tmp_data = 0;
- switch(pReloc.size(*m_LDBackend.getRelocator())) {
- case 8u:
- std::memcpy(target_addr, &pReloc.target(), 1);
- break;
+ switch (pReloc.size(*m_LDBackend.getRelocator())) {
+ case 8u:
+ std::memcpy(target_addr, &pReloc.target(), 1);
+ break;
- case 16u:
- tmp_data = mcld::bswap16(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 2);
- break;
+ case 16u:
+ tmp_data = mcld::bswap16(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 2);
+ break;
- case 32u:
- tmp_data = mcld::bswap32(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 4);
- break;
+ case 32u:
+ tmp_data = mcld::bswap32(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 4);
+ break;
- case 64u:
- tmp_data = mcld::bswap64(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 8);
- break;
+ case 64u:
+ tmp_data = mcld::bswap64(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 8);
+ break;
- default:
- break;
+ default:
+ break;
}
+ } else {
+ std::memcpy(target_addr,
+ &pReloc.target(),
+ pReloc.size(*m_LDBackend.getRelocator()) / 8);
}
- else
- std::memcpy(target_addr, &pReloc.target(),
- pReloc.size(*m_LDBackend.getRelocator())/8);
}
+} // namespace mcld
diff --git a/lib/Object/SectionMap.cpp b/lib/Object/SectionMap.cpp
index 4453d42..615c493 100644
--- a/lib/Object/SectionMap.cpp
+++ b/lib/Object/SectionMap.cpp
@@ -6,44 +6,47 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/SectionMap.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/NullFragment.h>
+#include "mcld/Object/SectionMap.h"
+
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/WildcardPattern.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
#include <cstring>
#include <climits>
#if !defined(MCLD_ON_WIN32)
#include <fnmatch.h>
-#define fnmatch0(pattern,string) (fnmatch(pattern,string,0) == 0)
+#define fnmatch0(pattern, string) (fnmatch(pattern, string, 0) == 0)
#else
#include <windows.h>
#include <shlwapi.h>
-#define fnmatch0(pattern,string) (PathMatchSpec(string, pattern) == true)
+#define fnmatch0(pattern, string) (PathMatchSpec(string, pattern) == true)
#endif
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// SectionMap::Input
//===----------------------------------------------------------------------===//
SectionMap::Input::Input(const std::string& pName,
InputSectDesc::KeepPolicy pPolicy)
- : m_Policy(pPolicy)
-{
+ : m_Policy(pPolicy) {
m_Spec.m_pWildcardFile =
- WildcardPattern::create("*", WildcardPattern::SORT_NONE);
+ WildcardPattern::create("*", WildcardPattern::SORT_NONE);
m_Spec.m_pExcludeFiles = NULL;
StringList* sections = StringList::create();
sections->push_back(
- WildcardPattern::create(pName, WildcardPattern::SORT_NONE));
+ WildcardPattern::create(pName, WildcardPattern::SORT_NONE));
m_Spec.m_pWildcardSections = sections;
m_pSection = LDSection::Create(pName, LDFileFormat::TEXT, 0, 0);
@@ -54,8 +57,7 @@
}
SectionMap::Input::Input(const InputSectDesc& pInputDesc)
- : m_Policy(pInputDesc.policy())
-{
+ : m_Policy(pInputDesc.policy()) {
m_Spec.m_pWildcardFile = pInputDesc.spec().m_pWildcardFile;
m_Spec.m_pExcludeFiles = pInputDesc.spec().m_pExcludeFiles;
m_Spec.m_pWildcardSections = pInputDesc.spec().m_pWildcardSections;
@@ -70,9 +72,7 @@
// SectionMap::Output
//===----------------------------------------------------------------------===//
SectionMap::Output::Output(const std::string& pName)
- : m_Name(pName),
- m_Order(UINT_MAX)
-{
+ : m_Name(pName), m_Order(UINT_MAX) {
m_Prolog.m_pVMA = NULL;
m_Prolog.m_Type = OutputSectDesc::LOAD;
m_Prolog.m_pLMA = NULL;
@@ -93,11 +93,10 @@
}
SectionMap::Output::Output(const OutputSectDesc& pOutputDesc)
- : m_Name(pOutputDesc.name()),
- m_Prolog(pOutputDesc.prolog()),
- m_Epilog(pOutputDesc.epilog()),
- m_Order(UINT_MAX)
-{
+ : m_Name(pOutputDesc.name()),
+ m_Prolog(pOutputDesc.prolog()),
+ m_Epilog(pOutputDesc.epilog()),
+ m_Order(UINT_MAX) {
m_pSection = LDSection::Create(m_Name, LDFileFormat::TEXT, 0, 0);
SectionData* sd = SectionData::Create(*m_pSection);
m_pSection->setSectionData(sd);
@@ -105,14 +104,12 @@
m_bIsDiscard = m_Name.compare("/DISCARD/") == 0;
}
-bool SectionMap::Output::hasContent() const
-{
+bool SectionMap::Output::hasContent() const {
return m_pSection != NULL && m_pSection->size() != 0;
}
SectionMap::Output::const_dot_iterator
-SectionMap::Output::find_first_explicit_dot() const
-{
+SectionMap::Output::find_first_explicit_dot() const {
for (const_dot_iterator it = dot_begin(), ie = dot_end(); it != ie; ++it) {
if ((*it).type() == Assignment::DEFAULT)
return it;
@@ -120,8 +117,7 @@
return dot_end();
}
-SectionMap::Output::dot_iterator SectionMap::Output::find_first_explicit_dot()
-{
+SectionMap::Output::dot_iterator SectionMap::Output::find_first_explicit_dot() {
for (dot_iterator it = dot_begin(), ie = dot_end(); it != ie; ++it) {
if ((*it).type() == Assignment::DEFAULT)
return it;
@@ -130,11 +126,11 @@
}
SectionMap::Output::const_dot_iterator
-SectionMap::Output::find_last_explicit_dot() const
-{
+SectionMap::Output::find_last_explicit_dot() const {
typedef DotAssignments::const_reverse_iterator CONST_RIT;
for (CONST_RIT rit = dotAssignments().rbegin(), rie = dotAssignments().rend();
- rit != rie; ++rit) {
+ rit != rie;
+ ++rit) {
if ((*rit).type() == Assignment::DEFAULT) {
return dot_begin() +
(dotAssignments().size() - (rit - dotAssignments().rbegin()) - 1);
@@ -143,11 +139,11 @@
return dot_end();
}
-SectionMap::Output::dot_iterator SectionMap::Output::find_last_explicit_dot()
-{
+SectionMap::Output::dot_iterator SectionMap::Output::find_last_explicit_dot() {
typedef DotAssignments::reverse_iterator RIT;
for (RIT rit = dotAssignments().rbegin(), rie = dotAssignments().rend();
- rit != rie; ++rit) {
+ rit != rie;
+ ++rit) {
if ((*rit).type() == Assignment::DEFAULT) {
return dot_begin() +
(dotAssignments().size() - (rit - dotAssignments().rbegin()) - 1);
@@ -159,8 +155,7 @@
//===----------------------------------------------------------------------===//
// SectionMap
//===----------------------------------------------------------------------===//
-SectionMap::~SectionMap()
-{
+SectionMap::~SectionMap() {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if (*out != NULL) {
@@ -174,10 +169,9 @@
}
}
-SectionMap::const_mapping
-SectionMap::find(const std::string& pInputFile,
- const std::string& pInputSection) const
-{
+SectionMap::const_mapping SectionMap::find(
+ const std::string& pInputFile,
+ const std::string& pInputSection) const {
const_iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
Output::const_iterator in, inBegin = (*out)->begin(), inEnd = (*out)->end();
@@ -190,8 +184,7 @@
}
SectionMap::mapping SectionMap::find(const std::string& pInputFile,
- const std::string& pInputSection)
-{
+ const std::string& pInputSection) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
Output::iterator in, inBegin = (*out)->begin(), inEnd = (*out)->end();
@@ -200,12 +193,12 @@
return std::make_pair(*out, *in);
}
}
- return std::make_pair((Output*)NULL, (Input*)NULL);
+ return std::make_pair(reinterpret_cast<Output*>(NULL),
+ reinterpret_cast<Input*>(NULL));
}
-SectionMap::const_iterator
-SectionMap::find(const std::string& pOutputSection) const
-{
+SectionMap::const_iterator SectionMap::find(
+ const std::string& pOutputSection) const {
const_iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -214,9 +207,7 @@
return outEnd;
}
-SectionMap::iterator
-SectionMap::find(const std::string& pOutputSection)
-{
+SectionMap::iterator SectionMap::find(const std::string& pOutputSection) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -225,11 +216,10 @@
return outEnd;
}
-std::pair<SectionMap::mapping, bool>
-SectionMap::insert(const std::string& pInputSection,
- const std::string& pOutputSection,
- InputSectDesc::KeepPolicy pPolicy)
-{
+std::pair<SectionMap::mapping, bool> SectionMap::insert(
+ const std::string& pInputSection,
+ const std::string& pOutputSection,
+ InputSectDesc::KeepPolicy pPolicy) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -259,10 +249,9 @@
return std::make_pair(std::make_pair(output, input), true);
}
-std::pair<SectionMap::mapping, bool>
-SectionMap::insert(const InputSectDesc& pInputDesc,
- const OutputSectDesc& pOutputDesc)
-{
+std::pair<SectionMap::mapping, bool> SectionMap::insert(
+ const InputSectDesc& pInputDesc,
+ const OutputSectDesc& pOutputDesc) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputDesc.name()) == 0 &&
@@ -296,9 +285,8 @@
return std::make_pair(std::make_pair(output, input), true);
}
-SectionMap::iterator
-SectionMap::insert(iterator pPosition, LDSection* pSection)
-{
+SectionMap::iterator SectionMap::insert(iterator pPosition,
+ LDSection* pSection) {
Output* output = new Output(pSection->name());
output->append(new Input(pSection->name(), InputSectDesc::NoKeep));
output->setSection(pSection);
@@ -307,10 +295,9 @@
bool SectionMap::matched(const SectionMap::Input& pInput,
const std::string& pInputFile,
- const std::string& pInputSection) const
-{
+ const std::string& pInputSection) const {
if (pInput.spec().hasFile() && !matched(pInput.spec().file(), pInputFile))
- return false;
+ return false;
if (pInput.spec().hasExcludeFiles()) {
StringList::const_iterator file, fileEnd;
@@ -335,8 +322,7 @@
}
bool SectionMap::matched(const WildcardPattern& pPattern,
- const std::string& pName) const
-{
+ const std::string& pName) const {
if (pPattern.isPrefix()) {
llvm::StringRef name(pName);
return name.startswith(pPattern.prefix());
@@ -346,14 +332,12 @@
}
// fixupDotSymbols - ensure the dot symbols are valid
-void SectionMap::fixupDotSymbols()
-{
+void SectionMap::fixupDotSymbols() {
for (iterator it = begin() + 1, ie = end(); it != ie; ++it) {
// fixup the 1st explicit dot assignment if needed
if (!(*it)->dotAssignments().empty()) {
Output::dot_iterator dot = (*it)->find_first_explicit_dot();
- if (dot != (*it)->dot_end() &&
- (*dot).symbol().isDot() &&
+ if (dot != (*it)->dot_end() && (*dot).symbol().isDot() &&
(*dot).getRpnExpr().hasDot()) {
Assignment assign(Assignment::OUTPUT_SECTION,
Assignment::DEFAULT,
@@ -361,11 +345,13 @@
*RpnExpr::buildHelperExpr(it - 1));
Output::dot_iterator ref = (*it)->dotAssignments().insert(dot, assign);
for (RpnExpr::iterator tok = (*dot).getRpnExpr().begin(),
- tokEnd = (*dot).getRpnExpr().end(); tok != tokEnd; ++tok) {
+ tokEnd = (*dot).getRpnExpr().end();
+ tok != tokEnd;
+ ++tok) {
if ((*tok)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*tok)->isDot())
*tok = &((*ref).symbol());
- } // for each token in the RHS expr of the dot assignment
+ } // for each token in the RHS expr of the dot assignment
}
}
@@ -380,12 +366,15 @@
dot = (*it)->dotAssignments().insert(dot, assign);
}
for (RpnExpr::iterator tok = (*it)->prolog().vma().begin(),
- tokEnd = (*it)->prolog().vma().end(); tok != tokEnd; ++tok) {
+ tokEnd = (*it)->prolog().vma().end();
+ tok != tokEnd;
+ ++tok) {
if ((*tok)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*tok)->isDot())
*tok = &((*dot).symbol());
- } // for each token in the RHS expr of the dot assignment
+ } // for each token in the RHS expr of the dot assignment
}
-
- } // for each output section
+ } // for each output section
}
+
+} // namespace mcld
diff --git a/lib/Script/AssertCmd.cpp b/lib/Script/AssertCmd.cpp
index 618731d..8430534 100644
--- a/lib/Script/AssertCmd.cpp
+++ b/lib/Script/AssertCmd.cpp
@@ -6,35 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/AssertCmd.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
+#include "mcld/Script/AssertCmd.h"
-using namespace mcld;
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/raw_ostream.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// AssertCmd
//===----------------------------------------------------------------------===//
AssertCmd::AssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage)
- : ScriptCommand(ScriptCommand::ASSERT),
- m_RpnExpr(pRpnExpr),
- m_Message(pMessage)
-{
+ : ScriptCommand(ScriptCommand::ASSERT),
+ m_RpnExpr(pRpnExpr),
+ m_Message(pMessage) {
}
-AssertCmd::~AssertCmd()
-{
+AssertCmd::~AssertCmd() {
}
-AssertCmd& AssertCmd::operator=(const AssertCmd& pAssertCmd)
-{
+AssertCmd& AssertCmd::operator=(const AssertCmd& pAssertCmd) {
return *this;
}
-void AssertCmd::dump() const
-{
+void AssertCmd::dump() const {
mcld::outs() << "Assert ( ";
m_RpnExpr.dump();
@@ -42,7 +39,8 @@
mcld::outs() << " , " << m_Message << " )\n";
}
-void AssertCmd::activate(Module& pModule)
-{
+void AssertCmd::activate(Module& pModule) {
pModule.getScript().assertions().push_back(*this);
}
+
+} // namespace mcld
diff --git a/lib/Script/Assignment.cpp b/lib/Script/Assignment.cpp
index a7e0f46..333b366 100644
--- a/lib/Script/Assignment.cpp
+++ b/lib/Script/Assignment.cpp
@@ -6,20 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Module.h>
+#include "mcld/Script/Assignment.h"
+
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Assignment
@@ -28,39 +31,35 @@
Type pType,
SymOperand& pSymbol,
RpnExpr& pRpnExpr)
- : ScriptCommand(ScriptCommand::ASSIGNMENT),
- m_Level(pLevel),
- m_Type(pType),
- m_Symbol(pSymbol),
- m_RpnExpr(pRpnExpr)
-{
+ : ScriptCommand(ScriptCommand::ASSIGNMENT),
+ m_Level(pLevel),
+ m_Type(pType),
+ m_Symbol(pSymbol),
+ m_RpnExpr(pRpnExpr) {
}
-Assignment::~Assignment()
-{
+Assignment::~Assignment() {
}
-Assignment& Assignment::operator=(const Assignment& pAssignment)
-{
+Assignment& Assignment::operator=(const Assignment& pAssignment) {
return *this;
}
-void Assignment::dump() const
-{
+void Assignment::dump() const {
switch (type()) {
- case DEFAULT:
- break;
- case HIDDEN:
- mcld::outs() << "HIDDEN ( ";
- break;
- case PROVIDE:
- mcld::outs() << "PROVIDE ( ";
- break;
- case PROVIDE_HIDDEN:
- mcld::outs() << "PROVIDE_HIDDEN ( ";
- break;
- default:
- break;
+ case DEFAULT:
+ break;
+ case HIDDEN:
+ mcld::outs() << "HIDDEN ( ";
+ break;
+ case PROVIDE:
+ mcld::outs() << "PROVIDE ( ";
+ break;
+ case PROVIDE_HIDDEN:
+ mcld::outs() << "PROVIDE_HIDDEN ( ";
+ break;
+ default:
+ break;
}
m_Symbol.dump();
@@ -75,101 +74,104 @@
mcld::outs() << ";\n";
}
-void Assignment::activate(Module& pModule)
-{
+void Assignment::activate(Module& pModule) {
bool isLhsDot = m_Symbol.isDot();
LinkerScript& script = pModule.getScript();
switch (m_Level) {
- case OUTSIDE_SECTIONS:
- assert(!isLhsDot);
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
- break;
+ case OUTSIDE_SECTIONS:
+ assert(!isLhsDot);
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ break;
- case OUTPUT_SECTION: {
- bool hasDotInRhs = m_RpnExpr.hasDot();
- SectionMap::reference out = script.sectionMap().back();
- if (hasDotInRhs) {
- if (!isLhsDot && out->dotAssignments().empty()) {
- // . = ADDR ( `prev_output_sect' ) + SIZEOF ( `prev_output_sect' )
- SectionMap::iterator prev = script.sectionMap().begin() +
- script.sectionMap().size() - 2;
- Assignment assign(OUTPUT_SECTION,
- HIDDEN,
- *SymOperand::create("."),
- *RpnExpr::buildHelperExpr(prev));
- out->dotAssignments().push_back(assign);
- }
+ case OUTPUT_SECTION: {
+ bool hasDotInRhs = m_RpnExpr.hasDot();
+ SectionMap::reference out = script.sectionMap().back();
+ if (hasDotInRhs) {
+ if (!isLhsDot && out->dotAssignments().empty()) {
+ // . = ADDR ( `prev_output_sect' ) + SIZEOF ( `prev_output_sect' )
+ SectionMap::iterator prev =
+ script.sectionMap().begin() + script.sectionMap().size() - 2;
+ Assignment assign(OUTPUT_SECTION,
+ HIDDEN,
+ *SymOperand::create("."),
+ *RpnExpr::buildHelperExpr(prev));
+ out->dotAssignments().push_back(assign);
+ }
- if (!out->dotAssignments().empty()) {
- Assignment& prevDotAssign = out->dotAssignments().back();
- // If this is the 1st explicit assignment that includes both lhs dot and
- // rhs dot, then because of possible orphan sections, we are unable to
- // substitute the rhs dot now.
- if (!isLhsDot || prevDotAssign.type() == DEFAULT) {
- for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
- it != ie; ++it) {
- // substitute the rhs dot with the appropriate helper expr
- if ((*it)->kind() == ExprToken::OPERAND &&
- llvm::cast<Operand>(*it)->isDot())
- *it = &(prevDotAssign.symbol());
- } // for each expression token
+ if (!out->dotAssignments().empty()) {
+ Assignment& prevDotAssign = out->dotAssignments().back();
+ // If this is the 1st explicit assignment that includes both lhs dot
+ // and
+ // rhs dot, then because of possible orphan sections, we are unable to
+ // substitute the rhs dot now.
+ if (!isLhsDot || prevDotAssign.type() == DEFAULT) {
+ for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
+ it != ie;
+ ++it) {
+ // substitute the rhs dot with the appropriate helper expr
+ if ((*it)->kind() == ExprToken::OPERAND &&
+ llvm::cast<Operand>(*it)->isDot()) {
+ *it = &(prevDotAssign.symbol());
+ }
+ } // for each expression token
+ }
}
}
+
+ if (isLhsDot) {
+ out->dotAssignments().push_back(*this);
+ } else {
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ }
+ break;
}
- if (isLhsDot) {
- out->dotAssignments().push_back(*this);
- } else {
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
- }
+ case INPUT_SECTION: {
+ bool hasDotInRhs = m_RpnExpr.hasDot();
+ SectionMap::Output::reference in = script.sectionMap().back()->back();
+ if (hasDotInRhs) {
+ if (in->dotAssignments().empty()) {
+ // . = `frag'
+ RpnExpr* expr = RpnExpr::buildHelperExpr(
+ in->getSection()->getSectionData()->front());
+ Assignment assign(
+ INPUT_SECTION, HIDDEN, *SymOperand::create("."), *expr);
+ in->dotAssignments().push_back(
+ std::make_pair(reinterpret_cast<Fragment*>(NULL), assign));
+ }
- break;
- }
-
- case INPUT_SECTION: {
- bool hasDotInRhs = m_RpnExpr.hasDot();
- SectionMap::Output::reference in = script.sectionMap().back()->back();
- if (hasDotInRhs) {
- if (in->dotAssignments().empty()) {
- // . = `frag'
- RpnExpr* expr =
- RpnExpr::buildHelperExpr(in->getSection()->getSectionData()->front());
- Assignment assign(INPUT_SECTION,
- HIDDEN,
- *SymOperand::create("."),
- *expr);
- in->dotAssignments().push_back(std::make_pair((Fragment*)NULL, assign));
+ Assignment& prevDotAssign = in->dotAssignments().back().second;
+ for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
+ it != ie;
+ ++it) {
+ // substitute the rhs dot with the appropriate helper expr
+ if ((*it)->kind() == ExprToken::OPERAND &&
+ llvm::cast<Operand>(*it)->isDot()) {
+ *it = &(prevDotAssign.symbol());
+ }
+ } // end of for
}
- Assignment& prevDotAssign = in->dotAssignments().back().second;
- for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
- it != ie; ++it) {
- // substitute the rhs dot with the appropriate helper expr
- if ((*it)->kind() == ExprToken::OPERAND &&
- llvm::cast<Operand>(*it)->isDot())
- *it = &(prevDotAssign.symbol());
- } // end of for
+ if (isLhsDot) {
+ in->dotAssignments().push_back(std::make_pair(
+ in->getSection()->getSectionData()->front().getNextNode(), *this));
+ } else {
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ }
+ break;
}
-
- if (isLhsDot) {
- in->dotAssignments().push_back(
- std::make_pair(in->getSection()->getSectionData()->front().getNextNode(),
- *this));
- } else {
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
- }
-
- break;
- }
-
- } // end of switch
+ } // end of switch
}
-bool Assignment::assign(RpnEvaluator& pEvaluator)
-{
+bool Assignment::assign(RpnEvaluator& pEvaluator) {
uint64_t result = 0;
bool success = pEvaluator.eval(m_RpnExpr, result);
if (success)
m_Symbol.setValue(result);
return success;
}
+
+} // namespace mcld
diff --git a/lib/Script/BinaryOp.cpp b/lib/Script/BinaryOp.cpp
index 863eb34..e87c837 100644
--- a/lib/Script/BinaryOp.cpp
+++ b/lib/Script/BinaryOp.cpp
@@ -6,190 +6,175 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/BinaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/Script/BinaryOp.h"
+
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Target/TargetLDBackend.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// BinaryOp
//===----------------------------------------------------------------------===//
-template<>
+template <>
IntOperand* BinaryOp<Operator::MUL>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() * m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::DIV>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() / m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MOD>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() % m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::ADD>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() + m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::SUB>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() - m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() << m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() >> m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() < m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() <= m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::GT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() > m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::GE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() >= m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::EQ>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() == m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::NE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() != m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_AND>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() & m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_XOR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() ^ m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_OR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() | m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::LOGICAL_AND>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() && m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::LOGICAL_OR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() || m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
uint64_t value = m_pOperand[0]->value();
uint64_t align = m_pOperand[1]->value();
@@ -198,11 +183,10 @@
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
/* FIXME: Currently we handle relro in a different way, and now the result
of this expression won't affect DATA_SEGMENT_ALIGN. */
IntOperand* res = result();
@@ -212,10 +196,9 @@
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MAX>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value() >= m_pOperand[1]->value())
res->setValue(m_pOperand[0]->value());
@@ -224,10 +207,9 @@
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MIN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value() <= m_pOperand[1]->value())
res->setValue(m_pOperand[0]->value());
@@ -236,18 +218,15 @@
return res;
}
-
/* SEGMENT_START(segment, default) */
-template<>
-IntOperand*
-BinaryOp<Operator::SEGMENT_START>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
/* Currently we look up segment address from -T command line options. */
SectOperand* sect = llvm::cast<SectOperand>(m_pOperand[0]);
- const LinkerScript::AddressMap& addressMap =
- pModule.getScript().addressMap();
+ const LinkerScript::AddressMap& addressMap = pModule.getScript().addressMap();
LinkerScript::AddressMap::const_iterator addr;
if (sect->name().compare("text-segment") == 0)
addr = addressMap.find(".text");
@@ -266,3 +245,5 @@
}
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/CMakeLists.txt b/lib/Script/CMakeLists.txt
index 6fed079..1426a23 100644
--- a/lib/Script/CMakeLists.txt
+++ b/lib/Script/CMakeLists.txt
@@ -13,6 +13,7 @@
EntryCmd.cpp
FileToken.cpp
GroupCmd.cpp
+ InputCmd.cpp
InputSectDesc.cpp
InputToken.cpp
NameSpec.cpp
diff --git a/lib/Script/EntryCmd.cpp b/lib/Script/EntryCmd.cpp
index 9e33c53..345b153 100644
--- a/lib/Script/EntryCmd.cpp
+++ b/lib/Script/EntryCmd.cpp
@@ -6,35 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/EntryCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/EntryCmd.h"
-using namespace mcld;
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// EntryCmd
//===----------------------------------------------------------------------===//
EntryCmd::EntryCmd(const std::string& pEntry)
- : ScriptCommand(ScriptCommand::ENTRY),
- m_Entry(pEntry)
-{
+ : ScriptCommand(ScriptCommand::ENTRY), m_Entry(pEntry) {
}
-EntryCmd::~EntryCmd()
-{
+EntryCmd::~EntryCmd() {
}
-void EntryCmd::dump() const
-{
+void EntryCmd::dump() const {
mcld::outs() << "ENTRY ( " << m_Entry << " )\n";
}
-void EntryCmd::activate(Module& pModule)
-{
+void EntryCmd::activate(Module& pModule) {
LinkerScript& script = pModule.getScript();
if (!script.hasEntry())
script.setEntry(m_Entry);
}
+} // namespace mcld
diff --git a/lib/Script/FileToken.cpp b/lib/Script/FileToken.cpp
index 2247d6e..29e1544 100644
--- a/lib/Script/FileToken.cpp
+++ b/lib/Script/FileToken.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/FileToken.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/FileToken.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<FileToken, MCLD_SYMBOLS_PER_INPUT> FileTokenFactory;
static llvm::ManagedStatic<FileTokenFactory> g_FileTokenFactory;
@@ -18,34 +20,30 @@
//===----------------------------------------------------------------------===//
// FileToken
//===----------------------------------------------------------------------===//
-FileToken::FileToken()
-{
+FileToken::FileToken() {
}
FileToken::FileToken(const std::string& pName, bool pAsNeeded)
- : InputToken(InputToken::File, pName, pAsNeeded)
-{
+ : InputToken(InputToken::File, pName, pAsNeeded) {
}
-FileToken::~FileToken()
-{
+FileToken::~FileToken() {
}
-FileToken* FileToken::create(const std::string& pName, bool pAsNeeded)
-{
+FileToken* FileToken::create(const std::string& pName, bool pAsNeeded) {
FileToken* result = g_FileTokenFactory->allocate();
new (result) FileToken(pName, pAsNeeded);
return result;
}
-void FileToken::destroy(FileToken*& pFileToken)
-{
+void FileToken::destroy(FileToken*& pFileToken) {
g_FileTokenFactory->destroy(pFileToken);
g_FileTokenFactory->deallocate(pFileToken);
pFileToken = NULL;
}
-void FileToken::clear()
-{
+void FileToken::clear() {
g_FileTokenFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/GroupCmd.cpp b/lib/Script/GroupCmd.cpp
index 4673242..1cdf84c 100644
--- a/lib/Script/GroupCmd.cpp
+++ b/lib/Script/GroupCmd.cpp
@@ -6,21 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/GroupCmd.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/InputToken.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/Path.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/InputTree.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/GroupReader.h>
+#include "mcld/Script/GroupCmd.h"
+
+#include "mcld/LD/GroupReader.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerScript.h"
+
#include <llvm/Support/Casting.h>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GroupCmd
@@ -30,25 +32,24 @@
InputBuilder& pBuilder,
GroupReader& pGroupReader,
const LinkerConfig& pConfig)
- : ScriptCommand(ScriptCommand::GROUP),
- m_StringList(pStringList),
- m_InputTree(pInputTree),
- m_Builder(pBuilder),
- m_GroupReader(pGroupReader),
- m_Config(pConfig)
-{
+ : ScriptCommand(ScriptCommand::GROUP),
+ m_StringList(pStringList),
+ m_InputTree(pInputTree),
+ m_Builder(pBuilder),
+ m_GroupReader(pGroupReader),
+ m_Config(pConfig) {
}
-GroupCmd::~GroupCmd()
-{
+GroupCmd::~GroupCmd() {
}
-void GroupCmd::dump() const
-{
+void GroupCmd::dump() const {
mcld::outs() << "GROUP ( ";
bool prev = false, cur = false;
for (StringList::const_iterator it = m_StringList.begin(),
- ie = m_StringList.end(); it != ie; ++it) {
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Input);
InputToken* input = llvm::cast<InputToken>(*it);
cur = input->asNeeded();
@@ -70,8 +71,7 @@
mcld::outs() << " )\n";
}
-void GroupCmd::activate(Module& pModule)
-{
+void GroupCmd::activate(Module& pModule) {
LinkerScript& script = pModule.getScript();
// construct the Group tree
m_Builder.setCurrentTree(m_InputTree);
@@ -80,8 +80,9 @@
InputTree::iterator group = m_Builder.getCurrentNode();
for (StringList::const_iterator it = m_StringList.begin(),
- ie = m_StringList.end(); it != ie; ++it) {
-
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Input);
InputToken* token = llvm::cast<InputToken>(*it);
if (token->asNeeded())
@@ -90,69 +91,72 @@
m_Builder.getAttributes().unsetAsNeeded();
switch (token->type()) {
- case InputToken::File: {
- sys::fs::Path path;
+ case InputToken::File: {
+ sys::fs::Path path;
- // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
- // configured and the filename starts with '/'
- if (script.hasSysroot() &&
- (token->name().size() > 0 && token->name()[0] == '/')) {
+ // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
+ // configured and the filename starts with '/'
+ if (script.hasSysroot() &&
+ (token->name().size() > 0 && token->name()[0] == '/')) {
path = script.sysroot();
path.append(token->name());
- } else {
- // 2. Try to open the file in CWD
- path.assign(token->name());
- if (!sys::fs::exists(path)) {
- // 3. Search through the library search path
- sys::fs::Path* p =
- script.directories().find(token->name(), Input::Script);
- if (p != NULL)
- path = *p;
- }
- }
-
- if (!sys::fs::exists(path))
- fatal(diag::err_cannot_open_input) << path.filename() << path;
-
- m_Builder.createNode<InputTree::Positional>(
- path.filename().native(), path, Input::Unknown);
- break;
- }
- case InputToken::NameSpec: {
- const sys::fs::Path* path = NULL;
- // find out the real path of the namespec.
- if (m_Builder.getConstraint().isSharedSystem()) {
- // In the system with shared object support, we can find both archive
- // and shared object.
- if (m_Builder.getAttributes().isStatic()) {
- // with --static, we must search an archive.
- path = script.directories().find(token->name(), Input::Archive);
} else {
- // otherwise, with --Bdynamic, we can find either an archive or a
- // shared object.
- path = script.directories().find(token->name(), Input::DynObj);
+ // 2. Try to open the file in CWD
+ path.assign(token->name());
+ if (!sys::fs::exists(path)) {
+ // 3. Search through the library search path
+ sys::fs::Path* p =
+ script.directories().find(token->name(), Input::Script);
+ if (p != NULL)
+ path = *p;
+ }
}
- } else {
- // In the system without shared object support, only look for an archive
- path = script.directories().find(token->name(), Input::Archive);
+
+ if (!sys::fs::exists(path))
+ fatal(diag::err_cannot_open_input) << path.filename() << path;
+
+ m_Builder.createNode<InputTree::Positional>(
+ path.filename().native(), path, Input::Unknown);
+ break;
}
+ case InputToken::NameSpec: {
+ const sys::fs::Path* path = NULL;
+ // find out the real path of the namespec.
+ if (m_Builder.getConstraint().isSharedSystem()) {
+ // In the system with shared object support, we can find both archive
+ // and shared object.
+ if (m_Builder.getAttributes().isStatic()) {
+ // with --static, we must search an archive.
+ path = script.directories().find(token->name(), Input::Archive);
+ } else {
+ // otherwise, with --Bdynamic, we can find either an archive or a
+ // shared object.
+ path = script.directories().find(token->name(), Input::DynObj);
+ }
+ } else {
+ // In the system without shared object support, only look for an
+ // archive
+ path = script.directories().find(token->name(), Input::Archive);
+ }
- if (NULL == path)
- fatal(diag::err_cannot_find_namespec) << token->name();
+ if (path == NULL)
+ fatal(diag::err_cannot_find_namespec) << token->name();
- m_Builder.createNode<InputTree::Positional>(
- token->name(), *path, Input::Unknown);
- break;
- }
- default:
- assert(0 && "Invalid script token in GROUP!");
- break;
- } // end of switch
+ m_Builder.createNode<InputTree::Positional>(
+ token->name(), *path, Input::Unknown);
+ break;
+ }
+ default:
+ assert(0 && "Invalid script token in GROUP!");
+ break;
+ } // end of switch
Input* input = *m_Builder.getCurrentNode();
assert(input != NULL);
- if (!m_Builder.setMemory(*input, FileHandle::ReadOnly))
+ if (!m_Builder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
error(diag::err_cannot_open_input) << input->name() << input->path();
+ }
m_Builder.setContext(*input);
}
@@ -163,3 +167,4 @@
m_GroupReader.readGroup(group, m_InputTree.end(), m_Builder, m_Config);
}
+} // namespace mcld
diff --git a/lib/Script/InputCmd.cpp b/lib/Script/InputCmd.cpp
new file mode 100644
index 0000000..a497fd9
--- /dev/null
+++ b/lib/Script/InputCmd.cpp
@@ -0,0 +1,213 @@
+//===- InputCmd.cpp -------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/Script/InputCmd.h"
+
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+
+#include <llvm/Support/Casting.h>
+
+#include <cassert>
+#include <iostream>
+
+namespace mcld {
+
+//===----------------------------------------------------------------------===//
+// InputCmd
+//===----------------------------------------------------------------------===//
+InputCmd::InputCmd(StringList& pStringList,
+ InputTree& pInputTree,
+ InputBuilder& pBuilder,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig)
+ : ScriptCommand(ScriptCommand::INPUT),
+ m_StringList(pStringList),
+ m_InputTree(pInputTree),
+ m_Builder(pBuilder),
+ m_ObjectReader(pObjectReader),
+ m_ArchiveReader(pArchiveReader),
+ m_DynObjReader(pDynObjReader),
+ m_Config(pConfig) {
+}
+
+InputCmd::~InputCmd() {
+}
+
+void InputCmd::dump() const {
+ mcld::outs() << "INPUT ( ";
+ bool prev = false, cur = false;
+ for (StringList::const_iterator it = m_StringList.begin(),
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
+ assert((*it)->kind() == StrToken::Input);
+ InputToken* input = llvm::cast<InputToken>(*it);
+ cur = input->asNeeded();
+ if (!prev && cur)
+ mcld::outs() << "AS_NEEDED ( ";
+ else if (prev && !cur)
+ mcld::outs() << " )";
+
+ if (input->type() == InputToken::NameSpec)
+ mcld::outs() << "-l";
+ mcld::outs() << input->name() << " ";
+
+ prev = cur;
+ }
+
+ if (!m_StringList.empty() && prev)
+ mcld::outs() << " )";
+
+ mcld::outs() << " )\n";
+}
+
+void InputCmd::activate(Module& pModule) {
+ LinkerScript& script = pModule.getScript();
+ // construct the INPUT tree
+ m_Builder.setCurrentTree(m_InputTree);
+
+ bool is_begin_marked = false;
+ InputTree::iterator input_begin;
+
+ for (StringList::const_iterator it = m_StringList.begin(),
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
+ assert((*it)->kind() == StrToken::Input);
+ InputToken* token = llvm::cast<InputToken>(*it);
+ if (token->asNeeded())
+ m_Builder.getAttributes().setAsNeeded();
+ else
+ m_Builder.getAttributes().unsetAsNeeded();
+
+ switch (token->type()) {
+ case InputToken::File: {
+ sys::fs::Path path;
+
+ // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
+ // configured and the filename starts with '/'
+ if (script.hasSysroot() &&
+ (token->name().size() > 0 && token->name()[0] == '/')) {
+ path = script.sysroot();
+ path.append(token->name());
+ } else {
+ // 2. Try to open the file in CWD
+ path.assign(token->name());
+ if (!sys::fs::exists(path)) {
+ // 3. Search through the library search path
+ sys::fs::Path* p =
+ script.directories().find(token->name(), Input::Script);
+ if (p != NULL)
+ path = *p;
+ }
+ }
+
+ if (!sys::fs::exists(path))
+ fatal(diag::err_cannot_open_input) << path.filename() << path;
+
+ m_Builder.createNode<InputTree::Positional>(
+ path.filename().native(), path, Input::Unknown);
+ break;
+ }
+ case InputToken::NameSpec: {
+ const sys::fs::Path* path = NULL;
+ // find out the real path of the namespec.
+ if (m_Builder.getConstraint().isSharedSystem()) {
+ // In the system with shared object support, we can find both archive
+ // and shared object.
+ if (m_Builder.getAttributes().isStatic()) {
+ // with --static, we must search an archive.
+ path = script.directories().find(token->name(), Input::Archive);
+ } else {
+ // otherwise, with --Bdynamic, we can find either an archive or a
+ // shared object.
+ path = script.directories().find(token->name(), Input::DynObj);
+ }
+ } else {
+ // In the system without shared object support, only look for an
+ // archive
+ path = script.directories().find(token->name(), Input::Archive);
+ }
+
+ if (path == NULL)
+ fatal(diag::err_cannot_find_namespec) << token->name();
+
+ m_Builder.createNode<InputTree::Positional>(
+ token->name(), *path, Input::Unknown);
+ break;
+ }
+ default:
+ assert(0 && "Invalid script token in INPUT!");
+ break;
+ } // end of switch
+
+ InputTree::iterator input = m_Builder.getCurrentNode();
+ if (!is_begin_marked) {
+ input_begin = input;
+ is_begin_marked = true;
+ }
+ assert(*input != NULL);
+ if (!m_Builder.setMemory(**input,
+ FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
+ error(diag::err_cannot_open_input) << (*input)->name()
+ << (*input)->path();
+ }
+ m_Builder.setContext(**input);
+ }
+
+ for (InputTree::iterator input = input_begin, ie = m_InputTree.end();
+ input != ie;
+ ++input) {
+ bool doContinue = false;
+ if (m_ObjectReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::Object);
+ m_ObjectReader.readHeader(**input);
+ m_ObjectReader.readSections(**input);
+ m_ObjectReader.readSymbols(**input);
+ pModule.getObjectList().push_back(*input);
+ } else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::DynObj);
+ m_DynObjReader.readHeader(**input);
+ m_DynObjReader.readSymbols(**input);
+ pModule.getLibraryList().push_back(*input);
+ } else if (doContinue && m_ArchiveReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::Archive);
+ if (m_Config.options().isInExcludeLIBS(**input)) {
+ (*input)->setNoExport();
+ }
+ Archive archive(**input, m_Builder);
+ m_ArchiveReader.readArchive(m_Config, archive);
+ if (archive.numOfObjectMember() > 0) {
+ m_InputTree.merge<InputTree::Inclusive>(input, archive.inputs());
+ }
+ } else {
+ if (m_Config.options().warnMismatch())
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << m_Config.targets().triple().str();
+ }
+ }
+}
+
+} // namespace mcld
diff --git a/lib/Script/InputSectDesc.cpp b/lib/Script/InputSectDesc.cpp
index 842b720..e9ead82 100644
--- a/lib/Script/InputSectDesc.cpp
+++ b/lib/Script/InputSectDesc.cpp
@@ -6,14 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/InputSectDesc.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/InputSectDesc.h"
+
+#include "mcld/Script/WildcardPattern.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputSectDesc
@@ -21,23 +23,20 @@
InputSectDesc::InputSectDesc(KeepPolicy pPolicy,
const Spec& pSpec,
const OutputSectDesc& pOutputDesc)
- : ScriptCommand(ScriptCommand::INPUT_SECT_DESC),
- m_KeepPolicy(pPolicy),
- m_Spec(pSpec),
- m_OutputSectDesc(pOutputDesc)
-{
+ : ScriptCommand(ScriptCommand::INPUT_SECT_DESC),
+ m_KeepPolicy(pPolicy),
+ m_Spec(pSpec),
+ m_OutputSectDesc(pOutputDesc) {
}
-InputSectDesc::~InputSectDesc()
-{
+InputSectDesc::~InputSectDesc() {
}
-void InputSectDesc::dump() const
-{
+void InputSectDesc::dump() const {
if (m_KeepPolicy == Keep)
mcld::outs() << "KEEP (";
- assert (m_Spec.hasFile());
+ assert(m_Spec.hasFile());
if (m_Spec.file().sortPolicy() == WildcardPattern::SORT_BY_NAME)
mcld::outs() << "SORT (";
@@ -49,7 +48,9 @@
if (m_Spec.hasExcludeFiles()) {
mcld::outs() << "EXCLUDE_FILE (";
for (StringList::const_iterator it = m_Spec.excludeFiles().begin(),
- ie = m_Spec.excludeFiles().end(); it != ie; ++it) {
+ ie = m_Spec.excludeFiles().end();
+ it != ie;
+ ++it) {
mcld::outs() << (*it)->name() << " ";
}
mcld::outs() << ")";
@@ -57,25 +58,27 @@
if (m_Spec.hasSections()) {
for (StringList::const_iterator it = m_Spec.sections().begin(),
- ie = m_Spec.sections().end(); it != ie; ++it) {
+ ie = m_Spec.sections().end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Wildcard);
WildcardPattern* wildcard = llvm::cast<WildcardPattern>(*it);
switch (wildcard->sortPolicy()) {
- case WildcardPattern::SORT_BY_NAME:
- mcld::outs() << "SORT (";
- break;
- case WildcardPattern::SORT_BY_ALIGNMENT:
- mcld::outs() << "SORT_BY_ALIGNMENT (";
- break;
- case WildcardPattern::SORT_BY_NAME_ALIGNMENT:
- mcld::outs() << "SORT_BY_NAME_ALIGNMENT (";
- break;
- case WildcardPattern::SORT_BY_ALIGNMENT_NAME:
- mcld::outs() << "SORT_BY_ALIGNMENT_NAME (";
- break;
- default:
- break;
+ case WildcardPattern::SORT_BY_NAME:
+ mcld::outs() << "SORT (";
+ break;
+ case WildcardPattern::SORT_BY_ALIGNMENT:
+ mcld::outs() << "SORT_BY_ALIGNMENT (";
+ break;
+ case WildcardPattern::SORT_BY_NAME_ALIGNMENT:
+ mcld::outs() << "SORT_BY_NAME_ALIGNMENT (";
+ break;
+ case WildcardPattern::SORT_BY_ALIGNMENT_NAME:
+ mcld::outs() << "SORT_BY_ALIGNMENT_NAME (";
+ break;
+ default:
+ break;
}
mcld::outs() << wildcard->name() << " ";
@@ -96,7 +99,8 @@
mcld::outs() << "\n";
}
-void InputSectDesc::activate(Module& pModule)
-{
+void InputSectDesc::activate(Module& pModule) {
pModule.getScript().sectionMap().insert(*this, m_OutputSectDesc);
}
+
+} // namespace mcld
diff --git a/lib/Script/InputToken.cpp b/lib/Script/InputToken.cpp
index 45b006a..35c38e2 100644
--- a/lib/Script/InputToken.cpp
+++ b/lib/Script/InputToken.cpp
@@ -6,23 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/InputToken.h>
+#include "mcld/Script/InputToken.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputToken
//===----------------------------------------------------------------------===//
-InputToken::InputToken()
- : m_Type(Unknown), m_bAsNeeded(false)
-{
+InputToken::InputToken() : m_Type(Unknown), m_bAsNeeded(false) {
}
InputToken::InputToken(Type pType, const std::string& pName, bool pAsNeeded)
- : StrToken(StrToken::Input, pName), m_Type(pType), m_bAsNeeded(pAsNeeded)
-{
+ : StrToken(StrToken::Input, pName), m_Type(pType), m_bAsNeeded(pAsNeeded) {
}
-InputToken::~InputToken()
-{
+InputToken::~InputToken() {
}
+
+} // namespace mcld
diff --git a/lib/Script/NameSpec.cpp b/lib/Script/NameSpec.cpp
index da7a62c..0d0a178 100644
--- a/lib/Script/NameSpec.cpp
+++ b/lib/Script/NameSpec.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/NameSpec.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/NameSpec.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<NameSpec, MCLD_SYMBOLS_PER_INPUT> NameSpecFactory;
static llvm::ManagedStatic<NameSpecFactory> g_NameSpecFactory;
@@ -18,34 +20,30 @@
//===----------------------------------------------------------------------===//
// NameSpec
//===----------------------------------------------------------------------===//
-NameSpec::NameSpec()
-{
+NameSpec::NameSpec() {
}
NameSpec::NameSpec(const std::string& pName, bool pAsNeeded)
- : InputToken(InputToken::NameSpec, pName, pAsNeeded)
-{
+ : InputToken(InputToken::NameSpec, pName, pAsNeeded) {
}
-NameSpec::~NameSpec()
-{
+NameSpec::~NameSpec() {
}
-NameSpec* NameSpec::create(const std::string& pName, bool pAsNeeded)
-{
+NameSpec* NameSpec::create(const std::string& pName, bool pAsNeeded) {
NameSpec* result = g_NameSpecFactory->allocate();
new (result) NameSpec(pName, pAsNeeded);
return result;
}
-void NameSpec::destroy(NameSpec*& pNameSpec)
-{
+void NameSpec::destroy(NameSpec*& pNameSpec) {
g_NameSpecFactory->destroy(pNameSpec);
g_NameSpecFactory->deallocate(pNameSpec);
pNameSpec = NULL;
}
-void NameSpec::clear()
-{
+void NameSpec::clear() {
g_NameSpecFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/NullaryOp.cpp b/lib/Script/NullaryOp.cpp
index 69382ec..7272e22 100644
--- a/lib/Script/NullaryOp.cpp
+++ b/lib/Script/NullaryOp.cpp
@@ -6,40 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/NullaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/Script/NullaryOp.h"
-using namespace mcld;
+#include "mcld/Script/Operand.h"
+#include "mcld/Target/TargetLDBackend.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// NullaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand*
-NullaryOp<Operator::SIZEOF_HEADERS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::SIZEOF_HEADERS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.sectionStartOffset());
return res;
}
-template<>
-IntOperand*
-NullaryOp<Operator::MAXPAGESIZE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::MAXPAGESIZE>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.abiPageSize());
return res;
}
-template<>
-IntOperand*
-NullaryOp<Operator::COMMONPAGESIZE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::COMMONPAGESIZE>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.commonPageSize());
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/Operand.cpp b/lib/Script/Operand.cpp
index 690ba9b..95781dc 100644
--- a/lib/Script/Operand.cpp
+++ b/lib/Script/Operand.cpp
@@ -6,26 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Operand.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Script/Operand.h"
+
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Operand
//===----------------------------------------------------------------------===//
-Operand::Operand(Type pType)
- : ExprToken(ExprToken::OPERAND), m_Type(pType)
-{
+Operand::Operand(Type pType) : ExprToken(ExprToken::OPERAND), m_Type(pType) {
}
-Operand::~Operand()
-{
+Operand::~Operand() {
}
//===----------------------------------------------------------------------===//
@@ -34,43 +33,35 @@
typedef GCFactory<SymOperand, MCLD_SYMBOLS_PER_INPUT> SymOperandFactory;
static llvm::ManagedStatic<SymOperandFactory> g_SymOperandFactory;
-SymOperand::SymOperand()
- : Operand(Operand::SYMBOL), m_Value(0)
-{
+SymOperand::SymOperand() : Operand(Operand::SYMBOL), m_Value(0) {
}
SymOperand::SymOperand(const std::string& pName)
- : Operand(Operand::SYMBOL), m_Name(pName), m_Value(0)
-{
+ : Operand(Operand::SYMBOL), m_Name(pName), m_Value(0) {
}
-void SymOperand::dump() const
-{
+void SymOperand::dump() const {
mcld::outs() << m_Name;
}
-bool SymOperand::isDot() const
-{
+bool SymOperand::isDot() const {
assert(!m_Name.empty());
return m_Name.size() == 1 && m_Name[0] == '.';
}
-SymOperand* SymOperand::create(const std::string& pName)
-{
+SymOperand* SymOperand::create(const std::string& pName) {
SymOperand* result = g_SymOperandFactory->allocate();
new (result) SymOperand(pName);
return result;
}
-void SymOperand::destroy(SymOperand*& pOperand)
-{
+void SymOperand::destroy(SymOperand*& pOperand) {
g_SymOperandFactory->destroy(pOperand);
g_SymOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SymOperand::clear()
-{
+void SymOperand::clear() {
g_SymOperandFactory->clear();
}
@@ -80,37 +71,30 @@
typedef GCFactory<IntOperand, MCLD_SYMBOLS_PER_INPUT> IntOperandFactory;
static llvm::ManagedStatic<IntOperandFactory> g_IntOperandFactory;
-IntOperand::IntOperand()
- : Operand(Operand::INTEGER), m_Value(0)
-{
+IntOperand::IntOperand() : Operand(Operand::INTEGER), m_Value(0) {
}
IntOperand::IntOperand(uint64_t pValue)
- : Operand(Operand::INTEGER), m_Value(pValue)
-{
+ : Operand(Operand::INTEGER), m_Value(pValue) {
}
-void IntOperand::dump() const
-{
+void IntOperand::dump() const {
mcld::outs() << m_Value;
}
-IntOperand* IntOperand::create(uint64_t pValue)
-{
+IntOperand* IntOperand::create(uint64_t pValue) {
IntOperand* result = g_IntOperandFactory->allocate();
new (result) IntOperand(pValue);
return result;
}
-void IntOperand::destroy(IntOperand*& pOperand)
-{
+void IntOperand::destroy(IntOperand*& pOperand) {
g_IntOperandFactory->destroy(pOperand);
g_IntOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void IntOperand::clear()
-{
+void IntOperand::clear() {
g_IntOperandFactory->clear();
}
@@ -119,78 +103,66 @@
//===----------------------------------------------------------------------===//
typedef GCFactory<SectOperand, MCLD_SECTIONS_PER_INPUT> SectOperandFactory;
static llvm::ManagedStatic<SectOperandFactory> g_SectOperandFactory;
-SectOperand::SectOperand()
- : Operand(Operand::SECTION)
-{
+SectOperand::SectOperand() : Operand(Operand::SECTION) {
}
SectOperand::SectOperand(const std::string& pName)
- : Operand(Operand::SECTION), m_Name(pName)
-{
+ : Operand(Operand::SECTION), m_Name(pName) {
}
-void SectOperand::dump() const
-{
+void SectOperand::dump() const {
mcld::outs() << m_Name;
}
-SectOperand* SectOperand::create(const std::string& pName)
-{
+SectOperand* SectOperand::create(const std::string& pName) {
SectOperand* result = g_SectOperandFactory->allocate();
new (result) SectOperand(pName);
return result;
}
-void SectOperand::destroy(SectOperand*& pOperand)
-{
+void SectOperand::destroy(SectOperand*& pOperand) {
g_SectOperandFactory->destroy(pOperand);
g_SectOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SectOperand::clear()
-{
+void SectOperand::clear() {
g_SectOperandFactory->clear();
}
//===----------------------------------------------------------------------===//
// SectDescOperand
//===----------------------------------------------------------------------===//
-typedef GCFactory<SectDescOperand,
- MCLD_SECTIONS_PER_INPUT> SectDescOperandFactory;
+typedef GCFactory<SectDescOperand, MCLD_SECTIONS_PER_INPUT>
+ SectDescOperandFactory;
static llvm::ManagedStatic<SectDescOperandFactory> g_SectDescOperandFactory;
SectDescOperand::SectDescOperand()
- : Operand(Operand::SECTION_DESC), m_pOutputDesc(NULL)
-{
+ : Operand(Operand::SECTION_DESC), m_pOutputDesc(NULL) {
}
SectDescOperand::SectDescOperand(const SectionMap::Output* pOutputDesc)
- : Operand(Operand::SECTION_DESC), m_pOutputDesc(pOutputDesc)
-{
+ : Operand(Operand::SECTION_DESC), m_pOutputDesc(pOutputDesc) {
}
-void SectDescOperand::dump() const
-{
+void SectDescOperand::dump() const {
assert(m_pOutputDesc != NULL);
mcld::outs() << m_pOutputDesc->getSection()->name();
}
-SectDescOperand* SectDescOperand::create(const SectionMap::Output* pOutputDesc)
-{
+SectDescOperand* SectDescOperand::create(
+ const SectionMap::Output* pOutputDesc) {
SectDescOperand* result = g_SectDescOperandFactory->allocate();
new (result) SectDescOperand(pOutputDesc);
return result;
}
-void SectDescOperand::destroy(SectDescOperand*& pOperand)
-{
+void SectDescOperand::destroy(SectDescOperand*& pOperand) {
g_SectDescOperandFactory->destroy(pOperand);
g_SectDescOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SectDescOperand::clear()
-{
+void SectDescOperand::clear() {
g_SectDescOperandFactory->clear();
}
@@ -200,42 +172,36 @@
typedef GCFactory<FragOperand, MCLD_SYMBOLS_PER_INPUT> FragOperandFactory;
static llvm::ManagedStatic<FragOperandFactory> g_FragOperandFactory;
-FragOperand::FragOperand()
- : Operand(Operand::FRAGMENT), m_pFragment(NULL)
-{
+FragOperand::FragOperand() : Operand(Operand::FRAGMENT), m_pFragment(NULL) {
}
FragOperand::FragOperand(Fragment& pFragment)
- : Operand(Operand::FRAGMENT), m_pFragment(&pFragment)
-{
+ : Operand(Operand::FRAGMENT), m_pFragment(&pFragment) {
}
-void FragOperand::dump() const
-{
+void FragOperand::dump() const {
mcld::outs() << "fragment";
}
-uint64_t FragOperand::value() const
-{
+uint64_t FragOperand::value() const {
return m_pFragment->getOffset() +
m_pFragment->getParent()->getSection().addr();
}
-FragOperand* FragOperand::create(Fragment& pFragment)
-{
+FragOperand* FragOperand::create(Fragment& pFragment) {
FragOperand* result = g_FragOperandFactory->allocate();
new (result) FragOperand(pFragment);
return result;
}
-void FragOperand::destroy(FragOperand*& pOperand)
-{
+void FragOperand::destroy(FragOperand*& pOperand) {
g_FragOperandFactory->destroy(pOperand);
g_FragOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void FragOperand::clear()
-{
+void FragOperand::clear() {
g_FragOperandFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/Operator.cpp b/lib/Script/Operator.cpp
index e50a255..21b4ff1 100644
--- a/lib/Script/Operator.cpp
+++ b/lib/Script/Operator.cpp
@@ -6,385 +6,306 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/NullaryOp.h>
-#include <mcld/Script/UnaryOp.h>
-#include <mcld/Script/BinaryOp.h>
-#include <mcld/Script/TernaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/Operator.h"
-using namespace mcld;
+#include "mcld/Script/BinaryOp.h"
+#include "mcld/Script/NullaryOp.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/UnaryOp.h"
+#include "mcld/Script/TernaryOp.h"
+#include "mcld/Support/raw_ostream.h"
+
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// Operator
//===----------------------------------------------------------------------===//
const char* Operator::OpNames[] = {
- "+",
- "-",
- "!",
- "~",
- "*",
- "/",
- "%",
- "+",
- "-",
- "<<",
- ">>",
- "<",
- "<=",
- ">",
- ">=",
- "==",
- "!=",
- "&",
- "^",
- "|",
- "&&",
- "||",
- "?:",
- "=",
- "+=",
- "-=",
- "*=",
- "/=",
- "&=",
- "|=",
- "<<=",
- ">>=",
- "ABSOLUTE",
- "ADDR",
- "ALIGN",
- "ALIGNOF",
- "BLOCK",
- "DATA_SEGMENT_ALIGN",
- "DATA_SEGMENT_END",
- "DATA_SEGMENT_RELRO_END",
- "DEFINED",
- "LENGTH",
- "LOADADDR",
- "MAX",
- "MIN",
- "NEXT",
- "ORIGIN",
- "SEGMENT_START",
- "SIZEOF",
- "SIZEOF_HEADERS",
- "MAXPAGESIZE",
- "COMMONPAGESIZE"
-};
+ "+", "-", "!",
+ "~", "*", "/",
+ "%", "+", "-",
+ "<<", ">>", "<",
+ "<=", ">", ">=",
+ "==", "!=", "&",
+ "^", "|", "&&",
+ "||", "?:", "=",
+ "+=", "-=", "*=",
+ "/=", "&=", "|=",
+ "<<=", ">>=", "ABSOLUTE",
+ "ADDR", "ALIGN", "ALIGNOF",
+ "BLOCK", "DATA_SEGMENT_ALIGN", "DATA_SEGMENT_END",
+ "DATA_SEGMENT_RELRO_END", "DEFINED", "LENGTH",
+ "LOADADDR", "MAX", "MIN",
+ "NEXT", "ORIGIN", "SEGMENT_START",
+ "SIZEOF", "SIZEOF_HEADERS", "MAXPAGESIZE",
+ "COMMONPAGESIZE"};
-Operator::Operator(Arity pArity,
- Type pType)
- : ExprToken(ExprToken::OPERATOR),
- m_Arity(pArity),
- m_Type(pType)
-{
+Operator::Operator(Arity pArity, Type pType)
+ : ExprToken(ExprToken::OPERATOR), m_Arity(pArity), m_Type(pType) {
m_pIntOperand = IntOperand::create(0);
}
-Operator::~Operator()
-{
+Operator::~Operator() {
}
-void Operator::dump() const
-{
+void Operator::dump() const {
mcld::outs() << OpNames[type()];
}
/* Nullary operator */
-template<>
-Operator& Operator::create<Operator::SIZEOF_HEADERS>()
-{
+template <>
+Operator& Operator::create<Operator::SIZEOF_HEADERS>() {
static NullaryOp<Operator::SIZEOF_HEADERS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MAXPAGESIZE>()
-{
+template <>
+Operator& Operator::create<Operator::MAXPAGESIZE>() {
static NullaryOp<Operator::MAXPAGESIZE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::COMMONPAGESIZE>()
-{
+template <>
+Operator& Operator::create<Operator::COMMONPAGESIZE>() {
static NullaryOp<Operator::COMMONPAGESIZE> op;
return op;
}
/* Unary operator */
-template<>
-Operator& Operator::create<Operator::UNARY_PLUS>()
-{
+template <>
+Operator& Operator::create<Operator::UNARY_PLUS>() {
static UnaryOp<Operator::UNARY_PLUS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::UNARY_MINUS>()
-{
+template <>
+Operator& Operator::create<Operator::UNARY_MINUS>() {
static UnaryOp<Operator::UNARY_MINUS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_NOT>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_NOT>() {
static UnaryOp<Operator::LOGICAL_NOT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_NOT>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_NOT>() {
static UnaryOp<Operator::BITWISE_NOT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ABSOLUTE>()
-{
+template <>
+Operator& Operator::create<Operator::ABSOLUTE>() {
static UnaryOp<Operator::ABSOLUTE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ADDR>()
-{
+template <>
+Operator& Operator::create<Operator::ADDR>() {
static UnaryOp<Operator::ADDR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ALIGNOF>()
-{
+template <>
+Operator& Operator::create<Operator::ALIGNOF>() {
static UnaryOp<Operator::ALIGNOF> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_END>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_END>() {
static UnaryOp<Operator::DATA_SEGMENT_END> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DEFINED>()
-{
+template <>
+Operator& Operator::create<Operator::DEFINED>() {
static UnaryOp<Operator::DEFINED> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LENGTH>()
-{
+template <>
+Operator& Operator::create<Operator::LENGTH>() {
static UnaryOp<Operator::LENGTH> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOADADDR>()
-{
+template <>
+Operator& Operator::create<Operator::LOADADDR>() {
static UnaryOp<Operator::LOADADDR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::NEXT>()
-{
+template <>
+Operator& Operator::create<Operator::NEXT>() {
static UnaryOp<Operator::NEXT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ORIGIN>()
-{
+template <>
+Operator& Operator::create<Operator::ORIGIN>() {
static UnaryOp<Operator::ORIGIN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SIZEOF>()
-{
+template <>
+Operator& Operator::create<Operator::SIZEOF>() {
static UnaryOp<Operator::SIZEOF> op;
return op;
}
/* Binary operator */
-template<>
-Operator& Operator::create<Operator::MUL>()
-{
+template <>
+Operator& Operator::create<Operator::MUL>() {
static BinaryOp<Operator::MUL> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DIV>()
-{
+template <>
+Operator& Operator::create<Operator::DIV>() {
static BinaryOp<Operator::DIV> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MOD>()
-{
+template <>
+Operator& Operator::create<Operator::MOD>() {
static BinaryOp<Operator::MOD> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ADD>()
-{
+template <>
+Operator& Operator::create<Operator::ADD>() {
static BinaryOp<Operator::ADD> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SUB>()
-{
+template <>
+Operator& Operator::create<Operator::SUB>() {
static BinaryOp<Operator::SUB> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LSHIFT>()
-{
+template <>
+Operator& Operator::create<Operator::LSHIFT>() {
static BinaryOp<Operator::LSHIFT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::RSHIFT>()
-{
+template <>
+Operator& Operator::create<Operator::RSHIFT>() {
static BinaryOp<Operator::RSHIFT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LT>()
-{
+template <>
+Operator& Operator::create<Operator::LT>() {
static BinaryOp<Operator::LT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LE>()
-{
+template <>
+Operator& Operator::create<Operator::LE>() {
static BinaryOp<Operator::LE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::GT>()
-{
+template <>
+Operator& Operator::create<Operator::GT>() {
static BinaryOp<Operator::GT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::GE>()
-{
+template <>
+Operator& Operator::create<Operator::GE>() {
static BinaryOp<Operator::GE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::EQ>()
-{
+template <>
+Operator& Operator::create<Operator::EQ>() {
static BinaryOp<Operator::EQ> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::NE>()
-{
+template <>
+Operator& Operator::create<Operator::NE>() {
static BinaryOp<Operator::NE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_AND>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_AND>() {
static BinaryOp<Operator::BITWISE_AND> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_XOR>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_XOR>() {
static BinaryOp<Operator::BITWISE_XOR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_OR>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_OR>() {
static BinaryOp<Operator::BITWISE_OR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_AND>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_AND>() {
static BinaryOp<Operator::LOGICAL_AND> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_OR>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_OR>() {
static BinaryOp<Operator::LOGICAL_OR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ALIGN>()
-{
+template <>
+Operator& Operator::create<Operator::ALIGN>() {
static BinaryOp<Operator::ALIGN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>() {
static BinaryOp<Operator::DATA_SEGMENT_RELRO_END> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MAX>()
-{
+template <>
+Operator& Operator::create<Operator::MAX>() {
static BinaryOp<Operator::MAX> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MIN>()
-{
+template <>
+Operator& Operator::create<Operator::MIN>() {
static BinaryOp<Operator::MIN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SEGMENT_START>()
-{
+template <>
+Operator& Operator::create<Operator::SEGMENT_START>() {
static BinaryOp<Operator::SEGMENT_START> op;
return op;
}
/* Ternary operator */
-template<>
-Operator& Operator::create<Operator::TERNARY_IF>()
-{
+template <>
+Operator& Operator::create<Operator::TERNARY_IF>() {
static TernaryOp<Operator::TERNARY_IF> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>() {
static TernaryOp<Operator::DATA_SEGMENT_ALIGN> op;
return op;
}
+
+} // namespace mcld
diff --git a/lib/Script/OutputArchCmd.cpp b/lib/Script/OutputArchCmd.cpp
index 4393b84..3bba021 100644
--- a/lib/Script/OutputArchCmd.cpp
+++ b/lib/Script/OutputArchCmd.cpp
@@ -6,31 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputArchCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/OutputArchCmd.h"
+#include "mcld/Support/raw_ostream.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputArchCmd
//===----------------------------------------------------------------------===//
OutputArchCmd::OutputArchCmd(const std::string& pArch)
- : ScriptCommand(ScriptCommand::OUTPUT_ARCH),
- m_Arch(pArch)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_ARCH), m_Arch(pArch) {
}
-OutputArchCmd::~OutputArchCmd()
-{
+OutputArchCmd::~OutputArchCmd() {
}
-void OutputArchCmd::dump() const
-{
+void OutputArchCmd::dump() const {
mcld::outs() << "OUTPUT_ARCH ( " << m_Arch << " )\n";
}
-void OutputArchCmd::activate(Module& pModule)
-{
+void OutputArchCmd::activate(Module& pModule) {
// TODO
}
+} // namespace mcld
diff --git a/lib/Script/OutputCmd.cpp b/lib/Script/OutputCmd.cpp
index c37adcc..c4e5aeb 100644
--- a/lib/Script/OutputCmd.cpp
+++ b/lib/Script/OutputCmd.cpp
@@ -6,36 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/OutputCmd.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputCmd
//===----------------------------------------------------------------------===//
OutputCmd::OutputCmd(const std::string& pOutputFile)
- : ScriptCommand(ScriptCommand::OUTPUT),
- m_OutputFile(pOutputFile)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT), m_OutputFile(pOutputFile) {
}
-OutputCmd::~OutputCmd()
-{
+OutputCmd::~OutputCmd() {
}
-void OutputCmd::dump() const
-{
+void OutputCmd::dump() const {
mcld::outs() << "OUTPUT ( " << m_OutputFile << " )\n";
}
-void OutputCmd::activate(Module& pModule)
-{
+void OutputCmd::activate(Module& pModule) {
pModule.getScript().setOutputFile(m_OutputFile);
// TODO: set the output name if there is no `-o filename' on the cmdline.
// This option is to define a default name for the output file other than the
// usual default of a.out.
}
+} // namespace mcld
diff --git a/lib/Script/OutputFormatCmd.cpp b/lib/Script/OutputFormatCmd.cpp
index eca9df5..b0c4fa5 100644
--- a/lib/Script/OutputFormatCmd.cpp
+++ b/lib/Script/OutputFormatCmd.cpp
@@ -6,36 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputFormatCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/OutputFormatCmd.h"
+#include "mcld/Support/raw_ostream.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputFormatCmd
//===----------------------------------------------------------------------===//
OutputFormatCmd::OutputFormatCmd(const std::string& pFormat)
- : ScriptCommand(ScriptCommand::OUTPUT_FORMAT)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_FORMAT) {
m_FormatList.push_back(pFormat);
}
OutputFormatCmd::OutputFormatCmd(const std::string& pDefault,
const std::string& pBig,
const std::string& pLittle)
- : ScriptCommand(ScriptCommand::OUTPUT_FORMAT)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_FORMAT) {
m_FormatList.push_back(pDefault);
m_FormatList.push_back(pBig);
m_FormatList.push_back(pLittle);
}
-OutputFormatCmd::~OutputFormatCmd()
-{
+OutputFormatCmd::~OutputFormatCmd() {
}
-void OutputFormatCmd::dump() const
-{
+void OutputFormatCmd::dump() const {
mcld::outs() << "OUTPUT_FORMAT ( ";
assert(m_FormatList.size() == 1 || m_FormatList.size() == 3);
for (size_t i = 0; i < m_FormatList.size(); ++i) {
@@ -46,8 +42,8 @@
mcld::outs() << " )\n";
}
-void OutputFormatCmd::activate(Module& pModule)
-{
+void OutputFormatCmd::activate(Module& pModule) {
// TODO
}
+} // namespace mcld
diff --git a/lib/Script/OutputSectDesc.cpp b/lib/Script/OutputSectDesc.cpp
index 3442c4e..df994ca 100644
--- a/lib/Script/OutputSectDesc.cpp
+++ b/lib/Script/OutputSectDesc.cpp
@@ -6,40 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/Script/InputSectDesc.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/OutputSectDesc.h"
+
+#include "mcld/Script/InputSectDesc.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/StrToken.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputSectDesc
//===----------------------------------------------------------------------===//
-OutputSectDesc::OutputSectDesc(const std::string& pName,
- const Prolog& pProlog)
- : ScriptCommand(ScriptCommand::OUTPUT_SECT_DESC),
- m_Name(pName),
- m_Prolog(pProlog)
-{
+OutputSectDesc::OutputSectDesc(const std::string& pName, const Prolog& pProlog)
+ : ScriptCommand(ScriptCommand::OUTPUT_SECT_DESC),
+ m_Name(pName),
+ m_Prolog(pProlog) {
}
-OutputSectDesc::~OutputSectDesc()
-{
+OutputSectDesc::~OutputSectDesc() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
}
-void OutputSectDesc::dump() const
-{
+void OutputSectDesc::dump() const {
mcld::outs() << m_Name << "\t";
if (m_Prolog.hasVMA()) {
@@ -48,23 +47,23 @@
}
switch (m_Prolog.type()) {
- case NOLOAD:
- mcld::outs() << "(NOLOAD)";
- break;
- case DSECT:
- mcld::outs() << "(DSECT)";
- break;
- case COPY:
- mcld::outs() << "(COPY)";
- break;
- case INFO:
- mcld::outs() << "(INFO)";
- break;
- case OVERLAY:
- mcld::outs() << "(OVERLAY)";
- break;
- default:
- break;
+ case NOLOAD:
+ mcld::outs() << "(NOLOAD)";
+ break;
+ case DSECT:
+ mcld::outs() << "(DSECT)";
+ break;
+ case COPY:
+ mcld::outs() << "(COPY)";
+ break;
+ case INFO:
+ mcld::outs() << "(INFO)";
+ break;
+ case OVERLAY:
+ mcld::outs() << "(OVERLAY)";
+ break;
+ default:
+ break;
}
mcld::outs() << ":\n";
@@ -87,27 +86,27 @@
}
switch (m_Prolog.constraint()) {
- case ONLY_IF_RO:
- mcld::outs() << "\tONLY_IF_RO\n";
- break;
- case ONLY_IF_RW:
- mcld::outs() << "\tONLY_IF_RW\n";
- break;
- default:
- break;
+ case ONLY_IF_RO:
+ mcld::outs() << "\tONLY_IF_RO\n";
+ break;
+ case ONLY_IF_RW:
+ mcld::outs() << "\tONLY_IF_RW\n";
+ break;
+ default:
+ break;
}
mcld::outs() << "\t{\n";
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::INPUT_SECT_DESC:
- mcld::outs() << "\t\t";
- (*it)->dump();
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::INPUT_SECT_DESC:
+ mcld::outs() << "\t\t";
+ (*it)->dump();
+ break;
+ default:
+ assert(0);
+ break;
}
}
mcld::outs() << "\t}";
@@ -119,7 +118,9 @@
if (m_Epilog.hasPhdrs()) {
for (StringList::const_iterator it = m_Epilog.phdrs().begin(),
- ie = m_Epilog.phdrs().end(); it != ie; ++it) {
+ ie = m_Epilog.phdrs().end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::String);
mcld::outs() << ":" << (*it)->name() << " ";
}
@@ -132,55 +133,54 @@
mcld::outs() << "\n";
}
-void OutputSectDesc::push_back(ScriptCommand* pCommand)
-{
+void OutputSectDesc::push_back(ScriptCommand* pCommand) {
switch (pCommand->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::INPUT_SECT_DESC:
- m_OutputSectCmds.push_back(pCommand);
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::INPUT_SECT_DESC:
+ m_OutputSectCmds.push_back(pCommand);
+ break;
+ default:
+ assert(0);
+ break;
}
}
-void OutputSectDesc::setEpilog(const Epilog& pEpilog)
-{
- m_Epilog.m_pRegion = pEpilog.m_pRegion;
+void OutputSectDesc::setEpilog(const Epilog& pEpilog) {
+ m_Epilog.m_pRegion = pEpilog.m_pRegion;
m_Epilog.m_pLMARegion = pEpilog.m_pLMARegion;
- m_Epilog.m_pPhdrs = pEpilog.m_pPhdrs;
- m_Epilog.m_pFillExp = pEpilog.m_pFillExp;
+ m_Epilog.m_pPhdrs = pEpilog.m_pPhdrs;
+ m_Epilog.m_pFillExp = pEpilog.m_pFillExp;
}
-void OutputSectDesc::activate(Module& pModule)
-{
+void OutputSectDesc::activate(Module& pModule) {
// Assignment in an output section
OutputSectCmds assignments;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- assignments.push_back(*it);
- break;
- case ScriptCommand::INPUT_SECT_DESC: {
- (*it)->activate(pModule);
+ case ScriptCommand::ASSIGNMENT:
+ assignments.push_back(*it);
+ break;
+ case ScriptCommand::INPUT_SECT_DESC: {
+ (*it)->activate(pModule);
- for (iterator assign = assignments.begin(), assignEnd = assignments.end();
- assign != assignEnd; ++assign) {
- (*assign)->activate(pModule);
+ for (iterator assign = assignments.begin(),
+ assignEnd = assignments.end();
+ assign != assignEnd;
+ ++assign) {
+ (*assign)->activate(pModule);
+ }
+ assignments.clear();
+ break;
}
- assignments.clear();
- break;
- }
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
}
if (!assignments.empty()) {
- InputSectDesc::Spec spec;;
+ InputSectDesc::Spec spec;
spec.m_pWildcardFile = NULL;
spec.m_pExcludeFiles = NULL;
spec.m_pWildcardSections = NULL;
@@ -188,9 +188,12 @@
pModule.getScript().sectionMap().insert(inputDesc, *this);
for (iterator assign = assignments.begin(), assignEnd = assignments.end();
- assign != assignEnd; ++assign) {
+ assign != assignEnd;
+ ++assign) {
(*assign)->activate(pModule);
}
assignments.clear();
}
}
+
+} // namespace mcld
diff --git a/lib/Script/RpnEvaluator.cpp b/lib/Script/RpnEvaluator.cpp
index 52cb79f..636a89a 100644
--- a/lib/Script/RpnEvaluator.cpp
+++ b/lib/Script/RpnEvaluator.cpp
@@ -6,103 +6,103 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Script/ExprToken.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Module.h>
+#include "mcld/Script/RpnEvaluator.h"
+
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Script/ExprToken.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
#include <llvm/Support/DataTypes.h>
+
#include <stack>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
RpnEvaluator::RpnEvaluator(const Module& pModule,
const TargetLDBackend& pBackend)
- : m_Module(pModule),
- m_Backend(pBackend)
-{
+ : m_Module(pModule), m_Backend(pBackend) {
}
-bool RpnEvaluator::eval(const RpnExpr& pExpr, uint64_t& pResult)
-{
+bool RpnEvaluator::eval(const RpnExpr& pExpr, uint64_t& pResult) {
std::stack<Operand*> operandStack;
for (RpnExpr::const_iterator it = pExpr.begin(), ie = pExpr.end(); it != ie;
- ++it) {
- switch((*it)->kind()) {
- case ExprToken::OPERATOR: {
- Operator* op = llvm::cast<Operator>(*it);
- switch (op->arity()) {
- case Operator::NULLARY: {
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::UNARY: {
- Operand* opd = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd);
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::BINARY: {
- Operand* opd2 = operandStack.top();
- operandStack.pop();
- Operand* opd1 = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd1);
- op->appendOperand(opd2);
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::TERNARY: {
- Operand* opd3 = operandStack.top();
- operandStack.pop();
- Operand* opd2 = operandStack.top();
- operandStack.pop();
- Operand* opd1 = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd1);
- op->appendOperand(opd2);
- op->appendOperand(opd3);
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- } // end of switch operator arity
- break;
- }
-
- case ExprToken::OPERAND: {
- Operand* opd = llvm::cast<Operand>(*it);
- switch (opd->type()) {
- case Operand::SYMBOL: {
- // It's possible that there are no operators in an expression, so
- // we set up symbol operand here.
- if (!opd->isDot()) {
- SymOperand* sym_opd = llvm::cast<SymOperand>(opd);
- const LDSymbol* symbol =
- m_Module.getNamePool().findSymbol(sym_opd->name());
- if (symbol == NULL) {
- fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
- << "mclinker@googlegroups.com";
+ ++it) {
+ switch ((*it)->kind()) {
+ case ExprToken::OPERATOR: {
+ Operator* op = llvm::cast<Operator>(*it);
+ switch (op->arity()) {
+ case Operator::NULLARY: {
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
}
- sym_opd->setValue(symbol->value());
- }
- operandStack.push(opd);
+ case Operator::UNARY: {
+ Operand* opd = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ case Operator::BINARY: {
+ Operand* opd2 = operandStack.top();
+ operandStack.pop();
+ Operand* opd1 = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd1);
+ op->appendOperand(opd2);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ case Operator::TERNARY: {
+ Operand* opd3 = operandStack.top();
+ operandStack.pop();
+ Operand* opd2 = operandStack.top();
+ operandStack.pop();
+ Operand* opd1 = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd1);
+ op->appendOperand(opd2);
+ op->appendOperand(opd3);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ } // end of switch operator arity
break;
}
- default:
- operandStack.push(opd);
- break;
- } // end of switch operand type
- break;
- }
- } // end of switch
- } // end of for
+ case ExprToken::OPERAND: {
+ Operand* opd = llvm::cast<Operand>(*it);
+ switch (opd->type()) {
+ case Operand::SYMBOL: {
+ // It's possible that there are no operators in an expression, so
+ // we set up symbol operand here.
+ if (!opd->isDot()) {
+ SymOperand* sym_opd = llvm::cast<SymOperand>(opd);
+ const LDSymbol* symbol =
+ m_Module.getNamePool().findSymbol(sym_opd->name());
+ if (symbol == NULL) {
+ fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
+ << "mclinker@googlegroups.com";
+ }
+ sym_opd->setValue(symbol->value());
+ }
+ operandStack.push(opd);
+ break;
+ }
+ default:
+ operandStack.push(opd);
+ break;
+ } // end of switch operand type
+ break;
+ }
+ } // end of switch
+ } // end of for
// stack top is result
assert(operandStack.top()->type() == Operand::SYMBOL ||
@@ -112,3 +112,4 @@
return true;
}
+} // namespace mcld
diff --git a/lib/Script/RpnExpr.cpp b/lib/Script/RpnExpr.cpp
index a9a4cae..51699e5 100644
--- a/lib/Script/RpnExpr.cpp
+++ b/lib/Script/RpnExpr.cpp
@@ -6,16 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/ExprToken.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/RpnExpr.h"
+
+#include "mcld/Script/ExprToken.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<RpnExpr, MCLD_SYMBOLS_PER_INPUT> ExprFactory;
static llvm::ManagedStatic<ExprFactory> g_ExprFactory;
@@ -23,16 +25,13 @@
//===----------------------------------------------------------------------===//
// RpnExpr
//===----------------------------------------------------------------------===//
-RpnExpr::RpnExpr()
-{
+RpnExpr::RpnExpr() {
}
-RpnExpr::~RpnExpr()
-{
+RpnExpr::~RpnExpr() {
}
-bool RpnExpr::hasDot() const
-{
+bool RpnExpr::hasDot() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
if ((*it)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*it)->isDot())
@@ -41,52 +40,44 @@
return false;
}
-void RpnExpr::dump() const
-{
+void RpnExpr::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
(*it)->dump();
mcld::outs() << " ";
}
}
-void RpnExpr::push_back(ExprToken* pToken)
-{
+void RpnExpr::push_back(ExprToken* pToken) {
m_TokenQueue.push_back(pToken);
}
-RpnExpr* RpnExpr::create()
-{
+RpnExpr* RpnExpr::create() {
RpnExpr* result = g_ExprFactory->allocate();
new (result) RpnExpr();
return result;
}
-void RpnExpr::destroy(RpnExpr*& pRpnExpr)
-{
+void RpnExpr::destroy(RpnExpr*& pRpnExpr) {
g_ExprFactory->destroy(pRpnExpr);
g_ExprFactory->deallocate(pRpnExpr);
pRpnExpr = NULL;
}
-void RpnExpr::clear()
-{
+void RpnExpr::clear() {
g_ExprFactory->clear();
}
-RpnExpr::iterator RpnExpr::insert(iterator pPosition, ExprToken* pToken)
-{
+RpnExpr::iterator RpnExpr::insert(iterator pPosition, ExprToken* pToken) {
return m_TokenQueue.insert(pPosition, pToken);
}
-void RpnExpr::erase(iterator pPosition)
-{
+void RpnExpr::erase(iterator pPosition) {
m_TokenQueue.erase(pPosition);
}
// buildHelperExpr - build the helper expr:
// ADDR ( `output_sect' ) + SIZEOF ( `output_sect' )
-RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter)
-{
+RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter) {
RpnExpr* expr = RpnExpr::create();
expr->push_back(SectDescOperand::create(*pIter));
expr->push_back(&Operator::create<Operator::ADDR>());
@@ -97,9 +88,10 @@
}
// buildHelperExpr - build the helper expr: `fragment'
-RpnExpr* RpnExpr::buildHelperExpr(Fragment& pFrag)
-{
+RpnExpr* RpnExpr::buildHelperExpr(Fragment& pFrag) {
RpnExpr* expr = RpnExpr::create();
expr->push_back(FragOperand::create(pFrag));
return expr;
}
+
+} // namespace mcld
diff --git a/lib/Script/ScriptCommand.cpp b/lib/Script/ScriptCommand.cpp
index e360645..a2d39af 100644
--- a/lib/Script/ScriptCommand.cpp
+++ b/lib/Script/ScriptCommand.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptCommand.h>
+#include "mcld/Script/ScriptCommand.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ScriptCommand
//===----------------------------------------------------------------------===//
-ScriptCommand::~ScriptCommand()
-{
+ScriptCommand::~ScriptCommand() {
}
+} // namespace mcld
diff --git a/lib/Script/ScriptFile.cpp b/lib/Script/ScriptFile.cpp
index 00a8056..7738866 100644
--- a/lib/Script/ScriptFile.cpp
+++ b/lib/Script/ScriptFile.cpp
@@ -6,36 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/ScriptCommand.h>
-#include <mcld/Script/EntryCmd.h>
-#include <mcld/Script/OutputFormatCmd.h>
-#include <mcld/Script/GroupCmd.h>
-#include <mcld/Script/OutputCmd.h>
-#include <mcld/Script/SearchDirCmd.h>
-#include <mcld/Script/OutputArchCmd.h>
-#include <mcld/Script/AssertCmd.h>
-#include <mcld/Script/SectionsCmd.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/InputTree.h>
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
+#include "mcld/Script/ScriptFile.h"
+
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/Script/AssertCmd.h"
+#include "mcld/Script/EntryCmd.h"
+#include "mcld/Script/GroupCmd.h"
+#include "mcld/Script/InputCmd.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/OutputArchCmd.h"
+#include "mcld/Script/OutputCmd.h"
+#include "mcld/Script/OutputFormatCmd.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/ScriptCommand.h"
+#include "mcld/Script/SearchDirCmd.h"
+#include "mcld/Script/SectionsCmd.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/StrToken.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/InputTree.h"
+
#include <llvm/Support/Casting.h>
#include <llvm/Support/ManagedStatic.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
-typedef HashEntry<std::string,
- void*,
- hash::StringCompare<std::string> > ParserStrEntry;
+typedef HashEntry<std::string, void*, hash::StringCompare<std::string> >
+ ParserStrEntry;
typedef HashTable<ParserStrEntry,
hash::StringHash<hash::DJB>,
EntryFactory<ParserStrEntry> > ParserStrPool;
@@ -45,46 +48,41 @@
// ScriptFile
//===----------------------------------------------------------------------===//
ScriptFile::ScriptFile(Kind pKind, Input& pInput, InputBuilder& pBuilder)
- : m_Kind(pKind),
- m_Input(pInput),
- m_Name(pInput.path().native()),
- m_pInputTree(NULL),
- m_Builder(pBuilder),
- m_bHasSectionsCmd(false),
- m_bInSectionsCmd(false),
- m_bInOutputSectDesc(false),
- m_pRpnExpr(NULL),
- m_pStringList(NULL),
- m_bAsNeeded(false)
-{
+ : m_Kind(pKind),
+ m_Input(pInput),
+ m_Name(pInput.path().native()),
+ m_pInputTree(NULL),
+ m_Builder(pBuilder),
+ m_bHasSectionsCmd(false),
+ m_bInSectionsCmd(false),
+ m_bInOutputSectDesc(false),
+ m_pRpnExpr(NULL),
+ m_pStringList(NULL),
+ m_bAsNeeded(false) {
// FIXME: move creation of input tree out of ScriptFile.
m_pInputTree = new InputTree();
}
-ScriptFile::~ScriptFile()
-{
+ScriptFile::~ScriptFile() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
- if (NULL != m_pInputTree)
+ if (m_pInputTree != NULL)
delete m_pInputTree;
}
-void ScriptFile::dump() const
-{
+void ScriptFile::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
(*it)->dump();
}
-void ScriptFile::activate(Module& pModule)
-{
+void ScriptFile::activate(Module& pModule) {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
(*it)->activate(pModule);
}
-void ScriptFile::addEntryPoint(const std::string& pSymbol)
-{
+void ScriptFile::addEntryPoint(const std::string& pSymbol) {
EntryCmd* entry = new EntryCmd(pSymbol);
if (m_bInSectionsCmd) {
@@ -96,57 +94,63 @@
}
}
-void ScriptFile::addOutputFormatCmd(const std::string& pName)
-{
+void ScriptFile::addOutputFormatCmd(const std::string& pName) {
m_CommandQueue.push_back(new OutputFormatCmd(pName));
}
void ScriptFile::addOutputFormatCmd(const std::string& pDefault,
const std::string& pBig,
- const std::string& pLittle)
-{
+ const std::string& pLittle) {
m_CommandQueue.push_back(new OutputFormatCmd(pDefault, pBig, pLittle));
}
+void ScriptFile::addInputCmd(StringList& pStringList,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig) {
+ m_CommandQueue.push_back(new InputCmd(pStringList,
+ *m_pInputTree,
+ m_Builder,
+ pObjectReader,
+ pArchiveReader,
+ pDynObjReader,
+ pConfig));
+}
+
void ScriptFile::addGroupCmd(StringList& pStringList,
GroupReader& pGroupReader,
- const LinkerConfig& pConfig)
-{
- m_CommandQueue.push_back(
- new GroupCmd(pStringList, *m_pInputTree, m_Builder, pGroupReader, pConfig));
+ const LinkerConfig& pConfig) {
+ m_CommandQueue.push_back(new GroupCmd(
+ pStringList, *m_pInputTree, m_Builder, pGroupReader, pConfig));
}
-void ScriptFile::addOutputCmd(const std::string& pFileName)
-{
+void ScriptFile::addOutputCmd(const std::string& pFileName) {
m_CommandQueue.push_back(new OutputCmd(pFileName));
}
-void ScriptFile::addSearchDirCmd(const std::string& pPath)
-{
+void ScriptFile::addSearchDirCmd(const std::string& pPath) {
m_CommandQueue.push_back(new SearchDirCmd(pPath));
}
-void ScriptFile::addOutputArchCmd(const std::string& pArch)
-{
+void ScriptFile::addOutputArchCmd(const std::string& pArch) {
m_CommandQueue.push_back(new OutputArchCmd(pArch));
}
-void ScriptFile::addAssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage)
-{
+void ScriptFile::addAssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage) {
m_CommandQueue.push_back(new AssertCmd(pRpnExpr, pMessage));
}
void ScriptFile::addAssignment(const std::string& pSymbolName,
RpnExpr& pRpnExpr,
- Assignment::Type pType)
-{
+ Assignment::Type pType) {
if (m_bInSectionsCmd) {
assert(!m_CommandQueue.empty());
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
if (m_bInOutputSectDesc) {
assert(!sections->empty());
OutputSectDesc* output_desc =
- llvm::cast<OutputSectDesc>(sections->back());
+ llvm::cast<OutputSectDesc>(sections->back());
output_desc->push_back(new Assignment(Assignment::INPUT_SECTION,
pType,
*(SymOperand::create(pSymbolName)),
@@ -165,26 +169,22 @@
}
}
-bool ScriptFile::hasSectionsCmd() const
-{
+bool ScriptFile::hasSectionsCmd() const {
return m_bHasSectionsCmd;
}
-void ScriptFile::enterSectionsCmd()
-{
+void ScriptFile::enterSectionsCmd() {
m_bHasSectionsCmd = true;
m_bInSectionsCmd = true;
m_CommandQueue.push_back(new SectionsCmd());
}
-void ScriptFile::leaveSectionsCmd()
-{
+void ScriptFile::leaveSectionsCmd() {
m_bInSectionsCmd = false;
}
void ScriptFile::enterOutputSectDesc(const std::string& pName,
- const OutputSectDesc::Prolog& pProlog)
-{
+ const OutputSectDesc::Prolog& pProlog) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -193,8 +193,7 @@
m_bInOutputSectDesc = true;
}
-void ScriptFile::leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog)
-{
+void ScriptFile::leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -207,8 +206,7 @@
}
void ScriptFile::addInputSectDesc(InputSectDesc::KeepPolicy pPolicy,
- const InputSectDesc::Spec& pSpec)
-{
+ const InputSectDesc::Spec& pSpec) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -219,34 +217,30 @@
output_sect->push_back(new InputSectDesc(pPolicy, pSpec, *output_sect));
}
-RpnExpr* ScriptFile::createRpnExpr()
-{
+RpnExpr* ScriptFile::createRpnExpr() {
m_pRpnExpr = RpnExpr::create();
return m_pRpnExpr;
}
-StringList* ScriptFile::createStringList()
-{
+StringList* ScriptFile::createStringList() {
m_pStringList = StringList::create();
return m_pStringList;
}
-void ScriptFile::setAsNeeded(bool pEnable)
-{
+void ScriptFile::setAsNeeded(bool pEnable) {
m_bAsNeeded = pEnable;
}
const std::string& ScriptFile::createParserStr(const char* pText,
- size_t pLength)
-{
+ size_t pLength) {
bool exist = false;
ParserStrEntry* entry =
- g_ParserStrPool->insert(std::string(pText, pLength), exist);
+ g_ParserStrPool->insert(std::string(pText, pLength), exist);
return entry->key();
}
-void ScriptFile::clearParserStrPool()
-{
+void ScriptFile::clearParserStrPool() {
g_ParserStrPool->clear();
}
+} // namespace mcld
diff --git a/lib/Script/ScriptParser.yy b/lib/Script/ScriptParser.yy
index 745a4ef..0e32a44 100644
--- a/lib/Script/ScriptParser.yy
+++ b/lib/Script/ScriptParser.yy
@@ -9,16 +9,16 @@
%{
/* C/C++ Declarations */
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/FileToken.h>
-#include <mcld/Script/NameSpec.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Script/ScriptReader.h"
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/FileToken.h"
+#include "mcld/Script/NameSpec.h"
+#include "mcld/Script/WildcardPattern.h"
+#include "mcld/Support/MsgHandling.h"
using namespace mcld;
#undef yylex
@@ -26,10 +26,10 @@
%}
%code requires {
-#include <mcld/Script/StrToken.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/InputSectDesc.h>
+#include "mcld/Script/StrToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/OutputSectDesc.h"
+#include "mcld/Script/InputSectDesc.h"
#include <llvm/Support/DataTypes.h>
using namespace mcld;
@@ -50,6 +50,9 @@
%parse-param { const class LinkerConfig& m_LDConfig }
%parse-param { class ScriptFile& m_ScriptFile }
%parse-param { class ScriptScanner& m_ScriptScanner }
+%parse-param { class ObjectReader& m_ObjectReader}
+%parse-param { class ArchiveReader& m_ArchiveReader}
+%parse-param { class DynObjReader& m_DynObjReader}
%parse-param { class GroupReader& m_GroupReader}
%lex-param { const class ScriptFile& m_ScriptFile }
@@ -215,6 +218,7 @@
script_command : entry_command
| output_format_command
| group_command
+ | input_command
| output_command
| search_dir_command
| output_arch_command
@@ -238,6 +242,13 @@
{ m_ScriptFile.addGroupCmd(*$3, m_GroupReader, m_LDConfig); }
;
+input_command : INPUT '(' input_list ')'
+ {
+ m_ScriptFile.addInputCmd(*$3, m_ObjectReader, m_ArchiveReader,
+ m_DynObjReader, m_LDConfig);
+ }
+ ;
+
search_dir_command : SEARCH_DIR '(' STRING ')'
{ m_ScriptFile.addSearchDirCmd(*$3); }
;
diff --git a/lib/Script/ScriptReader.cpp b/lib/Script/ScriptReader.cpp
index 37c3ce9..00a766f 100644
--- a/lib/Script/ScriptReader.cpp
+++ b/lib/Script/ScriptReader.cpp
@@ -6,40 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/Script/ScriptReader.h"
+
+#include "mcld/MC/Input.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/ADT/StringRef.h>
#include <istream>
#include <sstream>
-using namespace mcld;
+namespace mcld {
-ScriptReader::ScriptReader(GroupReader& pGroupReader)
- : m_GroupReader(pGroupReader)
-{
+ScriptReader::ScriptReader(ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ GroupReader& pGroupReader)
+ : m_ObjectReader(pObjectReader),
+ m_ArchiveReader(pArchiveReader),
+ m_DynObjReader(pDynObjReader),
+ m_GroupReader(pGroupReader) {
}
-ScriptReader::~ScriptReader()
-{
+ScriptReader::~ScriptReader() {
}
/// isMyFormat
-bool ScriptReader::isMyFormat(Input& input, bool &doContinue) const
-{
+bool ScriptReader::isMyFormat(Input& input, bool& doContinue) const {
doContinue = true;
// always return true now
return true;
}
bool ScriptReader::readScript(const LinkerConfig& pConfig,
- ScriptFile& pScriptFile)
-{
- bool result = false;
+ ScriptFile& pScriptFile) {
Input& input = pScriptFile.input();
size_t size = input.memArea()->size();
llvm::StringRef region = input.memArea()->request(input.fileOffset(), size);
@@ -50,9 +52,11 @@
ScriptParser parser(pConfig,
pScriptFile,
scanner,
+ m_ObjectReader,
+ m_ArchiveReader,
+ m_DynObjReader,
m_GroupReader);
- result = (0 == parser.parse());;
-
- return result;
+ return parser.parse() == 0;
}
+} // namespace mcld
diff --git a/lib/Script/ScriptScanner.ll b/lib/Script/ScriptScanner.ll
index f3fd921..c1c3f74 100644
--- a/lib/Script/ScriptScanner.ll
+++ b/lib/Script/ScriptScanner.ll
@@ -10,9 +10,9 @@
%{
/* C/C++ Declarations */
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/ADT/StringRef.h>
#include <string>
@@ -375,7 +375,7 @@
}
}
-} /* namespace of mcld */
+} /* namespace mcld */
#ifdef yylex
#undef yylex
diff --git a/lib/Script/SearchDirCmd.cpp b/lib/Script/SearchDirCmd.cpp
index dd9a56f..53ec2dd 100644
--- a/lib/Script/SearchDirCmd.cpp
+++ b/lib/Script/SearchDirCmd.cpp
@@ -6,33 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/SearchDirCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/SearchDirCmd.h"
-using namespace mcld;
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// SearchDirCmd
//===----------------------------------------------------------------------===//
SearchDirCmd::SearchDirCmd(const std::string& pPath)
- : ScriptCommand(ScriptCommand::SEARCH_DIR),
- m_Path(pPath)
-{
+ : ScriptCommand(ScriptCommand::SEARCH_DIR), m_Path(pPath) {
}
-SearchDirCmd::~SearchDirCmd()
-{
+SearchDirCmd::~SearchDirCmd() {
}
-void SearchDirCmd::dump() const
-{
+void SearchDirCmd::dump() const {
mcld::outs() << "SEARCH_DIR ( " << m_Path << " )\n";
}
-void SearchDirCmd::activate(Module& pModule)
-{
+void SearchDirCmd::activate(Module& pModule) {
pModule.getScript().directories().insert(m_Path);
}
+} // namespace mcld
diff --git a/lib/Script/SectionsCmd.cpp b/lib/Script/SectionsCmd.cpp
index 4ecc838..7978da4 100644
--- a/lib/Script/SectionsCmd.cpp
+++ b/lib/Script/SectionsCmd.cpp
@@ -6,89 +6,87 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/SectionsCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/SectionsCmd.h"
+
+#include "mcld/Support/raw_ostream.h"
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// SectionsCmd
//===----------------------------------------------------------------------===//
-SectionsCmd::SectionsCmd()
- : ScriptCommand(ScriptCommand::SECTIONS)
-{
+SectionsCmd::SectionsCmd() : ScriptCommand(ScriptCommand::SECTIONS) {
}
-SectionsCmd::~SectionsCmd()
-{
+SectionsCmd::~SectionsCmd() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
}
-void SectionsCmd::dump() const
-{
+void SectionsCmd::dump() const {
mcld::outs() << "SECTIONS\n{\n";
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ENTRY:
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::OUTPUT_SECT_DESC:
- mcld::outs() << "\t";
- (*it)->dump();
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ENTRY:
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::OUTPUT_SECT_DESC:
+ mcld::outs() << "\t";
+ (*it)->dump();
+ break;
+ default:
+ assert(0);
+ break;
}
}
mcld::outs() << "}\n";
}
-void SectionsCmd::push_back(ScriptCommand* pCommand)
-{
+void SectionsCmd::push_back(ScriptCommand* pCommand) {
switch (pCommand->getKind()) {
- case ScriptCommand::ENTRY:
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::OUTPUT_SECT_DESC:
- m_SectionCommands.push_back(pCommand);
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ENTRY:
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::OUTPUT_SECT_DESC:
+ m_SectionCommands.push_back(pCommand);
+ break;
+ default:
+ assert(0);
+ break;
}
}
-void SectionsCmd::activate(Module& pModule)
-{
+void SectionsCmd::activate(Module& pModule) {
// Assignment between output sections
SectionCommands assignments;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ENTRY:
- (*it)->activate(pModule);
- break;
- case ScriptCommand::ASSIGNMENT:
- assignments.push_back(*it);
- break;
- case ScriptCommand::OUTPUT_SECT_DESC: {
- (*it)->activate(pModule);
+ case ScriptCommand::ENTRY:
+ (*it)->activate(pModule);
+ break;
+ case ScriptCommand::ASSIGNMENT:
+ assignments.push_back(*it);
+ break;
+ case ScriptCommand::OUTPUT_SECT_DESC: {
+ (*it)->activate(pModule);
- iterator assign, assignEnd = assignments.end();
- for (assign = assignments.begin(); assign != assignEnd; ++assign)
- (*assign)->activate(pModule);
- assignments.clear();
+ iterator assign, assignEnd = assignments.end();
+ for (assign = assignments.begin(); assign != assignEnd; ++assign)
+ (*assign)->activate(pModule);
+ assignments.clear();
- break;
- }
- default:
- assert(0);
- break;
+ break;
+ }
+ default:
+ assert(0);
+ break;
}
}
}
+
+} // namespace mcld
diff --git a/lib/Script/StrToken.cpp b/lib/Script/StrToken.cpp
index f886623..abcb78d 100644
--- a/lib/Script/StrToken.cpp
+++ b/lib/Script/StrToken.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/StrToken.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/StrToken.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<StrToken, MCLD_SYMBOLS_PER_INPUT> StrTokenFactory;
static llvm::ManagedStatic<StrTokenFactory> g_StrTokenFactory;
@@ -18,35 +20,30 @@
//===----------------------------------------------------------------------===//
// StrToken
//===----------------------------------------------------------------------===//
-StrToken::StrToken()
- : m_Kind(Unknown)
-{
+StrToken::StrToken() : m_Kind(Unknown) {
}
StrToken::StrToken(Kind pKind, const std::string& pString)
- : m_Kind(pKind), m_Name(pString)
-{
+ : m_Kind(pKind), m_Name(pString) {
}
-StrToken::~StrToken()
-{
+StrToken::~StrToken() {
}
-StrToken* StrToken::create(const std::string& pString)
-{
+StrToken* StrToken::create(const std::string& pString) {
StrToken* result = g_StrTokenFactory->allocate();
new (result) StrToken(String, pString);
return result;
}
-void StrToken::destroy(StrToken*& pStrToken)
-{
+void StrToken::destroy(StrToken*& pStrToken) {
g_StrTokenFactory->destroy(pStrToken);
g_StrTokenFactory->deallocate(pStrToken);
pStrToken = NULL;
}
-void StrToken::clear()
-{
+void StrToken::clear() {
g_StrTokenFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/StringList.cpp b/lib/Script/StringList.cpp
index e5637fb..f52b68b 100644
--- a/lib/Script/StringList.cpp
+++ b/lib/Script/StringList.cpp
@@ -6,13 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/StringList.h"
+
+#include "mcld/Script/StrToken.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<StringList, MCLD_SYMBOLS_PER_INPUT> StringListFactory;
static llvm::ManagedStatic<StringListFactory> g_StringListFactory;
@@ -20,41 +22,36 @@
//===----------------------------------------------------------------------===//
// StringList
//===----------------------------------------------------------------------===//
-StringList::StringList()
-{
+StringList::StringList() {
}
-StringList::~StringList()
-{
+StringList::~StringList() {
}
-void StringList::push_back(StrToken* pToken)
-{
+void StringList::push_back(StrToken* pToken) {
m_Tokens.push_back(pToken);
}
-void StringList::dump() const
-{
+void StringList::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
mcld::outs() << (*it)->name() << "\t";
mcld::outs() << "\n";
}
-StringList* StringList::create()
-{
+StringList* StringList::create() {
StringList* result = g_StringListFactory->allocate();
new (result) StringList();
return result;
}
-void StringList::destroy(StringList*& pStringList)
-{
+void StringList::destroy(StringList*& pStringList) {
g_StringListFactory->destroy(pStringList);
g_StringListFactory->deallocate(pStringList);
pStringList = NULL;
}
-void StringList::clear()
-{
+void StringList::clear() {
g_StringListFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/TernaryOp.cpp b/lib/Script/TernaryOp.cpp
index 131f460..12b889e 100644
--- a/lib/Script/TernaryOp.cpp
+++ b/lib/Script/TernaryOp.cpp
@@ -6,19 +6,20 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/TernaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/ADT/SizeTraits.h>
+#include "mcld/Script/TernaryOp.h"
-using namespace mcld;
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Script/Operand.h"
+
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// TernaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand*
-TernaryOp<Operator::TERNARY_IF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value())
res->setValue(m_pOperand[1]->value());
@@ -28,11 +29,10 @@
}
/* DATA_SEGMENT_ALIGN(maxpagesize, commonpagesize) */
-template<>
-IntOperand*
-TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
/* This is equivalent to either
(ALIGN(maxpagesize) + (. & (maxpagesize - 1)))
or
@@ -56,3 +56,4 @@
return res;
}
+} // namespace mcld
diff --git a/lib/Script/UnaryOp.cpp b/lib/Script/UnaryOp.cpp
index 866bbb2..d18333d 100644
--- a/lib/Script/UnaryOp.cpp
+++ b/lib/Script/UnaryOp.cpp
@@ -6,183 +6,179 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/UnaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Module.h>
+#include "mcld/Script/UnaryOp.h"
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// UnaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(+ m_pOperand->value());
+ res->setValue(+m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::UNARY_MINUS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::UNARY_MINUS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(- m_pOperand->value());
+ res->setValue(-m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::LOGICAL_NOT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::LOGICAL_NOT>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(! m_pOperand->value());
+ res->setValue(!m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::BITWISE_NOT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::BITWISE_NOT>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(~ m_pOperand->value());
+ res->setValue(~m_pOperand->value());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ABSOLUTE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ADDR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->addr());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ALIGNOF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->align());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::DATA_SEGMENT_END>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::DATA_SEGMENT_END>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand->value());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::DEFINED>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::LENGTH>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::LOADADDR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::NEXT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ORIGIN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::SIZEOF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->size());
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/WildcardPattern.cpp b/lib/Script/WildcardPattern.cpp
index 035250e..7470edf 100644
--- a/lib/Script/WildcardPattern.cpp
+++ b/lib/Script/WildcardPattern.cpp
@@ -6,42 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/WildcardPattern.h"
+
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
#include <cassert>
-using namespace mcld;
+namespace mcld {
-typedef GCFactory<WildcardPattern,
- MCLD_SYMBOLS_PER_INPUT> WildcardPatternFactory;
+typedef GCFactory<WildcardPattern, MCLD_SYMBOLS_PER_INPUT>
+ WildcardPatternFactory;
static llvm::ManagedStatic<WildcardPatternFactory> g_WildcardPatternFactory;
//===----------------------------------------------------------------------===//
// WildcardPattern
//===----------------------------------------------------------------------===//
-WildcardPattern::WildcardPattern()
- : m_bIsPrefix(false)
-{
+WildcardPattern::WildcardPattern() : m_bIsPrefix(false) {
}
WildcardPattern::WildcardPattern(const std::string& pPattern,
SortPolicy pPolicy)
- : StrToken(StrToken::Wildcard, pPattern), m_SortPolicy(pPolicy)
-{
+ : StrToken(StrToken::Wildcard, pPattern), m_SortPolicy(pPolicy) {
if (pPattern.find_first_of('*') == (pPattern.size() - 1))
m_bIsPrefix = true;
else
m_bIsPrefix = false;
}
-WildcardPattern::~WildcardPattern()
-{
+WildcardPattern::~WildcardPattern() {
}
-llvm::StringRef WildcardPattern::prefix() const
-{
+llvm::StringRef WildcardPattern::prefix() const {
if (isPrefix())
return llvm::StringRef(name().c_str(), name().size() - 1);
@@ -49,21 +46,20 @@
}
WildcardPattern* WildcardPattern::create(const std::string& pPattern,
- SortPolicy pPolicy)
-{
+ SortPolicy pPolicy) {
WildcardPattern* result = g_WildcardPatternFactory->allocate();
new (result) WildcardPattern(pPattern, pPolicy);
return result;
}
-void WildcardPattern::destroy(WildcardPattern*& pWildcardPattern)
-{
+void WildcardPattern::destroy(WildcardPattern*& pWildcardPattern) {
g_WildcardPatternFactory->destroy(pWildcardPattern);
g_WildcardPatternFactory->deallocate(pWildcardPattern);
pWildcardPattern = NULL;
}
-void WildcardPattern::clear()
-{
+void WildcardPattern::clear() {
g_WildcardPatternFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk
index dfff7c9..ad36732 100644
--- a/lib/Support/Android.mk
+++ b/lib/Support/Android.mk
@@ -16,8 +16,7 @@
RealPath.cpp \
SystemUtils.cpp \
Target.cpp \
- TargetRegistry.cpp \
- ToolOutputFile.cpp
+ TargetRegistry.cpp
# For the host
# =====================================================
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 033f88b..15e739c 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -6,44 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/CommandLine.h>
+#include "mcld/Support/CommandLine.h"
#include <llvm/ADT/StringRef.h>
-#include <llvm/ADT/Twine.h>
#include <llvm/ADT/StringSwitch.h>
+#include <llvm/ADT/Twine.h>
#include <llvm/Support/ErrorHandling.h>
-using namespace llvm;
-using namespace llvm::cl;
-
-using namespace mcld;
-
static const size_t MaxOptWidth = 8; // arbitrary spacing for printOptionDiff
+namespace llvm {
+namespace cl {
+
//===----------------------------------------------------------------------===//
// SearchDirParser
//===----------------------------------------------------------------------===//
// parse - Return true on error.
-bool SearchDirParser::parse(Option &pOption,
+bool SearchDirParser::parse(Option& pOption,
StringRef pArgName,
StringRef pArg,
- std::string &pValue)
-{
+ std::string& pValue) {
char separator = *(pArgName.data() + 1);
- if ('=' == separator)
+ if (separator == '=')
pValue = '=';
pValue += pArg.str();
return false;
}
-void SearchDirParser::printOptionDiff(const Option &pOption,
+void SearchDirParser::printOptionDiff(const Option& pOption,
StringRef pValue,
OptVal pDefault,
- size_t pGlobalWidth) const
-{
+ size_t pGlobalWidth) const {
printOptionName(pOption, pGlobalWidth);
outs() << "= " << pValue;
- size_t NumSpaces = MaxOptWidth > pValue.size()?MaxOptWidth - pValue.size():0;
+ size_t NumSpaces =
+ MaxOptWidth > pValue.size() ? MaxOptWidth - pValue.size() : 0;
outs().indent(NumSpaces) << " (default: ";
if (pDefault.hasValue())
outs() << pDefault.getValue();
@@ -52,28 +49,26 @@
outs() << ")\n";
}
-void SearchDirParser::anchor()
-{
+void SearchDirParser::anchor() {
// do nothing
}
//===----------------------------------------------------------------------===//
// parser<mcld::sys::fs::Path>
//===----------------------------------------------------------------------===//
-bool parser<mcld::sys::fs::Path>::parse(llvm::cl::Option &O,
- llvm::StringRef ArgName,
- llvm::StringRef Arg,
- mcld::sys::fs::Path &Val)
-{
+bool parser<mcld::sys::fs::Path>::parse(llvm::cl::Option& O,
+ llvm::StringRef ArgName,
+ llvm::StringRef Arg,
+ mcld::sys::fs::Path& Val) {
Val.assign<llvm::StringRef::const_iterator>(Arg.begin(), Arg.end());
return false;
}
-void parser<mcld::sys::fs::Path>::printOptionDiff(const llvm::cl::Option &O,
- const mcld::sys::fs::Path &V,
- parser<mcld::sys::fs::Path>::OptVal Default,
- size_t GlobalWidth) const
-{
+void parser<mcld::sys::fs::Path>::printOptionDiff(
+ const llvm::cl::Option& O,
+ const mcld::sys::fs::Path& V,
+ parser<mcld::sys::fs::Path>::OptVal Default,
+ size_t GlobalWidth) const {
printOptionName(O, GlobalWidth);
outs() << "= " << V;
size_t VSize = V.native().size();
@@ -86,87 +81,84 @@
outs() << ")\n";
}
-void parser<mcld::sys::fs::Path>::anchor()
-{
+void parser<mcld::sys::fs::Path>::anchor() {
// do nothing
}
//===----------------------------------------------------------------------===//
// parser<mcld::ZOption>
//===----------------------------------------------------------------------===//
-bool parser<mcld::ZOption>::parse(llvm::cl::Option &O,
+bool parser<mcld::ZOption>::parse(llvm::cl::Option& O,
llvm::StringRef ArgName,
llvm::StringRef Arg,
- mcld::ZOption &Val)
-{
- if (0 == Arg.compare("combreloc"))
- Val.setKind(ZOption::CombReloc);
- else if (0 == Arg.compare("nocombreloc"))
- Val.setKind(ZOption::NoCombReloc);
- else if (0 == Arg.compare("defs"))
- Val.setKind(ZOption::Defs);
- else if (0 == Arg.compare("execstack"))
- Val.setKind(ZOption::ExecStack);
- else if (0 == Arg.compare("noexecstack"))
- Val.setKind(ZOption::NoExecStack);
- else if (0 == Arg.compare("initfirst"))
- Val.setKind(ZOption::InitFirst);
- else if (0 == Arg.compare("interpose"))
- Val.setKind(ZOption::InterPose);
- else if (0 == Arg.compare("loadfltr"))
- Val.setKind(ZOption::LoadFltr);
- else if (0 == Arg.compare("muldefs"))
- Val.setKind(ZOption::MulDefs);
- else if (0 == Arg.compare("nocopyreloc"))
- Val.setKind(ZOption::NoCopyReloc);
- else if (0 == Arg.compare("nodefaultlib"))
- Val.setKind(ZOption::NoDefaultLib);
- else if (0 == Arg.compare("nodelete"))
- Val.setKind(ZOption::NoDelete);
- else if (0 == Arg.compare("nodlopen"))
- Val.setKind(ZOption::NoDLOpen);
- else if (0 == Arg.compare("nodump"))
- Val.setKind(ZOption::NoDump);
- else if (0 == Arg.compare("relro"))
- Val.setKind(ZOption::Relro);
- else if (0 == Arg.compare("norelro"))
- Val.setKind(ZOption::NoRelro);
- else if (0 == Arg.compare("lazy"))
- Val.setKind(ZOption::Lazy);
- else if (0 == Arg.compare("now"))
- Val.setKind(ZOption::Now);
- else if (0 == Arg.compare("origin"))
- Val.setKind(ZOption::Origin);
+ mcld::ZOption& Val) {
+ if (Arg.equals("combreloc"))
+ Val.setKind(mcld::ZOption::CombReloc);
+ else if (Arg.equals("nocombreloc"))
+ Val.setKind(mcld::ZOption::NoCombReloc);
+ else if (Arg.equals("defs"))
+ Val.setKind(mcld::ZOption::Defs);
+ else if (Arg.equals("execstack"))
+ Val.setKind(mcld::ZOption::ExecStack);
+ else if (Arg.equals("noexecstack"))
+ Val.setKind(mcld::ZOption::NoExecStack);
+ else if (Arg.equals("initfirst"))
+ Val.setKind(mcld::ZOption::InitFirst);
+ else if (Arg.equals("interpose"))
+ Val.setKind(mcld::ZOption::InterPose);
+ else if (Arg.equals("loadfltr"))
+ Val.setKind(mcld::ZOption::LoadFltr);
+ else if (Arg.equals("muldefs"))
+ Val.setKind(mcld::ZOption::MulDefs);
+ else if (Arg.equals("nocopyreloc"))
+ Val.setKind(mcld::ZOption::NoCopyReloc);
+ else if (Arg.equals("nodefaultlib"))
+ Val.setKind(mcld::ZOption::NoDefaultLib);
+ else if (Arg.equals("nodelete"))
+ Val.setKind(mcld::ZOption::NoDelete);
+ else if (Arg.equals("nodlopen"))
+ Val.setKind(mcld::ZOption::NoDLOpen);
+ else if (Arg.equals("nodump"))
+ Val.setKind(mcld::ZOption::NoDump);
+ else if (Arg.equals("relro"))
+ Val.setKind(mcld::ZOption::Relro);
+ else if (Arg.equals("norelro"))
+ Val.setKind(mcld::ZOption::NoRelro);
+ else if (Arg.equals("lazy"))
+ Val.setKind(mcld::ZOption::Lazy);
+ else if (Arg.equals("now"))
+ Val.setKind(mcld::ZOption::Now);
+ else if (Arg.equals("origin"))
+ Val.setKind(mcld::ZOption::Origin);
else if (Arg.startswith("common-page-size=")) {
- Val.setKind(ZOption::CommPageSize);
+ Val.setKind(mcld::ZOption::CommPageSize);
long long unsigned size = 0;
Arg.drop_front(17).getAsInteger(0, size);
Val.setPageSize(static_cast<uint64_t>(size));
- }
- else if (Arg.startswith("max-page-size=")) {
- Val.setKind(ZOption::MaxPageSize);
+ } else if (Arg.startswith("max-page-size=")) {
+ Val.setKind(mcld::ZOption::MaxPageSize);
long long unsigned size = 0;
Arg.drop_front(14).getAsInteger(0, size);
Val.setPageSize(static_cast<uint64_t>(size));
}
- if (ZOption::Unknown == Val.kind())
- llvm::report_fatal_error(llvm::Twine("unknown -z option: `") +
- Arg +
+ if (mcld::ZOption::Unknown == Val.kind())
+ llvm::report_fatal_error(llvm::Twine("unknown -z option: `") + Arg +
llvm::Twine("'\n"));
return false;
}
-void parser<mcld::ZOption>::printOptionDiff(const llvm::cl::Option &O,
- const mcld::ZOption &V,
- parser<mcld::ZOption>::OptVal Default,
- size_t GlobalWidth) const
-{
+void parser<mcld::ZOption>::printOptionDiff(
+ const llvm::cl::Option& O,
+ const mcld::ZOption& V,
+ parser<mcld::ZOption>::OptVal Default,
+ size_t GlobalWidth) const {
// TODO
}
-void parser<mcld::ZOption>::anchor()
-{
+void parser<mcld::ZOption>::anchor() {
// do nothing
}
+} // namespace cl
+} // namespace llvm
diff --git a/lib/Support/Demangle.cpp b/lib/Support/Demangle.cpp
index 6db5c34..3a11e1d 100644
--- a/lib/Support/Demangle.cpp
+++ b/lib/Support/Demangle.cpp
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/CXADemangle.tcc>
-#include <mcld/Support/Demangle.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/CXADemangle.tcc"
+#include "mcld/Support/Demangle.h"
#ifdef HAVE_CXXABI_H
#include <cxxabi.h>
@@ -26,9 +26,9 @@
// it into this helper function.
size_t output_leng;
int status;
- char* buffer = abi::__cxa_demangle(pName.c_str(), /*buffer=*/0,
- &output_leng, &status);
- if (status != 0) { // Failed
+ char* buffer =
+ abi::__cxa_demangle(pName.c_str(), /*buffer=*/0, &output_leng, &status);
+ if (status != 0) { // Failed
return pName;
}
std::string result(buffer);
@@ -40,8 +40,7 @@
#endif
}
-bool isCtorOrDtor(const char* pName, size_t pLength)
-{
+bool isCtorOrDtor(const char* pName, size_t pLength) {
arena<bs> a;
Db db(a);
db.cv = 0;
@@ -54,10 +53,8 @@
db.try_to_parse_template_args = true;
int internal_status = success;
demangle(pName, pName + pLength, db, internal_status);
- if (internal_status == success &&
- db.fix_forward_references &&
- !db.template_param.empty() &&
- !db.template_param.front().empty()) {
+ if (internal_status == success && db.fix_forward_references &&
+ !db.template_param.empty() && !db.template_param.front().empty()) {
db.fix_forward_references = false;
db.tag_templates = false;
db.names.clear();
@@ -73,4 +70,4 @@
return db.parsed_ctor_dtor_cv;
}
-} // namespace mcld
+} // namespace mcld
diff --git a/lib/Support/Directory.cpp b/lib/Support/Directory.cpp
index 20e974c..d13db10 100644
--- a/lib/Support/Directory.cpp
+++ b/lib/Support/Directory.cpp
@@ -6,86 +6,83 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Directory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/Directory.h"
+#include "mcld/Support/FileSystem.h"
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
-namespace { // anonymous
+namespace { // anonymous
-bool status_known(FileStatus f)
-{
+bool status_known(FileStatus f) {
return f.type() != StatusError;
}
-bool is_symlink(FileStatus f)
-{
+bool is_symlink(FileStatus f) {
return f.type() == SymlinkFile;
}
const Path dot_path(".");
const Path dot_dot_path("..");
-} // namespace of anonymous
+} // anonymous namespace
//===----------------------------------------------------------------------===//
// Directory
//===----------------------------------------------------------------------===//
Directory::Directory()
- : m_Path(),
- m_FileStatus(),
- m_SymLinkStatus(),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
+ : m_Path(),
+ m_FileStatus(),
+ m_SymLinkStatus(),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
}
-Directory::Directory(const Path& pPath,
- FileStatus st,
- FileStatus symlink_st)
- : m_Path(pPath),
- m_FileStatus(st),
- m_SymLinkStatus(symlink_st),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
+Directory::Directory(const Path& pPath, FileStatus st, FileStatus symlink_st)
+ : m_Path(pPath),
+ m_FileStatus(st),
+ m_SymLinkStatus(symlink_st),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
if (m_Path == dot_path)
detail::get_pwd(m_Path);
m_Path.m_append_separator_if_needed();
detail::open_dir(*this);
}
+Directory::Directory(const char* pPath, FileStatus st, FileStatus symlink_st)
+ : Directory(sys::fs::Path(pPath), st, symlink_st) {
+}
+
Directory::Directory(const Directory& pCopy)
- : m_Path(pCopy.m_Path),
- m_FileStatus(pCopy.m_FileStatus),
- m_SymLinkStatus(pCopy.m_SymLinkStatus),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
+ : m_Path(pCopy.m_Path),
+ m_FileStatus(pCopy.m_FileStatus),
+ m_SymLinkStatus(pCopy.m_SymLinkStatus),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
detail::open_dir(*this);
}
-Directory::~Directory()
-{
+Directory::~Directory() {
detail::close_dir(*this);
}
-bool Directory::isGood() const
-{
+bool Directory::isGood() const {
return (0 != m_Handler);
}
-Directory& Directory::operator=(const Directory& pCopy)
-{
+Directory& Directory::operator=(const Directory& pCopy) {
assign(pCopy.m_Path, pCopy.m_FileStatus, pCopy.m_SymLinkStatus);
return *this;
}
void Directory::assign(const Path& pPath,
FileStatus st,
- FileStatus symlink_st)
-{
+ FileStatus symlink_st) {
if (isGood())
clear();
@@ -99,48 +96,39 @@
detail::open_dir(*this);
}
-FileStatus Directory::status() const
-{
- if (!status_known(m_FileStatus))
- {
+FileStatus Directory::status() const {
+ if (!status_known(m_FileStatus)) {
// optimization: if the symlink status is known, and it isn't a symlink,
// then status and symlink_status are identical so just copy the
// symlink status to the regular status.
- if (status_known(m_SymLinkStatus)
- && !is_symlink(m_SymLinkStatus))
- {
+ if (status_known(m_SymLinkStatus) && !is_symlink(m_SymLinkStatus)) {
m_FileStatus = m_SymLinkStatus;
- }
- else detail::status(m_Path,m_FileStatus);
+ } else
+ detail::status(m_Path, m_FileStatus);
}
return m_FileStatus;
-
}
-FileStatus Directory::symlinkStatus() const
-{
+FileStatus Directory::symlinkStatus() const {
if (!status_known(m_SymLinkStatus))
- detail::symlink_status(m_Path,m_SymLinkStatus);
- return m_SymLinkStatus;
+ detail::symlink_status(m_Path, m_SymLinkStatus);
+ return m_SymLinkStatus;
}
-Directory::iterator Directory::begin()
-{
+Directory::iterator Directory::begin() {
if (m_CacheFull && m_Cache.empty())
return end();
PathCache::iterator iter = m_Cache.begin();
- if (NULL == iter.getEntry())
+ if (iter.getEntry() == NULL)
++iter;
return iterator(this, iter);
}
-Directory::iterator Directory::end()
-{
+Directory::iterator Directory::end() {
return iterator(0, m_Cache.end());
}
-void Directory::clear()
-{
+void Directory::clear() {
m_Path.native().clear();
m_FileStatus = FileStatus();
m_SymLinkStatus = FileStatus();
@@ -152,46 +140,40 @@
// DirIterator
DirIterator::DirIterator(Directory* pParent,
const DirIterator::DirCache::iterator& pIter)
- : m_pParent(pParent),
- m_Iter(pIter) {
+ : m_pParent(pParent), m_Iter(pIter) {
m_pEntry = m_Iter.getEntry();
}
DirIterator::DirIterator(const DirIterator& pCopy)
- : m_pParent(pCopy.m_pParent),
- m_Iter(pCopy.m_Iter),
- m_pEntry(pCopy.m_pEntry) {
+ : m_pParent(pCopy.m_pParent),
+ m_Iter(pCopy.m_Iter),
+ m_pEntry(pCopy.m_pEntry) {
}
-DirIterator::~DirIterator()
-{
+DirIterator::~DirIterator() {
}
-Path* DirIterator::path()
-{
- if (NULL == m_pParent)
+Path* DirIterator::path() {
+ if (m_pParent == NULL)
return NULL;
return &m_pEntry->value();
}
-const Path* DirIterator::path() const
-{
- if (NULL == m_pParent)
+const Path* DirIterator::path() const {
+ if (m_pParent == NULL)
return NULL;
return &m_pEntry->value();
}
-DirIterator& DirIterator::operator=(const DirIterator& pCopy)
-{
+DirIterator& DirIterator::operator=(const DirIterator& pCopy) {
m_pParent = pCopy.m_pParent;
m_Iter = pCopy.m_Iter;
m_pEntry = pCopy.m_pEntry;
return (*this);
}
-DirIterator& DirIterator::operator++()
-{
- if (0 == m_pParent)
+DirIterator& DirIterator::operator++() {
+ if (m_pParent == 0)
return *this;
// move forward one step first.
@@ -200,7 +182,7 @@
if (m_pParent->m_Cache.end() == m_Iter) {
if (!m_pParent->m_CacheFull) {
m_pEntry = detail::bring_one_into_cache(*this);
- if (0 == m_pEntry && m_pParent->m_CacheFull)
+ if (m_pEntry == 0 && m_pParent->m_CacheFull)
m_pParent = 0;
return *this;
}
@@ -212,8 +194,7 @@
return *this;
}
-DirIterator DirIterator::operator++(int)
-{
+DirIterator DirIterator::operator++(int pIn) {
DirIterator tmp(*this);
// move forward one step first.
@@ -222,7 +203,7 @@
if (m_pParent->m_Cache.end() == m_Iter) {
if (!m_pParent->m_CacheFull) {
m_pEntry = detail::bring_one_into_cache(*this);
- if (0 == m_pEntry && m_pParent->m_CacheFull)
+ if (m_pEntry == 0 && m_pParent->m_CacheFull)
m_pParent = 0;
return tmp;
}
@@ -234,23 +215,24 @@
return tmp;
}
-bool DirIterator::operator==(const DirIterator& y) const
-{
+bool DirIterator::operator==(const DirIterator& y) const {
if (m_pParent != y.m_pParent)
return false;
- if (0 == m_pParent)
+ if (m_pParent == 0)
return true;
const Path* x_path = path();
const Path* y_path = y.path();
- if (0 == x_path && 0 == y_path)
+ if (x_path == 0 && y_path == 0)
return true;
- if (0 == x_path || 0 == y_path)
+ if (x_path == 0 || y_path == 0)
return false;
return (*x_path == *y_path);
}
-bool DirIterator::operator!=(const DirIterator& y) const
-{
+bool DirIterator::operator!=(const DirIterator& y) const {
return !this->operator==(y);
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/FileHandle.cpp b/lib/Support/FileHandle.cpp
index 9c79598..e0494e8 100644
--- a/lib/Support/FileHandle.cpp
+++ b/lib/Support/FileHandle.cpp
@@ -7,40 +7,39 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/Config/Config.h"
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileSystem.h"
+
#include <errno.h>
#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
+#include <unistd.h>
#endif
#if defined(HAVE_FCNTL_H)
-# include <fcntl.h>
+#include <fcntl.h>
#endif
#include <sys/stat.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// FileHandle
//===----------------------------------------------------------------------===//
FileHandle::FileHandle()
- : m_Path(),
- m_Handler(-1),
- m_Size(0),
- m_State(GoodBit),
- m_OpenMode(NotOpen) {
+ : m_Path(),
+ m_Handler(-1),
+ m_Size(0),
+ m_State(GoodBit),
+ m_OpenMode(NotOpen) {
}
-FileHandle::~FileHandle()
-{
+FileHandle::~FileHandle() {
if (isOpened())
close();
}
-inline static int oflag(FileHandle::OpenMode pMode)
-{
+inline static int oflag(FileHandle::OpenMode pMode) {
int result = 0x0;
if (FileHandle::Unknown == pMode)
return result;
@@ -64,8 +63,7 @@
return result;
}
-inline static bool get_size(int pHandler, unsigned int &pSize)
-{
+inline static bool get_size(int pHandler, unsigned int& pSize) {
struct ::stat file_stat;
if (-1 == ::fstat(pHandler, &file_stat)) {
pSize = 0;
@@ -77,8 +75,7 @@
bool FileHandle::open(const sys::fs::Path& pPath,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
+ FileHandle::Permission pPerm) {
if (isOpened() || Unknown == pMode) {
setState(BadBit);
return false;
@@ -88,11 +85,12 @@
if (System == pPerm)
m_Handler = sys::fs::detail::open(pPath, oflag(pMode));
else
- m_Handler = sys::fs::detail::open(pPath, oflag(pMode), (int)pPerm);
+ m_Handler = sys::fs::detail::open(pPath, oflag(pMode),
+ static_cast<int>(pPerm));
m_Path = pPath;
- if (-1 == m_Handler) {
- m_OpenMode = NotOpen;
+ if (m_Handler == -1) {
+ m_OpenMode = OpenMode(NotOpen);
setState(FailBit);
return false;
}
@@ -105,15 +103,14 @@
return true;
}
-bool FileHandle::delegate(int pFD, FileHandle::OpenMode pMode)
-{
+bool FileHandle::delegate(int pFD, FileHandle::OpenModeEnum pMode) {
if (isOpened()) {
setState(BadBit);
return false;
}
m_Handler = pFD;
- m_OpenMode = pMode;
+ m_OpenMode = OpenMode(pMode);
m_State = (GoodBit | DeputedBit);
if (!get_size(m_Handler, m_Size)) {
@@ -124,15 +121,14 @@
return true;
}
-bool FileHandle::close()
-{
+bool FileHandle::close() {
if (!isOpened()) {
setState(BadBit);
return false;
}
if (isOwned()) {
- if (-1 == ::close(m_Handler)) {
+ if (::close(m_Handler) == -1) {
setState(FailBit);
return false;
}
@@ -140,19 +136,18 @@
m_Path.native().clear();
m_Size = 0;
- m_OpenMode = NotOpen;
+ m_OpenMode = OpenMode(NotOpen);
cleanState();
return true;
}
-bool FileHandle::truncate(size_t pSize)
-{
+bool FileHandle::truncate(size_t pSize) {
if (!isOpened() || !isWritable()) {
setState(BadBit);
return false;
}
- if (-1 == sys::fs::detail::ftruncate(m_Handler, pSize)) {
+ if (sys::fs::detail::ftruncate(m_Handler, pSize) == -1) {
setState(FailBit);
return false;
}
@@ -161,22 +156,19 @@
return true;
}
-bool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength) {
if (!isOpened() || !isReadable()) {
setState(BadBit);
return false;
}
- if (0 == pLength)
+ if (pLength == 0)
return true;
- ssize_t read_bytes = sys::fs::detail::pread(m_Handler,
- pMemBuffer,
- pLength,
- pStartOffset);
+ ssize_t read_bytes =
+ sys::fs::detail::pread(m_Handler, pMemBuffer, pLength, pStartOffset);
- if (-1 == read_bytes) {
+ if (read_bytes == -1) {
setState(FailBit);
return false;
}
@@ -184,23 +176,21 @@
return true;
}
-bool FileHandle::write(const void* pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::write(const void* pMemBuffer,
+ size_t pStartOffset,
+ size_t pLength) {
if (!isOpened() || !isWritable()) {
setState(BadBit);
return false;
}
- if (0 == pLength)
+ if (pLength == 0)
return true;
+ ssize_t write_bytes =
+ sys::fs::detail::pwrite(m_Handler, pMemBuffer, pLength, pStartOffset);
- ssize_t write_bytes = sys::fs::detail::pwrite(m_Handler,
- pMemBuffer,
- pLength,
- pStartOffset);
-
- if (-1 == write_bytes) {
+ if (write_bytes == -1) {
setState(FailBit);
return false;
}
@@ -208,59 +198,50 @@
return true;
}
-void FileHandle::setState(FileHandle::IOState pState)
-{
+void FileHandle::setState(FileHandle::IOState pState) {
m_State |= pState;
}
-void FileHandle::cleanState(FileHandle::IOState pState)
-{
+void FileHandle::cleanState(FileHandle::IOState pState) {
m_State = pState;
}
-bool FileHandle::isOpened() const
-{
- if (-1 != m_Handler && m_OpenMode != NotOpen && isGood())
+bool FileHandle::isOpened() const {
+ if (m_Handler != -1 && m_OpenMode != NotOpen && isGood())
return true;
return false;
}
// Assume Unknown OpenMode is readable
-bool FileHandle::isReadable() const
-{
+bool FileHandle::isReadable() const {
return (m_OpenMode & ReadOnly);
}
// Assume Unknown OpenMode is writable
-bool FileHandle::isWritable() const
-{
+bool FileHandle::isWritable() const {
return (m_OpenMode & WriteOnly);
}
// Assume Unknown OpenMode is both readable and writable
-bool FileHandle::isReadWrite() const
-{
+bool FileHandle::isReadWrite() const {
return (FileHandle::ReadWrite == (m_OpenMode & FileHandle::ReadWrite));
}
-bool FileHandle::isGood() const
-{
+bool FileHandle::isGood() const {
return !(m_State & (BadBit | FailBit));
}
-bool FileHandle::isBad() const
-{
+bool FileHandle::isBad() const {
return (m_State & BadBit);
}
-bool FileHandle::isFailed() const
-{
+bool FileHandle::isFailed() const {
return (m_State & (BadBit | FailBit));
}
-bool FileHandle::isOwned() const
-{
+bool FileHandle::isOwned() const {
return !(m_State & DeputedBit);
}
+} // namespace mcld
diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp
index 4887e6b..11435ea 100644
--- a/lib/Support/FileOutputBuffer.cpp
+++ b/lib/Support/FileOutputBuffer.cpp
@@ -1,4 +1,4 @@
-//===- FileOutputBuffer.cpp ------------------------------------------------===//
+//===- FileOutputBuffer.cpp -----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,36 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Path.h"
-using namespace mcld;
-using llvm::sys::fs::mapped_file_region;
+namespace mcld {
FileOutputBuffer::FileOutputBuffer(llvm::sys::fs::mapped_file_region* pRegion,
FileHandle& pFileHandle)
- : m_pRegion(pRegion), m_FileHandle(pFileHandle)
-{
+ : m_pRegion(pRegion), m_FileHandle(pFileHandle) {
}
-FileOutputBuffer::~FileOutputBuffer()
-{
+FileOutputBuffer::~FileOutputBuffer() {
// Unmap buffer, letting OS flush dirty pages to file on disk.
m_pRegion.reset(0);
}
-std::error_code FileOutputBuffer::create(FileHandle& pFileHandle,
- size_t pSize, std::unique_ptr<FileOutputBuffer>& pResult)
-{
+std::error_code FileOutputBuffer::create(
+ FileHandle& pFileHandle,
+ size_t pSize,
+ std::unique_ptr<FileOutputBuffer>& pResult) {
std::error_code ec;
- std::unique_ptr<mapped_file_region> mapped_file(new mapped_file_region(
- pFileHandle.handler(),
- false,
- mapped_file_region::readwrite,
- pSize,
- 0,
- ec));
+ std::unique_ptr<llvm::sys::fs::mapped_file_region> mapped_file(
+ new llvm::sys::fs::mapped_file_region(pFileHandle.handler(),
+ false, llvm::sys::fs::mapped_file_region::readwrite, pSize, 0, ec));
if (ec)
return ec;
@@ -46,14 +40,14 @@
return std::error_code();
}
-MemoryRegion FileOutputBuffer::request(size_t pOffset, size_t pLength)
-{
+MemoryRegion FileOutputBuffer::request(size_t pOffset, size_t pLength) {
if (pOffset > getBufferSize() || (pOffset + pLength) > getBufferSize())
return MemoryRegion();
return MemoryRegion(getBufferStart() + pOffset, pLength);
}
-llvm::StringRef FileOutputBuffer::getPath() const
-{
+llvm::StringRef FileOutputBuffer::getPath() const {
return m_FileHandle.path().native();
}
+
+} // namespace mcld
diff --git a/lib/Support/FileSystem.cpp b/lib/Support/FileSystem.cpp
index aaed86b..8986356 100644
--- a/lib/Support/FileSystem.cpp
+++ b/lib/Support/FileSystem.cpp
@@ -6,23 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/Path.h"
//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
-bool mcld::sys::fs::exists(const Path &pPath)
-{
+bool mcld::sys::fs::exists(const Path& pPath) {
mcld::sys::fs::FileStatus file_status;
mcld::sys::fs::detail::status(pPath, file_status);
return (file_status.type() != mcld::sys::fs::StatusError) &&
(file_status.type() != mcld::sys::fs::FileNotFound);
}
-bool mcld::sys::fs::is_directory(const Path &pPath)
-{
+bool mcld::sys::fs::is_directory(const Path& pPath) {
FileStatus file_status;
detail::status(pPath, file_status);
return (file_status.type() == mcld::sys::fs::DirectoryFile);
diff --git a/lib/Support/LEB128.cpp b/lib/Support/LEB128.cpp
index 02d7f24..9907e2b 100644
--- a/lib/Support/LEB128.cpp
+++ b/lib/Support/LEB128.cpp
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/LEB128.h>
+#include "mcld/Support/LEB128.h"
namespace mcld {
namespace leb128 {
//===---------------------- LEB128 Encoding APIs -------------------------===//
-template<>
-size_t encode<uint64_t>(ByteType *&pBuf, uint64_t pValue) {
+template <>
+size_t encode<uint64_t>(ByteType*& pBuf, uint64_t pValue) {
size_t size = 0;
do {
ByteType byte = pValue & 0x7f;
@@ -32,39 +32,39 @@
* Fast version for encoding 32-bit integer. This unrolls the loop in the
* generic version defined above.
*/
-template<>
-size_t encode<uint32_t>(ByteType *&pBuf, uint32_t pValue) {
+template <>
+size_t encode<uint32_t>(ByteType*& pBuf, uint32_t pValue) {
if ((pValue & ~0x7f) == 0) {
*pBuf++ = static_cast<ByteType>(pValue);
return 1;
- } else if ((pValue & ~0x3fff) == 0){
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 7) & 0x7f);
+ } else if ((pValue & ~0x3fff) == 0) {
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue >> 7) & 0x7f);
return 2;
} else if ((pValue & ~0x1fffff) == 0) {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 14) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue >> 14) & 0x7f);
return 3;
} else if ((pValue & ~0xfffffff) == 0) {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 14) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 21) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue >> 21) & 0x7f);
return 4;
} else {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 14) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 21) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 28) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue >> 28) & 0x7f);
return 5;
}
// unreachable
}
-template<>
-size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue) {
+template <>
+size_t encode<int64_t>(ByteType*& pBuf, int64_t pValue) {
size_t size = 0;
bool more = true;
@@ -72,7 +72,7 @@
ByteType byte = pValue & 0x7f;
pValue >>= 7;
- if (((pValue == 0) && ((byte & 0x40) == 0)) ||
+ if (((pValue == 0) && ((byte & 0x40) == 0)) ||
((pValue == -1) && ((byte & 0x40) == 0x40)))
more = false;
else
@@ -85,15 +85,15 @@
return size;
}
-template<>
-size_t encode<int32_t>(ByteType *&pBuf, int32_t pValue) {
+template <>
+size_t encode<int32_t>(ByteType*& pBuf, int32_t pValue) {
return encode<int64_t>(pBuf, static_cast<int64_t>(pValue));
}
//===---------------------- LEB128 Decoding APIs -------------------------===//
-template<>
-uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize) {
+template <>
+uint64_t decode<uint64_t>(const ByteType* pBuf, size_t& pSize) {
uint64_t result = 0;
if ((*pBuf & 0x80) == 0) {
@@ -101,19 +101,15 @@
return *pBuf;
} else if ((*(pBuf + 1) & 0x80) == 0) {
pSize = 2;
- return ((*(pBuf + 1) & 0x7f) << 7) |
- (*pBuf & 0x7f);
+ return ((*(pBuf + 1) & 0x7f) << 7) | (*pBuf & 0x7f);
} else if ((*(pBuf + 2) & 0x80) == 0) {
pSize = 3;
- return ((*(pBuf + 2) & 0x7f) << 14) |
- ((*(pBuf + 1) & 0x7f) << 7) |
+ return ((*(pBuf + 2) & 0x7f) << 14) | ((*(pBuf + 1) & 0x7f) << 7) |
(*pBuf & 0x7f);
} else {
pSize = 4;
- result = ((*(pBuf + 3) & 0x7f) << 21) |
- ((*(pBuf + 2) & 0x7f) << 14) |
- ((*(pBuf + 1) & 0x7f) << 7) |
- (*pBuf & 0x7f);
+ result = ((*(pBuf + 3) & 0x7f) << 21) | ((*(pBuf + 2) & 0x7f) << 14) |
+ ((*(pBuf + 1) & 0x7f) << 7) | (*pBuf & 0x7f);
}
if ((*(pBuf + 3) & 0x80) != 0) {
@@ -136,8 +132,8 @@
return result;
}
-template<>
-uint64_t decode<uint64_t>(const ByteType *&pBuf) {
+template <>
+uint64_t decode<uint64_t>(const ByteType*& pBuf) {
ByteType byte;
uint64_t result;
@@ -147,7 +143,7 @@
return result;
} else {
byte = *pBuf++;
- result |= ((byte & 0x7f) << 7);
+ result |= ((byte & 0x7f) << 7);
if ((byte & 0x80) == 0) {
return result;
} else {
@@ -184,8 +180,8 @@
* bit if necessary. This is rarely used, therefore we don't provide unrolling
* version like decode() to save the code size.
*/
-template<>
-int64_t decode<int64_t>(const ByteType *pBuf, size_t &pSize) {
+template <>
+int64_t decode<int64_t>(const ByteType* pBuf, size_t& pSize) {
uint64_t result = 0;
ByteType byte;
unsigned shift = 0;
@@ -205,8 +201,8 @@
return result;
}
-template<>
-int64_t decode<int64_t>(const ByteType *&pBuf) {
+template <>
+int64_t decode<int64_t>(const ByteType*& pBuf) {
uint64_t result = 0;
ByteType byte;
unsigned shift = 0;
@@ -224,5 +220,5 @@
return result;
}
-} // namespace of leb128
-} // namespace of mcld
+} // namespace leb128
+} // namespace mcld
diff --git a/lib/Support/MemoryArea.cpp b/lib/Support/MemoryArea.cpp
index d796283..c494355 100644
--- a/lib/Support/MemoryArea.cpp
+++ b/lib/Support/MemoryArea.cpp
@@ -6,47 +6,44 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/ErrorOr.h>
#include <cassert>
#include <system_error>
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// MemoryArea
//===--------------------------------------------------------------------===//
-MemoryArea::MemoryArea(llvm::StringRef pFilename)
-{
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer_or_error =
- llvm::MemoryBuffer::getFile(pFilename, /*FileSize*/ -1,
+MemoryArea::MemoryArea(llvm::StringRef pFilename) {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer> > buffer_or_error =
+ llvm::MemoryBuffer::getFile(pFilename,
+ /*FileSize*/ -1,
/*RequiresNullTerminator*/ false);
- if (std::error_code ec = buffer_or_error.getError()) {
- (void) ec;
+ if (!buffer_or_error) {
fatal(diag::fatal_cannot_read_input) << pFilename.str();
}
m_pMemoryBuffer = std::move(buffer_or_error.get());
}
-MemoryArea::MemoryArea(const char* pMemBuffer, size_t pSize)
-{
+MemoryArea::MemoryArea(const char* pMemBuffer, size_t pSize) {
llvm::StringRef mem(pMemBuffer, pSize);
- llvm::MemoryBuffer* buffer =
- llvm::MemoryBuffer::getMemBuffer(mem, /*BufferName*/ "NaN",
+ m_pMemoryBuffer =
+ llvm::MemoryBuffer::getMemBuffer(mem,
+ /*BufferName*/ "NaN",
/*RequiresNullTerminator*/ false);
- assert(buffer != NULL);
- m_pMemoryBuffer.reset(buffer);
}
-llvm::StringRef MemoryArea::request(size_t pOffset, size_t pLength)
-{
+llvm::StringRef MemoryArea::request(size_t pOffset, size_t pLength) {
return llvm::StringRef(m_pMemoryBuffer->getBufferStart() + pOffset, pLength);
}
-size_t MemoryArea::size() const
-{
+size_t MemoryArea::size() const {
return m_pMemoryBuffer->getBufferSize();
}
+
+} // namespace mcld
diff --git a/lib/Support/MemoryAreaFactory.cpp b/lib/Support/MemoryAreaFactory.cpp
index 655c525..66496d3 100644
--- a/lib/Support/MemoryAreaFactory.cpp
+++ b/lib/Support/MemoryAreaFactory.cpp
@@ -6,26 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MemoryAreaFactory.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/SystemUtils.h>
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/SystemUtils.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MemoryAreaFactory
//===----------------------------------------------------------------------===//
MemoryAreaFactory::MemoryAreaFactory(size_t pNum)
- : GCFactory<MemoryArea, 0>(pNum) {
+ : GCFactory<MemoryArea, 0>(pNum) {
}
-MemoryAreaFactory::~MemoryAreaFactory()
-{
+MemoryAreaFactory::~MemoryAreaFactory() {
}
MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
- FileHandle::OpenMode pMode)
-{
+ FileHandle::OpenMode pMode) {
llvm::StringRef name(pPath.native());
if (m_AreaMap.find(name) == m_AreaMap.end()) {
MemoryArea* result = allocate();
@@ -39,8 +37,7 @@
MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
+ FileHandle::Permission pPerm) {
llvm::StringRef name(pPath.native());
if (m_AreaMap.find(name) == m_AreaMap.end()) {
MemoryArea* result = allocate();
@@ -52,8 +49,7 @@
return m_AreaMap[name];
}
-MemoryArea* MemoryAreaFactory::produce(void* pMemBuffer, size_t pSize)
-{
+MemoryArea* MemoryAreaFactory::produce(void* pMemBuffer, size_t pSize) {
const char* base = reinterpret_cast<const char*>(pMemBuffer);
llvm::StringRef name(base, pSize);
if (m_AreaMap.find(name) == m_AreaMap.end()) {
@@ -66,14 +62,14 @@
return m_AreaMap[name];
}
-MemoryArea* MemoryAreaFactory::produce(int pFD, FileHandle::OpenMode pMode)
-{
+MemoryArea* MemoryAreaFactory::produce(int pFD, FileHandle::OpenMode pMode) {
// TODO
return NULL;
}
-void MemoryAreaFactory::destruct(MemoryArea* pArea)
-{
+void MemoryAreaFactory::destruct(MemoryArea* pArea) {
destroy(pArea);
deallocate(pArea);
}
+
+} // namespace mcld
diff --git a/lib/Support/MsgHandling.cpp b/lib/Support/MsgHandling.cpp
index fdcf13f..e2a7dfe 100644
--- a/lib/Support/MsgHandling.cpp
+++ b/lib/Support/MsgHandling.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticEngine.h>
-#include <mcld/LD/DiagnosticLineInfo.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-#include <mcld/LD/TextDiagnosticPrinter.h>
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/LD/DiagnosticEngine.h"
+#include "mcld/LD/DiagnosticLineInfo.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+#include "mcld/LD/MsgHandler.h"
+#include "mcld/LD/TextDiagnosticPrinter.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/raw_ostream.h"
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/raw_ostream.h>
@@ -20,35 +20,33 @@
#include <cstdlib>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// static variables
//===----------------------------------------------------------------------===//
static llvm::ManagedStatic<DiagnosticEngine> g_pEngine;
-void
-mcld::InitializeDiagnosticEngine(const mcld::LinkerConfig& pConfig,
- DiagnosticPrinter* pPrinter)
-{
+void InitializeDiagnosticEngine(const LinkerConfig& pConfig,
+ DiagnosticPrinter* pPrinter) {
g_pEngine->reset(pConfig);
- if (NULL != pPrinter)
+ if (pPrinter != NULL)
g_pEngine->setPrinter(*pPrinter, false);
else {
- DiagnosticPrinter* printer = new TextDiagnosticPrinter(mcld::errs(), pConfig);
+ DiagnosticPrinter* printer =
+ new TextDiagnosticPrinter(errs(), pConfig);
g_pEngine->setPrinter(*printer, true);
}
}
-DiagnosticEngine& mcld::getDiagnosticEngine()
-{
+DiagnosticEngine& getDiagnosticEngine() {
return *g_pEngine;
}
-bool mcld::Diagnose()
-{
+bool Diagnose() {
if (g_pEngine->getPrinter()->getNumErrors() > 0) {
- // If we reached here, we are failing ungracefully. Run the interrupt handlers
+ // If we reached here, we are failing ungracefully. Run the interrupt
+ // handlers
// to make sure any special cleanups get done, in particular that we remove
// files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
@@ -58,8 +56,8 @@
return true;
}
-void mcld::FinalizeDiagnosticEngine()
-{
+void FinalizeDiagnosticEngine() {
g_pEngine->getPrinter()->finish();
}
+} // namespace mcld
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 57d4bd8..1f6b1a5 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -6,146 +6,133 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Support/Path.h"
+
+#include "mcld/Config/Config.h"
+#include "mcld/Support/FileSystem.h"
+
#include <llvm/ADT/StringRef.h>
-#include <locale>
-#include <string.h>
#include <istream>
+#include <locale>
#include <ostream>
+#include <string.h>
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
//===--------------------------------------------------------------------===//
// Helper
//===--------------------------------------------------------------------===//
namespace {
#if defined(MCLD_ON_WIN32)
-bool is_separator(char value)
-{
+bool is_separator(char value) {
return (value == separator || value == preferred_separator);
}
const Path::StringType separator_str("/");
#else
-bool is_separator(char value)
-{
+bool is_separator(char value) {
return (value == separator);
}
const Path::StringType separator_str("/");
#endif
-} // anonymous namespace
-
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// Path
//===--------------------------------------------------------------------===//
-Path::Path()
- : m_PathName() {
+Path::Path() : m_PathName() {
}
-Path::Path(const Path::ValueType* s )
- : m_PathName(s) {
+Path::Path(const Path::ValueType* s) : m_PathName(s) {
}
-Path::Path(const Path::StringType &s )
- : m_PathName(s) {
+Path::Path(const Path::StringType& s) : m_PathName(s) {
}
-Path::Path(const Path& pCopy)
- : m_PathName(pCopy.m_PathName) {
+Path::Path(const Path& pCopy) : m_PathName(pCopy.m_PathName) {
}
-Path::~Path()
-{
+Path::~Path() {
}
-bool Path::isFromRoot() const
-{
+bool Path::isFromRoot() const {
if (m_PathName.empty())
return false;
return (separator == m_PathName[0]);
}
-bool Path::isFromPWD() const
-{
- if (2 > m_PathName.size())
+bool Path::isFromPWD() const {
+ if (m_PathName.size() < 2)
return false;
return ('.' == m_PathName[0] && separator == m_PathName[1]);
}
-Path& Path::assign(const Path::StringType &s)
-{
+Path& Path::assign(const Path::StringType& s) {
m_PathName.assign(s);
return *this;
}
-Path& Path::assign(const Path::ValueType* s, unsigned int length)
-{
- if (0 == s || 0 == length)
+Path& Path::assign(const Path::ValueType* s, unsigned int length) {
+ if (s == 0 || length == 0)
assert(0 && "assign a null or empty string to Path");
m_PathName.assign(s, length);
return *this;
}
-//a,/b a/,b a/,b/ a,b is a/b
-Path& Path::append(const Path& pPath)
-{
- //first path is a/,second path is /b
- if(m_PathName[m_PathName.length()-1] == separator &&
- pPath.native()[0] == separator) {
- unsigned int old_size = m_PathName.size()-1;
- unsigned int new_size = old_size + pPath.native().size();
-
- m_PathName.resize(new_size);
- strcpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
- }
- //first path is a,second path is b
- else if(this->native()[this->native().size()-1] != separator &&
- pPath.native()[0] != separator) {
+// a,/b a/,b a/,b/ a,b is a/b
+Path& Path::append(const Path& pPath) {
+ // first path is a/,second path is /b
+ if (m_PathName[m_PathName.length() - 1] == separator &&
+ pPath.native()[0] == separator) {
+ llvm::StringRef path(pPath.native());
+ m_PathName.append(path.begin() + 1, path.end());
+ } else if (this->native()[this->native().size() - 1] != separator &&
+ pPath.native()[0] != separator) {
+ // first path is a,second path is b
m_PathName.append(separator_str);
m_PathName.append(pPath.native());
- }
- // a/,b or a,/b just append
- else {
+ } else {
+ // a/,b or a,/b just append
m_PathName.append(pPath.native());
}
return *this;
}
-bool Path::empty() const
-{
+// a,/b a/,b a/,b/ a,b is a/b
+Path& Path::append(const StringType& pPath) {
+ Path path(pPath);
+ this->append(path);
+ return *this;
+}
+
+bool Path::empty() const {
return m_PathName.empty();
}
-Path::StringType Path::generic_string() const
-{
+Path::StringType Path::generic_string() const {
StringType result = m_PathName;
detail::canonicalize(result);
return result;
}
-bool Path::canonicalize()
-{
+bool Path::canonicalize() {
return detail::canonicalize(m_PathName);
}
-Path::StringType::size_type Path::m_append_separator_if_needed()
-{
+Path::StringType::size_type Path::m_append_separator_if_needed() {
#if defined(MCLD_ON_WIN32)
// On Windows platform, path can not append separator.
return 0;
#endif
StringType::value_type last_char = m_PathName[m_PathName.size() - 1];
- if (!m_PathName.empty() &&
- !is_separator(last_char)) {
+ if (!m_PathName.empty() && !is_separator(last_char)) {
StringType::size_type tmp(m_PathName.size());
m_PathName += separator_str;
return tmp;
@@ -153,11 +140,10 @@
return 0;
}
-void Path::m_erase_redundant_separator(Path::StringType::size_type pSepPos)
-{
- size_t begin=pSepPos;
+void Path::m_erase_redundant_separator(Path::StringType::size_type pSepPos) {
+ size_t begin = pSepPos;
// skip '/' or '\\'
- while(separator == m_PathName[pSepPos]) {
+ while (separator == m_PathName[pSepPos]) {
#if defined(MCLD_ON_WIN32)
pSepPos += 2;
#else
@@ -165,20 +151,18 @@
#endif
}
- if(begin!=pSepPos)
- m_PathName.erase(begin+1,pSepPos-begin-1);
+ if (begin != pSepPos)
+ m_PathName.erase(begin + 1, pSepPos - begin - 1);
}
-Path Path::parent_path() const
-{
+Path Path::parent_path() const {
size_t end_pos = m_PathName.find_last_of(separator);
if (end_pos != StringType::npos)
return Path(m_PathName.substr(0, end_pos));
return Path();
}
-Path Path::filename() const
-{
+Path Path::filename() const {
size_t pos = m_PathName.find_last_of(separator);
if (pos != StringType::npos) {
++pos;
@@ -187,16 +171,14 @@
return Path(*this);
}
-Path Path::stem() const
-{
- size_t begin_pos = m_PathName.find_last_of(separator)+1;
- size_t end_pos = m_PathName.find_last_of(dot);
+Path Path::stem() const {
+ size_t begin_pos = m_PathName.find_last_of(separator) + 1;
+ size_t end_pos = m_PathName.find_last_of(dot);
Path result_path(m_PathName.substr(begin_pos, end_pos - begin_pos));
return result_path;
}
-Path Path::extension() const
-{
+Path Path::extension() const {
size_t pos = m_PathName.find_last_of('.');
if (pos == StringType::npos)
return Path();
@@ -206,20 +188,20 @@
//===--------------------------------------------------------------------===//
// non-member functions
//===--------------------------------------------------------------------===//
-bool mcld::sys::fs::operator==(const Path& pLHS,const Path& pRHS)
-{
- return (pLHS.generic_string()==pRHS.generic_string());
+bool operator==(const Path& pLHS, const Path& pRHS) {
+ return (pLHS.generic_string() == pRHS.generic_string());
}
-bool mcld::sys::fs::operator!=(const Path& pLHS,const Path& pRHS)
-{
- return !(pLHS==pRHS);
+bool operator!=(const Path& pLHS, const Path& pRHS) {
+ return !(pLHS == pRHS);
}
-Path mcld::sys::fs::operator+(const Path& pLHS, const Path& pRHS)
-{
+Path operator+(const Path& pLHS, const Path& pRHS) {
mcld::sys::fs::Path result = pLHS;
result.append(pRHS);
return result;
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/RealPath.cpp b/lib/Support/RealPath.cpp
index b62f443..bac06be 100644
--- a/lib/Support/RealPath.cpp
+++ b/lib/Support/RealPath.cpp
@@ -9,45 +9,39 @@
#include "mcld/Support/RealPath.h"
#include "mcld/Support/FileSystem.h"
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
//==========================
// RealPath
-RealPath::RealPath()
- : Path() {
+RealPath::RealPath() : Path() {
}
-RealPath::RealPath(const RealPath::ValueType* s )
- : Path(s) {
+RealPath::RealPath(const RealPath::ValueType* s) : Path(s) {
initialize();
}
-RealPath::RealPath(const RealPath::StringType &s )
- : Path(s) {
+RealPath::RealPath(const RealPath::StringType& s) : Path(s) {
initialize();
}
-RealPath::RealPath(const Path& pPath)
- : Path(pPath) {
+RealPath::RealPath(const Path& pPath) : Path(pPath) {
initialize();
}
-RealPath::~RealPath()
-{
+RealPath::~RealPath() {
}
-RealPath& RealPath::assign(const Path& pPath)
-{
+RealPath& RealPath::assign(const Path& pPath) {
Path::m_PathName.assign(pPath.native());
return (*this);
}
-void RealPath::initialize()
-{
+void RealPath::initialize() {
if (isFromRoot()) {
detail::canonicalize(m_PathName);
- }
- else if (isFromPWD()) {
+ } else if (isFromPWD()) {
Path path_name;
detail::get_pwd(path_name);
path_name.native() += preferred_separator;
@@ -57,3 +51,6 @@
}
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index b261db8..b80f5eb 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -7,9 +7,7 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/Config/Config.h"
-#include <mcld/Support/SystemUtils.h>
-
-using namespace mcld::sys;
+#include "mcld/Support/SystemUtils.h"
//===----------------------------------------------------------------------===//
// Non-member functions
diff --git a/lib/Support/Target.cpp b/lib/Support/Target.cpp
index d0e5f29..945598c 100644
--- a/lib/Support/Target.cpp
+++ b/lib/Support/Target.cpp
@@ -6,76 +6,70 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+
#include <llvm/ADT/Triple.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Target
//===----------------------------------------------------------------------===//
Target::Target()
- : Name(NULL),
- TripleMatchQualityFn(NULL),
- TargetMachineCtorFn(NULL),
- MCLinkerCtorFn(NULL),
- TargetLDBackendCtorFn(NULL),
- DiagnosticLineInfoCtorFn(NULL) {
+ : Name(NULL),
+ TripleMatchQualityFn(NULL),
+ TargetMachineCtorFn(NULL),
+ MCLinkerCtorFn(NULL),
+ TargetLDBackendCtorFn(NULL),
+ DiagnosticLineInfoCtorFn(NULL) {
}
-unsigned int Target::getTripleQuality(const llvm::Triple& pTriple) const
-{
- if (NULL == TripleMatchQualityFn)
+unsigned int Target::getTripleQuality(const llvm::Triple& pTriple) const {
+ if (TripleMatchQualityFn == NULL)
return 0;
return TripleMatchQualityFn(pTriple);
}
-MCLDTargetMachine*
-Target::createTargetMachine(const std::string& pTriple,
- const llvm::Target& pTarget,
- llvm::TargetMachine& pTM) const
-{
- if (NULL == TargetMachineCtorFn)
+MCLDTargetMachine* Target::createTargetMachine(const std::string& pTriple,
+ const llvm::Target& pTarget,
+ llvm::TargetMachine& pTM) const {
+ if (TargetMachineCtorFn == NULL)
return NULL;
return TargetMachineCtorFn(pTarget, *this, pTM, pTriple);
}
/// createMCLinker - create target-specific MCLinker
-MCLinker*
-Target::createMCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- Module& pModule,
- FileHandle& pFileHandle) const
-{
- if (NULL == MCLinkerCtorFn)
+MCLinker* Target::createMCLinker(const std::string& pTriple,
+ LinkerConfig& pConfig,
+ Module& pModule,
+ FileHandle& pFileHandle) const {
+ if (MCLinkerCtorFn == NULL)
return NULL;
return MCLinkerCtorFn(pTriple, pConfig, pModule, pFileHandle);
}
/// emulate - given MCLinker default values for the other aspects of the
/// target system.
-bool Target::emulate(LinkerScript& pScript, LinkerConfig& pConfig) const
-{
- if (NULL == EmulationFn)
+bool Target::emulate(LinkerScript& pScript, LinkerConfig& pConfig) const {
+ if (EmulationFn == NULL)
return false;
return EmulationFn(pScript, pConfig);
}
/// createLDBackend - create target-specific LDBackend
-TargetLDBackend* Target::createLDBackend(const LinkerConfig& pConfig) const
-{
- if (NULL == TargetLDBackendCtorFn)
- return NULL;
- return TargetLDBackendCtorFn(pConfig);
+TargetLDBackend* Target::createLDBackend(const LinkerConfig& pConfig) const {
+ if (TargetLDBackendCtorFn == NULL)
+ return NULL;
+ return TargetLDBackendCtorFn(pConfig);
}
/// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
-DiagnosticLineInfo*
-Target::createDiagnosticLineInfo(const mcld::Target& pTarget,
- const std::string& pTriple) const
-{
- if (NULL == DiagnosticLineInfoCtorFn)
+DiagnosticLineInfo* Target::createDiagnosticLineInfo(
+ const mcld::Target& pTarget,
+ const std::string& pTriple) const {
+ if (DiagnosticLineInfoCtorFn == NULL)
return NULL;
return DiagnosticLineInfoCtorFn(pTarget, pTriple);
}
+} // namespace mcld
diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp
index afffc5c..75fd3fc 100644
--- a/lib/Support/TargetRegistry.cpp
+++ b/lib/Support/TargetRegistry.cpp
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/TargetRegistry.h"
-using namespace mcld;
+namespace mcld {
TargetRegistry::TargetListTy mcld::TargetRegistry::s_TargetList;
@@ -17,48 +17,45 @@
//===----------------------------------------------------------------------===//
void TargetRegistry::RegisterTarget(Target& pTarget,
const char* pName,
- Target::TripleMatchQualityFnTy pQualityFn)
-{
+ Target::TripleMatchQualityFnTy pQualityFn) {
pTarget.Name = pName;
pTarget.TripleMatchQualityFn = pQualityFn;
s_TargetList.push_back(&pTarget);
}
-const Target* TargetRegistry::lookupTarget(const std::string &pTriple,
- std::string &pError)
-{
+const Target* TargetRegistry::lookupTarget(const std::string& pTriple,
+ std::string& pError) {
if (empty()) {
pError = "Unable to find target for this triple (no target are registered)";
return NULL;
}
llvm::Triple triple(pTriple);
- Target* best = NULL, *ambiguity = NULL;
+ Target* best = NULL, * ambiguity = NULL;
unsigned int highest = 0;
for (iterator target = begin(), ie = end(); target != ie; ++target) {
unsigned int quality = (*target)->getTripleQuality(triple);
if (quality > 0) {
- if (NULL == best || highest < quality) {
+ if (best == NULL || highest < quality) {
highest = quality;
best = *target;
ambiguity = NULL;
- }
- else if (highest == quality) {
+ } else if (highest == quality) {
ambiguity = *target;
}
}
}
- if (NULL == best) {
+ if (best == NULL) {
pError = "No availaible targets are compatible with this triple.";
return NULL;
}
if (NULL != ambiguity) {
- pError = std::string("Ambiguous targets: \"") +
- best->name() + "\" and \"" + ambiguity->name() + "\"";
+ pError = std::string("Ambiguous targets: \"") + best->name() + "\" and \"" +
+ ambiguity->name() + "\"";
return NULL;
}
@@ -67,19 +64,20 @@
const Target* TargetRegistry::lookupTarget(const std::string& pArchName,
llvm::Triple& pTriple,
- std::string& pError)
-{
+ std::string& pError) {
const Target* result = NULL;
if (!pArchName.empty()) {
for (mcld::TargetRegistry::iterator it = mcld::TargetRegistry::begin(),
- ie = mcld::TargetRegistry::end(); it != ie; ++it) {
+ ie = mcld::TargetRegistry::end();
+ it != ie;
+ ++it) {
if (pArchName == (*it)->name()) {
result = *it;
break;
}
}
- if (NULL == result) {
+ if (result == NULL) {
pError = std::string("invalid target '") + pArchName + "'.\n";
return NULL;
}
@@ -87,19 +85,19 @@
// Adjust the triple to match (if known), otherwise stick with the
// module/host triple.
llvm::Triple::ArchType type =
- llvm::Triple::getArchTypeForLLVMName(pArchName);
+ llvm::Triple::getArchTypeForLLVMName(pArchName);
if (llvm::Triple::UnknownArch != type)
pTriple.setArch(type);
- }
- else {
+ } else {
std::string error;
result = lookupTarget(pTriple.getTriple(), error);
- if (NULL == result) {
- pError = std::string("unable to get target for `") +
- pTriple.getTriple() + "'\n" +
- "(Detail: " + error + ")\n";
+ if (result == NULL) {
+ pError = std::string("unable to get target for `") + pTriple.getTriple() +
+ "'\n" + "(Detail: " + error + ")\n";
return NULL;
}
}
return result;
}
+
+} // namespace mcld
diff --git a/lib/Support/ToolOutputFile.cpp b/lib/Support/ToolOutputFile.cpp
deleted file mode 100644
index 3e4844c..0000000
--- a/lib/Support/ToolOutputFile.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===- ToolOutputFile.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/Support/ToolOutputFile.h>
-
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/MemoryArea.h>
-
-#include <mcld/Support/SystemUtils.h>
-#include <mcld/Support/MsgHandling.h>
-
-#include <llvm/Support/FileUtilities.h>
-#include <llvm/Support/Signals.h>
-#include <llvm/Support/Path.h>
-#include <llvm/Support/FormattedStream.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// CleanupInstaller
-//===----------------------------------------------------------------------===//
-ToolOutputFile::CleanupInstaller::CleanupInstaller(const sys::fs::Path& pPath)
- : Keep(false), m_Path(pPath) {
- // Arrange for the file to be deleted if the process is killed.
- if ("-" != m_Path.native())
- llvm::sys::RemoveFileOnSignal(m_Path.native());
-}
-
-ToolOutputFile::CleanupInstaller::~CleanupInstaller()
-{
- // Delete the file if the client hasn't told us not to.
- // FIXME: In Windows, some path in CJK characters can not be removed by LLVM
- // llvm::sys::Path
- if (!Keep && "_" != m_Path.native()) {
- bool Existed = false;
- llvm::sys::fs::remove(m_Path.native(), Existed);
- }
-
- // Ok, the file is successfully written and closed, or deleted. There's no
- // further need to clean it up on signals.
- if ("_" != m_Path.native())
- llvm::sys::DontRemoveFileOnSignal(m_Path.native());
-}
-
-//===----------------------------------------------------------------------===//
-// ToolOutputFile
-//===----------------------------------------------------------------------===//
-ToolOutputFile::ToolOutputFile(const sys::fs::Path& pPath,
- FileHandle::OpenMode pMode,
- FileHandle::Permission pPermission)
- : m_Installer(pPath),
- m_pFdOstream(NULL),
- m_pFormattedOstream(NULL) {
-
- if (!m_FileHandle.open(pPath, pMode, pPermission)) {
- // If open fails, no clean-up is needed.
- m_Installer.Keep = true;
- fatal(diag::err_cannot_open_output_file)
- << pPath
- << sys::strerror(m_FileHandle.error());
- return;
- }
-}
-
-ToolOutputFile::~ToolOutputFile()
-{
- if (m_pFormattedOstream != NULL)
- delete m_pFormattedOstream;
- if (m_pFdOstream != NULL)
- delete m_pFdOstream;
-}
-
-void ToolOutputFile::keep()
-{
- m_Installer.Keep = true;
-}
-
-/// os - Return the containeed raw_fd_ostream.
-/// Since os is rarely used, we lazily initialize it.
-llvm::raw_fd_ostream& ToolOutputFile::os()
-{
- if (m_pFdOstream == NULL) {
- assert(m_FileHandle.isOpened() &&
- m_FileHandle.isGood() &&
- m_FileHandle.isWritable());
- m_pFdOstream = new llvm::raw_fd_ostream(m_FileHandle.handler(), false);
- }
- return *m_pFdOstream;
-}
-
-/// formatted_os - Return the contained formatted_raw_ostream
-llvm::formatted_raw_ostream& ToolOutputFile::formatted_os()
-{
- if (m_pFormattedOstream == NULL) {
- m_pFormattedOstream = new llvm::formatted_raw_ostream(os());
- }
- return *m_pFormattedOstream;
-}
diff --git a/lib/Support/Unix/FileSystem.inc b/lib/Support/Unix/FileSystem.inc
index 811085e..67fdd73 100644
--- a/lib/Support/Unix/FileSystem.inc
+++ b/lib/Support/Unix/FileSystem.inc
@@ -6,28 +6,31 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Directory.h"
+
+#include <llvm/Support/ErrorHandling.h>
+
#include <string>
+
+#include <dirent.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <dirent.h>
#include <unistd.h>
-#include <fcntl.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Directory.h>
-#include <llvm/Support/ErrorHandling.h>
-namespace mcld{
-namespace sys{
-namespace fs{
-namespace detail{
+namespace mcld {
+namespace sys {
+namespace fs {
+namespace detail {
std::string static_library_extension = ".a";
std::string shared_library_extension = ".so";
-std::string executable_extension = "";
-std::string relocatable_extension = ".o";
-std::string assembly_extension = ".s";
-std::string bitcode_extension = ".bc";
+std::string executable_extension = "";
+std::string relocatable_extension = ".o";
+std::string assembly_extension = ".s";
+std::string bitcode_extension = ".bc";
//===----------------------------------------------------------------------===//
// Helper Functions
@@ -36,10 +39,9 @@
// @return value -1: read error
// 0: read the end
// 1: success
-static int read_dir(intptr_t& pDir, std::string& pOutFilename)
-{
+static int read_dir(intptr_t& pDir, std::string& pOutFilename) {
errno = 0;
- dirent *cur_dir = ::readdir(reinterpret_cast<DIR*>(pDir));
+ dirent* cur_dir = ::readdir(reinterpret_cast<DIR*>(pDir));
if (0 == cur_dir && 0 != errno)
return -1;
@@ -58,11 +60,10 @@
return 1;
}
-void open_dir(Directory& pDir)
-{
+void open_dir(Directory& pDir) {
pDir.m_Handler = reinterpret_cast<intptr_t>(opendir(pDir.path().c_str()));
if (0 == pDir.m_Handler) {
- errno = 0; // opendir() will set errno if it failed to open directory.
+ errno = 0; // opendir() will set errno if it failed to open directory.
// set cache is full, then Directory::begin() can return end().
pDir.m_CacheFull = true;
return;
@@ -70,39 +71,37 @@
// read one entry for advance the end element of the cache.
std::string path(pDir.path().native());
switch (read_dir(pDir.m_Handler, path)) {
- case 1: {
- // find a new directory
- bool exist = false;
- mcld::sys::fs::PathCache::entry_type* entry = pDir.m_Cache.insert(path, exist);
- if (!exist)
- entry->setValue(path);
- return;
- }
- case 0:
- // FIXME: a warning function
- pDir.m_CacheFull = true;
- return;
- default:
- case -1:
- llvm::report_fatal_error(std::string("Can't read directory: ")+
- pDir.path().native());
+ case 1: {
+ // find a new directory
+ bool exist = false;
+ mcld::sys::fs::PathCache::entry_type* entry =
+ pDir.m_Cache.insert(path, exist);
+ if (!exist)
+ entry->setValue(sys::fs::Path(path));
+ return;
+ }
+ case 0:
+ // FIXME: a warning function
+ pDir.m_CacheFull = true;
+ return;
+ default:
+ case -1:
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
+ pDir.path().native());
}
}
-void close_dir(Directory& pDir)
-{
+void close_dir(Directory& pDir) {
if (pDir.m_Handler)
- closedir(reinterpret_cast<DIR *>(pDir.m_Handler));
+ closedir(reinterpret_cast<DIR*>(pDir.m_Handler));
pDir.m_Handler = 0;
}
-int open(const Path& pPath, int pOFlag)
-{
+int open(const Path& pPath, int pOFlag) {
return ::open(pPath.native().c_str(), pOFlag);
}
-int open(const Path& pPath, int pOFlag, int pPerm)
-{
+int open(const Path& pPath, int pOFlag, int pPerm) {
mode_t perm = 0;
if (pPerm & FileHandle::ReadOwner)
perm |= S_IRUSR;
@@ -126,37 +125,32 @@
return ::open(pPath.native().c_str(), pOFlag, perm);
}
-ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset) {
return ::pread(pFD, pBuf, pCount, pOffset);
}
-ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset) {
return ::pwrite(pFD, pBuf, pCount, pOffset);
}
-int ftruncate(int pFD, size_t pLength)
-{
+int ftruncate(int pFD, size_t pLength) {
return ::ftruncate(pFD, pLength);
}
-void get_pwd(Path& pPWD)
-{
+void get_pwd(Path& pPWD) {
char* pwd = (char*)malloc(PATH_MAX);
pPWD.assign(getcwd(pwd, PATH_MAX));
free(pwd);
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
+} // namespace detail
+} // namespace fs
+} // namespace sys
//===----------------------------------------------------------------------===//
// FileHandler
//===----------------------------------------------------------------------===//
-bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength) {
if (!isOpened()) {
setState(BadBit);
return false;
@@ -170,18 +164,15 @@
// read-only
prot = PROT_READ;
flag = MAP_FILE | MAP_PRIVATE;
- }
- else if (!isReadable() && isWritable()) {
+ } else if (!isReadable() && isWritable()) {
// write-only
prot = PROT_WRITE;
flag = MAP_FILE | MAP_SHARED;
- }
- else if (isReadWrite()) {
+ } else if (isReadWrite()) {
// read and write
prot = PROT_READ | PROT_WRITE;
flag = MAP_FILE | MAP_SHARED;
- }
- else {
+ } else {
// can not read/write
setState(BadBit);
return false;
@@ -197,8 +188,7 @@
return true;
}
-bool FileHandle::munmap(void* pMemBuffer, size_t pLength)
-{
+bool FileHandle::munmap(void* pMemBuffer, size_t pLength) {
if (!isOpened()) {
setState(BadBit);
return false;
@@ -212,5 +202,4 @@
return true;
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Support/Unix/PathV3.inc b/lib/Support/Unix/PathV3.inc
index d7e4cbc..1e6881b 100644
--- a/lib/Support/Unix/PathV3.inc
+++ b/lib/Support/Unix/PathV3.inc
@@ -6,30 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/Path.h"
+
#include <llvm/Support/ErrorHandling.h>
#include <cerrno>
+#include <stack>
#include <stdio.h>
+#include <string>
#include <sys/stat.h>
#include <sys/types.h>
-#include <string>
-#include <stack>
#include <unistd.h>
-namespace mcld{
-namespace sys{
-namespace fs{
+namespace mcld {
+namespace sys {
+namespace fs {
//===----------------------------------------------------------------------===//
// mcld::sys::fs::detail
//===----------------------------------------------------------------------===//
-namespace detail{
+namespace detail {
// return the last charactor being handled.
-size_t canonicalize(std::string& pathname)
-{
+size_t canonicalize(std::string& pathname) {
// Variable Index //
// SepTable - stack of result separators
// LR(1) Algorithm //
@@ -54,12 +54,12 @@
std::stack<size_t> slash_stack;
slash_stack.push(-1);
while (handler < pathname.size()) {
- if (separator == pathname[handler]) { // handler = 1st '/'
+ if (separator == pathname[handler]) { // handler = 1st '/'
size_t next = handler + 1;
if (next >= pathname.size())
return handler;
- switch(pathname[next]) { // next = handler + 1;
- case separator: { // '//'
+ switch (pathname[next]) { // next = handler + 1;
+ case separator: { // '//'
while (next < pathname.size() && separator == pathname[next])
++next;
// next is the last not '/'
@@ -68,122 +68,112 @@
slash_stack.push(handler);
break;
}
- case '.': { // '/.'
- ++next; // next = handler + 2
- if (next >= pathname.size()) // '/.'
+ case '.': { // '/.'
+ ++next; // next = handler + 2
+ if (next >= pathname.size()) // '/.'
return handler;
switch (pathname[next]) {
- case separator: { // '/./'
+ case separator: { // '/./'
pathname.erase(handler, 2);
break;
}
- case '.': { // '/..'
- ++next; // next = handler + 3;
- if (next >= pathname.size()) // '/..?'
+ case '.': { // '/..'
+ ++next; // next = handler + 3;
+ if (next >= pathname.size()) // '/..?'
return handler;
- switch(pathname[next]) {
- case separator: { // '/../'
+ switch (pathname[next]) {
+ case separator: { // '/../'
handler = slash_stack.top();
slash_stack.pop();
- pathname.erase(handler+1, next-handler);
+ pathname.erase(handler + 1, next - handler);
if (static_cast<size_t>(-1) == handler) {
slash_stack.push(-1);
handler = pathname.find_first_of(separator, handler);
}
break;
}
- case '.': { // '/...', illegal
+ case '.': { // '/...', illegal
return handler;
break;
}
- default : { // '/..a'
+ default: { // '/..a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+3);
+ handler = pathname.find_first_of(separator, handler + 3);
break;
}
}
break;
}
- default : { // '/.a'
+ default: { // '/.a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+2);
+ handler = pathname.find_first_of(separator, handler + 2);
break;
}
}
break;
}
- default : { // '/a
+ default: { // '/a
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+1);
+ handler = pathname.find_first_of(separator, handler + 1);
break;
}
}
- }
- else {
+ } else {
handler = pathname.find_first_of(separator, handler);
}
}
return handler;
}
-bool not_found_error(int perrno)
-{
+bool not_found_error(int perrno) {
return perrno == ENOENT || perrno == ENOTDIR;
}
-void status(const Path& p, FileStatus& pFileStatus)
-{
+void status(const Path& p, FileStatus& pFileStatus) {
struct stat path_stat;
- if(stat(p.c_str(), &path_stat)!= 0)
- {
- if(not_found_error(errno))
- {
+ if (stat(p.c_str(), &path_stat) != 0) {
+ if (not_found_error(errno)) {
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
- }
- else if(S_ISDIR(path_stat.st_mode))
+ } else if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- else if(S_ISREG(path_stat.st_mode))
+ else if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- else if(S_ISBLK(path_stat.st_mode))
+ else if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- else if(S_ISCHR(path_stat.st_mode))
+ else if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- else if(S_ISFIFO(path_stat.st_mode))
+ else if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
- else if(S_ISSOCK(path_stat.st_mode))
+ else if (S_ISSOCK(path_stat.st_mode))
pFileStatus.setType(SocketFile);
else
pFileStatus.setType(TypeUnknown);
}
-void symlink_status(const Path& p, FileStatus& pFileStatus)
-{
+void symlink_status(const Path& p, FileStatus& pFileStatus) {
struct stat path_stat;
- if(lstat(p.c_str(), &path_stat)!= 0)
- {
- if(errno == ENOENT || errno == ENOTDIR) // these are not errors
+ if (lstat(p.c_str(), &path_stat) != 0) {
+ if (errno == ENOENT || errno == ENOTDIR) // these are not errors
{
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
}
- if(S_ISREG(path_stat.st_mode))
+ if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- if(S_ISDIR(path_stat.st_mode))
+ if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- if(S_ISLNK(path_stat.st_mode))
+ if (S_ISLNK(path_stat.st_mode))
pFileStatus.setType(SymlinkFile);
- if(S_ISBLK(path_stat.st_mode))
+ if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- if(S_ISCHR(path_stat.st_mode))
+ if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- if(S_ISFIFO(path_stat.st_mode))
+ if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
- if(S_ISSOCK(path_stat.st_mode))
+ if (S_ISSOCK(path_stat.st_mode))
pFileStatus.setType(SocketFile);
else
pFileStatus.setType(TypeUnknown);
@@ -196,33 +186,31 @@
// of cache. (a real end)
// 2. Some but not all elements had been put into cache, and we stoped.
// An iterator now is staying at the end of cache. (a temporal end)
-mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter)
-{
+mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter) {
mcld::sys::fs::PathCache::entry_type* entry = 0;
std::string path(pIter.m_pParent->m_Path.native());
switch (read_dir(pIter.m_pParent->m_Handler, path)) {
- case 1: {
- // read one
- bool exist = false;
- entry = pIter.m_pParent->m_Cache.insert(path, exist);
- if (!exist)
- entry->setValue(path);
- break;
- }
- case 0:// meet real end
- pIter.m_pParent->m_CacheFull = true;
- break;
- default:
- case -1:
- llvm::report_fatal_error(std::string("Can't read directory: ")+
- pIter.m_pParent->path().native());
- break;
+ case 1: {
+ // read one
+ bool exist = false;
+ entry = pIter.m_pParent->m_Cache.insert(path, exist);
+ if (!exist)
+ entry->setValue(sys::fs::Path(path));
+ break;
+ }
+ case 0: // meet real end
+ pIter.m_pParent->m_CacheFull = true;
+ break;
+ default:
+ case -1:
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
+ pIter.m_pParent->path().native());
+ break;
}
return entry;
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace detail
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Unix/System.inc b/lib/Support/Unix/System.inc
index f2064ec..4c16ec2 100644
--- a/lib/Support/Unix/System.inc
+++ b/lib/Support/Unix/System.inc
@@ -6,27 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include <llvm/ADT/StringRef.h>
+
+#include <fcntl.h>
+#include <cstdlib>
#include <cstring>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
-#include <ctype.h>
-#include <cstdlib>
-#include <fcntl.h>
#include <unistd.h>
-#include <llvm/ADT/StringRef.h>
+namespace mcld {
+namespace sys {
-namespace mcld{
-namespace sys{
-
-char *strerror(int errnum)
-{
+char* strerror(int errnum) {
return std::strerror(errnum);
}
-static std::string getOSVersion()
-{
+static std::string getOSVersion() {
struct utsname info;
if (uname(&info))
@@ -35,12 +33,13 @@
return info.release;
}
-std::string getDefaultTargetTriple()
-{
+std::string getDefaultTargetTriple() {
llvm::StringRef TargetTripleString(MCLD_DEFAULT_TARGET_TRIPLE);
- std::pair<llvm::StringRef, llvm::StringRef> ArchSplit = TargetTripleString.split('-');
+ std::pair<llvm::StringRef, llvm::StringRef> ArchSplit =
+ TargetTripleString.split('-');
- // Normalize the arch, since the target triple may not actually match the target.
+ // Normalize the arch, since the target triple may not actually match the
+ // target.
std::string Arch = ArchSplit.first;
std::string Triple(Arch);
@@ -48,8 +47,8 @@
Triple += ArchSplit.second;
// Force i<N>86 to i386.
- if (Triple[0] == 'i' && isdigit(Triple[1]) &&
- Triple[2] == '8' && Triple[3] == '6')
+ if (Triple[0] == 'i' && isdigit(Triple[1]) && Triple[2] == '8' &&
+ Triple[3] == '6')
Triple[1] = '3';
// On darwin, we want to update the version to match that of the
@@ -63,23 +62,19 @@
return Triple;
}
-int GetPageSize()
-{
+int GetPageSize() {
return getpagesize();
}
/// random - generate a random number.
-long GetRandomNum()
-{
+long GetRandomNum() {
return ::random();
}
/// srandom - set the initial seed value for future calls to random().
-void SetRandomSeed(unsigned pSeed)
-{
+void SetRandomSeed(unsigned pSeed) {
::srandom(pSeed);
}
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Windows/FileSystem.inc b/lib/Support/Windows/FileSystem.inc
index 98b1e01..f08464b 100644
--- a/lib/Support/Windows/FileSystem.inc
+++ b/lib/Support/Windows/FileSystem.inc
@@ -6,41 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Directory.h"
+
#include <string>
+
+#include <cstdlib>
#include <io.h>
#include <fcntl.h>
-#include <cstdlib>
-#include <windows.h>
-#include <sys/stat.h>
#include <limits.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Directory.h>
+#include <sys/stat.h>
+#include <windows.h>
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
+#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
+#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
+#define STDERR_FILENO 2
#endif
-namespace mcld{
-namespace sys{
-namespace fs{
-namespace detail{
+namespace mcld {
+namespace sys {
+namespace fs {
+namespace detail {
// FIXME: the extension depends on target machine, not host machine.
Path::StringType static_library_extension = ".a";
Path::StringType shared_library_extension = ".so";
-Path::StringType executable_extension = ".exe";
-Path::StringType relocatable_extension = ".o";
-Path::StringType assembly_extension = ".s";
-Path::StringType bitcode_extension = ".bc";
+Path::StringType executable_extension = ".exe";
+Path::StringType relocatable_extension = ".o";
+Path::StringType assembly_extension = ".s";
+Path::StringType bitcode_extension = ".bc";
-void open_dir(Directory& pDir)
-{
+void open_dir(Directory& pDir) {
fs::Path file_filter(pDir.path());
file_filter.append("*");
@@ -62,40 +63,34 @@
entry->setValue(path);
}
-void close_dir(Directory& pDir)
-{
+void close_dir(Directory& pDir) {
if (pDir.m_Handler)
FindClose(reinterpret_cast<HANDLE>(pDir.m_Handler));
pDir.m_Handler = 0;
}
-int open(const Path& pPath, int pOFlag)
-{
+int open(const Path& pPath, int pOFlag) {
return ::_open(pPath.native().c_str(), pOFlag | _O_BINARY);
}
-int open(const Path& pPath, int pOFlag, int pPerm)
-{
+int open(const Path& pPath, int pOFlag, int pPerm) {
int perm = 0;
- if (pPerm & FileHandle::ReadOwner ||
- pPerm & FileHandle::ReadGroup ||
+ if (pPerm & FileHandle::ReadOwner || pPerm & FileHandle::ReadGroup ||
pPerm & FileHandle::ReadOther)
perm |= _S_IREAD;
- if (pPerm & FileHandle::WriteOwner ||
- pPerm & FileHandle::WriteGroup ||
+ if (pPerm & FileHandle::WriteOwner || pPerm & FileHandle::WriteGroup ||
pPerm & FileHandle::WriteOther)
perm |= _S_IWRITE;
return ::_open(pPath.native().c_str(), pOFlag | _O_BINARY, perm);
}
-ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset) {
ssize_t ret;
off_t old_pos;
if (-1 == (old_pos = ::lseek(pFD, 0, SEEK_CUR)))
- return -1;
+ return -1;
if (-1 == ::lseek(pFD, pOffset, SEEK_SET))
return -1;
@@ -104,7 +99,7 @@
int err = errno;
::lseek(pFD, old_pos, SEEK_SET);
errno = err;
- return -1;
+ return -1;
}
if (-1 == ::lseek(pFD, old_pos, SEEK_SET))
@@ -113,8 +108,7 @@
return ret;
}
-ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset) {
ssize_t ret;
off_t old_pos;
if (-1 == (old_pos = ::lseek(pFD, 0, SEEK_CUR)))
@@ -136,38 +130,33 @@
return ret;
}
-int ftruncate(int pFD, size_t pLength)
-{
+int ftruncate(int pFD, size_t pLength) {
return ::_chsize(pFD, pLength);
}
-void get_pwd(Path& pPWD)
-{
+void get_pwd(Path& pPWD) {
char* pwd = (char*)malloc(PATH_MAX);
pPWD.assign(_getcwd(pwd, PATH_MAX));
free(pwd);
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
+} // namespace detail
+} // namespace fs
+} // namespace sys
//===----------------------------------------------------------------------===//
// FileHandle
//===----------------------------------------------------------------------===//
-bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength) {
// FIXME: This implementation reduces mmap to read. Use Windows APIs.
pMemBuffer = (void*)::malloc(pLength);
return read(pMemBuffer, pStartOffset, pLength);
}
-bool FileHandle::munmap(void* pMemBuffer, size_t pLength)
-{
+bool FileHandle::munmap(void* pMemBuffer, size_t pLength) {
// FIXME: This implementation reduces mmap to read. Use Windows APIs.
free(pMemBuffer);
return true;
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Support/Windows/PathV3.inc b/lib/Support/Windows/PathV3.inc
index 2f36c93..0372a06 100644
--- a/lib/Support/Windows/PathV3.inc
+++ b/lib/Support/Windows/PathV3.inc
@@ -6,23 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Path.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "mcld/Support/Path.h"
+
#include <stack>
-namespace mcld{
-namespace sys{
-namespace fs{
+#include <sys/stat.h>
+#include <sys/types.h>
+
+namespace mcld {
+namespace sys {
+namespace fs {
//===----------------------------------------------------------------------===//
// mcld::sys::fs::detail
//===----------------------------------------------------------------------===//
-namespace detail{
+namespace detail {
// return the last charactor being handled.
-size_t canonicalize(std::string& pathname)
-{
+size_t canonicalize(std::string& pathname) {
// Variable Index //
// SepTable - stack of result separators
// LR(1) Algorithm //
@@ -47,12 +48,12 @@
std::stack<size_t> slash_stack;
slash_stack.push(-1);
while (handler < pathname.size()) {
- if (separator == pathname[handler]) { // handler = 1st '/'
+ if (separator == pathname[handler]) { // handler = 1st '/'
size_t next = handler + 1;
if (next >= pathname.size())
return handler;
- switch(pathname[next]) { // next = handler + 1;
- case separator: { // '//'
+ switch (pathname[next]) { // next = handler + 1;
+ case separator: { // '//'
while (next < pathname.size() && separator == pathname[next])
++next;
// next is the last not '/'
@@ -61,97 +62,89 @@
slash_stack.push(handler);
break;
}
- case '.': { // '/.'
- ++next; // next = handler + 2
- if (next >= pathname.size()) // '/.'
+ case '.': { // '/.'
+ ++next; // next = handler + 2
+ if (next >= pathname.size()) // '/.'
return handler;
switch (pathname[next]) {
- case separator: { // '/./'
+ case separator: { // '/./'
pathname.erase(handler, 2);
break;
}
- case '.': { // '/..'
- ++next; // next = handler + 3;
- if (next >= pathname.size()) // '/..?'
+ case '.': { // '/..'
+ ++next; // next = handler + 3;
+ if (next >= pathname.size()) // '/..?'
return handler;
- switch(pathname[next]) {
- case separator: { // '/../'
+ switch (pathname[next]) {
+ case separator: { // '/../'
handler = slash_stack.top();
slash_stack.pop();
- pathname.erase(handler+1, next-handler);
+ pathname.erase(handler + 1, next - handler);
if (static_cast<size_t>(-1) == handler) {
slash_stack.push(-1);
handler = pathname.find_first_of(separator, handler);
}
break;
}
- case '.': { // '/...', illegal
+ case '.': { // '/...', illegal
return handler;
break;
}
- default : { // '/..a'
+ default: { // '/..a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+3);
+ handler = pathname.find_first_of(separator, handler + 3);
break;
}
}
break;
}
- default : { // '/.a'
+ default: { // '/.a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+2);
+ handler = pathname.find_first_of(separator, handler + 2);
break;
}
}
break;
}
- default : { // '/a
+ default: { // '/a
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+1);
+ handler = pathname.find_first_of(separator, handler + 1);
break;
}
}
- }
- else {
+ } else {
handler = pathname.find_first_of(separator, handler);
}
}
return handler;
}
-bool not_found_error(int perrno)
-{
+bool not_found_error(int perrno) {
return perrno == ENOENT || perrno == ENOTDIR;
}
-void status(const Path& p, FileStatus& pFileStatus)
-{
+void status(const Path& p, FileStatus& pFileStatus) {
struct ::_stat path_stat;
- if(::_stat(p.c_str(), &path_stat)!= 0)
- {
- if(not_found_error(errno))
- {
+ if (::_stat(p.c_str(), &path_stat) != 0) {
+ if (not_found_error(errno)) {
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
- }
- else if(S_ISDIR(path_stat.st_mode))
+ } else if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- else if(S_ISREG(path_stat.st_mode))
+ else if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- else if(S_ISBLK(path_stat.st_mode))
+ else if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- else if(S_ISCHR(path_stat.st_mode))
+ else if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- else if(S_ISFIFO(path_stat.st_mode))
+ else if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
else
pFileStatus.setType(TypeUnknown);
}
-void symlink_status(const Path& p, FileStatus& pFileStatus)
-{
+void symlink_status(const Path& p, FileStatus& pFileStatus) {
pFileStatus.setType(FileNotFound);
}
@@ -162,8 +155,7 @@
// of cache. (a real end)
// 2. Some but not all elements had beed put into cache, and we stoped.
// An iterator now is staying at the end of cache. (a temporal end)
-mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter)
-{
+mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter) {
mcld::sys::fs::PathCache::entry_type* entry = 0;
fs::Path file_filter(pIter.m_pParent->m_Path);
file_filter.append("*");
@@ -179,21 +171,18 @@
entry = pIter.m_pParent->m_Cache.insert(path, exist);
if (!exist)
entry->setValue(path);
- }
- else if (ERROR_NO_MORE_FILES == GetLastError()){
+ } else if (ERROR_NO_MORE_FILES == GetLastError()) {
// meet real end
pIter.m_pParent->m_CacheFull = true;
- }
- else {
- llvm::report_fatal_error(std::string("Can't read directory: ")+
+ } else {
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
pIter.m_pParent->path().native());
}
return entry;
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace detail
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Windows/System.inc b/lib/Support/Windows/System.inc
index 9102963..e45ad36 100644
--- a/lib/Support/Windows/System.inc
+++ b/lib/Support/Windows/System.inc
@@ -7,49 +7,44 @@
//
//===----------------------------------------------------------------------===//
#include <string>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+
#include <cstdlib>
#include <cstring>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <windows.h>
-namespace mcld{
-namespace sys{
+namespace mcld {
+namespace sys {
-char* strerror(int errnum)
-{
+char* strerror(int errnum) {
return std::strerror(errnum);
}
-std::string getDefaultTargetTriple()
-{
+std::string getDefaultTargetTriple() {
return MCLD_DEFAULT_TARGET_TRIPLE;
}
-int GetPageSize()
-{
+int GetPageSize() {
static int _pagesize = 0;
- if (! _pagesize) {
+ if (!_pagesize) {
SYSTEM_INFO sysinfo;
- GetSystemInfo (&sysinfo);
+ GetSystemInfo(&sysinfo);
_pagesize = sysinfo.dwPageSize;
}
return _pagesize;
}
/// random - generate a random number.
-long GetRandomNum()
-{
+long GetRandomNum() {
return ::rand();
}
/// srandom - set the initial seed value for future calls to random().
-void SetRandomSeed(unsigned pSeed)
-{
+void SetRandomSeed(unsigned pSeed) {
::srand(pSeed);
}
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 32e362a..4da1237 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -6,87 +6,80 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/raw_ostream.h"
#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
+#include <unistd.h>
#endif
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) || defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
-#include <io.h>
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
+#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
+#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
+#define STDERR_FILENO 2
#endif
#endif
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// raw_ostream
//===----------------------------------------------------------------------===//
-mcld::raw_fd_ostream::raw_fd_ostream(const char *pFilename,
- std::string &pErrorInfo,
- llvm::sys::fs::OpenFlags pFlags)
- : llvm::raw_fd_ostream(pFilename, pErrorInfo, pFlags),
- m_bConfigColor(false),
- m_bSetColor(false) {
+raw_fd_ostream::raw_fd_ostream(const char* pFilename,
+ std::error_code& pErrorCode,
+ llvm::sys::fs::OpenFlags pFlags)
+ : llvm::raw_fd_ostream(pFilename, pErrorCode, pFlags),
+ m_bConfigColor(false),
+ m_bSetColor(false) {
}
-mcld::raw_fd_ostream::raw_fd_ostream(int pFD,
+raw_fd_ostream::raw_fd_ostream(int pFD,
bool pShouldClose,
bool pUnbuffered)
- : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered),
- m_bConfigColor(false),
- m_bSetColor(false) {
+ : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered),
+ m_bConfigColor(false),
+ m_bSetColor(false) {
}
-mcld::raw_fd_ostream::~raw_fd_ostream()
-{
+raw_fd_ostream::~raw_fd_ostream() {
}
-void mcld::raw_fd_ostream::setColor(bool pEnable)
-{
+void raw_fd_ostream::setColor(bool pEnable) {
m_bConfigColor = true;
m_bSetColor = pEnable;
}
-llvm::raw_ostream &
-mcld::raw_fd_ostream::changeColor(enum llvm::raw_ostream::Colors pColor,
- bool pBold,
- bool pBackground)
-{
+llvm::raw_ostream& raw_fd_ostream::changeColor(
+ enum llvm::raw_ostream::Colors pColor,
+ bool pBold,
+ bool pBackground) {
if (!is_displayed())
return *this;
return llvm::raw_fd_ostream::changeColor(pColor, pBold, pBackground);
}
-llvm::raw_ostream& mcld::raw_fd_ostream::resetColor()
-{
+llvm::raw_ostream& raw_fd_ostream::resetColor() {
if (!is_displayed())
return *this;
return llvm::raw_fd_ostream::resetColor();
}
-llvm::raw_ostream& mcld::raw_fd_ostream::reverseColor()
-{
+llvm::raw_ostream& raw_fd_ostream::reverseColor() {
if (!is_displayed())
return *this;
return llvm::raw_ostream::reverseColor();
}
-bool mcld::raw_fd_ostream::is_displayed() const
-{
+bool raw_fd_ostream::is_displayed() const {
if (m_bConfigColor)
return m_bSetColor;
@@ -96,15 +89,16 @@
//===----------------------------------------------------------------------===//
// outs(), errs(), nulls()
//===----------------------------------------------------------------------===//
-mcld::raw_fd_ostream& mcld::outs() {
+raw_fd_ostream& outs() {
// Set buffer settings to model stdout behavior.
- static mcld::raw_fd_ostream S(STDOUT_FILENO, false);
+ static raw_fd_ostream S(STDOUT_FILENO, false);
return S;
}
-mcld::raw_fd_ostream& mcld::errs() {
+raw_fd_ostream& errs() {
// Set standard error to be unbuffered by default.
- static mcld::raw_fd_ostream S(STDERR_FILENO, false, true);
+ static raw_fd_ostream S(STDERR_FILENO, false, true);
return S;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64.h b/lib/Target/AArch64/AArch64.h
index df389e8..189fde8 100644
--- a/lib/Target/AArch64/AArch64.h
+++ b/lib/Target/AArch64/AArch64.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64_H
-#define TARGET_AARCH64_AARCH64_H
+#ifndef TARGET_AARCH64_AARCH64_H_
+#define TARGET_AARCH64_AARCH64_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -21,10 +21,9 @@
extern mcld::Target TheAArch64Target;
-TargetLDBackend *createAArch64LDBackend(const llvm::Target&,
+TargetLDBackend* createAArch64LDBackend(const llvm::Target&,
const std::string&);
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_AARCH64_AARCH64_H_
diff --git a/lib/Target/AArch64/AArch64Diagnostic.cpp b/lib/Target/AArch64/AArch64Diagnostic.cpp
index 6fddce4..e99884f 100644
--- a/lib/Target/AArch64/AArch64Diagnostic.cpp
+++ b/lib/Target/AArch64/AArch64Diagnostic.cpp
@@ -6,31 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "AArch64.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createAArch64Diagnostic - the help function to create corresponding
// AArch64Diagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createAArch64DiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeAArch64Diagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeAArch64DiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheAArch64Target,
- createAArch64DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(
+ mcld::TheAArch64Target, mcld::createAArch64DiagLineInfo);
}
-
diff --git a/lib/Target/AArch64/AArch64ELFDynamic.cpp b/lib/Target/AArch64/AArch64ELFDynamic.cpp
index 3aa572a..d1ead4f 100644
--- a/lib/Target/AArch64/AArch64ELFDynamic.cpp
+++ b/lib/Target/AArch64/AArch64ELFDynamic.cpp
@@ -8,44 +8,39 @@
//===----------------------------------------------------------------------===//
#include "AArch64ELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LinkerConfig.h"
-using namespace mcld;
+namespace mcld {
AArch64ELFDynamic::AArch64ELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-AArch64ELFDynamic::~AArch64ELFDynamic()
-{
+AArch64ELFDynamic::~AArch64ELFDynamic() {
}
-void AArch64ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void AArch64ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (config().options().hasNow()) {
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
- }
- else {
+ } else {
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
}
-void AArch64ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void AArch64ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (config().options().hasNow()) {
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
- }
- else {
+ } else {
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64ELFDynamic.h b/lib/Target/AArch64/AArch64ELFDynamic.h
index 7596da5..35dcd66 100644
--- a/lib/Target/AArch64/AArch64ELFDynamic.h
+++ b/lib/Target/AArch64/AArch64ELFDynamic.h
@@ -6,23 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64ELFDYNAMIC_H
-#define TARGET_AARCH64_AARCH64ELFDYNAMIC_H
+#ifndef TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
+#define TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class AArch64ELFDynamic : public ELFDynamic {
-public:
+ public:
AArch64ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~AArch64ELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
diff --git a/lib/Target/AArch64/AArch64ELFMCLinker.cpp b/lib/Target/AArch64/AArch64ELFMCLinker.cpp
deleted file mode 100644
index a311435..0000000
--- a/lib/Target/AArch64/AArch64ELFMCLinker.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===- AArch64ELFMCLinker.cpp ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64ELFMCLinker.h"
-
-#include <mcld/LinkerConfig.h>
-#include <mcld/Object/SectionMap.h>
-
-using namespace mcld;
-
-AArch64ELFMCLinker::AArch64ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module &pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-AArch64ELFMCLinker::~AArch64ELFMCLinker()
-{
-}
-
diff --git a/lib/Target/AArch64/AArch64ELFMCLinker.h b/lib/Target/AArch64/AArch64ELFMCLinker.h
deleted file mode 100644
index 95b4884..0000000
--- a/lib/Target/AArch64/AArch64ELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- AArch64ELFMCLinker.h -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64ELFMCLINKER_H
-#define TARGET_AARCH64_AARCH64ELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class AArch64ELFMCLinker
- * \brief AArch64ELFMCLinker sets up the environment for linking.
- */
-class AArch64ELFMCLinker : public ELFMCLinker
-{
-public:
- AArch64ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~AArch64ELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/AArch64/AArch64Emulation.cpp b/lib/Target/AArch64/AArch64Emulation.cpp
index 02f4b01..69bc493 100644
--- a/lib/Target/AArch64/AArch64Emulation.cpp
+++ b/lib/Target/AArch64/AArch64Emulation.cpp
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateAArch64ELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateAArch64ELF(LinkerScript& pScript,
+ LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -44,8 +44,7 @@
//===----------------------------------------------------------------------===//
// emulateAArch64LD - the help function to emulate AArch64 ld
//===----------------------------------------------------------------------===//
-bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -58,7 +57,7 @@
return MCLDEmulateAArch64ELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// AArch64Emulation
@@ -68,4 +67,3 @@
mcld::TargetRegistry::RegisterEmulation(mcld::TheAArch64Target,
mcld::emulateAArch64LD);
}
-
diff --git a/lib/Target/AArch64/AArch64GNUInfo.h b/lib/Target/AArch64/AArch64GNUInfo.h
index 554b27c..491d189 100644
--- a/lib/Target/AArch64/AArch64GNUInfo.h
+++ b/lib/Target/AArch64/AArch64GNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64GNUINFO_H
-#define TARGET_AARCH64_AARCH64GNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_AARCH64_AARCH64GNUINFO_H_
+#define TARGET_AARCH64_AARCH64GNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class AArch64GNUInfo : public GNUInfo
-{
-public:
- AArch64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class AArch64GNUInfo : public GNUInfo {
+ public:
+ explicit AArch64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_AARCH64; }
@@ -29,7 +28,6 @@
uint64_t flags() const { return 0x0; }
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_AARCH64_AARCH64GNUINFO_H_
diff --git a/lib/Target/AArch64/AArch64GOT.cpp b/lib/Target/AArch64/AArch64GOT.cpp
index 4864c07..0d4c7cd 100644
--- a/lib/Target/AArch64/AArch64GOT.cpp
+++ b/lib/Target/AArch64/AArch64GOT.cpp
@@ -8,57 +8,50 @@
//===----------------------------------------------------------------------===//
#include "AArch64GOT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
-
namespace {
- const unsigned int AArch64GOT0Num = 3;
-} // end of anonymous namespace
+const unsigned int AArch64GOT0Num = 3;
+} // end of anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AArch64GOT
AArch64GOT::AArch64GOT(LDSection& pSection)
- : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL)
-{
+ : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL) {
}
-AArch64GOT::~AArch64GOT()
-{
+AArch64GOT::~AArch64GOT() {
}
-void AArch64GOT::createGOT0()
-{
+void AArch64GOT::createGOT0() {
// create GOT0, and put them into m_SectionData immediately
for (unsigned int i = 0; i < AArch64GOT0Num; ++i)
new AArch64GOTEntry(0, m_SectionData);
}
-bool AArch64GOT::hasGOT1() const
-{
+bool AArch64GOT::hasGOT1() const {
return ((!m_GOT.empty()) || (!m_GOTPLT.empty()));
}
-AArch64GOTEntry* AArch64GOT::createGOT()
-{
+AArch64GOTEntry* AArch64GOT::createGOT() {
AArch64GOTEntry* entry = new AArch64GOTEntry(0, NULL);
m_GOT.push_back(entry);
return entry;
}
-AArch64GOTEntry* AArch64GOT::createGOTPLT()
-{
+AArch64GOTEntry* AArch64GOT::createGOTPLT() {
AArch64GOTEntry* entry = new AArch64GOTEntry(0, NULL);
m_GOTPLT.push_back(entry);
return entry;
}
-void AArch64GOT::finalizeSectionSize()
-{
+void AArch64GOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::FragmentListType& frag_list = m_SectionData->getFragmentList();
// setup GOT0 offset
@@ -78,7 +71,6 @@
entry->setParent(m_SectionData);
entry->setOffset(offset);
offset += entry->size();
-
}
}
m_GOTPLT.clear();
@@ -101,20 +93,18 @@
m_Section.setSize(offset);
}
-void AArch64GOT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<AArch64GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void AArch64GOT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<AArch64GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void AArch64GOT::applyGOTPLT(uint64_t pPLTBase)
-{
- if (NULL == m_pGOTPLTFront)
+void AArch64GOT::applyGOTPLT(uint64_t pPLTBase) {
+ if (m_pGOTPLTFront == NULL)
return;
SectionData::iterator entry(m_pGOTPLTFront);
SectionData::iterator e_end;
- if (NULL == m_pGOTFront)
+ if (m_pGOTFront == NULL)
e_end = m_SectionData->end();
else
e_end = SectionData::iterator(m_pGOTFront);
@@ -125,17 +115,17 @@
}
}
-uint64_t AArch64GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t AArch64GOT::emit(MemoryRegion& pRegion) {
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
AArch64GOTEntry* got = NULL;
uint64_t result = 0x0;
for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
- got = &(llvm::cast<AArch64GOTEntry>((*it)));
- *buffer = static_cast<uint64_t>(got->getValue());
- result += AArch64GOTEntry::EntrySize;
+ got = &(llvm::cast<AArch64GOTEntry>((*it)));
+ *buffer = static_cast<uint64_t>(got->getValue());
+ result += AArch64GOTEntry::EntrySize;
}
return result;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64GOT.h b/lib/Target/AArch64/AArch64GOT.h
index 0e46e9e..f790e8b 100644
--- a/lib/Target/AArch64/AArch64GOT.h
+++ b/lib/Target/AArch64/AArch64GOT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64GOT_H
-#define TARGET_AARCH64_AARCH64GOT_H
+#ifndef TARGET_AARCH64_AARCH64GOT_H_
+#define TARGET_AARCH64_AARCH64GOT_H_
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Target/GOT.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
@@ -23,12 +23,10 @@
/** \class AArch64GOTEntry
* \brief GOT Entry with size of 8 bytes
*/
-class AArch64GOTEntry : public GOT::Entry<8>
-{
-public:
+class AArch64GOTEntry : public GOT::Entry<8> {
+ public:
AArch64GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<8>(pContent, pParent)
- {}
+ : GOT::Entry<8>(pContent, pParent) {}
};
/** \class AArch64GOT
@@ -53,10 +51,9 @@
* +--------------+
*
*/
-class AArch64GOT : public GOT
-{
-public:
- AArch64GOT(LDSection &pSection);
+class AArch64GOT : public GOT {
+ public:
+ explicit AArch64GOT(LDSection& pSection);
~AArch64GOT();
@@ -78,12 +75,12 @@
bool hasGOT1() const;
-private:
+ private:
typedef std::vector<AArch64GOTEntry*> EntryListType;
typedef EntryListType::iterator entry_iterator;
typedef EntryListType::const_iterator const_entry_iterator;
-private:
+ private:
AArch64GOTEntry* m_pGOTPLTFront;
AArch64GOTEntry* m_pGOTFront;
@@ -94,7 +91,6 @@
EntryListType m_GOT;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_AARCH64_AARCH64GOT_H_
diff --git a/lib/Target/AArch64/AArch64LDBackend.cpp b/lib/Target/AArch64/AArch64LDBackend.cpp
index cf07428..9224275 100644
--- a/lib/Target/AArch64/AArch64LDBackend.cpp
+++ b/lib/Target/AArch64/AArch64LDBackend.cpp
@@ -12,57 +12,53 @@
#include "AArch64LDBackend.h"
#include "AArch64Relocator.h"
-#include <cstring>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
-#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AArch64GNULDBackend
//===----------------------------------------------------------------------===//
AArch64GNULDBackend::AArch64GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pGOTPLT(NULL),
- m_pPLT(NULL),
- m_pRelaDyn(NULL),
- m_pRelaPLT(NULL),
- // m_pAttrData(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL)
- // m_pAttributes(NULL)
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL),
+ m_pPLT(NULL),
+ m_pRelaDyn(NULL),
+ m_pRelaPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL) {
}
-AArch64GNULDBackend::~AArch64GNULDBackend()
-{
+AArch64GNULDBackend::~AArch64GNULDBackend() {
if (m_pRelocator != NULL)
delete m_pRelocator;
if (m_pGOT == m_pGOTPLT) {
@@ -85,10 +81,7 @@
}
void AArch64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
- // TODO
-
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
@@ -101,8 +94,7 @@
// set m_pGOTPLT to the same .got
m_pGOT->createGOT0();
m_pGOTPLT = m_pGOT;
- }
- else {
+ } else {
// Otherwise, got should be seperated to two sections, .got and .got.plt
// initialize .got.plt
LDSection& gotplt = file_format->getGOTPLT();
@@ -126,93 +118,83 @@
}
void AArch64GNULDBackend::initTargetSymbols(IRBuilder& pBuilder,
- Module& pModule)
-{
+ Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
if (LinkerConfig::Object != config().codeGenType()) {
- m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ m_pGOTSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
- // TODO
}
-bool AArch64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool AArch64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new AArch64Relocator(*this, config());
}
return true;
}
-const Relocator* AArch64GNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* AArch64GNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* AArch64GNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* AArch64GNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void AArch64GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void AArch64GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// define symbol _GLOBAL_OFFSET_TABLE_ when .got create
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
-void AArch64GNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void AArch64GNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new AArch64ELFDynamic(*this, config());
if (LinkerConfig::Object != config().codeGenType()) {
// set .got size
if (config().options().hasNow()) {
// when building shared object, the GOTPLT section is must
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
- }
- else {
+ } else {
// when building shared object, the GOTPLT section is must
if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ m_pGOTPLT->hasGOT1() || m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
@@ -227,37 +209,38 @@
ELFFileFormat* file_format = getOutputFormat();
// set .rela.dyn size
if (!m_pRelaDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelaDyn().setSize(
- m_pRelaDyn->numOfRelocs() * getRelaEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelaDyn().setSize(m_pRelaDyn->numOfRelocs() *
+ getRelaEntrySize());
}
// set .rela.plt size
if (!m_pRelaPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelaPlt().setSize(
- m_pRelaPLT->numOfRelocs() * getRelaEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelaPlt().setSize(m_pRelaPLT->numOfRelocs() *
+ getRelaEntrySize());
}
}
}
-void AArch64GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *file_format = getOutputFormat();
+void AArch64GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* file_format = getOutputFormat();
// apply PLT
if (file_format->hasPLT()) {
- assert(NULL != m_pPLT);
+ assert(m_pPLT != NULL);
m_pPLT->applyPLT0();
m_pPLT->applyPLT1();
}
// apply GOTPLT
if ((config().options().hasNow() && file_format->hasGOT()) ||
- file_format->hasGOTPLT()) {
- assert(NULL != m_pGOTPLT);
+ file_format->hasGOTPLT()) {
+ assert(m_pGOTPLT != NULL);
if (LinkerConfig::DynObj == config().codeGenType())
m_pGOTPLT->applyGOT0(file_format->getDynamic().addr());
else {
@@ -267,21 +250,18 @@
}
}
-AArch64ELFDynamic& AArch64GNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+AArch64ELFDynamic& AArch64GNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-const AArch64ELFDynamic& AArch64GNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const AArch64ELFDynamic& AArch64GNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t AArch64GNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -305,9 +285,8 @@
return pRegion.size();
}
-unsigned int
-AArch64GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int AArch64GNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -327,111 +306,92 @@
bool AArch64GNULDBackend::doRelax(Module& pModule,
IRBuilder& pBuilder,
- bool& pFinished)
-{
+ bool& pFinished) {
// TODO
return false;
}
-bool AArch64GNULDBackend::initTargetStubs()
-{
+bool AArch64GNULDBackend::initTargetStubs() {
// TODO
return true;
}
-void AArch64GNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void AArch64GNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-bool AArch64GNULDBackend::finalizeTargetSymbols()
-{
+bool AArch64GNULDBackend::finalizeTargetSymbols() {
// TODO
return true;
}
bool AArch64GNULDBackend::mergeSection(Module& pModule,
const Input& pInput,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// TODO
return true;
}
-bool AArch64GNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool AArch64GNULDBackend::readSection(Input& pInput, SectionData& pSD) {
// TODO
return true;
}
-AArch64GOT& AArch64GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+AArch64GOT& AArch64GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-const AArch64GOT& AArch64GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+const AArch64GOT& AArch64GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-AArch64GOT& AArch64GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT && "GOTPLT section not exist");
+AArch64GOT& AArch64GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL && "GOTPLT section not exist");
return *m_pGOTPLT;
}
-const AArch64GOT& AArch64GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT && "GOTPLT section not exist");
+const AArch64GOT& AArch64GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL && "GOTPLT section not exist");
return *m_pGOTPLT;
}
-AArch64PLT& AArch64GNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+AArch64PLT& AArch64GNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const AArch64PLT& AArch64GNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const AArch64PLT& AArch64GNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& AArch64GNULDBackend::getRelaDyn()
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+OutputRelocSection& AArch64GNULDBackend::getRelaDyn() {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-const OutputRelocSection& AArch64GNULDBackend::getRelaDyn() const
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+const OutputRelocSection& AArch64GNULDBackend::getRelaDyn() const {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-OutputRelocSection& AArch64GNULDBackend::getRelaPLT()
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+OutputRelocSection& AArch64GNULDBackend::getRelaPLT() {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-const OutputRelocSection& AArch64GNULDBackend::getRelaPLT() const
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+const OutputRelocSection& AArch64GNULDBackend::getRelaPLT() const {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
// createAArch64LDBackend - the help funtion to create corresponding
// AArch64LDBackend
//===----------------------------------------------------------------------===//
-TargetLDBackend* createAArch64LDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createAArch64LDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -448,18 +408,17 @@
createAArch64COFFObjectWriter);
**/
}
- return new AArch64GNULDBackend(pConfig,
- new AArch64GNUInfo(pConfig.targets().triple()));
+ return new AArch64GNULDBackend(
+ pConfig, new AArch64GNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeAArch64LDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheAArch64Target,
- createAArch64LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheAArch64Target,
+ mcld::createAArch64LDBackend);
}
-
diff --git a/lib/Target/AArch64/AArch64LDBackend.h b/lib/Target/AArch64/AArch64LDBackend.h
index 00e14fa..b94d535 100644
--- a/lib/Target/AArch64/AArch64LDBackend.h
+++ b/lib/Target/AArch64/AArch64LDBackend.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64LDBACKEND_H
-#define TARGET_AARCH64_AARCH64LDBACKEND_H
+#ifndef TARGET_AARCH64_AARCH64LDBACKEND_H_
+#define TARGET_AARCH64_AARCH64LDBACKEND_H_
#include "AArch64ELFDynamic.h"
#include "AArch64GOT.h"
#include "AArch64PLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
@@ -24,17 +24,16 @@
//===----------------------------------------------------------------------===//
/// AArch64GNULDBackend - linker backend of AArch64 target of GNU ELF format
///
-class AArch64GNULDBackend : public GNULDBackend
-{
-public:
+class AArch64GNULDBackend : public GNULDBackend {
+ public:
static const int64_t AARCH64_MAX_FWD_BRANCH_OFFSET = (((1 << 25) - 1) << 2);
static const int64_t AARCH64_MAX_BWD_BRANCH_OFFSET = (-((1 << 25) << 2));
-public:
+ public:
AArch64GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~AArch64GNULDBackend();
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output.
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -62,7 +61,6 @@
/// Use co-variant return type to return its own dynamic section.
const AArch64ELFDynamic& dynamic() const;
-
/// emitSectionData - write out the section data into the memory region.
/// When writers get a LDSection whose kind is LDFileFormat::Target, writers
/// call back target backend to emit the data.
@@ -96,10 +94,11 @@
OutputRelocSection& getRelaPLT();
const OutputRelocSection& getRelaPLT() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
- /// getTargetSectionOrder - compute the layout order of AArch64 target sections
+ /// getTargetSectionOrder - compute the layout order of AArch64 target
+ /// sections
unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const;
/// finalizeTargetSymbols - finalize the symbol value
@@ -111,7 +110,7 @@
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
int64_t maxFwdBranchOffset() { return AARCH64_MAX_FWD_BRANCH_OFFSET; }
@@ -130,18 +129,16 @@
bool initTargetStubs();
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return 16; }
+ size_t getRelEntrySize() { return 16; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return 24; }
+ size_t getRelaEntrySize() { return 24; }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
virtual void doCreateProgramHdrs(Module& pModule);
-private:
+ private:
Relocator* m_pRelocator;
AArch64GOT* m_pGOT;
@@ -164,7 +161,7 @@
// LDSection* m_pDebugOverlay; // .AArch64.debug_overlay
// LDSection* m_pOverlayTable; // .AArch64.overlay_table
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64LDBACKEND_H_
diff --git a/lib/Target/AArch64/AArch64MCLinker.cpp b/lib/Target/AArch64/AArch64MCLinker.cpp
deleted file mode 100644
index 538461a..0000000
--- a/lib/Target/AArch64/AArch64MCLinker.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-//===- AArch64MCLinker.cpp-------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64ELFMCLinker.h"
-
-#include "AArch64.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-namespace mcld {
-//===----------------------------------------------------------------------===//
-// createAArch64MCLinker - the help function to create corresponding
-// AArch64MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createAArch64MCLinker(const std::string& pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new AArch64ELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// AArch64MCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeAArch64MCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheAArch64Target,
- createAArch64MCLinker);
-}
-
diff --git a/lib/Target/AArch64/AArch64PLT.cpp b/lib/Target/AArch64/AArch64PLT.cpp
index c24327d..e9c8cee 100644
--- a/lib/Target/AArch64/AArch64PLT.cpp
+++ b/lib/Target/AArch64/AArch64PLT.cpp
@@ -10,40 +10,39 @@
#include "AArch64PLT.h"
#include "AArch64RelocationHelpers.h"
-#include <new>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
+#include <new>
-using namespace mcld;
+namespace mcld {
AArch64PLT0::AArch64PLT0(SectionData& pParent)
- : PLT::Entry<sizeof(aarch64_plt0)>(pParent) {}
+ : PLT::Entry<sizeof(aarch64_plt0)>(pParent) {
+}
AArch64PLT1::AArch64PLT1(SectionData& pParent)
- : PLT::Entry<sizeof(aarch64_plt1)>(pParent) {}
+ : PLT::Entry<sizeof(aarch64_plt1)>(pParent) {
+}
//===----------------------------------------------------------------------===//
// AArch64PLT
-AArch64PLT::AArch64PLT(LDSection& pSection, AArch64GOT &pGOTPLT)
- : PLT(pSection), m_GOT(pGOTPLT) {
+AArch64PLT::AArch64PLT(LDSection& pSection, AArch64GOT& pGOTPLT)
+ : PLT(pSection), m_GOT(pGOTPLT) {
new AArch64PLT0(*m_pSectionData);
}
-AArch64PLT::~AArch64PLT()
-{
+AArch64PLT::~AArch64PLT() {
}
-bool AArch64PLT::hasPLT1() const
-{
+bool AArch64PLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-void AArch64PLT::finalizeSectionSize()
-{
+void AArch64PLT::finalizeSectionSize() {
uint64_t size = (m_pSectionData->size() - 1) * sizeof(aarch64_plt1) +
sizeof(aarch64_plt0);
m_Section.setSize(size);
@@ -56,16 +55,14 @@
}
}
-AArch64PLT1* AArch64PLT::create()
-{
+AArch64PLT1* AArch64PLT::create() {
AArch64PLT1* plt1_entry = new (std::nothrow) AArch64PLT1(*m_pSectionData);
if (!plt1_entry)
fatal(diag::fail_allocate_memory_plt);
return plt1_entry;
}
-void AArch64PLT::applyPLT0()
-{
+void AArch64PLT::applyPLT0() {
// malloc plt0
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -87,20 +84,20 @@
// get the address of got entry 2
uint64_t got_ent2_base = got_base + sizeof(AArch64GOTEntry::EntrySize) * 2;
// compute the immediate
- AArch64Relocator::DWord imm = helper_get_page_address(got_ent2_base) -
- helper_get_page_address(plt_base + (sizeof(AArch64PLT0::EntrySize) * 8));
+ AArch64Relocator::DWord imm =
+ helper_get_page_address(got_ent2_base) -
+ helper_get_page_address(plt_base + (sizeof(AArch64PLT0::EntrySize) * 8));
data[1] = helper_reencode_adr_imm(data[1], imm >> 12);
// apply 3rd instruction
data[2] = helper_reencode_add_imm(data[2],
helper_get_page_offset(got_ent2_base) >> 3);
// apply 4th instruction
- data[3] = helper_reencode_add_imm(data[3],
- helper_get_page_offset(got_ent2_base));
+ data[3] =
+ helper_reencode_add_imm(data[3], helper_get_page_offset(got_ent2_base));
plt0->setValue(reinterpret_cast<unsigned char*>(data));
}
-void AArch64PLT::applyPLT1()
-{
+void AArch64PLT::applyPLT1() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -117,7 +114,7 @@
// first plt1 address
uint32_t PLTEntryAddress = plt_base + AArch64PLT0::EntrySize;
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint32_t PLT1EntrySize = AArch64PLT1::EntrySize;
AArch64PLT1* plt1 = NULL;
@@ -134,8 +131,8 @@
Out[1] = helper_reencode_add_imm(
Out[1], helper_get_page_offset(GOTEntryAddress) >> 3);
// apply 3rd instruction
- Out[2] = helper_reencode_add_imm(
- Out[2], helper_get_page_offset(GOTEntryAddress));
+ Out[2] = helper_reencode_add_imm(Out[2],
+ helper_get_page_offset(GOTEntryAddress));
plt1->setValue(reinterpret_cast<unsigned char*>(Out));
++it;
@@ -147,14 +144,14 @@
m_GOT.applyGOTPLT(plt_base);
}
-uint64_t AArch64PLT::emit(MemoryRegion& pRegion)
-{
+uint64_t AArch64PLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
unsigned char* buffer = pRegion.begin();
- memcpy(buffer, llvm::cast<AArch64PLT0>((*it)).getValue(),
- AArch64PLT0::EntrySize);
+ memcpy(buffer,
+ llvm::cast<AArch64PLT0>((*it)).getValue(),
+ AArch64PLT0::EntrySize);
result += AArch64PLT0::EntrySize;
++it;
@@ -169,3 +166,4 @@
return result;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64PLT.h b/lib/Target/AArch64/AArch64PLT.h
index c63e2e0..cab067a 100644
--- a/lib/Target/AArch64/AArch64PLT.h
+++ b/lib/Target/AArch64/AArch64PLT.h
@@ -6,57 +6,50 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64PLT_H
-#define TARGET_AARCH64_AARCH64PLT_H
+#ifndef TARGET_AARCH64_AARCH64PLT_H_
+#define TARGET_AARCH64_AARCH64PLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
const uint8_t aarch64_plt0[] = {
- 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
- 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
- 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
- 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
- 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
- 0x1f, 0x20, 0x03, 0xd5, /* nop */
- 0x1f, 0x20, 0x03, 0xd5, /* nop */
- 0x1f, 0x20, 0x03, 0xd5 /* nop */
+ 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
+ 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
+ 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
+ 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
+ 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
+ 0x1f, 0x20, 0x03, 0xd5, /* nop */
+ 0x1f, 0x20, 0x03, 0xd5, /* nop */
+ 0x1f, 0x20, 0x03, 0xd5 /* nop */
};
const uint8_t aarch64_plt1[] = {
- 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
- 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
- 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
- 0x20, 0x02, 0x1f, 0xd6 /* br x17. */
+ 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
+ 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
+ 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
+ 0x20, 0x02, 0x1f, 0xd6 /* br x17. */
};
-} // anonymous namespace
-
namespace mcld {
class AArch64GOT;
-class AArch64PLT0 : public PLT::Entry<sizeof(aarch64_plt0)>
-{
-public:
+class AArch64PLT0 : public PLT::Entry<sizeof(aarch64_plt0)> {
+ public:
AArch64PLT0(SectionData& pParent);
};
-class AArch64PLT1 : public PLT::Entry<sizeof(aarch64_plt1)>
-{
-public:
+class AArch64PLT1 : public PLT::Entry<sizeof(aarch64_plt1)> {
+ public:
AArch64PLT1(SectionData& pParent);
};
/** \class AArch64PLT
* \brief AArch64 Procedure Linkage Table
*/
-class AArch64PLT : public PLT
-{
-public:
+class AArch64PLT : public PLT {
+ public:
AArch64PLT(LDSection& pSection, AArch64GOT& pGOTPLT);
~AArch64PLT();
@@ -76,11 +69,10 @@
uint64_t emit(MemoryRegion& pRegion);
-private:
+ private:
AArch64GOT& m_GOT;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_AARCH64_AARCH64PLT_H_
diff --git a/lib/Target/AArch64/AArch64RelocationFunctions.h b/lib/Target/AArch64/AArch64RelocationFunctions.h
index 14c8c73..65a8bc2 100644
--- a/lib/Target/AArch64/AArch64RelocationFunctions.h
+++ b/lib/Target/AArch64/AArch64RelocationFunctions.h
@@ -6,105 +6,110 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
+#define TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
-#define DECL_AARCH64_APPLY_RELOC_FUNC(Name) \
-static AArch64Relocator::Result Name (Relocation& pEntry, AArch64Relocator& pParent);
+#define DECL_AARCH64_APPLY_RELOC_FUNC(Name) \
+ static AArch64Relocator::Result Name(Relocation& pEntry, \
+ AArch64Relocator& pParent);
-#define DECL_AARCH64_APPLY_RELOC_FUNCS \
-DECL_AARCH64_APPLY_RELOC_FUNC(none) \
-DECL_AARCH64_APPLY_RELOC_FUNC(abs) \
-DECL_AARCH64_APPLY_RELOC_FUNC(rel) \
-DECL_AARCH64_APPLY_RELOC_FUNC(call) \
-DECL_AARCH64_APPLY_RELOC_FUNC(condbr) \
-DECL_AARCH64_APPLY_RELOC_FUNC(adr_prel_pg_hi21) \
-DECL_AARCH64_APPLY_RELOC_FUNC(add_abs_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(adr_got_page) \
-DECL_AARCH64_APPLY_RELOC_FUNC(ld64_got_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(ldst_abs_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(unsupport)
+#define DECL_AARCH64_APPLY_RELOC_FUNCS \
+ DECL_AARCH64_APPLY_RELOC_FUNC(none) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(abs) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(rel) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(call) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(condbr) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(adr_prel_pg_hi21) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(add_abs_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(adr_got_page) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(ld64_got_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(ldst_abs_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(unsupported)
-#define DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ValueType, MappedType) \
- ValueType(0x0, MappedType(&none, "R_AARCH64_NULL")), \
- ValueType(0x100, MappedType(&none, "R_AARCH64_NONE")), \
- ValueType(0x101, MappedType(&abs, "R_AARCH64_ABS64", 64)), \
- ValueType(0x102, MappedType(&abs, "R_AARCH64_ABS32", 32)), \
- ValueType(0x103, MappedType(&abs, "R_AARCH64_ABS16", 16)), \
- ValueType(0x104, MappedType(&rel, "R_AARCH64_PREL64", 64)), \
- ValueType(0x105, MappedType(&rel, "R_AARCH64_PREL32", 32)), \
- ValueType(0x106, MappedType(&rel, "R_AARCH64_PREL16", 16)), \
- ValueType(0x107, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G0")), \
- ValueType(0x108, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G0_NC")), \
- ValueType(0x109, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G1")), \
- ValueType(0x10a, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G1_NC")), \
- ValueType(0x10b, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G2")), \
- ValueType(0x10c, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G2_NC")), \
- ValueType(0x10d, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G3")), \
- ValueType(0x10e, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G0")), \
- ValueType(0x10f, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G1")), \
- ValueType(0x110, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G2")), \
- ValueType(0x111, MappedType(&unsupport, "R_AARCH64_LD_PREL_LO19")), \
- ValueType(0x112, MappedType(&unsupport, "R_AARCH64_ADR_PREL_LO21")), \
- ValueType(0x113, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21", 32)), \
- ValueType(0x114, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21_NC", 32)), \
- ValueType(0x115, MappedType(&add_abs_lo12, "R_AARCH64_ADD_ABS_LO12_NC", 32)), \
- ValueType(0x116, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST8_ABS_LO12_NC", 32)), \
- ValueType(0x117, MappedType(&unsupport, "R_AARCH64_TSTBR14")), \
- ValueType(0x118, MappedType(&condbr, "R_AARCH64_CONDBR19", 32)), \
- ValueType(0x11a, MappedType(&call, "R_AARCH64_JUMP26", 32)), \
- ValueType(0x11b, MappedType(&call, "R_AARCH64_CALL26", 32)), \
- ValueType(0x11c, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST16_ABS_LO12_NC", 32)), \
- ValueType(0x11d, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST32_ABS_LO12_NC", 32)), \
- ValueType(0x11e, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST64_ABS_LO12_NC", 32)), \
- ValueType(0x12b, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST128_ABS_LO12_NC", 32)), \
- ValueType(0x137, MappedType(&adr_got_page, "R_AARCH64_ADR_GOT_PAGE", 32)), \
- ValueType(0x138, MappedType(&ld64_got_lo12, "R_AARCH64_LD64_GOT_LO12_NC", 32)), \
- ValueType(0x20b, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G2")), \
- ValueType(0x20c, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G1")), \
- ValueType(0x20d, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC")), \
- ValueType(0x20e, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G0")), \
- ValueType(0x20f, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC")), \
- ValueType(0x210, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_HI12")), \
- ValueType(0x211, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_LO12")), \
- ValueType(0x212, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC")), \
- ValueType(0x213, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12")), \
- ValueType(0x214, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC")), \
- ValueType(0x215, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12")), \
- ValueType(0x216, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC")), \
- ValueType(0x217, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12")), \
- ValueType(0x218, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC")), \
- ValueType(0x219, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12")), \
- ValueType(0x21a, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC")), \
- ValueType(0x21b, MappedType(&unsupport, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G1")), \
- ValueType(0x21c, MappedType(&unsupport, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC")), \
- ValueType(0x21d, MappedType(&unsupport, "R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21")), \
- ValueType(0x21e, MappedType(&unsupport, "R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC")), \
- ValueType(0x21f, MappedType(&unsupport, "R_AARCH64_TLSIE_LD_GOTTPREL_PREL19")), \
- ValueType(0x220, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G2")), \
- ValueType(0x221, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G1")), \
- ValueType(0x222, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G1_NC")), \
- ValueType(0x223, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G0")), \
- ValueType(0x224, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G0_NC")), \
- ValueType(0x225, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_HI12")), \
- ValueType(0x226, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_LO12")), \
- ValueType(0x227, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_LO12_NC")), \
- ValueType(0x228, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST8_TPREL_LO12")), \
- ValueType(0x229, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC")), \
- ValueType(0x22a, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST16_TPREL_LO12")), \
- ValueType(0x22b, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC")), \
- ValueType(0x22c, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST32_TPREL_LO12")), \
- ValueType(0x22d, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC")), \
- ValueType(0x22e, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST64_TPREL_LO12")), \
- ValueType(0x22f, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC")), \
- ValueType(0x232, MappedType(&unsupport, "R_AARCH64_TLSDESC_ADR_PAGE")), \
- ValueType(0x233, MappedType(&unsupport, "R_AARCH64_TLSDESC_LD64_LO12_NC")), \
- ValueType(0x234, MappedType(&unsupport, "R_AARCH64_TLSDESC_ADD_LO12_NC")), \
- ValueType(0x239, MappedType(&unsupport, "R_AARCH64_TLSDESC_CALL")), \
- ValueType( 1024, MappedType(&unsupport, "R_AARCH64_COPY")), \
- ValueType( 1025, MappedType(&unsupport, "R_AARCH64_GLOB_DAT")), \
- ValueType( 1026, MappedType(&unsupport, "R_AARCH64_JUMP_SLOT")), \
- ValueType( 1027, MappedType(&unsupport, "R_AARCH64_RELATIVE")), \
- ValueType( 1028, MappedType(&unsupport, "R_AARCH64_TLS_DTPREL64")), \
- ValueType( 1029, MappedType(&unsupport, "R_AARCH64_TLS_DTPMOD64")), \
- ValueType( 1030, MappedType(&unsupport, "R_AARCH64_TLS_TPREL64")), \
- ValueType( 1031, MappedType(&unsupport, "R_AARCH64_TLSDESC")), \
- ValueType( 1032, MappedType(&unsupport, "R_AARCH64_IRELATIVE"))
+#define DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ValueType, MappedType) /* NOLINT */\
+ ValueType(0x0, MappedType(&none, "R_AARCH64_NULL", 0)), /* NOLINT */\
+ ValueType(0x100, MappedType(&none, "R_AARCH64_NONE", 0)), /* NOLINT */\
+ ValueType(0x101, MappedType(&abs, "R_AARCH64_ABS64", 64)), /* NOLINT */\
+ ValueType(0x102, MappedType(&abs, "R_AARCH64_ABS32", 32)), /* NOLINT */\
+ ValueType(0x103, MappedType(&abs, "R_AARCH64_ABS16", 16)), /* NOLINT */\
+ ValueType(0x104, MappedType(&rel, "R_AARCH64_PREL64", 64)), /* NOLINT */\
+ ValueType(0x105, MappedType(&rel, "R_AARCH64_PREL32", 32)), /* NOLINT */\
+ ValueType(0x106, MappedType(&rel, "R_AARCH64_PREL16", 16)), /* NOLINT */\
+ ValueType(0x107, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G0", 0)), /* NOLINT */\
+ ValueType(0x108, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x109, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G1", 0)), /* NOLINT */\
+ ValueType(0x10a, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x10b, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G2", 0)), /* NOLINT */\
+ ValueType(0x10c, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G2_NC", 0)), /* NOLINT */\
+ ValueType(0x10d, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G3", 0)), /* NOLINT */\
+ ValueType(0x10e, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G0", 0)), /* NOLINT */\
+ ValueType(0x10f, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G1", 0)), /* NOLINT */\
+ ValueType(0x110, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G2", 0)), /* NOLINT */\
+ ValueType(0x111, MappedType(&unsupported, "R_AARCH64_LD_PREL_LO19", 0)), /* NOLINT */\
+ ValueType(0x112, MappedType(&unsupported, "R_AARCH64_ADR_PREL_LO21", 0)), /* NOLINT */\
+ ValueType(0x113, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21", 32)), /* NOLINT */\
+ ValueType(0x114, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21_NC", 32)), /* NOLINT */\
+ ValueType(0x115, MappedType(&add_abs_lo12, "R_AARCH64_ADD_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x116, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST8_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x117, MappedType(&unsupported, "R_AARCH64_TSTBR14", 0)), /* NOLINT */\
+ ValueType(0x118, MappedType(&condbr, "R_AARCH64_CONDBR19", 32)), /* NOLINT */\
+ ValueType(0x11a, MappedType(&call, "R_AARCH64_JUMP26", 32)), /* NOLINT */\
+ ValueType(0x11b, MappedType(&call, "R_AARCH64_CALL26", 32)), /* NOLINT */\
+ ValueType(0x11c, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST16_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x11d, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST32_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x11e, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST64_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x12b, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST128_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x137, MappedType(&adr_got_page, "R_AARCH64_ADR_GOT_PAGE", 32)), /* NOLINT */\
+ ValueType(0x138, MappedType(&ld64_got_lo12, "R_AARCH64_LD64_GOT_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x20b, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G2", 0)), /* NOLINT */\
+ ValueType(0x20c, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x20d, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x20e, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G0", 0)), /* NOLINT */\
+ ValueType(0x20f, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x210, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_HI12", 0)), /* NOLINT */\
+ ValueType(0x211, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x212, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x213, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x214, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x215, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x216, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x217, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x218, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x219, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x21a, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x21b, MappedType(&unsupported, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x21c, MappedType(&unsupported, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x21d, MappedType(&unsupported, "R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21", 0)), /* NOLINT */\
+ ValueType(0x21e, MappedType(&unsupported, "R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x21f, MappedType(&unsupported, "R_AARCH64_TLSIE_LD_GOTTPREL_PREL19", 0)), /* NOLINT */\
+ ValueType(0x220, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G2", 0)), /* NOLINT */\
+ ValueType(0x221, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x222, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x223, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G0", 0)), /* NOLINT */\
+ ValueType(0x224, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x225, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_HI12", 0)), /* NOLINT */\
+ ValueType(0x226, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x227, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x228, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST8_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x229, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22a, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST16_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22b, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22c, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST32_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22d, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22e, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST64_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22f, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x232, MappedType(&unsupported, "R_AARCH64_TLSDESC_ADR_PAGE", 0)), /* NOLINT */\
+ ValueType(0x233, MappedType(&unsupported, "R_AARCH64_TLSDESC_LD64_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x234, MappedType(&unsupported, "R_AARCH64_TLSDESC_ADD_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x239, MappedType(&unsupported, "R_AARCH64_TLSDESC_CALL", 0)), /* NOLINT */\
+ ValueType(1024, MappedType(&unsupported, "R_AARCH64_COPY", 0)), /* NOLINT */\
+ ValueType(1025, MappedType(&unsupported, "R_AARCH64_GLOB_DAT", 0)), /* NOLINT */\
+ ValueType(1026, MappedType(&unsupported, "R_AARCH64_JUMP_SLOT", 0)), /* NOLINT */\
+ ValueType(1027, MappedType(&unsupported, "R_AARCH64_RELATIVE", 0)), /* NOLINT */\
+ ValueType(1028, MappedType(&unsupported, "R_AARCH64_TLS_DTPREL64", 0)), /* NOLINT */\
+ ValueType(1029, MappedType(&unsupported, "R_AARCH64_TLS_DTPMOD64", 0)), /* NOLINT */\
+ ValueType(1030, MappedType(&unsupported, "R_AARCH64_TLS_TPREL64", 0)), /* NOLINT */\
+ ValueType(1031, MappedType(&unsupported, "R_AARCH64_TLSDESC", 0)), /* NOLINT */\
+ ValueType(1032, MappedType(&unsupported, "R_AARCH64_IRELATIVE", 0)) /* NOLINT */
+
+#endif // TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/AArch64/AArch64RelocationHelpers.h b/lib/Target/AArch64/AArch64RelocationHelpers.h
index beb6be8..44c849d 100644
--- a/lib/Target/AArch64/AArch64RelocationHelpers.h
+++ b/lib/Target/AArch64/AArch64RelocationHelpers.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H
-#define TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H
+#ifndef TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
+#define TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
#include "AArch64Relocator.h"
#include <llvm/Support/Host.h>
@@ -17,9 +17,8 @@
// Relocation helper functions
//===----------------------------------------------------------------------===//
// Return true if overflow
-static inline bool
-helper_check_signed_overflow(Relocator::DWord pValue, unsigned bits)
-{
+static inline bool helper_check_signed_overflow(Relocator::DWord pValue,
+ unsigned bits) {
if (bits >= sizeof(int64_t) * 8)
return false;
int64_t signed_val = static_cast<int64_t>(pValue);
@@ -30,90 +29,78 @@
return false;
}
-static inline Relocator::Address
-helper_get_page_address(Relocator::Address pValue)
-{
- return (pValue & ~ (Relocator::Address) 0xFFF);
+static inline Relocator::Address helper_get_page_address(
+ Relocator::Address pValue) {
+ return (pValue & ~(Relocator::Address)0xFFF);
}
-static inline Relocator::Address
-helper_get_page_offset(Relocator::Address pValue)
-{
- return (pValue & (Relocator::Address) 0xFFF);
+static inline Relocator::Address helper_get_page_offset(
+ Relocator::Address pValue) {
+ return (pValue & (Relocator::Address)0xFFF);
}
-static inline uint32_t get_mask(uint32_t pValue)
-{
+static inline uint32_t get_mask(uint32_t pValue) {
return ((1u << (pValue)) - 1);
}
-static inline uint32_t
-helper_reencode_adr_imm(uint32_t pInst, uint32_t pImm)
-{
- return (pInst & ~((get_mask(2) << 29) | (get_mask(19) << 5)))
- | ((pImm & get_mask(2)) << 29) | ((pImm & (get_mask(19) << 2)) << 3);
+static inline uint32_t helper_reencode_adr_imm(uint32_t pInst, uint32_t pImm) {
+ return (pInst & ~((get_mask(2) << 29) | (get_mask(19) << 5))) |
+ ((pImm & get_mask(2)) << 29) | ((pImm & (get_mask(19) << 2)) << 3);
}
// Reencode the imm field of add immediate.
-static inline uint32_t helper_reencode_add_imm(uint32_t pInst, uint32_t pImm)
-{
+static inline uint32_t helper_reencode_add_imm(uint32_t pInst, uint32_t pImm) {
return (pInst & ~(get_mask(12) << 10)) | ((pImm & get_mask(12)) << 10);
}
// Encode the 26-bit offset of unconditional branch.
-static inline uint32_t
-helper_reencode_branch_offset_26(uint32_t pInst, uint32_t pOff)
-{
+static inline uint32_t helper_reencode_branch_offset_26(uint32_t pInst,
+ uint32_t pOff) {
return (pInst & ~get_mask(26)) | (pOff & get_mask(26));
}
// Encode the 19-bit offset of conditional branch and compare & branch.
-static inline uint32_t
-helper_reencode_cond_branch_ofs_19(uint32_t pInst, uint32_t pOff)
-{
+static inline uint32_t helper_reencode_cond_branch_ofs_19(uint32_t pInst,
+ uint32_t pOff) {
return (pInst & ~(get_mask(19) << 5)) | ((pOff & get_mask(19)) << 5);
}
// Reencode the imm field of ld/st pos immediate.
-static inline uint32_t
-helper_reencode_ldst_pos_imm (uint32_t pInst, uint32_t pImm)
-{
+static inline uint32_t helper_reencode_ldst_pos_imm(uint32_t pInst,
+ uint32_t pImm) {
return (pInst & ~(get_mask(12) << 10)) | ((pImm & get_mask(12)) << 10);
}
-static inline uint32_t helper_get_upper32(Relocator::DWord pData)
-{
+static inline uint32_t helper_get_upper32(Relocator::DWord pData) {
if (llvm::sys::IsLittleEndianHost)
return pData >> 32;
return pData & 0xFFFFFFFF;
}
-static inline void helper_put_upper32(uint32_t pData, Relocator::DWord& pDes)
-{
+static inline void helper_put_upper32(uint32_t pData, Relocator::DWord& pDes) {
*(reinterpret_cast<uint32_t*>(&pDes)) = pData;
}
-static inline Relocator::Address
-helper_get_PLT_address(ResolveInfo& pSym, AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_get_PLT_address(
+ ResolveInfo& pSym,
+ AArch64Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static inline AArch64PLT1&
-helper_PLT_init(Relocation& pReloc, AArch64Relocator& pParent)
-{
+static inline AArch64PLT1& helper_PLT_init(Relocation& pReloc,
+ AArch64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
AArch64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
AArch64PLT1* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
AArch64GOTEntry* gotplt_entry = ld_backend.getGOTPLT().createGOTPLT();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -127,18 +114,16 @@
}
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static inline Relocation&
-helper_DynRela_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- AArch64Relocator& pParent)
-{
+static inline Relocation& helper_DynRela_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ AArch64Relocator& pParent) {
AArch64GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelaDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == R_AARCH64_RELATIVE || NULL == pSym)
+ if (pType == R_AARCH64_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -148,40 +133,34 @@
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_AARCH64_RELATIVE
-static inline bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const AArch64Relocator& pParent)
-
-{
+static inline bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const AArch64Relocator& pParent) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pParent.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static inline Relocator::Address
-helper_get_GOT_address(ResolveInfo& pSym, AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_get_GOT_address(
+ ResolveInfo& pSym,
+ AArch64Relocator& pParent) {
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static inline Relocator::Address
-helper_GOT_ORG(AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_GOT_ORG(AArch64Relocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static inline AArch64GOTEntry&
-helper_GOT_init(Relocation& pReloc, bool pHasRel, AArch64Relocator& pParent)
-{
+static inline AArch64GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ AArch64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
AArch64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
AArch64GOTEntry* got_entry = ld_backend.getGOT().createGOT();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -190,17 +169,15 @@
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(AArch64Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
got_entry->setValue(AArch64Relocator::SymVal);
- Relocation& rel_entry = helper_DynRela_init(rsym, *got_entry, 0x0,
- R_AARCH64_RELATIVE, pParent);
+ Relocation& rel_entry = helper_DynRela_init(
+ rsym, *got_entry, 0x0, R_AARCH64_RELATIVE, pParent);
rel_entry.setAddend(AArch64Relocator::SymVal);
pParent.getRelRelMap().record(pReloc, rel_entry);
- }
- else {
+ } else {
helper_DynRela_init(rsym, *got_entry, 0x0, R_AARCH64_GLOB_DAT, pParent);
got_entry->setValue(0);
}
@@ -208,5 +185,6 @@
return *got_entry;
}
-}
-#endif
+} // namespace mcld
+
+#endif // TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
diff --git a/lib/Target/AArch64/AArch64Relocator.cpp b/lib/Target/AArch64/AArch64Relocator.cpp
index db99762..a884924 100644
--- a/lib/Target/AArch64/AArch64Relocator.cpp
+++ b/lib/Target/AArch64/AArch64Relocator.cpp
@@ -7,23 +7,23 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+
+#include "AArch64Relocator.h"
+#include "AArch64RelocationFunctions.h"
+#include "AArch64RelocationHelpers.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include "AArch64Relocator.h"
-#include "AArch64RelocationFunctions.h"
-#include "AArch64RelocationHelpers.h"
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Relocation Functions and Tables
@@ -36,12 +36,12 @@
// the table entry of applying functions
class ApplyFunctionEntry {
-public:
+ public:
ApplyFunctionEntry() {}
ApplyFunctionEntry(ApplyFunctionType pFunc,
const char* pName,
size_t pSize = 0)
- : func(pFunc), name(pName), size(pSize) { }
+ : func(pFunc), name(pName), size(pSize) {}
ApplyFunctionType func;
const char* name;
size_t size;
@@ -49,29 +49,27 @@
typedef std::map<Relocator::Type, ApplyFunctionEntry> ApplyFunctionMap;
static const ApplyFunctionMap::value_type ApplyFunctionList[] = {
- DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ApplyFunctionMap::value_type,
- ApplyFunctionEntry)
-};
+ DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ApplyFunctionMap::value_type,
+ ApplyFunctionEntry)};
// declare the table of applying functions
static ApplyFunctionMap ApplyFunctions(ApplyFunctionList,
- ApplyFunctionList + sizeof(ApplyFunctionList)/sizeof(ApplyFunctionList[0]));
+ ApplyFunctionList +
+ sizeof(ApplyFunctionList) /
+ sizeof(ApplyFunctionList[0]));
//===----------------------------------------------------------------------===//
// AArch64Relocator
//===----------------------------------------------------------------------===//
AArch64Relocator::AArch64Relocator(AArch64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent) {
+ : Relocator(pConfig), m_Target(pParent) {
}
-AArch64Relocator::~AArch64Relocator()
-{
+AArch64Relocator::~AArch64Relocator() {
}
-Relocator::Result AArch64Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result AArch64Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
// valid types are 0x0, 0x100-0x239
if ((type < 0x100 || type > 0x239) && (type != 0x0)) {
@@ -81,19 +79,16 @@
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char* AArch64Relocator::getName(Relocator::Type pType) const
-{
+const char* AArch64Relocator::getName(Relocator::Type pType) const {
assert(ApplyFunctions.find(pType) != ApplyFunctions.end());
return ApplyFunctions[pType].name;
}
-Relocator::Size AArch64Relocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size AArch64Relocator::getSize(Relocation::Type pType) const {
return ApplyFunctions[pType].size;
}
-void AArch64Relocator::addCopyReloc(ResolveInfo& pSym)
-{
+void AArch64Relocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& rel_entry = *getTarget().getRelaDyn().create();
rel_entry.setType(R_AARCH64_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -107,8 +102,7 @@
/// copy.
/// This is executed at scan relocation stage.
LDSymbol& AArch64Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+ const ResolveInfo& pSym) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = getTarget().getOutputFormat();
@@ -140,24 +134,23 @@
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
return *cpy_sym;
}
-void
-AArch64Relocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
-{
+void AArch64Relocator::scanLocalReloc(Relocation& pReloc,
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_AARCH64_ABS64:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -184,8 +177,10 @@
if (config().isCodeIndep()) {
// set up the dyn rel directly
Relocation& reloc = helper_DynRela_init(rsym,
- *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(), pReloc.type(), *this);
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ pReloc.type(),
+ *this);
getRelRelMap().record(pReloc, reloc);
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
@@ -202,9 +197,9 @@
// If building PIC object, a dynamic relocation with
// type RELATIVE is needed to relocate this GOT entry.
if (config().isCodeIndep())
- helper_GOT_init(pReloc, true, *this);
+ helper_GOT_init(pReloc, true, *this);
else
- helper_GOT_init(pReloc, false, *this);
+ helper_GOT_init(pReloc, false, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -217,11 +212,10 @@
void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_AARCH64_ABS64:
case llvm::ELF::R_AARCH64_ABS32:
case llvm::ELF::R_AARCH64_ABS16:
@@ -229,7 +223,7 @@
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -239,14 +233,14 @@
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -258,8 +252,7 @@
R_AARCH64_RELATIVE,
*this);
getRelRelMap().record(pReloc, reloc);
- }
- else {
+ } else {
Relocation& reloc = helper_DynRela_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
@@ -277,7 +270,7 @@
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -293,9 +286,9 @@
// All other dynamic relocations may lead to run-time relocation
// overflow.
if (getTarget().isDynamicSymbol(*rsym) &&
- getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false) &&
+ getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false) &&
getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
@@ -316,7 +309,7 @@
// if symbol is defined in the ouput file and it's not
// preemptible, no need plt
if (rsym->isDefine() && !rsym->isDyn() &&
- !getTarget().isSymbolPreemptible(*rsym)) {
+ !getTarget().isSymbolPreemptible(*rsym)) {
return;
}
@@ -331,9 +324,9 @@
case llvm::ELF::R_AARCH64_ADR_PREL_PG_HI21:
case R_AARCH64_ADR_PREL_PG_HI21_NC:
- if (getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
@@ -341,7 +334,7 @@
}
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -378,14 +371,13 @@
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if an GOT/PLT/Dynamic Relocation
@@ -405,31 +397,45 @@
issueUndefRef(pReloc, pSection, pInput);
}
+uint32_t AArch64Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_AARCH64_ABS32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void AArch64Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//===----------------------------------------------------------------------===//
// Each relocation function implementation
//===----------------------------------------------------------------------===//
// R_AARCH64_NONE
-Relocator::Result none(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, AArch64Relocator& pParent) {
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, AArch64Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, AArch64Relocator& pParent) {
+ return Relocator::Unsupported;
}
// R_AARCH64_ABS64: S + A
// R_AARCH64_ABS32: S + A
// R_AARCH64_ABS16: S + A
-Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != dyn_rel);
+ bool has_dyn_rel = (dyn_rel != NULL);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
// If the flag of target section is not ALLOC, we will not scan this
@@ -455,8 +461,7 @@
if (llvm::ELF::R_AARCH64_ABS64 == pReloc.type() &&
R_AARCH64_RELATIVE == dyn_rel->type()) {
dyn_rel->setAddend(S + A);
- }
- else {
+ } else {
dyn_rel->setAddend(A);
return Relocator::OK;
}
@@ -471,15 +476,14 @@
// R_AARCH64_PREL64: S + A - P
// R_AARCH64_PREL32: S + A - P
// R_AARCH64_PREL16: S + A - P
-Relocator::Result rel(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
- Relocator::DWord P = pReloc.place();
+ Relocator::DWord A = pReloc.addend();
+ Relocator::DWord P = pReloc.place();
if (llvm::ELF::R_AARCH64_PREL64 != pReloc.type())
- A += pReloc.target() & get_mask(pParent.getSize(pReloc.type()));
+ A += pReloc.target() & get_mask(pParent.getSize(pReloc.type()));
else
A += pReloc.target();
@@ -505,11 +509,10 @@
}
// R_AARCH64_ADD_ABS_LO12_NC: S + A
-Relocator::Result add_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result add_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
Relocator::Address value = 0x0;
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
value = helper_get_page_offset(S + A);
pReloc.target() = helper_reencode_add_imm(pReloc.target(), value);
@@ -519,9 +522,8 @@
// R_AARCH64_ADR_PREL_PG_HI21: ((PG(S + A) - PG(P)) >> 12)
// R_AARCH64_ADR_PREL_PG_HI21_NC: ((PG(S + A) - PG(P)) >> 12)
-Relocator::Result
-adr_prel_pg_hi21(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result adr_prel_pg_hi21(Relocation& pReloc,
+ AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
// if plt entry exists, the S value is the plt entry address
@@ -529,9 +531,9 @@
S = helper_get_PLT_address(*rsym, pParent);
}
Relocator::DWord A = pReloc.addend();
- Relocator::DWord P = pReloc.place() ;
- Relocator::DWord X = helper_get_page_address(S + A) -
- helper_get_page_address(P);
+ Relocator::DWord P = pReloc.place();
+ Relocator::DWord X =
+ helper_get_page_address(S + A) - helper_get_page_address(P);
pReloc.target() = helper_reencode_adr_imm(pReloc.target(), (X >> 12));
@@ -540,13 +542,11 @@
// R_AARCH64_CALL26: S + A - P
// R_AARCH64_JUMP26: S + A - P
-Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & AArch64Relocator::ReservePLT)) {
// change target to NOP
@@ -555,7 +555,7 @@
}
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
// S depends on PLT exists or not
@@ -571,13 +571,11 @@
}
// R_AARCH64_CONDBR19: S + A - P
-Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & AArch64Relocator::ReservePLT)) {
// change target to NOP
@@ -586,7 +584,7 @@
}
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
// S depends on PLT exists or not
@@ -602,8 +600,7 @@
}
// R_AARCH64_ADR_GOT_PAGE: Page(G(GDAT(S+A))) - Page(P)
-Relocator::Result adr_got_page(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result adr_got_page(Relocation& pReloc, AArch64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & AArch64Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -611,26 +608,25 @@
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
- Relocator::DWord X = helper_get_page_address(GOT_S + A) -
- helper_get_page_address(P);
+ Relocator::DWord X =
+ helper_get_page_address(GOT_S + A) - helper_get_page_address(P);
pReloc.target() = helper_reencode_adr_imm(pReloc.target(), (X >> 12));
// setup got entry value if needed
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && AArch64Relocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && AArch64Relocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
// setup relocation addend if needed
Relocation* dyn_rela = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rela) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
+ if ((dyn_rela != NULL) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
dyn_rela->setAddend(pReloc.symValue());
}
return Relocator::OK;
}
// R_AARCH64_LD64_GOT_LO12_NC: G(GDAT(S+A))
-Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & AArch64Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -643,12 +639,12 @@
// setup got entry value if needed
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && AArch64Relocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && AArch64Relocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
// setup relocation addend if needed
Relocation* dyn_rela = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rela) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
+ if ((dyn_rela != NULL) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
dyn_rela->setAddend(pReloc.symValue());
}
@@ -660,35 +656,31 @@
// R_AARCH64_LDST32_ABS_LO12_NC: S + A
// R_AARCH64_LDST64_ABS_LO12_NC: S + A
// R_AARCH64_LDST128_ABS_LO12_NC: S + A
-Relocator::Result ldst_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result ldst_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord X = helper_get_page_offset(S + A);
- switch(pReloc.type()) {
- case llvm::ELF::R_AARCH64_LDST8_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), X);
- break;
- case llvm::ELF::R_AARCH64_LDST16_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 1));
- break;
- case llvm::ELF::R_AARCH64_LDST32_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 2));
- break;
- case llvm::ELF::R_AARCH64_LDST64_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 3));
- break;
- case llvm::ELF::R_AARCH64_LDST128_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 4));
- break;
+ switch (pReloc.type()) {
+ case llvm::ELF::R_AARCH64_LDST8_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), X);
+ break;
+ case llvm::ELF::R_AARCH64_LDST16_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 1));
+ break;
+ case llvm::ELF::R_AARCH64_LDST32_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 2));
+ break;
+ case llvm::ELF::R_AARCH64_LDST64_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 3));
+ break;
+ case llvm::ELF::R_AARCH64_LDST128_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 4));
+ break;
default:
- break;
+ break;
}
return Relocator::OK;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64Relocator.h b/lib/Target/AArch64/AArch64Relocator.h
index 7fe8302..6116147 100644
--- a/lib/Target/AArch64/AArch64Relocator.h
+++ b/lib/Target/AArch64/AArch64Relocator.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64RELOCATOR_H
-#define TARGET_AARCH64_AARCH64RELOCATOR_H
+#ifndef TARGET_AARCH64_AARCH64RELOCATOR_H_
+#define TARGET_AARCH64_AARCH64RELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "AArch64LDBackend.h"
namespace mcld {
@@ -20,24 +20,23 @@
// static relocations
R_AARCH64_ADR_PREL_PG_HI21_NC = 0x114,
// dyanmic rlocations
- R_AARCH64_COPY = 1024,
- R_AARCH64_GLOB_DAT = 1025,
- R_AARCH64_JUMP_SLOT = 1026,
- R_AARCH64_RELATIVE = 1027,
- R_AARCH64_TLS_DTPREL64 = 1028,
- R_AARCH64_TLS_DTPMOD64 = 1029,
- R_AARCH64_TLS_TPREL64 = 1030,
- R_AARCH64_TLSDESC = 1031,
- R_AARCH64_IRELATIVE = 1032
+ R_AARCH64_COPY = 1024,
+ R_AARCH64_GLOB_DAT = 1025,
+ R_AARCH64_JUMP_SLOT = 1026,
+ R_AARCH64_RELATIVE = 1027,
+ R_AARCH64_TLS_DTPREL64 = 1028,
+ R_AARCH64_TLS_DTPMOD64 = 1029,
+ R_AARCH64_TLS_TPREL64 = 1030,
+ R_AARCH64_TLSDESC = 1031,
+ R_AARCH64_IRELATIVE = 1032
};
/** \class AArch64Relocator
* \brief AArch64Relocator creates and destroys the AArch64 relocations.
*
*/
-class AArch64Relocator : public Relocator
-{
-public:
+class AArch64Relocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, AArch64GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, AArch64PLT1> SymPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
@@ -61,10 +60,10 @@
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -72,38 +71,33 @@
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
+ public:
AArch64Relocator(AArch64GNULDBackend& pParent, const LinkerConfig& pConfig);
~AArch64Relocator();
Result applyRelocation(Relocation& pRelocation);
- AArch64GNULDBackend& getTarget()
- { return m_Target; }
+ AArch64GNULDBackend& getTarget() { return m_Target; }
- const AArch64GNULDBackend& getTarget() const
- { return m_Target; }
+ const AArch64GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -117,7 +111,15 @@
LDSection& pSection,
Input& pInput);
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc, const LDSection& pSection);
void scanGlobalReloc(Relocation& pReloc,
@@ -134,7 +136,7 @@
LDSymbol& defineSymbolforCopyReloc(IRBuilder& pLinker,
const ResolveInfo& pSym);
-private:
+ private:
AArch64GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymPLTMap m_SymPLTMap;
@@ -142,7 +144,6 @@
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_AARCH64_AARCH64RELOCATOR_H_
diff --git a/lib/Target/AArch64/AArch64TargetMachine.cpp b/lib/Target/AArch64/AArch64TargetMachine.cpp
deleted file mode 100644
index c0515f4..0000000
--- a/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- AArch64TargetMachine.cpp -------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64TargetMachine.h"
-#include "AArch64.h"
-
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-AArch64BaseTargetMachine::AArch64BaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
-//===----------------------------------------------------------------------===//
-// Initialize MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeAArch64LDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::AArch64BaseTargetMachine> X(mcld::TheAArch64Target);
-}
-
diff --git a/lib/Target/AArch64/AArch64TargetMachine.h b/lib/Target/AArch64/AArch64TargetMachine.h
deleted file mode 100644
index aee0e8c..0000000
--- a/lib/Target/AArch64/AArch64TargetMachine.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- AArch64TargetMachine.h ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64TARGETMACHINE_H
-#define TARGET_AARCH64_AARCH64TARGETMACHINE_H
-
-#include "AArch64.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class AArch64BaseTargetMachine : public MCLDTargetMachine
-{
-public:
- AArch64BaseTargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/AArch64/Android.mk b/lib/Target/AArch64/Android.mk
index 31383bf..a143c53 100644
--- a/lib/Target/AArch64/Android.mk
+++ b/lib/Target/AArch64/Android.mk
@@ -3,14 +3,11 @@
mcld_aarch64_target_SRC_FILES := \
AArch64Diagnostic.cpp \
AArch64ELFDynamic.cpp \
- AArch64ELFMCLinker.cpp \
AArch64Emulation.cpp \
AArch64GOT.cpp \
AArch64LDBackend.cpp \
- AArch64MCLinker.cpp \
AArch64PLT.cpp \
- AArch64Relocator.cpp \
- AArch64TargetMachine.cpp
+ AArch64Relocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp b/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
index 13472c9..6d98eba 100644
--- a/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
+++ b/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -18,5 +18,4 @@
mcld::RegisterTarget<llvm::Triple::aarch64> X(TheAArch64Target, "aarch64");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/ARM/ARM.h b/lib/Target/ARM/ARM.h
index f368ba8..c79fc66 100644
--- a/lib/Target/ARM/ARM.h
+++ b/lib/Target/ARM/ARM.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARM_H
-#define TARGET_ARM_ARM_H
+#ifndef TARGET_ARM_ARM_H_
+#define TARGET_ARM_ARM_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -22,9 +22,8 @@
extern mcld::Target TheARMTarget;
extern mcld::Target TheThumbTarget;
-TargetLDBackend *createARMLDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createARMLDBackend(const llvm::Target&, const std::string&);
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARM_H_
diff --git a/lib/Target/ARM/ARMDiagnostic.cpp b/lib/Target/ARM/ARMDiagnostic.cpp
index 77cb87e..4442a4b 100644
--- a/lib/Target/ARM/ARMDiagnostic.cpp
+++ b/lib/Target/ARM/ARMDiagnostic.cpp
@@ -6,30 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "ARM.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createARMDiagnostic - the help function to create corresponding ARMDiagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createARMDiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeARMDiagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMDiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheARMTarget, createARMDiagLineInfo);
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheThumbTarget, createARMDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheARMTarget,
+ mcld::createARMDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheThumbTarget,
+ mcld::createARMDiagLineInfo);
}
-
diff --git a/lib/Target/ARM/ARMELFAttributeData.cpp b/lib/Target/ARM/ARMELFAttributeData.cpp
index 8656b7e..fda6991 100644
--- a/lib/Target/ARM/ARMELFAttributeData.cpp
+++ b/lib/Target/ARM/ARMELFAttributeData.cpp
@@ -8,17 +8,18 @@
//===----------------------------------------------------------------------===//
#include "ARMELFAttributeData.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/LEB128.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/LEB128.h"
+#include "mcld/Support/MsgHandling.h"
+#include <llvm/ADT/STLExtras.h>
-using namespace mcld;
+namespace mcld {
-const ELFAttributeValue *ARMELFAttributeData::getAttributeValue(TagType pTag) const
-{
+const ELFAttributeValue* ARMELFAttributeData::getAttributeValue(
+ TagType pTag) const {
if (pTag <= Tag_Max) {
- const ELFAttributeValue &attr_value = m_Attrs[pTag];
+ const ELFAttributeValue& attr_value = m_Attrs[pTag];
if (attr_value.isInitialized()) {
return &attr_value;
@@ -38,9 +39,8 @@
}
std::pair<ELFAttributeValue*, bool>
-ARMELFAttributeData::getOrCreateAttributeValue(TagType pTag)
-{
- ELFAttributeValue *attr_value = NULL;
+ARMELFAttributeData::getOrCreateAttributeValue(TagType pTag) {
+ ELFAttributeValue* attr_value = NULL;
if (pTag <= Tag_Max) {
attr_value = &m_Attrs[pTag];
@@ -60,8 +60,7 @@
}
}
-unsigned int ARMELFAttributeData::GetAttributeValueType(TagType pTag)
-{
+unsigned int ARMELFAttributeData::GetAttributeValueType(TagType pTag) {
// See ARM [ABI-addenda], 2.2.6.
switch (pTag) {
case Tag_compatibility: {
@@ -78,8 +77,8 @@
if (pTag < 32)
return ELFAttributeValue::Int;
else
- return ((pTag & 1) ? ELFAttributeValue::String :
- ELFAttributeValue::Int);
+ return ((pTag & 1) ? ELFAttributeValue::String
+ : ELFAttributeValue::Int);
}
}
// unreachable
@@ -96,9 +95,8 @@
*
* @ref ARM [ABI-addenda], 2.3.7.3
*/
-static int
-decode_secondary_compatibility_attribute(const ELFAttributeValue &pValue)
-{
+static int decode_secondary_compatibility_attribute(
+ const ELFAttributeValue& pValue) {
// The encoding of Tag_also_compatible_with is:
//
// Tag_also_compatible_with (=65), NTSB: data
@@ -111,7 +109,7 @@
assert((pValue.type() == ELFAttributeValue::String) &&
"Value of Tag_also_compatible_with must be a string!");
- const std::string &data = pValue.getStringValue();
+ const std::string& data = pValue.getStringValue();
// Though the integer is in LEB128 format, but they occupy only 1 byte in
// currently defined value.
@@ -135,23 +133,23 @@
* This helper array keeps the ordering of the values in attributes such as
* Tag_ABI_align_needed which are sored as 1 > 2 > 0.
*/
-static const int value_ordering_120[] = { 0, 2, 1 };
+static const int value_ordering_120[] = {0, 2, 1};
-} // anonymous namespace
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// End Helper Functions for merge()
//===--------------------------------------------------------------------===//
bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
- const Input &pInput, TagType pTag,
- const ELFAttributeValue& pInAttr)
-{
+ const Input& pInput,
+ TagType pTag,
+ const ELFAttributeValue& pInAttr) {
// Pre-condition
// 1. The out_attr must be initailized and has value of the same type as
// pInAttr.
// 2. The value helf by out_attr and pInAttr must be different.
- ELFAttributeValue &out_attr = m_Attrs[pTag];
+ ELFAttributeValue& out_attr = m_Attrs[pTag];
// Attribute in the output must have value assigned.
assert(out_attr.isInitialized() && "No output attribute to be merged!");
@@ -212,7 +210,7 @@
case Tag_T2EE_use: {
assert((out_attr.type() == ELFAttributeValue::Int) &&
(pInAttr.type() == ELFAttributeValue::Int) &&
- "should have integer parameeter!");
+ "should have integer parameeter!");
if (pInAttr.getIntValue() > out_attr.getIntValue())
out_attr.setIntValue(pInAttr.getIntValue());
break;
@@ -223,7 +221,7 @@
case Tag_ABI_PCS_RO_data: {
assert((out_attr.type() == ELFAttributeValue::Int) &&
(pInAttr.type() == ELFAttributeValue::Int) &&
- "should have integer parameeter!");
+ "should have integer parameeter!");
if (pInAttr.getIntValue() < out_attr.getIntValue())
out_attr.setIntValue(pInAttr.getIntValue());
break;
@@ -321,8 +319,7 @@
else if (pInAttr.getIntValue() != Enum_Containerized_As_Possible &&
pConfig.options().warnMismatch())
warning(diag::warn_mismatch_enum_size)
- << pInput.name() << pInAttr.getIntValue()
- << out_attr.getIntValue();
+ << pInput.name() << pInAttr.getIntValue() << out_attr.getIntValue();
break;
}
// Tag_ABI_FP_16bit_format
@@ -431,9 +428,9 @@
out_attr.setIntValue(pInAttr.getIntValue());
else {
if (pConfig.options().warnMismatch())
- warning(diag::warn_mismatch_wchar_size)
- << pInput.name() << pInAttr.getIntValue()
- << out_attr.getIntValue();
+ warning(diag::warn_mismatch_wchar_size) << pInput.name()
+ << pInAttr.getIntValue()
+ << out_attr.getIntValue();
}
}
break;
@@ -474,17 +471,13 @@
*
* @ref ARM [ABI-addenda], 2.3.7.3
*/
-static void
-encode_secondary_compatibility_attribute(ELFAttributeValue &pValue, int pArch)
-{
+static void encode_secondary_compatibility_attribute(ELFAttributeValue& pValue,
+ int pArch) {
if ((pArch < 0) || (pArch > ARMELFAttributeData::CPU_Arch_Max)) {
pValue.setStringValue("");
} else {
char new_value[] = {
- ARMELFAttributeData::Tag_CPU_arch,
- static_cast<char>(pArch),
- 0
- };
+ ARMELFAttributeData::Tag_CPU_arch, static_cast<char>(pArch), 0};
pValue.setStringValue(std::string(new_value, sizeof(new_value)));
}
return;
@@ -493,9 +486,7 @@
/*
* Combine the main and secondary CPU arch value
*/
-static int
-calculate_cpu_arch(int cpu_arch, int secondary_arch)
-{
+static int calculate_cpu_arch(int cpu_arch, int secondary_arch) {
// short-circuit
if ((secondary_arch < 0) ||
((cpu_arch + secondary_arch) != (ARMELFAttributeData::CPU_Arch_ARM_V4T +
@@ -519,32 +510,30 @@
* profile.
*/
#define CPU(C) ARMELFAttributeData::CPU_Arch_ARM_ ## C
-static const int cpu_compatibility_table[][CPU(V4T_Plus_V6_M) + 1] =
-{
- /* old\new ARM v6T2 ARM v6K ARM v7 ARM v6-M ARM v6S-M ARM v7E-M ARMv8, ARM v4t + v6-M */
- /* Pre v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 },
- /* ARM v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 },
- /* ARM v4T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V4T) },
- /* ARM v5T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5T) },
- /* ARM v5TE */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TE) },
- /* ARM v5TEJ */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TEJ) },
- /* ARM v6 */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6) },
- /* ARM v6KZ */ { CPU(V7), CPU(V6KZ), CPU(V7), CPU(V6KZ), CPU(V6KZ), CPU(V7E_M), CPU(V8), CPU(V6KZ) },
- /* ARM v6T2 */ { CPU(V6T2), CPU(V7), CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V6T2) },
- /* ARM v6K */ { 0, CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6K) },
- /* ARM v7 */ { 0, 0, CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V7) },
- /* ARM v6-M */ { 0, 0, 0, CPU(V6_M), CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6_M) },
- /* ARM v6S-M */ { 0, 0, 0, 0, CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6S_M) },
- /* ARM v7E-M */ { 0, 0, 0, 0, 0, CPU(V7E_M), CPU(V8), CPU(V7E_M) },
- /* ARM v8 */ { 0, 0, 0, 0, 0, 0, CPU(V8), CPU(V8) },
- /* v4T + v6-M */ { 0, 0, 0, 0, 0, 0, 0, CPU(V4T_Plus_V6_M) }
+static const int cpu_compatibility_table[][CPU(V4T_Plus_V6_M) + 1] = {
+ /* old\new ARM v6T2 ARM v6K ARM v7 ARM v6-M ARM v6S-M ARM v7E-M ARMv8, ARM v4t + v6-M */ // NOLINT
+ /* Pre v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 }, // NOLINT
+ /* ARM v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 }, // NOLINT
+ /* ARM v4T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V4T) }, // NOLINT
+ /* ARM v5T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5T) }, // NOLINT
+ /* ARM v5TE */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TE) }, // NOLINT
+ /* ARM v5TEJ */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TEJ) }, // NOLINT
+ /* ARM v6 */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6) }, // NOLINT
+ /* ARM v6KZ */ { CPU(V7), CPU(V6KZ), CPU(V7), CPU(V6KZ), CPU(V6KZ), CPU(V7E_M), CPU(V8), CPU(V6KZ) }, // NOLINT
+ /* ARM v6T2 */ { CPU(V6T2), CPU(V7), CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V6T2) }, // NOLINT
+ /* ARM v6K */ { 0, CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6K) }, // NOLINT
+ /* ARM v7 */ { 0, 0, CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V7) }, // NOLINT
+ /* ARM v6-M */ { 0, 0, 0, CPU(V6_M), CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6_M) }, // NOLINT
+ /* ARM v6S-M */ { 0, 0, 0, 0, CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6S_M) }, // NOLINT
+ /* ARM v7E-M */ { 0, 0, 0, 0, 0, CPU(V7E_M), CPU(V8), CPU(V7E_M) }, // NOLINT
+ /* ARM v8 */ { 0, 0, 0, 0, 0, 0, CPU(V8), CPU(V8) }, // NOLINT
+ /* v4T + v6-M */ { 0, 0, 0, 0, 0, 0, 0, CPU(V4T_Plus_V6_M) } // NOLINT
};
/*
* Helper function to determine the merge of two different CPU arch.
*/
-static int merge_cpu_arch(int out_cpu_arch, int in_cpu_arch)
-{
+static int merge_cpu_arch(int out_cpu_arch, int in_cpu_arch) {
if (out_cpu_arch > CPU(V4T_Plus_V6_M))
return in_cpu_arch;
@@ -571,21 +560,21 @@
* merge of Tag_CPU_arch.
*/
static const char* generic_cpu_name_table[] = {
- /* Pre v4 */"Pre v4",
- /* Pre v4 */"ARM v4",
- /* ARM v4T */"ARM v4T",
- /* ARM v5T */"ARM v5T",
- /* ARM v5TE */"ARM v5TE",
- /* ARM v5TEJ */"ARM v5TEJ",
- /* ARM v6 */"ARM v6",
- /* ARM v6KZ */"ARM v6KZ",
- /* ARM v6T2 */"ARM v6T2",
- /* ARM v6K */"ARM v6K",
- /* ARM v7 */"ARM v7",
- /* ARM v6-M */"ARM v6-M",
- /* ARM v6S-M */"ARM v6S-M",
- /* ARM v7E-M */"ARM v7E-M",
- /* ARM v8 */"ARM v8",
+ /* Pre v4 */ "Pre v4",
+ /* Pre v4 */ "ARM v4",
+ /* ARM v4T */ "ARM v4T",
+ /* ARM v5T */ "ARM v5T",
+ /* ARM v5TE */ "ARM v5TE",
+ /* ARM v5TEJ */ "ARM v5TEJ",
+ /* ARM v6 */ "ARM v6",
+ /* ARM v6KZ */ "ARM v6KZ",
+ /* ARM v6T2 */ "ARM v6T2",
+ /* ARM v6K */ "ARM v6K",
+ /* ARM v7 */ "ARM v7",
+ /* ARM v6-M */ "ARM v6-M",
+ /* ARM v6S-M */ "ARM v6S-M",
+ /* ARM v7E-M */ "ARM v7E-M",
+ /* ARM v8 */ "ARM v8",
};
static const char* get_generic_cpu_name(int cpu_arch) {
@@ -601,15 +590,15 @@
int version;
int regs;
} fp_configs[] = {
- { 0, 0 },
- { 1, 16 },
- { 2, 16 },
- { 3, 32 },
- { 3, 16 },
- { 4, 32 },
- { 4, 16 },
- { 8, 32 },
- { 8, 16 },
+ {0, 0},
+ {1, 16},
+ {2, 16},
+ {3, 32},
+ {3, 16},
+ {4, 32},
+ {4, 16},
+ {8, 32},
+ {8, 16},
};
static const size_t num_fp_configs =
@@ -628,48 +617,44 @@
// fp_config_hash_table[ h(8, 16) = 8 ] = 8
//
// h(0, 0) = 0
-static const uint8_t fp_config_hash_table[] =
-{
+static const uint8_t fp_config_hash_table[] = {
#define UND static_cast<uint8_t>(-1)
- /* 0 */0,
- /* 1 */1,
- /* 2 */2,
- /* 3 */4,
- /* 4 */6,
- /* 5 */UND,
- /* 6 */UND,
- /* 7 */3,
- /* 8 */8,
- /* 9 */5,
- /* 10 */UND,
- /* 11 */UND,
- /* 12 */UND,
- /* 13 */UND,
- /* 14 */UND,
- /* 15 */UND,
- /* 16 */UND,
- /* 17 */7,
+ /* 0 */ 0,
+ /* 1 */ 1,
+ /* 2 */ 2,
+ /* 3 */ 4,
+ /* 4 */ 6,
+ /* 5 */ UND,
+ /* 6 */ UND,
+ /* 7 */ 3,
+ /* 8 */ 8,
+ /* 9 */ 5,
+ /* 10 */ UND,
+ /* 11 */ UND,
+ /* 12 */ UND,
+ /* 13 */ UND,
+ /* 14 */ UND,
+ /* 15 */ UND,
+ /* 16 */ UND,
+ /* 17 */ 7,
#undef UND
};
-static const size_t num_hash_table_entries =
- sizeof(fp_config_hash_table) / sizeof(fp_config_hash_table[0]);
-
-static int calculate_fp_config_hash(const struct fp_config_data &pConfig)
-{
+static int calculate_fp_config_hash(const struct fp_config_data& pConfig) {
int x = pConfig.version;
int y = pConfig.regs;
return (x * (y >> 4) + (y >> 5));
}
-static int get_fp_arch_of_config(const struct fp_config_data &pConfig)
-{
+static int get_fp_arch_of_config(const struct fp_config_data& pConfig) {
int hash = calculate_fp_config_hash(pConfig);
- assert(static_cast<size_t>(hash) < num_hash_table_entries);
+ assert(static_cast<size_t>(hash) <
+ llvm::array_lengthof(fp_config_hash_table));
return fp_config_hash_table[hash];
}
-static bool is_allowed_use_of_div(int cpu_arch, int cpu_arch_profile,
+static bool is_allowed_use_of_div(int cpu_arch,
+ int cpu_arch_profile,
int div_use) {
// 0: The code was permitted to use SDIV and UDIV in the Thumb ISA on v7-R or
// v7-M.
@@ -689,25 +674,22 @@
}
case 2:
// For future proofing
- default: {
- return true;
- }
+ default: { return true; }
}
}
-} // anonymous namespace
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// End Helper Functions for postMerge()
//===--------------------------------------------------------------------===//
bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
- const Input &pInput)
-{
+ const Input& pInput) {
// Process Tag_CPU_arch, Tag_CPU_name, Tag_CPU_raw_name, and
// Tag_also_compatible_with.
- ELFAttributeValue &out_cpu_arch_attr = m_Attrs[Tag_CPU_arch];
- ELFAttributeValue &out_secondary_compatibility_attr =
+ ELFAttributeValue& out_cpu_arch_attr = m_Attrs[Tag_CPU_arch];
+ ELFAttributeValue& out_secondary_compatibility_attr =
m_Attrs[Tag_also_compatible_with];
if ((m_CurrentCPUArch < 0) && out_cpu_arch_attr.isInitialized()) {
@@ -723,7 +705,7 @@
int out_secondary_arch = -1;
if (out_secondary_compatibility_attr.isInitialized())
out_secondary_arch = decode_secondary_compatibility_attribute(
- out_secondary_compatibility_attr);
+ out_secondary_compatibility_attr);
m_CurrentCPUArch = calculate_cpu_arch(out_cpu_arch, out_secondary_arch);
}
@@ -736,8 +718,8 @@
int result_cpu_arch = merge_cpu_arch(m_CurrentCPUArch, in_cpu_arch);
if (result_cpu_arch < 0) {
- warning(diag::warn_mismatch_cpu_arch_profile)
- << in_cpu_arch << pInput.name();
+ warning(diag::warn_mismatch_cpu_arch_profile) << in_cpu_arch
+ << pInput.name();
} else {
if (result_cpu_arch != m_CurrentCPUArch) {
// Value of Tag_CPU_arch are going to changea.
@@ -754,8 +736,8 @@
out_secondary_compatibility_attr, -1);
}
- ELFAttributeValue &out_cpu_name = m_Attrs[Tag_CPU_name];
- ELFAttributeValue &out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
+ ELFAttributeValue& out_cpu_name = m_Attrs[Tag_CPU_name];
+ ELFAttributeValue& out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
if (m_CurrentCPUArch != in_cpu_arch) {
// Unable to guess the Tag_CPU_name. Use the generic name.
@@ -769,13 +751,13 @@
} else {
// Use the value of Tag_CPU_name and Tag_CPU_raw_name from the input.
if (!m_CPUName.empty()) {
- ELFAttributeValue &out_cpu_name = m_Attrs[Tag_CPU_name];
+ ELFAttributeValue& out_cpu_name = m_Attrs[Tag_CPU_name];
assert(out_cpu_name.isInitialized() && "CPU name has never set!");
out_cpu_name.setStringValue(m_CPUName);
}
if (!m_CPURawName.empty()) {
- ELFAttributeValue &out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
+ ELFAttributeValue& out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
assert(out_cpu_raw_name.isInitialized() &&
"CPU raw name has never set!");
out_cpu_raw_name.setStringValue(m_CPURawName);
@@ -783,12 +765,12 @@
}
}
}
- } // (m_CPUArch >= 0)
+ } // (m_CPUArch >= 0)
// Process Tag_ABI_VFP_args.
if (m_VFPArgs >= 0) {
- ELFAttributeValue &out_attr = m_Attrs[Tag_ABI_VFP_args];
- ELFAttributeValue &out_float_number_model_attr =
+ ELFAttributeValue& out_attr = m_Attrs[Tag_ABI_VFP_args];
+ ELFAttributeValue& out_float_number_model_attr =
m_Attrs[Tag_ABI_FP_number_model];
assert(out_attr.isInitialized() && "VFP args has never set!");
@@ -806,7 +788,7 @@
}
// Process Tag_FP_arch.
- ELFAttributeValue &out_fp_arch_attr = m_Attrs[Tag_FP_arch];
+ ELFAttributeValue& out_fp_arch_attr = m_Attrs[Tag_FP_arch];
if (m_FPArch >= 0) {
assert(out_fp_arch_attr.isInitialized() && "FP arch has never set!");
@@ -837,26 +819,28 @@
}
} else {
if (out_fp_arch_attr.getIntValue() < num_fp_configs) {
- const struct fp_config_data &input_fp_config = fp_configs[ m_FPArch ];
+ const struct fp_config_data& input_fp_config = fp_configs[m_FPArch];
- const struct fp_config_data &output_fp_config =
- fp_configs[ out_fp_arch_attr.getIntValue() ];
+ const struct fp_config_data& output_fp_config =
+ fp_configs[out_fp_arch_attr.getIntValue()];
const struct fp_config_data result_fp_config = {
- /*version*/((output_fp_config.version > input_fp_config.version) ?
- output_fp_config.version : input_fp_config.version),
- /* regs */((output_fp_config.regs > input_fp_config.regs) ?
- output_fp_config.regs : input_fp_config.regs),
+ /*version*/ ((output_fp_config.version > input_fp_config.version)
+ ? output_fp_config.version
+ : input_fp_config.version),
+ /* regs */ ((output_fp_config.regs > input_fp_config.regs)
+ ? output_fp_config.regs
+ : input_fp_config.regs),
};
// Find the attribute value corresponding the result_fp_config
out_fp_arch_attr.setIntValue(get_fp_arch_of_config(result_fp_config));
}
}
}
- } // (m_FPArch >= 0)
+ } // (m_FPArch >= 0)
// Process Tag_ABI_HardFP_use.
- ELFAttributeValue &out_hardfp_use_attr = m_Attrs[Tag_ABI_HardFP_use];
+ ELFAttributeValue& out_hardfp_use_attr = m_Attrs[Tag_ABI_HardFP_use];
if (!m_HardFPUseInitialized && out_hardfp_use_attr.isInitialized()) {
m_HardFPUse = out_hardfp_use_attr.getIntValue();
@@ -882,10 +866,10 @@
}
// Move the value of Tag_MPextension_use_legacy to Tag_MPextension_use.
- ELFAttributeValue &out_mpextension_use_legacy =
+ ELFAttributeValue& out_mpextension_use_legacy =
m_Attrs[Tag_MPextension_use_legacy];
- ELFAttributeValue &out_mpextension_use = m_Attrs[Tag_MPextension_use];
+ ELFAttributeValue& out_mpextension_use = m_Attrs[Tag_MPextension_use];
// If Tag_MPextension_use_legacy has value, it must be introduced by current
// input since it is reset every time after the merge completed.
@@ -903,7 +887,7 @@
// Check the consistency between m_MPextensionUse and the value of
// Tag_MPextension_use_legacy.
if (static_cast<unsigned>(m_MPextensionUse) !=
- out_mpextension_use_legacy.getIntValue()) {
+ out_mpextension_use_legacy.getIntValue()) {
error(diag::error_mismatch_mpextension_use) << pInput.name();
return false;
}
@@ -929,13 +913,13 @@
assert(out_mpextension_use.isInitialized());
if (static_cast<unsigned>(m_MPextensionUse) >
- out_mpextension_use.getIntValue()) {
+ out_mpextension_use.getIntValue()) {
out_mpextension_use.setIntValue(m_MPextensionUse);
}
}
// Process Tag_DIV_use.
- ELFAttributeValue &out_div_use_attr = m_Attrs[Tag_DIV_use];
+ ELFAttributeValue& out_div_use_attr = m_Attrs[Tag_DIV_use];
if (!m_DIVUseInitialized && out_div_use_attr.isInitialized()) {
// Perform the merge by reverting value of Tag_DIV_use and setup m_DIVUse.
@@ -947,7 +931,7 @@
if (m_DIVUse >= 0) {
assert(out_div_use_attr.isInitialized());
- const ELFAttributeValue &out_cpu_arch_profile_attr =
+ const ELFAttributeValue& out_cpu_arch_profile_attr =
m_Attrs[Tag_CPU_arch_profile];
int out_cpu_arch_profile = Arch_Profile_None;
@@ -958,7 +942,8 @@
if (m_DIVUse == 1) {
// Input (=1) was not permitted to use SDIV and UDIV. See whether current
// output was explicitly permitted the use.
- if (!is_allowed_use_of_div(m_CurrentCPUArch, out_cpu_arch_profile,
+ if (!is_allowed_use_of_div(m_CurrentCPUArch,
+ out_cpu_arch_profile,
out_div_use_attr.getIntValue())) {
out_div_use_attr.setIntValue(1);
}
@@ -967,8 +952,8 @@
// Output does not explicitly forbid the use of SDIV/UDIV. See whether
// the input attribute can allow it under current CPU architecture
// profile.
- if (is_allowed_use_of_div(m_CurrentCPUArch, out_cpu_arch_profile,
- m_DIVUse)) {
+ if (is_allowed_use_of_div(
+ m_CurrentCPUArch, out_cpu_arch_profile, m_DIVUse)) {
out_div_use_attr.setIntValue(m_DIVUse);
}
}
@@ -984,7 +969,7 @@
// Size contributed by known attributes
for (unsigned i = 0; i <= Tag_Max; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit()) {
result += leb128::size(static_cast<uint32_t>(tag));
@@ -994,10 +979,11 @@
// Size contributed by unknown attributes
for (UnknownAttrsMap::const_iterator unknown_attr_it = m_UnknownAttrs.begin(),
- unknown_attr_end = m_UnknownAttrs.end();
- unknown_attr_it != unknown_attr_end; ++unknown_attr_it) {
+ unknown_attr_end = m_UnknownAttrs.end();
+ unknown_attr_it != unknown_attr_end;
+ ++unknown_attr_it) {
TagType tag = unknown_attr_it->first;
- const ELFAttributeValue &value = unknown_attr_it->second;
+ const ELFAttributeValue& value = unknown_attr_it->second;
if (value.shouldEmit()) {
result += leb128::size(static_cast<uint32_t>(tag));
@@ -1008,18 +994,18 @@
return result;
}
-size_t ARMELFAttributeData::emit(char *pBuf) const {
- char *buffer = pBuf;
+size_t ARMELFAttributeData::emit(char* pBuf) const {
+ char* buffer = pBuf;
// Tag_conformance "should be emitted first in a file-scope sub-subsection of
// the first public subsection of the attribute section."
//
// See ARM [ABI-addenda], 2.3.7.4 Conformance tag
- const ELFAttributeValue &attr_conformance = m_Attrs[Tag_conformance];
+ const ELFAttributeValue& attr_conformance = m_Attrs[Tag_conformance];
if (attr_conformance.shouldEmit()) {
- if (!ELFAttributeData::WriteAttribute(Tag_conformance, attr_conformance,
- buffer)) {
+ if (!ELFAttributeData::WriteAttribute(
+ Tag_conformance, attr_conformance, buffer)) {
return 0;
}
}
@@ -1028,11 +1014,11 @@
// subsection other that the conformance tag"
//
// See ARM [ABI-addenda], 2.3.7.5 No defaults tag
- const ELFAttributeValue &attr_nodefaults = m_Attrs[Tag_nodefaults];
+ const ELFAttributeValue& attr_nodefaults = m_Attrs[Tag_nodefaults];
if (attr_nodefaults.shouldEmit()) {
- if (!ELFAttributeData::WriteAttribute(Tag_nodefaults, attr_nodefaults,
- buffer)) {
+ if (!ELFAttributeData::WriteAttribute(
+ Tag_nodefaults, attr_nodefaults, buffer)) {
return 0;
}
}
@@ -1041,7 +1027,7 @@
// Tag_nodefaults (=64)
for (unsigned i = 0; i < Tag_nodefaults; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit() &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1051,7 +1037,7 @@
for (unsigned i = (Tag_nodefaults + 1); i <= Tag_Max; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit() && (i != Tag_conformance) &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1060,10 +1046,11 @@
}
for (UnknownAttrsMap::const_iterator unknown_attr_it = m_UnknownAttrs.begin(),
- unknown_attr_end = m_UnknownAttrs.end();
- unknown_attr_it != unknown_attr_end; ++unknown_attr_it) {
+ unknown_attr_end = m_UnknownAttrs.end();
+ unknown_attr_it != unknown_attr_end;
+ ++unknown_attr_it) {
TagType tag = unknown_attr_it->first;
- const ELFAttributeValue &value = unknown_attr_it->second;
+ const ELFAttributeValue& value = unknown_attr_it->second;
if (value.shouldEmit() &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1074,8 +1061,7 @@
return (buffer - pBuf);
}
-bool ARMELFAttributeData::usingThumb() const
-{
+bool ARMELFAttributeData::usingThumb() const {
int arch = m_Attrs[Tag_CPU_arch].getIntValue();
if ((arch == CPU_Arch_ARM_V6_M) || (arch == CPU_Arch_ARM_V6S_M))
return true;
@@ -1086,8 +1072,9 @@
return arch == Arch_Profile_Microcontroller;
}
-bool ARMELFAttributeData::usingThumb2() const
-{
+bool ARMELFAttributeData::usingThumb2() const {
int arch = m_Attrs[Tag_CPU_arch].getIntValue();
return (arch == CPU_Arch_ARM_V6T2) || (arch == CPU_Arch_ARM_V7);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMELFAttributeData.h b/lib/Target/ARM/ARMELFAttributeData.h
index 1183b3d..19dcf21 100644
--- a/lib/Target/ARM/ARMELFAttributeData.h
+++ b/lib/Target/ARM/ARMELFAttributeData.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFATTRIBUTEDATA_H
-#define TARGET_ARM_ARMELFATTRIBUTEDATA_H
+#ifndef TARGET_ARM_ARMELFATTRIBUTEDATA_H_
+#define TARGET_ARM_ARMELFATTRIBUTEDATA_H_
-#include <mcld/Target/ELFAttributeData.h>
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Target/ELFAttributeData.h"
+#include "mcld/Target/ELFAttributeValue.h"
#include <map>
#include <string>
@@ -23,82 +23,82 @@
*
*/
class ARMELFAttributeData : public ELFAttributeData {
-public:
+ public:
enum Tag {
// 0-3 are generic and are defined in ELFAttributeData.
- Tag_CPU_raw_name = 4,
- Tag_CPU_name = 5,
- Tag_CPU_arch = 6,
- Tag_CPU_arch_profile = 7,
- Tag_ARM_ISA_use = 8,
- Tag_THUMB_ISA_use = 9,
- Tag_FP_arch = 10,
- Tag_WMMX_arch = 11,
- Tag_Advanced_SIMD_arch = 12,
- Tag_PCS_config = 13,
- Tag_ABI_PCS_R9_use = 14,
- Tag_ABI_PCS_RW_data = 15,
- Tag_ABI_PCS_RO_data = 16,
- Tag_ABI_PCS_GOT_use = 17,
- Tag_ABI_PCS_wchar_t = 18,
- Tag_ABI_FP_rounding = 19,
- Tag_ABI_FP_denormal = 20,
- Tag_ABI_FP_exceptions = 21,
- Tag_ABI_FP_user_exceptions = 22,
- Tag_ABI_FP_number_model = 23,
- Tag_ABI_align_needed = 24,
- Tag_ABI_align_preserved = 25,
- Tag_ABI_enum_size = 26,
- Tag_ABI_HardFP_use = 27,
- Tag_ABI_VFP_args = 28,
- Tag_ABI_WMMX_args = 29,
- Tag_ABI_optimization_goals = 30,
- Tag_ABI_FP_optimization_goals = 31,
- Tag_compatibility = 32,
+ Tag_CPU_raw_name = 4,
+ Tag_CPU_name = 5,
+ Tag_CPU_arch = 6,
+ Tag_CPU_arch_profile = 7,
+ Tag_ARM_ISA_use = 8,
+ Tag_THUMB_ISA_use = 9,
+ Tag_FP_arch = 10,
+ Tag_WMMX_arch = 11,
+ Tag_Advanced_SIMD_arch = 12,
+ Tag_PCS_config = 13,
+ Tag_ABI_PCS_R9_use = 14,
+ Tag_ABI_PCS_RW_data = 15,
+ Tag_ABI_PCS_RO_data = 16,
+ Tag_ABI_PCS_GOT_use = 17,
+ Tag_ABI_PCS_wchar_t = 18,
+ Tag_ABI_FP_rounding = 19,
+ Tag_ABI_FP_denormal = 20,
+ Tag_ABI_FP_exceptions = 21,
+ Tag_ABI_FP_user_exceptions = 22,
+ Tag_ABI_FP_number_model = 23,
+ Tag_ABI_align_needed = 24,
+ Tag_ABI_align_preserved = 25,
+ Tag_ABI_enum_size = 26,
+ Tag_ABI_HardFP_use = 27,
+ Tag_ABI_VFP_args = 28,
+ Tag_ABI_WMMX_args = 29,
+ Tag_ABI_optimization_goals = 30,
+ Tag_ABI_FP_optimization_goals = 31,
+ Tag_compatibility = 32,
- Tag_CPU_unaligned_access = 34,
+ Tag_CPU_unaligned_access = 34,
- Tag_FP_HP_extension = 36,
+ Tag_FP_HP_extension = 36,
- Tag_ABI_FP_16bit_format = 38,
+ Tag_ABI_FP_16bit_format = 38,
- Tag_MPextension_use = 42,
+ Tag_MPextension_use = 42,
- Tag_DIV_use = 44,
+ Tag_DIV_use = 44,
- Tag_nodefaults = 64,
- Tag_also_compatible_with = 65,
- Tag_T2EE_use = 66,
- Tag_conformance = 67,
- Tag_Virtualization_use = 68,
+ Tag_nodefaults = 64,
+ Tag_also_compatible_with = 65,
+ Tag_T2EE_use = 66,
+ Tag_conformance = 67,
+ Tag_Virtualization_use = 68,
- Tag_MPextension_use_legacy = 70,
+ Tag_MPextension_use_legacy = 70,
Tag_Max = Tag_MPextension_use_legacy,
// Alias
- Tag_VFP_arch = Tag_FP_arch,
- Tag_ABI_align8_needed = Tag_ABI_align_needed,
- Tag_ABI_align8_preserved = Tag_ABI_align_preserved,
- Tag_VFP_HP_extension = Tag_FP_HP_extension
+ Tag_VFP_arch = Tag_FP_arch,
+ Tag_ABI_align8_needed = Tag_ABI_align_needed,
+ Tag_ABI_align8_preserved = Tag_ABI_align_preserved,
+ Tag_VFP_HP_extension = Tag_FP_HP_extension
};
// For Tag_CPU_arch
enum {
CPU_Arch_ARM_Pre_V4,
- CPU_Arch_ARM_V4, // e.g., SA110
- CPU_Arch_ARM_V4T, // e.g., ARM7TDMI
- CPU_Arch_ARM_V5T, // e.g., ARM9TDMI
- CPU_Arch_ARM_V5TE, // e.g., ARM946E-S
- CPU_Arch_ARM_V5TEJ, // e.g., ARM926EJ-S
- CPU_Arch_ARM_V6, // e.g., ARM1136J-S
- CPU_Arch_ARM_V6KZ, // e.g., ARM1176JZ-S
- CPU_Arch_ARM_V6T2, // e.g., ARM1156T2F-S
- CPU_Arch_ARM_V6K, // e.g., ARM1136J-S
- CPU_Arch_ARM_V7, // e.g., Cortex A8, Cortex M3
- CPU_Arch_ARM_V6_M, // e.g., Cortex M1
- CPU_Arch_ARM_V6S_M, // e.g., v6-M with the value of System extensions
- CPU_Arch_ARM_V7E_M, // e.g., v7-M with DSP extensions
+ CPU_Arch_ARM_V4, // e.g., SA110
+ CPU_Arch_ARM_V4T, // e.g., ARM7TDMI
+ CPU_Arch_ARM_V5T, // e.g., ARM9TDMI
+ CPU_Arch_ARM_V5TE, // e.g., ARM946E-S
+ CPU_Arch_ARM_V5TEJ, // e.g., ARM926EJ-S
+ CPU_Arch_ARM_V6, // e.g., ARM1136J-S
+ CPU_Arch_ARM_V6KZ, // e.g., ARM1176JZ-S
+ CPU_Arch_ARM_V6T2, // e.g., ARM1156T2F-S
+ CPU_Arch_ARM_V6K, // e.g., ARM1136J-S
+ CPU_Arch_ARM_V7, // e.g., Cortex A8, Cortex M3
+ CPU_Arch_ARM_V6_M, // e.g., Cortex M1
+ CPU_Arch_ARM_V6S_M, // e.g., v6-M with the value of System extensions
+ CPU_Arch_ARM_V7E_M, // e.g., v7-M with DSP extensions
CPU_Arch_ARM_V8,
CPU_Arch_Max = CPU_Arch_ARM_V8,
@@ -113,11 +113,11 @@
// For Tag_CPU_arch_profile
enum {
- Arch_Profile_None = 0,
- Arch_Profile_Application = 'A',
- Arch_Profile_Realtime = 'R',
- Arch_Profile_Microcontroller = 'M',
- Arch_Profile_RealOrApp = 'S'
+ Arch_Profile_None = 0,
+ Arch_Profile_Application = 'A',
+ Arch_Profile_Realtime = 'R',
+ Arch_Profile_Microcontroller = 'M',
+ Arch_Profile_RealOrApp = 'S'
};
// For Tag_ABI_enum_size
@@ -129,12 +129,7 @@
};
// For Tag_ABI_PCS_R9_use
- enum {
- R9_V6,
- R9_SB,
- R9_TLS,
- R9_Unused
- };
+ enum { R9_V6, R9_SB, R9_TLS, R9_Unused };
// For Tag_ABI_PCS_RW_data
enum {
@@ -144,20 +139,21 @@
RW_data_unused
};
-public:
+ public:
// ARM [ABI-addenda], 2.2.2: A public attributes subsection is named aeabi.
ARMELFAttributeData()
- : ELFAttributeData("aeabi"), m_CurrentCPUArch(-1),
- m_DIVUseInitialized(false), m_HardFPUseInitialized(false) { }
+ : ELFAttributeData("aeabi"),
+ m_CurrentCPUArch(-1),
+ m_DIVUseInitialized(false),
+ m_HardFPUseInitialized(false) {}
-public:
- virtual const ELFAttributeValue *getAttributeValue(TagType pTag) const;
+ public:
+ virtual const ELFAttributeValue* getAttributeValue(TagType pTag) const;
- virtual std::pair<ELFAttributeValue*, bool>
- getOrCreateAttributeValue(TagType pTag);
+ virtual std::pair<ELFAttributeValue*, bool> getOrCreateAttributeValue(
+ TagType pTag);
- virtual bool preMerge(const Input &pInput)
- {
+ virtual bool preMerge(const Input& pInput) {
// Reset states.
m_CPUArch = -1;
m_CPUName.clear();
@@ -171,24 +167,26 @@
return true;
}
- virtual bool merge(const LinkerConfig& pConfig, const Input &pInput,
- TagType pTag, const ELFAttributeValue& pInAttr);
+ virtual bool merge(const LinkerConfig& pConfig,
+ const Input& pInput,
+ TagType pTag,
+ const ELFAttributeValue& pInAttr);
- virtual bool postMerge(const LinkerConfig& pConfig, const Input &pInput);
+ virtual bool postMerge(const LinkerConfig& pConfig, const Input& pInput);
virtual size_t sizeOutput() const;
- virtual size_t emit(char *pBuf) const;
+ virtual size_t emit(char* pBuf) const;
virtual bool usingThumb() const;
virtual bool usingThumb2() const;
-private:
+ private:
/// GetAttributeValueType - obtain the value type of the indicated tag.
static unsigned int GetAttributeValueType(TagType pTag);
-private:
+ private:
// The storage for known tags which is indexed by the tag
ELFAttributeValue m_Attrs[Tag_Max + 1];
@@ -231,13 +229,14 @@
// Record the value of input Tag_ABI_VFP_args.
int m_VFPArgs;
- // Record the value of input Tag_MPextension_use and Tag_MPextension_use_legacy.
+ // Record the value of input Tag_MPextension_use and
+ // Tag_MPextension_use_legacy.
int m_MPextensionUse;
// Record the value of input Tag_DIV_use.
int m_DIVUse;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMELFATTRIBUTEDATA_H_
diff --git a/lib/Target/ARM/ARMELFDynamic.cpp b/lib/Target/ARM/ARMELFDynamic.cpp
index cbec6e8..8cddb9f 100644
--- a/lib/Target/ARM/ARMELFDynamic.cpp
+++ b/lib/Target/ARM/ARMELFDynamic.cpp
@@ -8,31 +8,28 @@
//===----------------------------------------------------------------------===//
#include "ARMELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
ARMELFDynamic::ARMELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-ARMELFDynamic::~ARMELFDynamic()
-{
+ARMELFDynamic::~ARMELFDynamic() {
}
-void ARMELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void ARMELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void ARMELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void ARMELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMELFDynamic.h b/lib/Target/ARM/ARMELFDynamic.h
index 43ec688..e876668 100644
--- a/lib/Target/ARM/ARMELFDynamic.h
+++ b/lib/Target/ARM/ARMELFDynamic.h
@@ -6,23 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFDYNAMIC_H
-#define TARGET_ARM_ARMELFDYNAMIC_H
+#ifndef TARGET_ARM_ARMELFDYNAMIC_H_
+#define TARGET_ARM_ARMELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class ARMELFDynamic : public ELFDynamic {
-public:
+ public:
ARMELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~ARMELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMELFDYNAMIC_H_
diff --git a/lib/Target/ARM/ARMELFMCLinker.cpp b/lib/Target/ARM/ARMELFMCLinker.cpp
deleted file mode 100644
index 8e9a440..0000000
--- a/lib/Target/ARM/ARMELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- ARMELFMCLinker.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMELFMCLinker.h"
-
-using namespace mcld;
-
-ARMELFMCLinker::ARMELFMCLinker(LinkerConfig& pConfig,
- mcld::Module &pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-ARMELFMCLinker::~ARMELFMCLinker()
-{
-}
-
diff --git a/lib/Target/ARM/ARMELFMCLinker.h b/lib/Target/ARM/ARMELFMCLinker.h
deleted file mode 100644
index 5ee18ff..0000000
--- a/lib/Target/ARM/ARMELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- ARMELFMCLinker.h ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFMCLINKER_H
-#define TARGET_ARM_ARMELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class ARMELFMCLinker
- * \brief ARMELFMCLinker sets up the environment for linking.
- */
-class ARMELFMCLinker : public ELFMCLinker
-{
-public:
- ARMELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~ARMELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/ARM/ARMEmulation.cpp b/lib/Target/ARM/ARMEmulation.cpp
index a890a87..10a714f 100644
--- a/lib/Target/ARM/ARMEmulation.cpp
+++ b/lib/Target/ARM/ARMEmulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "ARM.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Target/ELFEmulation.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
-static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -46,8 +45,7 @@
//===----------------------------------------------------------------------===//
// emulateARMLD - the help function to emulate ARM ld
//===----------------------------------------------------------------------===//
-bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -60,14 +58,15 @@
return MCLDEmulateARMELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// ARMEmulation
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMEmulation() {
// Register the emulation
- mcld::TargetRegistry::RegisterEmulation(mcld::TheARMTarget, mcld::emulateARMLD);
- mcld::TargetRegistry::RegisterEmulation(mcld::TheThumbTarget, mcld::emulateARMLD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheARMTarget,
+ mcld::emulateARMLD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheThumbTarget,
+ mcld::emulateARMLD);
}
-
diff --git a/lib/Target/ARM/ARMGNUInfo.h b/lib/Target/ARM/ARMGNUInfo.h
index 79f2463..f14ed36 100644
--- a/lib/Target/ARM/ARMGNUInfo.h
+++ b/lib/Target/ARM/ARMGNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMGNUINFO_H
-#define TARGET_ARM_ARMGNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_ARM_ARMGNUINFO_H_
+#define TARGET_ARM_ARMGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class ARMGNUInfo : public GNUInfo
-{
-public:
- ARMGNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class ARMGNUInfo : public GNUInfo {
+ public:
+ explicit ARMGNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_ARM; }
@@ -26,7 +25,6 @@
uint64_t flags() const { return llvm::ELF::EF_ARM_EABI_VER5; }
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARMGNUINFO_H_
diff --git a/lib/Target/ARM/ARMGOT.cpp b/lib/Target/ARM/ARMGOT.cpp
index 7ad10ac..a7dd170 100644
--- a/lib/Target/ARM/ARMGOT.cpp
+++ b/lib/Target/ARM/ARMGOT.cpp
@@ -8,53 +8,47 @@
//===----------------------------------------------------------------------===//
#include "ARMGOT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
-
namespace {
- const unsigned int ARMGOT0Num = 3;
-} // end of anonymous namespace
+const unsigned int ARMGOT0Num = 3;
+} // end of anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMGOT
ARMGOT::ARMGOT(LDSection& pSection)
- : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL)
-{
+ : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL) {
// create GOT0, and put them into m_SectionData immediately
for (unsigned int i = 0; i < ARMGOT0Num; ++i)
new ARMGOTEntry(0, m_SectionData);
}
-ARMGOT::~ARMGOT()
-{
+ARMGOT::~ARMGOT() {
}
-bool ARMGOT::hasGOT1() const
-{
+bool ARMGOT::hasGOT1() const {
return ((!m_GOT.empty()) || (!m_GOTPLT.empty()));
}
-ARMGOTEntry* ARMGOT::createGOT()
-{
+ARMGOTEntry* ARMGOT::createGOT() {
ARMGOTEntry* entry = new ARMGOTEntry(0, NULL);
m_GOT.push_back(entry);
return entry;
}
-ARMGOTEntry* ARMGOT::createGOTPLT()
-{
+ARMGOTEntry* ARMGOT::createGOTPLT() {
ARMGOTEntry* entry = new ARMGOTEntry(0, NULL);
m_GOTPLT.push_back(entry);
return entry;
}
-void ARMGOT::finalizeSectionSize()
-{
+void ARMGOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::FragmentListType& frag_list = m_SectionData->getFragmentList();
// setup GOT0 offset
@@ -96,20 +90,18 @@
m_Section.setSize(offset);
}
-void ARMGOT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<ARMGOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void ARMGOT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<ARMGOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void ARMGOT::applyGOTPLT(uint64_t pPLTBase)
-{
- if (NULL == m_pGOTPLTFront)
+void ARMGOT::applyGOTPLT(uint64_t pPLTBase) {
+ if (m_pGOTPLTFront == NULL)
return;
SectionData::iterator entry(m_pGOTPLTFront);
SectionData::iterator e_end;
- if (NULL == m_pGOTFront)
+ if (m_pGOTFront == NULL)
e_end = m_SectionData->end();
else
e_end = SectionData::iterator(m_pGOTFront);
@@ -120,17 +112,17 @@
}
}
-uint64_t ARMGOT::emit(MemoryRegion& pRegion)
-{
+uint64_t ARMGOT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
ARMGOTEntry* got = NULL;
uint64_t result = 0x0;
for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
- got = &(llvm::cast<ARMGOTEntry>((*it)));
- *buffer = static_cast<uint32_t>(got->getValue());
- result += ARMGOTEntry::EntrySize;
+ got = &(llvm::cast<ARMGOTEntry>((*it)));
+ *buffer = static_cast<uint32_t>(got->getValue());
+ result += ARMGOTEntry::EntrySize;
}
return result;
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMGOT.h b/lib/Target/ARM/ARMGOT.h
index e4515a5..26d39e7 100644
--- a/lib/Target/ARM/ARMGOT.h
+++ b/lib/Target/ARM/ARMGOT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMGOT_H
-#define TARGET_ARM_ARMGOT_H
+#ifndef TARGET_ARM_ARMGOT_H_
+#define TARGET_ARM_ARMGOT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
#include <vector>
@@ -21,12 +21,10 @@
/** \class ARMGOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class ARMGOTEntry : public GOT::Entry<4>
-{
-public:
+class ARMGOTEntry : public GOT::Entry<4> {
+ public:
ARMGOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class ARMGOT
@@ -46,10 +44,9 @@
* +--------------+
*
*/
-class ARMGOT : public GOT
-{
-public:
- ARMGOT(LDSection &pSection);
+class ARMGOT : public GOT {
+ public:
+ explicit ARMGOT(LDSection& pSection);
~ARMGOT();
@@ -66,12 +63,12 @@
bool hasGOT1() const;
-private:
+ private:
typedef std::vector<ARMGOTEntry*> EntryListType;
typedef EntryListType::iterator entry_iterator;
typedef EntryListType::const_iterator const_entry_iterator;
-private:
+ private:
ARMGOTEntry* m_pGOTPLTFront;
ARMGOTEntry* m_pGOTFront;
@@ -82,7 +79,6 @@
EntryListType m_GOT;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARMGOT_H_
diff --git a/lib/Target/ARM/ARMLDBackend.cpp b/lib/Target/ARM/ARMLDBackend.cpp
index 2b30df8..aa429f8 100644
--- a/lib/Target/ARM/ARMLDBackend.cpp
+++ b/lib/Target/ARM/ARMLDBackend.cpp
@@ -17,59 +17,58 @@
#include "THMToTHMStub.h"
#include "THMToARMStub.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/GNUInfo.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
-#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMGNULDBackend
//===----------------------------------------------------------------------===//
ARMGNULDBackend::ARMGNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pPLT(NULL),
- m_pRelDyn(NULL),
- m_pRelPLT(NULL),
- m_pAttrData(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_pEXIDXStart(NULL),
- m_pEXIDXEnd(NULL),
- m_pEXIDX(NULL),
- m_pEXTAB(NULL),
- m_pAttributes(NULL) {
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pPLT(NULL),
+ m_pRelDyn(NULL),
+ m_pRelPLT(NULL),
+ m_pAttrData(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_pEXIDXStart(NULL),
+ m_pEXIDXEnd(NULL),
+ m_pEXIDX(NULL),
+ m_pEXTAB(NULL),
+ m_pAttributes(NULL) {
}
-ARMGNULDBackend::~ARMGNULDBackend()
-{
+ARMGNULDBackend::~ARMGNULDBackend() {
delete m_pRelocator;
delete m_pGOT;
delete m_pPLT;
@@ -79,25 +78,26 @@
delete m_pAttrData;
}
-void ARMGNULDBackend::initTargetSections(Module& pModule, ObjectBuilder& pBuilder)
-{
- // FIXME: Currently we set exidx and extab to "Exception" and directly emit
- // them from input
- m_pEXIDX = pBuilder.CreateSection(".ARM.exidx",
- LDFileFormat::Target,
- llvm::ELF::SHT_ARM_EXIDX,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_LINK_ORDER,
- config().targets().bitclass() / 8);
- m_pEXTAB = pBuilder.CreateSection(".ARM.extab",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- m_pAttributes = pBuilder.CreateSection(".ARM.attributes",
- LDFileFormat::Target,
- llvm::ELF::SHT_ARM_ATTRIBUTES,
- 0x0,
- 0x1);
+void ARMGNULDBackend::initTargetSections(Module& pModule,
+ ObjectBuilder& pBuilder) {
+ // FIXME: Currently we set exidx and extab to "Exception" and directly emit
+ // them from input
+ m_pEXIDX =
+ pBuilder.CreateSection(".ARM.exidx",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_ARM_EXIDX,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_LINK_ORDER,
+ config().targets().bitclass() / 8);
+ m_pEXTAB = pBuilder.CreateSection(".ARM.extab",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ m_pAttributes = pBuilder.CreateSection(".ARM.attributes",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_ARM_ATTRIBUTES,
+ 0x0,
+ 0x1);
// initialize "aeabi" attributes subsection
m_pAttrData = new ARMELFAttributeData();
@@ -126,102 +126,95 @@
}
}
-void ARMGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void ARMGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
if (LinkerConfig::Object != config().codeGenType()) {
- m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ m_pGOTSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
- if (NULL != m_pEXIDX && 0x0 != m_pEXIDX->size()) {
+ if (m_pEXIDX != NULL && m_pEXIDX->size() != 0x0) {
FragmentRef* exidx_start =
- FragmentRef::Create(m_pEXIDX->getSectionData()->front(), 0x0);
- FragmentRef* exidx_end =
- FragmentRef::Create(m_pEXIDX->getSectionData()->front(),
- m_pEXIDX->size());
+ FragmentRef::Create(m_pEXIDX->getSectionData()->front(), 0x0);
+ FragmentRef* exidx_end = FragmentRef::Create(
+ m_pEXIDX->getSectionData()->front(), m_pEXIDX->size());
m_pEXIDXStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_start",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- exidx_start, // FragRef
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_start",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ exidx_start, // FragRef
+ ResolveInfo::Default);
- m_pEXIDXEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_end",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- exidx_end, // FragRef
- ResolveInfo::Default);
+ m_pEXIDXEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_end",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ exidx_end, // FragRef
+ ResolveInfo::Default);
// change __exidx_start/_end to local dynamic category
- if (NULL != m_pEXIDXStart)
+ if (m_pEXIDXStart != NULL)
pModule.getSymbolTable().changeToDynamic(*m_pEXIDXStart);
- if (NULL != m_pEXIDXEnd)
+ if (m_pEXIDXEnd != NULL)
pModule.getSymbolTable().changeToDynamic(*m_pEXIDXEnd);
} else {
m_pEXIDXStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Default);
- m_pEXIDXEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Default);
+ m_pEXIDXEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Default);
}
}
-bool ARMGNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool ARMGNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new ARMRelocator(*this, config());
}
return true;
}
-const Relocator* ARMGNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* ARMGNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* ARMGNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* ARMGNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new ARMELFDynamic(*this, config());
// set attribute section size
@@ -230,9 +223,8 @@
// set .got size
// when building shared object, the .got section is must
if (LinkerConfig::Object != config().codeGenType()) {
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
@@ -244,31 +236,32 @@
ELFFileFormat* file_format = getOutputFormat();
// set .rel.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelDyn().setSize(
- m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
// set .rel.plt size
if (!m_pRelPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelPlt().setSize(
- m_pRelPLT->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelEntrySize());
}
}
}
-void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *file_format = getOutputFormat();
+void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* file_format = getOutputFormat();
// apply PLT
if (file_format->hasPLT()) {
// Since we already have the size of LDSection PLT, m_pPLT should not be
// NULL.
- assert(NULL != m_pPLT);
+ assert(m_pPLT != NULL);
m_pPLT->applyPLT0();
m_pPLT->applyPLT1();
}
@@ -276,7 +269,7 @@
// apply GOT
if (file_format->hasGOT()) {
// Since we already have the size of GOT, m_pGOT should not be NULL.
- assert(NULL != m_pGOT);
+ assert(m_pGOT != NULL);
if (LinkerConfig::DynObj == config().codeGenType())
m_pGOT->applyGOT0(file_format->getDynamic().addr());
else {
@@ -288,51 +281,45 @@
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-ARMELFDynamic& ARMGNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+ARMELFDynamic& ARMGNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const ARMELFDynamic& ARMGNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const ARMELFDynamic& ARMGNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-void ARMGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void ARMGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// define symbol _GLOBAL_OFFSET_TABLE_ when .got create
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
-
}
uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -358,11 +345,10 @@
uint8_t* out_offset = pRegion.begin();
for (frag_iter = sect_data->begin(); frag_iter != frag_end; ++frag_iter) {
size_t size = frag_iter->size();
- switch(frag_iter->getKind()) {
+ switch (frag_iter->getKind()) {
case Fragment::Fillment: {
- const FillFragment& fill_frag =
- llvm::cast<FillFragment>(*frag_iter);
- if (0 == fill_frag.getValueSize()) {
+ const FillFragment& fill_frag = llvm::cast<FillFragment>(*frag_iter);
+ if (fill_frag.getValueSize() == 0) {
// virtual fillment, ignore it.
break;
}
@@ -372,7 +358,7 @@
}
case Fragment::Region: {
const RegionFragment& region_frag =
- llvm::cast<RegionFragment>(*frag_iter);
+ llvm::cast<RegionFragment>(*frag_iter);
const char* start = region_frag.getRegion().begin();
memcpy(out_offset, start, size);
break;
@@ -386,9 +372,9 @@
break;
default:
llvm::report_fatal_error(
- "unsupported value size for align fragment emission yet.\n");
+ "unsupported value size for align fragment emission yet.\n");
break;
- } // end switch
+ } // end switch
break;
}
case Fragment::Null: {
@@ -398,29 +384,28 @@
default:
llvm::report_fatal_error("unsupported fragment type.\n");
break;
- } // end switch
+ } // end switch
out_offset += size;
- } // end for
+ } // end for
return pRegion.size();
}
/// finalizeSymbol - finalize the symbol value
-bool ARMGNULDBackend::finalizeTargetSymbols()
-{
+bool ARMGNULDBackend::finalizeTargetSymbols() {
return true;
}
bool ARMGNULDBackend::mergeSection(Module& pModule,
const Input& pInput,
- LDSection& pSection)
-{
+ LDSection& pSection) {
switch (pSection.type()) {
case llvm::ELF::SHT_ARM_ATTRIBUTES: {
return attribute().merge(pInput, pSection);
}
case llvm::ELF::SHT_ARM_EXIDX: {
- assert(NULL != pSection.getLink());
- if (LDFileFormat::Ignore == pSection.getLink()->kind()) {
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->kind() == LDFileFormat::Ignore) ||
+ (pSection.getLink()->kind() == LDFileFormat::Folded)) {
// if the target section of the .ARM.exidx is Ignore, then it should be
// ignored as well
pSection.setKind(LDFileFormat::Ignore);
@@ -433,19 +418,19 @@
builder.MergeSection(pInput, pSection);
return true;
}
- } // end of switch
+ } // end of switch
return true;
}
-void ARMGNULDBackend::setUpReachedSectionsForGC(const Module& pModule,
- GarbageCollection::SectionReachedListMap& pSectReachedListMap) const
-{
+void ARMGNULDBackend::setUpReachedSectionsForGC(
+ const Module& pModule,
+ GarbageCollection::SectionReachedListMap& pSectReachedListMap) const {
// traverse all the input relocations to find the relocation sections applying
// .ARM.exidx sections
Module::const_obj_iterator input, inEnd = pModule.obj_end();
for (input = pModule.obj_begin(); input != inEnd; ++input) {
LDContext::const_sect_iterator rs,
- rsEnd = (*input)->context()->relocSectEnd();
+ rsEnd = (*input)->context()->relocSectEnd();
for (rs = (*input)->context()->relocSectBegin(); rs != rsEnd; ++rs) {
// bypass the discarded relocation section
// 1. its section kind is changed to Ignore. (The target section is a
@@ -464,12 +449,12 @@
GarbageCollection::SectionListTy* reached_sects = NULL;
RelocData::iterator reloc_it, rEnd = reloc_sect->getRelocData()->end();
for (reloc_it = reloc_sect->getRelocData()->begin(); reloc_it != rEnd;
- ++reloc_it) {
+ ++reloc_it) {
Relocation* reloc = llvm::cast<Relocation>(reloc_it);
ResolveInfo* sym = reloc->symInfo();
// only the target symbols defined in the input fragments can make the
// reference
- if (NULL == sym)
+ if (sym == NULL)
continue;
if (!sym->isDefine() || !sym->outSymbol()->hasFragRef())
continue;
@@ -477,7 +462,7 @@
// only the target symbols defined in the concerned sections can make
// the reference
const LDSection* target_sect =
- &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
if (target_sect->kind() != LDFileFormat::TEXT &&
target_sect->kind() != LDFileFormat::DATA &&
target_sect->kind() != LDFileFormat::BSS)
@@ -501,8 +486,7 @@
}
}
-bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD) {
Fragment* frag = NULL;
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
@@ -512,8 +496,7 @@
// If the input section's size is zero, we got a NULL region.
// use a virtual fill fragment
frag = new FillFragment(0x0, 0, 0);
- }
- else {
+ } else {
frag = new RegionFragment(region);
}
@@ -521,69 +504,58 @@
return true;
}
-ARMGOT& ARMGNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+ARMGOT& ARMGNULDBackend::getGOT() {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-const ARMGOT& ARMGNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+const ARMGOT& ARMGNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-ARMPLT& ARMGNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+ARMPLT& ARMGNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const ARMPLT& ARMGNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const ARMPLT& ARMGNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& ARMGNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn && ".rel.dyn section not exist");
+OutputRelocSection& ARMGNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL && ".rel.dyn section not exist");
return *m_pRelDyn;
}
-const OutputRelocSection& ARMGNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn && ".rel.dyn section not exist");
+const OutputRelocSection& ARMGNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL && ".rel.dyn section not exist");
return *m_pRelDyn;
}
-OutputRelocSection& ARMGNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPLT && ".rel.plt section not exist");
+OutputRelocSection& ARMGNULDBackend::getRelPLT() {
+ assert(m_pRelPLT != NULL && ".rel.plt section not exist");
return *m_pRelPLT;
}
-const OutputRelocSection& ARMGNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPLT && ".rel.plt section not exist");
+const OutputRelocSection& ARMGNULDBackend::getRelPLT() const {
+ assert(m_pRelPLT != NULL && ".rel.plt section not exist");
return *m_pRelPLT;
}
-ARMELFAttributeData& ARMGNULDBackend::getAttributeData()
-{
- assert(NULL != m_pAttrData && ".ARM.attributes section not exist");
+ARMELFAttributeData& ARMGNULDBackend::getAttributeData() {
+ assert(m_pAttrData != NULL && ".ARM.attributes section not exist");
return *m_pAttrData;
}
-const ARMELFAttributeData& ARMGNULDBackend::getAttributeData() const
-{
- assert(NULL != m_pAttrData && ".ARM.attributes section not exist");
+const ARMELFAttributeData& ARMGNULDBackend::getAttributeData() const {
+ assert(m_pAttrData != NULL && ".ARM.attributes section not exist");
return *m_pAttrData;
}
-unsigned int
-ARMGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int ARMGNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -604,10 +576,10 @@
}
/// doRelax
-bool
-ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool ARMGNULDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
ELFFileFormat* file_format = getOutputFormat();
@@ -637,40 +609,43 @@
if (symbol->hasFragRef()) {
uint64_t value = symbol->fragRef()->getOutputOffset();
uint64_t addr =
- symbol->fragRef()->frag()->getParent()->getSection().addr();
+ symbol->fragRef()->frag()->getParent()->getSection().addr();
sym_value = addr + value;
}
- if (relocation->symInfo()->isGlobal() &&
- (relocation->symInfo()->reserved() & ARMRelocator::ReservePLT) != 0x0) {
- // FIXME: we need to find out the address of the specific plt entry
+ if ((relocation->symInfo()->reserved() &
+ ARMRelocator::ReservePLT) != 0x0) {
+ // FIXME: we need to find out the address of the specific plt
+ // entry
assert(file_format->hasPLT());
sym_value = file_format->getPLT().addr();
}
-
- Stub* stub = getStubFactory()->create(*relocation, // relocation
- sym_value, // symbol value
+ Stub* stub = getStubFactory()->create(*relocation, // relocation
+ sym_value, // symbol value
pBuilder,
*getBRIslandFactory());
- if (NULL != stub) {
+ if (stub != NULL) {
switch (config().options().getStripSymbolMode()) {
case GeneralOptions::StripAllSymbols:
case GeneralOptions::StripLocals:
break;
default: {
// a stub symbol should be local
- assert(NULL != stub->symInfo() && stub->symInfo()->isLocal());
+ assert(stub->symInfo() != NULL && stub->symInfo()->isLocal());
LDSection& symtab = file_format->getSymTab();
LDSection& strtab = file_format->getStrTab();
// increase the size of .symtab and .strtab if needed
if (config().targets().is32Bits())
- symtab.setSize(symtab.size() + sizeof(llvm::ELF::Elf32_Sym));
+ symtab.setSize(symtab.size() +
+ sizeof(llvm::ELF::Elf32_Sym));
else
- symtab.setSize(symtab.size() + sizeof(llvm::ELF::Elf64_Sym));
+ symtab.setSize(symtab.size() +
+ sizeof(llvm::ELF::Elf64_Sym));
symtab.setInfo(symtab.getInfo() + 1);
- strtab.setSize(strtab.size() + stub->symInfo()->nameSize() + 1);
+ strtab.setSize(strtab.size() + stub->symInfo()->nameSize() +
+ 1);
}
- } // end of switch
+ } // end of switch
isRelaxed = true;
}
break;
@@ -680,17 +655,18 @@
break;
default:
break;
- } // end of switch
-
- } // for all relocations
- } // for all relocation section
- } // for all inputs
+ } // end of switch
+ } // for all relocations
+ } // for all relocation section
+ } // for all inputs
// find the first fragment w/ invalid offset due to stub insertion
Fragment* invalid = NULL;
pFinished = true;
for (BranchIslandFactory::iterator island = getBRIslandFactory()->begin(),
- island_end = getBRIslandFactory()->end(); island != island_end; ++island) {
+ island_end = getBRIslandFactory()->end();
+ island != island_end;
+ ++island) {
if ((*island).end() == file_format->getText().getSectionData()->end())
break;
@@ -703,7 +679,7 @@
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -712,16 +688,15 @@
// reset the size of .text
if (isRelaxed) {
file_format->getText().setSize(
- file_format->getText().getSectionData()->back().getOffset() +
- file_format->getText().getSectionData()->back().size());
+ file_format->getText().getSectionData()->back().getOffset() +
+ file_format->getText().getSectionData()->back().size());
}
return isRelaxed;
}
/// initTargetStubs
-bool ARMGNULDBackend::initTargetStubs()
-{
- if (NULL != getStubFactory()) {
+bool ARMGNULDBackend::initTargetStubs() {
+ if (getStubFactory() != NULL) {
getStubFactory()->addPrototype(new ARMToARMStub(config().isCodeIndep()));
getStubFactory()->addPrototype(new ARMToTHMStub(config().isCodeIndep()));
getStubFactory()->addPrototype(
@@ -734,8 +709,7 @@
}
/// maxFwdBranchOffset
-int64_t ARMGNULDBackend::maxFwdBranchOffset()
-{
+int64_t ARMGNULDBackend::maxFwdBranchOffset() {
if (m_pAttrData->usingThumb2()) {
return THM2_MAX_FWD_BRANCH_OFFSET;
} else {
@@ -744,8 +718,7 @@
}
/// maxBwdBranchOffset
-int64_t ARMGNULDBackend::maxBwdBranchOffset()
-{
+int64_t ARMGNULDBackend::maxBwdBranchOffset() {
if (m_pAttrData->usingThumb2()) {
return THM2_MAX_BWD_BRANCH_OFFSET;
} else {
@@ -755,36 +728,28 @@
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void ARMGNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
- if (NULL != m_pEXIDX && 0x0 != m_pEXIDX->size()) {
- // make PT_ARM_EXIDX
- ELFSegment* exidx_seg = elfSegmentTable().produce(llvm::ELF::PT_ARM_EXIDX,
- llvm::ELF::PF_R);
- exidx_seg->append(m_pEXIDX);
- }
+void ARMGNULDBackend::doCreateProgramHdrs(Module& pModule) {
+ if (m_pEXIDX != NULL && m_pEXIDX->size() != 0x0) {
+ // make PT_ARM_EXIDX
+ ELFSegment* exidx_seg =
+ elfSegmentTable().produce(llvm::ELF::PT_ARM_EXIDX, llvm::ELF::PF_R);
+ exidx_seg->append(m_pEXIDX);
+ }
}
/// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe
/// function pointer access
-bool
-ARMGNULDBackend::mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection)
- const
-{
+bool ARMGNULDBackend::mayHaveUnsafeFunctionPointerAccess(
+ const LDSection& pSection) const {
llvm::StringRef name(pSection.name());
- return !name.startswith(".ARM.exidx") &&
- !name.startswith(".ARM.extab") &&
+ return !name.startswith(".ARM.exidx") && !name.startswith(".ARM.extab") &&
GNULDBackend::mayHaveUnsafeFunctionPointerAccess(pSection);
}
-
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createARMLDBackend - the help funtion to create corresponding ARMLDBackend
///
-TargetLDBackend* createARMLDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createARMLDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -801,17 +766,19 @@
createARMCOFFObjectWriter);
**/
}
- return new ARMGNULDBackend(pConfig, new ARMGNUInfo(pConfig.targets().triple()));
+ return new ARMGNULDBackend(pConfig,
+ new ARMGNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMLDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheARMTarget, createARMLDBackend);
- mcld::TargetRegistry::RegisterTargetLDBackend(TheThumbTarget, createARMLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheARMTarget,
+ mcld::createARMLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheThumbTarget,
+ mcld::createARMLDBackend);
}
-
diff --git a/lib/Target/ARM/ARMLDBackend.h b/lib/Target/ARM/ARMLDBackend.h
index 14d3fde..aad31e8 100644
--- a/lib/Target/ARM/ARMLDBackend.h
+++ b/lib/Target/ARM/ARMLDBackend.h
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMLDBACKEND_H
-#define TARGET_ARM_ARMLDBACKEND_H
+#ifndef TARGET_ARM_ARMLDBACKEND_H_
+#define TARGET_ARM_ARMLDBACKEND_H_
#include "ARMELFDynamic.h"
#include "ARMGOT.h"
#include "ARMPLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
class ARMELFAttributeData;
-class LinkerConfig;
class GNUInfo;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
/// ARMGNULDBackend - linker backend of ARM target of GNU ELF format
///
-class ARMGNULDBackend : public GNULDBackend
-{
-public:
+class ARMGNULDBackend : public GNULDBackend {
+ public:
// max branch offsets for ARM, THUMB, and THUMB2
- // @ref gold/arm.cc:99
static const int32_t ARM_MAX_FWD_BRANCH_OFFSET = ((((1 << 23) - 1) << 2) + 8);
static const int32_t ARM_MAX_BWD_BRANCH_OFFSET = ((-((1 << 23) << 2)) + 8);
- static const int32_t THM_MAX_FWD_BRANCH_OFFSET = ((1 << 22) -2 + 4);
+ static const int32_t THM_MAX_FWD_BRANCH_OFFSET = ((1 << 22) - 2 + 4);
static const int32_t THM_MAX_BWD_BRANCH_OFFSET = (-(1 << 22) + 4);
static const int32_t THM2_MAX_FWD_BRANCH_OFFSET = (((1 << 24) - 2) + 4);
static const int32_t THM2_MAX_BWD_BRANCH_OFFSET = (-(1 << 24) + 4);
-public:
+ public:
ARMGNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~ARMGNULDBackend();
-public:
+ public:
typedef std::vector<llvm::ELF::Elf32_Dyn*> ELF32DynList;
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output.
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -72,7 +70,6 @@
/// Use co-variant return type to return its own dynamic section.
const ARMELFDynamic& dynamic() const;
-
/// emitSectionData - write out the section data into the memory region.
/// When writers get a LDSection whose kind is LDFileFormat::Target, writers
/// call back target backend to emit the data.
@@ -106,7 +103,7 @@
ARMELFAttributeData& getAttributeData();
const ARMELFAttributeData& getAttributeData() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
/// getTargetSectionOrder - compute the layout order of ARM target sections
@@ -120,8 +117,9 @@
/// setUpReachedSectionsForGC - set the reference from section XXX to
/// .ARM.exidx.XXX to make sure GC correctly handle section exidx
- void setUpReachedSectionsForGC(const Module& pModule,
- GarbageCollection::SectionReachedListMap& pSectReachedListMap) const;
+ void setUpReachedSectionsForGC(
+ const Module& pModule,
+ GarbageCollection::SectionReachedListMap& pSectReachedListMap) const;
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
@@ -130,7 +128,7 @@
/// function pointer access
bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection) const;
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
/// maxFwdBranchOffset
@@ -151,18 +149,19 @@
bool initTargetStubs();
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return 8; }
+ size_t getRelEntrySize() { return 8; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { assert(0 && "ARM backend with Rela type relocation\n"); return 12; }
+ size_t getRelaEntrySize() {
+ assert(0 && "ARM backend with Rela type relocation\n");
+ return 12;
+ }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
virtual void doCreateProgramHdrs(Module& pModule);
-private:
+ private:
Relocator* m_pRelocator;
ARMGOT* m_pGOT;
@@ -181,14 +180,13 @@
LDSymbol* m_pEXIDXEnd;
// variable name : ELF
- LDSection* m_pEXIDX; // .ARM.exidx
- LDSection* m_pEXTAB; // .ARM.extab
- LDSection* m_pAttributes; // .ARM.attributes
-// LDSection* m_pPreemptMap; // .ARM.preemptmap
-// LDSection* m_pDebugOverlay; // .ARM.debug_overlay
-// LDSection* m_pOverlayTable; // .ARM.overlay_table
+ LDSection* m_pEXIDX; // .ARM.exidx
+ LDSection* m_pEXTAB; // .ARM.extab
+ LDSection* m_pAttributes; // .ARM.attributes
+ // LDSection* m_pPreemptMap; // .ARM.preemptmap
+ // LDSection* m_pDebugOverlay; // .ARM.debug_overlay
+ // LDSection* m_pOverlayTable; // .ARM.overlay_table
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARMLDBACKEND_H_
diff --git a/lib/Target/ARM/ARMMCLinker.cpp b/lib/Target/ARM/ARMMCLinker.cpp
deleted file mode 100644
index dcee683..0000000
--- a/lib/Target/ARM/ARMMCLinker.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- ARMMCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMELFMCLinker.h"
-
-#include "ARM.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-namespace mcld {
-//===----------------------------------------------------------------------===//
-// createARMMCLinker - the help function to create corresponding ARMMCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createARMMCLinker(const std::string& pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new ARMELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// ARMMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeARMMCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheARMTarget, createARMMCLinker);
- mcld::TargetRegistry::RegisterMCLinker(TheThumbTarget, createARMMCLinker);
-}
-
diff --git a/lib/Target/ARM/ARMPLT.cpp b/lib/Target/ARM/ARMPLT.cpp
index 9ca2af1..b1b87e2 100644
--- a/lib/Target/ARM/ARMPLT.cpp
+++ b/lib/Target/ARM/ARMPLT.cpp
@@ -1,4 +1,4 @@
-//===- ARMPLT.cpp -----------------------------------------------------------===//
+//===- ARMPLT.cpp ---------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -9,42 +9,39 @@
#include "ARMGOT.h"
#include "ARMPLT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <new>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
+namespace mcld {
-using namespace mcld;
+ARMPLT0::ARMPLT0(SectionData& pParent) : PLT::Entry<sizeof(arm_plt0)>(pParent) {
+}
-ARMPLT0::ARMPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(arm_plt0)>(pParent) {}
-
-ARMPLT1::ARMPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(arm_plt1)>(pParent) {}
+ARMPLT1::ARMPLT1(SectionData& pParent) : PLT::Entry<sizeof(arm_plt1)>(pParent) {
+}
//===----------------------------------------------------------------------===//
// ARMPLT
-ARMPLT::ARMPLT(LDSection& pSection, ARMGOT &pGOTPLT)
- : PLT(pSection), m_GOT(pGOTPLT) {
+ARMPLT::ARMPLT(LDSection& pSection, ARMGOT& pGOTPLT)
+ : PLT(pSection), m_GOT(pGOTPLT) {
new ARMPLT0(*m_pSectionData);
}
-ARMPLT::~ARMPLT()
-{
+ARMPLT::~ARMPLT() {
}
-bool ARMPLT::hasPLT1() const
-{
+bool ARMPLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-void ARMPLT::finalizeSectionSize()
-{
- uint64_t size = (m_pSectionData->size() - 1) * sizeof(arm_plt1) +
- sizeof(arm_plt0);
+void ARMPLT::finalizeSectionSize() {
+ uint64_t size =
+ (m_pSectionData->size() - 1) * sizeof(arm_plt1) + sizeof(arm_plt0);
m_Section.setSize(size);
uint32_t offset = 0;
@@ -55,16 +52,14 @@
}
}
-ARMPLT1* ARMPLT::create()
-{
+ARMPLT1* ARMPLT::create() {
ARMPLT1* plt1_entry = new (std::nothrow) ARMPLT1(*m_pSectionData);
if (!plt1_entry)
fatal(diag::fail_allocate_memory_plt);
return plt1_entry;
}
-void ARMPLT::applyPLT0()
-{
+void ARMPLT::applyPLT0() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -97,8 +92,7 @@
plt0->setValue(reinterpret_cast<unsigned char*>(data));
}
-void ARMPLT::applyPLT1()
-{
+void ARMPLT::applyPLT1() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -110,13 +104,11 @@
assert(it != ie && "FragmentList is empty, applyPLT1 failed!");
uint32_t GOTEntrySize = ARMGOTEntry::EntrySize;
- uint32_t GOTEntryAddress =
- got_base + GOTEntrySize * 3;
+ uint32_t GOTEntryAddress = got_base + GOTEntrySize * 3;
- uint64_t PLTEntryAddress =
- plt_base + ARMPLT0::EntrySize; //Offset of PLT0
+ uint64_t PLTEntryAddress = plt_base + ARMPLT0::EntrySize; // Offset of PLT0
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint64_t PLT1EntrySize = ARMPLT1::EntrySize;
ARMPLT1* plt1 = NULL;
@@ -146,8 +138,7 @@
m_GOT.applyGOTPLT(plt_base);
}
-uint64_t ARMPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t ARMPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
@@ -167,3 +158,4 @@
return result;
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMPLT.h b/lib/Target/ARM/ARMPLT.h
index bacda93..2d5883c 100644
--- a/lib/Target/ARM/ARMPLT.h
+++ b/lib/Target/ARM/ARMPLT.h
@@ -6,53 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMPLT_H
-#define TARGET_ARM_ARMPLT_H
+#ifndef TARGET_ARM_ARMPLT_H_
+#define TARGET_ARM_ARMPLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Support/MemoryRegion.h"
const uint32_t arm_plt0[] = {
- 0xe52de004, // str lr, [sp, #-4]!
- 0xe59fe004, // ldr lr, [pc, #4]
- 0xe08fe00e, // add lr, pc, lr
- 0xe5bef008, // ldr pc, [lr, #8]!
- 0x00000000 // &GOT[0] - .
+ 0xe52de004, // str lr, [sp, #-4]!
+ 0xe59fe004, // ldr lr, [pc, #4]
+ 0xe08fe00e, // add lr, pc, lr
+ 0xe5bef008, // ldr pc, [lr, #8]!
+ 0x00000000 // &GOT[0] - .
};
const uint32_t arm_plt1[] = {
- 0xe28fc600, // add ip, pc, #0xNN00000
- 0xe28cca00, // add ip, ip, #0xNN000
- 0xe5bcf000 // ldr pc, [ip, #0xNNN]!
+ 0xe28fc600, // add ip, pc, #0xNN00000
+ 0xe28cca00, // add ip, ip, #0xNN000
+ 0xe5bcf000 // ldr pc, [ip, #0xNNN]!
};
-} // anonymous namespace
-
namespace mcld {
class ARMGOT;
-class ARMPLT0 : public PLT::Entry<sizeof(arm_plt0)>
-{
-public:
+class ARMPLT0 : public PLT::Entry<sizeof(arm_plt0)> {
+ public:
ARMPLT0(SectionData& pParent);
};
-class ARMPLT1 : public PLT::Entry<sizeof(arm_plt1)>
-{
-public:
+class ARMPLT1 : public PLT::Entry<sizeof(arm_plt1)> {
+ public:
ARMPLT1(SectionData& pParent);
};
/** \class ARMPLT
* \brief ARM Procedure Linkage Table
*/
-class ARMPLT : public PLT
-{
-public:
+class ARMPLT : public PLT {
+ public:
ARMPLT(LDSection& pSection, ARMGOT& pGOTPLT);
~ARMPLT();
@@ -72,11 +65,10 @@
uint64_t emit(MemoryRegion& pRegion);
-private:
+ private:
ARMGOT& m_GOT;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARMPLT_H_
diff --git a/lib/Target/ARM/ARMRelocationFunctions.h b/lib/Target/ARM/ARMRelocationFunctions.h
index 58f00ce..141d8a7 100644
--- a/lib/Target/ARM/ARMRelocationFunctions.h
+++ b/lib/Target/ARM/ARMRelocationFunctions.h
@@ -6,167 +6,169 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
+#define TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
#define DECL_ARM_APPLY_RELOC_FUNC(Name) \
-static ARMRelocator::Result Name (Relocation& pEntry, \
- ARMRelocator& pParent);
+ static ARMRelocator::Result Name(Relocation& pEntry, ARMRelocator& pParent);
-#define DECL_ARM_APPLY_RELOC_FUNCS \
-DECL_ARM_APPLY_RELOC_FUNC(none) \
-DECL_ARM_APPLY_RELOC_FUNC(abs32) \
-DECL_ARM_APPLY_RELOC_FUNC(rel32) \
-DECL_ARM_APPLY_RELOC_FUNC(gotoff32) \
-DECL_ARM_APPLY_RELOC_FUNC(base_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(got_brel) \
-DECL_ARM_APPLY_RELOC_FUNC(call) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_call) \
-DECL_ARM_APPLY_RELOC_FUNC(movw_prel_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(movw_abs_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(movt_abs) \
-DECL_ARM_APPLY_RELOC_FUNC(movt_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_abs_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_prel_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_brel) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movt_abs) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movt_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(prel31) \
-DECL_ARM_APPLY_RELOC_FUNC(got_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(tls) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump8) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump11) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump19) \
-DECL_ARM_APPLY_RELOC_FUNC(unsupport)
+#define DECL_ARM_APPLY_RELOC_FUNCS \
+ DECL_ARM_APPLY_RELOC_FUNC(none) \
+ DECL_ARM_APPLY_RELOC_FUNC(abs32) \
+ DECL_ARM_APPLY_RELOC_FUNC(rel32) \
+ DECL_ARM_APPLY_RELOC_FUNC(gotoff32) \
+ DECL_ARM_APPLY_RELOC_FUNC(base_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(got_brel) \
+ DECL_ARM_APPLY_RELOC_FUNC(call) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_call) \
+ DECL_ARM_APPLY_RELOC_FUNC(movw_prel_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(movw_abs_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(movt_abs) \
+ DECL_ARM_APPLY_RELOC_FUNC(movt_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_abs_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_prel_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_brel) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movt_abs) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movt_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(prel31) \
+ DECL_ARM_APPLY_RELOC_FUNC(got_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(tls) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump8) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump11) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump19) \
+ DECL_ARM_APPLY_RELOC_FUNC(unsupported)
+#define DECL_ARM_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_ARM_NONE" }, \
+ { &call, 1, "R_ARM_PC24" }, \
+ { &abs32, 2, "R_ARM_ABS32" }, \
+ { &rel32, 3, "R_ARM_REL32" }, \
+ { &unsupported, 4, "R_ARM_LDR_PC_G0" }, \
+ { &unsupported, 5, "R_ARM_ABS16" }, \
+ { &unsupported, 6, "R_ARM_ABS12" }, \
+ { &unsupported, 7, "R_ARM_THM_ABS5" }, \
+ { &unsupported, 8, "R_ARM_ABS8" }, \
+ { &unsupported, 9, "R_ARM_SBREL32" }, \
+ { &thm_call, 10, "R_ARM_THM_CALL" }, \
+ { &unsupported, 11, "R_ARM_THM_PC8" }, \
+ { &unsupported, 12, "R_ARM_BREL_ADJ" }, \
+ { &unsupported, 13, "R_ARM_TLS_DESC" }, \
+ { &unsupported, 14, "R_ARM_THM_SWI8" }, \
+ { &unsupported, 15, "R_ARM_XPC25" }, \
+ { &unsupported, 16, "R_ARM_THM_XPC22" }, \
+ { &unsupported, 17, "R_ARM_TLS_DTPMOD32" }, \
+ { &unsupported, 18, "R_ARM_TLS_DTPOFF32" }, \
+ { &unsupported, 19, "R_ARM_TLS_TPOFF32" }, \
+ { &unsupported, 20, "R_ARM_COPY" }, \
+ { &unsupported, 21, "R_ARM_GLOB_DAT" }, \
+ { &unsupported, 22, "R_ARM_JUMP_SLOT" }, \
+ { &unsupported, 23, "R_ARM_RELATIVE" }, \
+ { &gotoff32, 24, "R_ARM_GOTOFF32" }, \
+ { &base_prel, 25, "R_ARM_BASE_PREL" }, \
+ { &got_brel, 26, "R_ARM_GOT_BREL" }, \
+ { &call, 27, "R_ARM_PLT32" }, \
+ { &call, 28, "R_ARM_CALL" }, \
+ { &call, 29, "R_ARM_JUMP24" }, \
+ { &thm_call, 30, "R_ARM_THM_JUMP24" }, \
+ { &unsupported, 31, "R_ARM_BASE_ABS" }, \
+ { &unsupported, 32, "R_ARM_ALU_PCREL_7_0" }, \
+ { &unsupported, 33, "R_ARM_ALU_PCREL_15_8" }, \
+ { &unsupported, 34, "R_ARM_ALU_PCREL_23_15" }, \
+ { &unsupported, 35, "R_ARM_LDR_SBREL_11_0_NC" }, \
+ { &unsupported, 36, "R_ARM_ALU_SBREL_19_12_NC" }, \
+ { &unsupported, 37, "R_ARM_ALU_SBREL_27_20_CK" }, \
+ { &abs32, 38, "R_ARM_TARGET1" }, \
+ { &unsupported, 39, "R_ARM_SBREL31" }, \
+ { &none, 40, "R_ARM_V4BX" }, \
+ { &got_prel, 41, "R_ARM_TARGET2" }, \
+ { &prel31, 42, "R_ARM_PREL31" }, \
+ { &movw_abs_nc, 43, "R_ARM_MOVW_ABS_NC" }, \
+ { &movt_abs, 44, "R_ARM_MOVT_ABS" }, \
+ { &movw_prel_nc, 45, "R_ARM_MOVW_PREL_NC" }, \
+ { &movt_prel, 46, "R_ARM_MOVT_PREL" }, \
+ { &thm_movw_abs_nc, 47, "R_ARM_THM_MOVW_ABS_NC" }, \
+ { &thm_movt_abs, 48, "R_ARM_THM_MOVT_ABS" }, \
+ { &thm_movw_prel_nc, 49, "R_ARM_THM_MOVW_PREL_NC" }, \
+ { &thm_movt_prel, 50, "R_ARM_THM_MOVT_PREL" }, \
+ { &thm_jump19, 51, "R_ARM_THM_JUMP19" }, \
+ { &unsupported, 52, "R_ARM_THM_JUMP6" }, \
+ { &unsupported, 53, "R_ARM_THM_ALU_PREL_11_0" }, \
+ { &unsupported, 54, "R_ARM_THM_PC12" }, \
+ { &unsupported, 55, "R_ARM_ABS32_NOI" }, \
+ { &unsupported, 56, "R_ARM_REL32_NOI" }, \
+ { &unsupported, 57, "R_ARM_ALU_PC_G0_NC" }, \
+ { &unsupported, 58, "R_ARM_ALU_PC_G0" }, \
+ { &unsupported, 59, "R_ARM_ALU_PC_G1_NC" }, \
+ { &unsupported, 60, "R_ARM_ALU_PC_G1" }, \
+ { &unsupported, 61, "R_ARM_ALU_PC_G2" }, \
+ { &unsupported, 62, "R_ARM_LDR_PC_G1" }, \
+ { &unsupported, 63, "R_ARM_LDR_PC_G2" }, \
+ { &unsupported, 64, "R_ARM_LDRS_PC_G0" }, \
+ { &unsupported, 65, "R_ARM_LDRS_PC_G1" }, \
+ { &unsupported, 66, "R_ARM_LDRS_PC_G2" }, \
+ { &unsupported, 67, "R_ARM_LDC_PC_G0" }, \
+ { &unsupported, 68, "R_ARM_LDC_PC_G1" }, \
+ { &unsupported, 69, "R_ARM_LDC_PC_G2" }, \
+ { &unsupported, 70, "R_ARM_ALU_SB_G0_NC" }, \
+ { &unsupported, 71, "R_ARM_ALU_SB_G0" }, \
+ { &unsupported, 72, "R_ARM_ALU_SB_G1_NC" }, \
+ { &unsupported, 73, "R_ARM_ALU_SB_G1" }, \
+ { &unsupported, 74, "R_ARM_ALU_SB_G2" }, \
+ { &unsupported, 75, "R_ARM_LDR_SB_G0" }, \
+ { &unsupported, 76, "R_ARM_LDR_SB_G1" }, \
+ { &unsupported, 77, "R_ARM_LDR_SB_G2" }, \
+ { &unsupported, 78, "R_ARM_LDRS_SB_G0" }, \
+ { &unsupported, 79, "R_ARM_LDRS_SB_G1" }, \
+ { &unsupported, 80, "R_ARM_LDRS_SB_G2" }, \
+ { &unsupported, 81, "R_ARM_LDC_SB_G0" }, \
+ { &unsupported, 82, "R_ARM_LDC_SB_G1" }, \
+ { &unsupported, 83, "R_ARM_LDC_SB_G2" }, \
+ { &unsupported, 84, "R_ARM_MOVW_BREL_NC" }, \
+ { &unsupported, 85, "R_ARM_MOVT_BREL" }, \
+ { &unsupported, 86, "R_ARM_MOVW_BREL" }, \
+ { &thm_movw_brel, 87, "R_ARM_THM_MOVW_BREL_NC" }, \
+ { &thm_movt_prel, 88, "R_ARM_THM_MOVT_BREL" }, \
+ { &thm_movw_brel, 89, "R_ARM_THM_MOVW_BREL" }, \
+ { &unsupported, 90, "R_ARM_TLS_GOTDESC" }, \
+ { &unsupported, 91, "R_ARM_TLS_CALL" }, \
+ { &unsupported, 92, "R_ARM_TLS_DESCSEQ" }, \
+ { &unsupported, 93, "R_ARM_THM_TLS_CALL" }, \
+ { &unsupported, 94, "R_ARM_PLT32_ABS" }, \
+ { &unsupported, 95, "R_ARM_GOT_ABS" }, \
+ { &got_prel, 96, "R_ARM_GOT_PREL" }, \
+ { &unsupported, 97, "R_ARM_GOT_PREL12" }, \
+ { &unsupported, 98, "R_ARM_GOTOFF12" }, \
+ { &unsupported, 99, "R_ARM_GOTRELAX" }, \
+ { &unsupported, 100, "R_ARM_GNU_VTENTRY" }, \
+ { &unsupported, 101, "R_ARM_GNU_VTINERIT" }, \
+ { &thm_jump11, 102, "R_ARM_THM_JUMP11" }, \
+ { &thm_jump8, 103, "R_ARM_THM_JUMP8" }, \
+ { &tls, 104, "R_ARM_TLS_GD32" }, \
+ { &unsupported, 105, "R_ARM_TLS_LDM32" }, \
+ { &unsupported, 106, "R_ARM_TLS_LDO32" }, \
+ { &tls, 107, "R_ARM_TLS_IE32" }, \
+ { &tls, 108, "R_ARM_TLS_LE32" }, \
+ { &unsupported, 109, "R_ARM_TLS_LDO12" }, \
+ { &unsupported, 110, "R_ARM_TLS_LE12" }, \
+ { &unsupported, 111, "R_ARM_TLS_IE12GP" }, \
+ { &unsupported, 112, "R_ARM_PRIVATE_0" }, \
+ { &unsupported, 113, "R_ARM_PRIVATE_1" }, \
+ { &unsupported, 114, "R_ARM_PRIVATE_2" }, \
+ { &unsupported, 115, "R_ARM_PRIVATE_3" }, \
+ { &unsupported, 116, "R_ARM_PRIVATE_4" }, \
+ { &unsupported, 117, "R_ARM_PRIVATE_5" }, \
+ { &unsupported, 118, "R_ARM_PRIVATE_6" }, \
+ { &unsupported, 119, "R_ARM_PRIVATE_7" }, \
+ { &unsupported, 120, "R_ARM_PRIVATE_8" }, \
+ { &unsupported, 121, "R_ARM_PRIVATE_9" }, \
+ { &unsupported, 122, "R_ARM_PRIVATE_10" }, \
+ { &unsupported, 123, "R_ARM_PRIVATE_11" }, \
+ { &unsupported, 124, "R_ARM_PRIVATE_12" }, \
+ { &unsupported, 125, "R_ARM_PRIVATE_13" }, \
+ { &unsupported, 126, "R_ARM_PRIVATE_14" }, \
+ { &unsupported, 127, "R_ARM_PRIVATE_15" }, \
+ { &unsupported, 128, "R_ARM_ME_TOO" }, \
+ { &unsupported, 129, "R_ARM_THM_TLS_DESCSEQ16" }, \
+ { &unsupported, 130, "R_ARM_THM_TLS_DESCSEQ32" }
-#define DECL_ARM_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_ARM_NONE" }, \
- { &call, 1, "R_ARM_PC24" }, \
- { &abs32, 2, "R_ARM_ABS32" }, \
- { &rel32, 3, "R_ARM_REL32" }, \
- { &unsupport, 4, "R_ARM_LDR_PC_G0" }, \
- { &unsupport, 5, "R_ARM_ABS16" }, \
- { &unsupport, 6, "R_ARM_ABS12" }, \
- { &unsupport, 7, "R_ARM_THM_ABS5" }, \
- { &unsupport, 8, "R_ARM_ABS8" }, \
- { &unsupport, 9, "R_ARM_SBREL32" }, \
- { &thm_call, 10, "R_ARM_THM_CALL" }, \
- { &unsupport, 11, "R_ARM_THM_PC8" }, \
- { &unsupport, 12, "R_ARM_BREL_ADJ" }, \
- { &unsupport, 13, "R_ARM_TLS_DESC" }, \
- { &unsupport, 14, "R_ARM_THM_SWI8" }, \
- { &unsupport, 15, "R_ARM_XPC25" }, \
- { &unsupport, 16, "R_ARM_THM_XPC22" }, \
- { &unsupport, 17, "R_ARM_TLS_DTPMOD32" }, \
- { &unsupport, 18, "R_ARM_TLS_DTPOFF32" }, \
- { &unsupport, 19, "R_ARM_TLS_TPOFF32" }, \
- { &unsupport, 20, "R_ARM_COPY" }, \
- { &unsupport, 21, "R_ARM_GLOB_DAT" }, \
- { &unsupport, 22, "R_ARM_JUMP_SLOT" }, \
- { &unsupport, 23, "R_ARM_RELATIVE" }, \
- { &gotoff32, 24, "R_ARM_GOTOFF32" }, \
- { &base_prel, 25, "R_ARM_BASE_PREL" }, \
- { &got_brel, 26, "R_ARM_GOT_BREL" }, \
- { &call, 27, "R_ARM_PLT32" }, \
- { &call, 28, "R_ARM_CALL" }, \
- { &call, 29, "R_ARM_JUMP24" }, \
- { &thm_call, 30, "R_ARM_THM_JUMP24" }, \
- { &unsupport, 31, "R_ARM_BASE_ABS" }, \
- { &unsupport, 32, "R_ARM_ALU_PCREL_7_0" }, \
- { &unsupport, 33, "R_ARM_ALU_PCREL_15_8" }, \
- { &unsupport, 34, "R_ARM_ALU_PCREL_23_15" }, \
- { &unsupport, 35, "R_ARM_LDR_SBREL_11_0_NC" }, \
- { &unsupport, 36, "R_ARM_ALU_SBREL_19_12_NC"}, \
- { &unsupport, 37, "R_ARM_ALU_SBREL_27_20_CK"}, \
- { &abs32, 38, "R_ARM_TARGET1" }, \
- { &unsupport, 39, "R_ARM_SBREL31" }, \
- { &none, 40, "R_ARM_V4BX" }, \
- { &got_prel, 41, "R_ARM_TARGET2" }, \
- { &prel31, 42, "R_ARM_PREL31" }, \
- { &movw_abs_nc, 43, "R_ARM_MOVW_ABS_NC" }, \
- { &movt_abs, 44, "R_ARM_MOVT_ABS" }, \
- { &movw_prel_nc, 45, "R_ARM_MOVW_PREL_NC" }, \
- { &movt_prel, 46, "R_ARM_MOVT_PREL" }, \
- { &thm_movw_abs_nc, 47, "R_ARM_THM_MOVW_ABS_NC" }, \
- { &thm_movt_abs, 48, "R_ARM_THM_MOVT_ABS" }, \
- { &thm_movw_prel_nc, 49, "R_ARM_THM_MOVW_PREL_NC" }, \
- { &thm_movt_prel, 50, "R_ARM_THM_MOVT_PREL" }, \
- { &thm_jump19, 51, "R_ARM_THM_JUMP19" }, \
- { &unsupport, 52, "R_ARM_THM_JUMP6" }, \
- { &unsupport, 53, "R_ARM_THM_ALU_PREL_11_0" }, \
- { &unsupport, 54, "R_ARM_THM_PC12" }, \
- { &unsupport, 55, "R_ARM_ABS32_NOI" }, \
- { &unsupport, 56, "R_ARM_REL32_NOI" }, \
- { &unsupport, 57, "R_ARM_ALU_PC_G0_NC" }, \
- { &unsupport, 58, "R_ARM_ALU_PC_G0" }, \
- { &unsupport, 59, "R_ARM_ALU_PC_G1_NC" }, \
- { &unsupport, 60, "R_ARM_ALU_PC_G1" }, \
- { &unsupport, 61, "R_ARM_ALU_PC_G2" }, \
- { &unsupport, 62, "R_ARM_LDR_PC_G1" }, \
- { &unsupport, 63, "R_ARM_LDR_PC_G2" }, \
- { &unsupport, 64, "R_ARM_LDRS_PC_G0" }, \
- { &unsupport, 65, "R_ARM_LDRS_PC_G1" }, \
- { &unsupport, 66, "R_ARM_LDRS_PC_G2" }, \
- { &unsupport, 67, "R_ARM_LDC_PC_G0" }, \
- { &unsupport, 68, "R_ARM_LDC_PC_G1" }, \
- { &unsupport, 69, "R_ARM_LDC_PC_G2" }, \
- { &unsupport, 70, "R_ARM_ALU_SB_G0_NC" }, \
- { &unsupport, 71, "R_ARM_ALU_SB_G0" }, \
- { &unsupport, 72, "R_ARM_ALU_SB_G1_NC" }, \
- { &unsupport, 73, "R_ARM_ALU_SB_G1" }, \
- { &unsupport, 74, "R_ARM_ALU_SB_G2" }, \
- { &unsupport, 75, "R_ARM_LDR_SB_G0" }, \
- { &unsupport, 76, "R_ARM_LDR_SB_G1" }, \
- { &unsupport, 77, "R_ARM_LDR_SB_G2" }, \
- { &unsupport, 78, "R_ARM_LDRS_SB_G0" }, \
- { &unsupport, 79, "R_ARM_LDRS_SB_G1" }, \
- { &unsupport, 80, "R_ARM_LDRS_SB_G2" }, \
- { &unsupport, 81, "R_ARM_LDC_SB_G0" }, \
- { &unsupport, 82, "R_ARM_LDC_SB_G1" }, \
- { &unsupport, 83, "R_ARM_LDC_SB_G2" }, \
- { &unsupport, 84, "R_ARM_MOVW_BREL_NC" }, \
- { &unsupport, 85, "R_ARM_MOVT_BREL" }, \
- { &unsupport, 86, "R_ARM_MOVW_BREL" }, \
- { &thm_movw_brel, 87, "R_ARM_THM_MOVW_BREL_NC" }, \
- { &thm_movt_prel, 88, "R_ARM_THM_MOVT_BREL" }, \
- { &thm_movw_brel, 89, "R_ARM_THM_MOVW_BREL" }, \
- { &unsupport, 90, "R_ARM_TLS_GOTDESC" }, \
- { &unsupport, 91, "R_ARM_TLS_CALL" }, \
- { &unsupport, 92, "R_ARM_TLS_DESCSEQ" }, \
- { &unsupport, 93, "R_ARM_THM_TLS_CALL" }, \
- { &unsupport, 94, "R_ARM_PLT32_ABS" }, \
- { &unsupport, 95, "R_ARM_GOT_ABS" }, \
- { &got_prel, 96, "R_ARM_GOT_PREL" }, \
- { &unsupport, 97, "R_ARM_GOT_PREL12" }, \
- { &unsupport, 98, "R_ARM_GOTOFF12" }, \
- { &unsupport, 99, "R_ARM_GOTRELAX" }, \
- { &unsupport, 100, "R_ARM_GNU_VTENTRY" }, \
- { &unsupport, 101, "R_ARM_GNU_VTINERIT" }, \
- { &thm_jump11, 102, "R_ARM_THM_JUMP11" }, \
- { &thm_jump8, 103, "R_ARM_THM_JUMP8" }, \
- { &tls, 104, "R_ARM_TLS_GD32" }, \
- { &unsupport, 105, "R_ARM_TLS_LDM32" }, \
- { &unsupport, 106, "R_ARM_TLS_LDO32" }, \
- { &tls, 107, "R_ARM_TLS_IE32" }, \
- { &tls, 108, "R_ARM_TLS_LE32" }, \
- { &unsupport, 109, "R_ARM_TLS_LDO12" }, \
- { &unsupport, 110, "R_ARM_TLS_LE12" }, \
- { &unsupport, 111, "R_ARM_TLS_IE12GP" }, \
- { &unsupport, 112, "R_ARM_PRIVATE_0" }, \
- { &unsupport, 113, "R_ARM_PRIVATE_1" }, \
- { &unsupport, 114, "R_ARM_PRIVATE_2" }, \
- { &unsupport, 115, "R_ARM_PRIVATE_3" }, \
- { &unsupport, 116, "R_ARM_PRIVATE_4" }, \
- { &unsupport, 117, "R_ARM_PRIVATE_5" }, \
- { &unsupport, 118, "R_ARM_PRIVATE_6" }, \
- { &unsupport, 119, "R_ARM_PRIVATE_7" }, \
- { &unsupport, 120, "R_ARM_PRIVATE_8" }, \
- { &unsupport, 121, "R_ARM_PRIVATE_9" }, \
- { &unsupport, 122, "R_ARM_PRIVATE_10" }, \
- { &unsupport, 123, "R_ARM_PRIVATE_11" }, \
- { &unsupport, 124, "R_ARM_PRIVATE_12" }, \
- { &unsupport, 125, "R_ARM_PRIVATE_13" }, \
- { &unsupport, 126, "R_ARM_PRIVATE_14" }, \
- { &unsupport, 127, "R_ARM_PRIVATE_15" }, \
- { &unsupport, 128, "R_ARM_ME_TOO" }, \
- { &unsupport, 129, "R_ARM_THM_TLS_DESCSEQ16" }, \
- { &unsupport, 130, "R_ARM_THM_TLS_DESCSEQ32" }
+#endif // TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/ARM/ARMRelocator.cpp b/lib/Target/ARM/ARMRelocator.cpp
index 248c528..2605664 100644
--- a/lib/Target/ARM/ARMRelocator.cpp
+++ b/lib/Target/ARM/ARMRelocator.cpp
@@ -1,47 +1,46 @@
-//===- ARMRelocator.cpp ----------------------------------------===//
+//===- ARMRelocator.cpp --------------------------------------------------===//
//
// The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+#include "ARMRelocator.h"
+#include "ARMRelocationFunctions.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include "ARMRelocator.h"
-#include "ARMRelocationFunctions.h"
-using namespace mcld;
+namespace mcld {
//=========================================//
// Relocation helper function //
//=========================================//
-static Relocator::DWord getThumbBit(const Relocation& pReloc)
-{
+static Relocator::DWord getThumbBit(const Relocation& pReloc) {
// Set thumb bit if
// - symbol has type of STT_FUNC, is defined and with bit 0 of its value set
Relocator::DWord thumbBit =
- ((!pReloc.symInfo()->isUndef() || pReloc.symInfo()->isDyn()) &&
- (pReloc.symInfo()->type() == ResolveInfo::Function) &&
- ((pReloc.symValue() & 0x1) != 0))?
- 1:0;
+ ((!pReloc.symInfo()->isUndef() || pReloc.symInfo()->isDyn()) &&
+ (pReloc.symInfo()->type() == ResolveInfo::Function) &&
+ ((pReloc.symValue() & 0x1) != 0))
+ ? 1
+ : 0;
return thumbBit;
}
// Using uint64_t to make sure those complicate operations won't cause
// undefined behavior.
-static
-uint64_t helper_sign_extend(uint64_t pVal, uint64_t pOri_width)
-{
+static uint64_t helper_sign_extend(uint64_t pVal, uint64_t pOri_width) {
assert(pOri_width <= 64);
if (pOri_width == 64)
return pVal;
@@ -53,49 +52,39 @@
return (pVal ^ sign_bit) - sign_bit;
}
-static
-uint64_t helper_bit_select(uint64_t pA, uint64_t pB, uint64_t pMask)
-{
- return (pA & ~pMask) | (pB & pMask) ;
+static uint64_t helper_bit_select(uint64_t pA, uint64_t pB, uint64_t pMask) {
+ return (pA & ~pMask) | (pB & pMask);
}
// Check if symbol can use relocation R_ARM_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const ARMRelocator& pFactory)
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const ARMRelocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
// Strip LSB (THUMB bit) if "S" is a THUMB target.
-static inline void helper_clear_thumb_bit(Relocator::DWord& pValue)
-{
+static inline void helper_clear_thumb_bit(Relocator::DWord& pValue) {
pValue &= (~0x1);
}
-static
-Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
- ARMRelocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
+ ARMRelocator& pParent) {
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static
-ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- ARMRelocator& pParent)
-{
+static ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
ARMGOTEntry* got_entry = ld_backend.getGOT().createGOT();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -103,8 +92,7 @@
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(ARMRelocator::SymVal);
- }
- else {
+ } else {
// Initialize corresponding dynamic relocation.
Relocation& rel_entry = *ld_backend.getRelDyn().create();
if (rsym->isLocal() || helper_use_relative_reloc(*rsym, pParent)) {
@@ -112,8 +100,7 @@
got_entry->setValue(ARMRelocator::SymVal);
rel_entry.setType(llvm::ELF::R_ARM_RELATIVE);
rel_entry.setSymInfo(NULL);
- }
- else {
+ } else {
// Initialize got entry to 0 for corresponding dynamic relocation.
got_entry->setValue(0);
rel_entry.setType(llvm::ELF::R_ARM_GLOB_DAT);
@@ -124,34 +111,28 @@
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(ARMRelocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(ARMRelocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static
-Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- ARMRelocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ ARMRelocator& pParent) {
ARMPLT1* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static
-ARMPLT1& helper_PLT_init(Relocation& pReloc, ARMRelocator& pParent)
-{
+static ARMPLT1& helper_PLT_init(Relocation& pReloc, ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
// initialize the plt and the corresponding gotplt and dyn relocation
ARMPLT1* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
ARMGOTEntry* gotplt_entry = ld_backend.getGOT().createGOTPLT();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -167,11 +148,9 @@
// Get an relocation entry in .rel.dyn and set its type to pType,
// its FragmentRef to pReloc->targetFrag() and its ResolveInfo to
// pReloc->symInfo()
-static
-void helper_DynRel_init(Relocation& pReloc,
- Relocator::Type pType,
- ARMRelocator& pParent)
-{
+static void helper_DynRel_init(Relocation& pReloc,
+ Relocator::Type pType,
+ ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
@@ -186,18 +165,16 @@
rel_entry.setSymInfo(rsym);
}
-static Relocator::DWord
-helper_extract_movw_movt_addend(Relocator::DWord pTarget)
-{
+static Relocator::DWord helper_extract_movw_movt_addend(
+ Relocator::DWord pTarget) {
// imm16: [19-16][11-0]
return helper_sign_extend((((pTarget >> 4)) & 0xf000U) | (pTarget & 0xfffU),
16);
}
-static Relocator::DWord
-helper_insert_val_movw_movt_inst(Relocator::DWord pTarget,
- Relocator::DWord pImm)
-{
+static Relocator::DWord helper_insert_val_movw_movt_inst(
+ Relocator::DWord pTarget,
+ Relocator::DWord pImm) {
// imm16: [19-16][11-0]
pTarget &= 0xfff0f000U;
pTarget |= pImm & 0x0fffU;
@@ -205,21 +182,18 @@
return pTarget;
}
-static Relocator::DWord
-helper_extract_thumb_movw_movt_addend(Relocator::DWord pValue)
-{
+static Relocator::DWord helper_extract_thumb_movw_movt_addend(
+ Relocator::DWord pValue) {
// imm16: [19-16][26][14-12][7-0]
- return helper_sign_extend((((pValue >> 4) & 0xf000U) |
- ((pValue >> 15) & 0x0800U) |
- ((pValue >> 4) & 0x0700U) |
- (pValue& 0x00ffU)),
- 16);
+ return helper_sign_extend(
+ (((pValue >> 4) & 0xf000U) | ((pValue >> 15) & 0x0800U) |
+ ((pValue >> 4) & 0x0700U) | (pValue & 0x00ffU)),
+ 16);
}
-static Relocator::DWord
-helper_insert_val_thumb_movw_movt_inst(Relocator::DWord pValue,
- Relocator::DWord pImm)
-{
+static Relocator::DWord helper_insert_val_thumb_movw_movt_inst(
+ Relocator::DWord pValue,
+ Relocator::DWord pImm) {
// imm16: [19-16][26][14-12][7-0]
pValue &= 0xfbf08f00U;
pValue |= (pImm & 0xf000U) << 4;
@@ -229,48 +203,39 @@
return pValue;
}
-static Relocator::DWord
-helper_thumb32_branch_offset(Relocator::DWord pUpper16,
- Relocator::DWord pLower16)
-{
- Relocator::DWord s = (pUpper16 & (1U << 10)) >> 10, // 26 bit
- u = pUpper16 & 0x3ffU, // 25-16
- l = pLower16 & 0x7ffU, // 10-0
- j1 = (pLower16 & (1U << 13)) >> 13, // 13
- j2 = (pLower16 & (1U << 11)) >> 11; // 11
- Relocator::DWord i1 = j1 ^ s? 0: 1,
- i2 = j2 ^ s? 0: 1;
+static Relocator::DWord helper_thumb32_branch_offset(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pLower16) {
+ Relocator::DWord s = (pUpper16 & (1U << 10)) >> 10, // 26 bit
+ u = pUpper16 & 0x3ffU, // 25-16
+ l = pLower16 & 0x7ffU, // 10-0
+ j1 = (pLower16 & (1U << 13)) >> 13, // 13
+ j2 = (pLower16 & (1U << 11)) >> 11; // 11
+
+ Relocator::DWord i1 = j1 ^ s ? 0 : 1, i2 = j2 ^ s ? 0 : 1;
// [31-25][24][23][22][21-12][11-1][0]
// 0 s i1 i2 u l 0
- return helper_sign_extend((s << 24) | (i1 << 23) | (i2 << 22) |
- (u << 12) | (l << 1),
- 25);
+ return helper_sign_extend(
+ (s << 24) | (i1 << 23) | (i2 << 22) | (u << 12) | (l << 1), 25);
}
-static Relocator::DWord
-helper_thumb32_branch_upper(Relocator::DWord pUpper16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_branch_upper(Relocator::DWord pUpper16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
return (pUpper16 & ~0x7ffU) | ((pOffset >> 12) & 0x3ffU) | (sign << 10);
}
-static Relocator::DWord
-helper_thumb32_branch_lower(Relocator::DWord pLower16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_branch_lower(Relocator::DWord pLower16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
- return ((pLower16 & ~0x2fffU) |
- ((((pOffset >> 23) & 1) ^ !sign) << 13) |
- ((((pOffset >> 22) & 1) ^ !sign) << 11) |
- ((pOffset >> 1) & 0x7ffU));
+ return ((pLower16 & ~0x2fffU) | ((((pOffset >> 23) & 1) ^ !sign) << 13) |
+ ((((pOffset >> 22) & 1) ^ !sign) << 11) | ((pOffset >> 1) & 0x7ffU));
}
-static Relocator::DWord
-helper_thumb32_cond_branch_offset(Relocator::DWord pUpper16,
- Relocator::DWord pLower16)
-{
+static Relocator::DWord helper_thumb32_cond_branch_offset(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pLower16) {
uint32_t s = (pUpper16 & 0x0400U) >> 10;
uint32_t j1 = (pLower16 & 0x2000U) >> 13;
uint32_t j2 = (pLower16 & 0x0800U) >> 11;
@@ -279,18 +244,16 @@
return helper_sign_extend((upper << 12) | (lower << 1), 21);
}
-static Relocator::DWord
-helper_thumb32_cond_branch_upper(Relocator::DWord pUpper16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_cond_branch_upper(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
return (pUpper16 & 0xfbc0U) | (sign << 10) | ((pOffset & 0x0003f000U) >> 12);
}
-static Relocator::DWord
-helper_thumb32_cond_branch_lower(Relocator::DWord pLower16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_cond_branch_lower(
+ Relocator::DWord pLower16,
+ Relocator::DWord pOffset) {
uint32_t j2 = (pOffset & 0x00080000U) >> 19;
uint32_t j1 = (pOffset & 0x00040000U) >> 18;
uint32_t lo = (pOffset & 0x00000ffeU) >> 1;
@@ -298,10 +261,8 @@
}
// Return true if overflow
-static bool
-helper_check_signed_overflow(Relocator::DWord pValue,
- unsigned bits)
-{
+static bool helper_check_signed_overflow(Relocator::DWord pValue,
+ unsigned bits) {
int32_t signed_val = static_cast<int32_t>(pValue);
int32_t max = (1 << (bits - 1)) - 1;
int32_t min = -(1 << (bits - 1));
@@ -312,10 +273,9 @@
}
}
-
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// Relocation Functions and Tables
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
DECL_ARM_APPLY_RELOC_FUNCS
/// the prototype of applying function
@@ -323,8 +283,7 @@
ARMRelocator& pParent);
// the table entry of applying functions
-struct ApplyFunctionTriple
-{
+struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -332,45 +291,37 @@
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_ARM_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_ARM_APPLY_RELOC_FUNC_PTRS};
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// ARMRelocator
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
ARMRelocator::ARMRelocator(ARMGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent) {
+ : Relocator(pConfig), m_Target(pParent) {
}
-ARMRelocator::~ARMRelocator()
-{
+ARMRelocator::~ARMRelocator() {
}
-Relocator::Result
-ARMRelocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result ARMRelocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type > 130) { // 131-255 doesn't noted in ARM spec
+ if (type > 130) { // 131-255 doesn't noted in ARM spec
return Relocator::Unknown;
}
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char* ARMRelocator::getName(Relocator::Type pType) const
-{
+const char* ARMRelocator::getName(Relocator::Type pType) const {
return ApplyFunctions[pType].name;
}
-Relocator::Size ARMRelocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size ARMRelocator::getSize(Relocation::Type pType) const {
return 32;
}
-void ARMRelocator::addCopyReloc(ResolveInfo& pSym)
-{
+void ARMRelocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& rel_entry = *getTarget().getRelDyn().create();
rel_entry.setType(llvm::ELF::R_ARM_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -383,10 +334,8 @@
/// section and all other reference to this symbol should refer to this
/// copy.
/// This is executed at scan relocation stage.
-LDSymbol&
-ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+LDSymbol& ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
+ const ResolveInfo& pSym) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = getTarget().getOutputFormat();
@@ -408,9 +357,7 @@
// allocate space in BSS for the copy symbol
Fragment* frag = new FillFragment(0x0, 1, pSym.size());
- uint64_t size = ObjectBuilder::AppendFragment(*frag,
- *bss_data,
- addralign);
+ uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_data, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
@@ -420,27 +367,25 @@
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
-
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
return *cpy_sym;
}
/// checkValidReloc - When we attempt to generate a dynamic relocation for
/// ouput file, check if the relocation is supported by dynamic linker.
-void ARMRelocator::checkValidReloc(Relocation& pReloc) const
-{
+void ARMRelocator::checkValidReloc(Relocation& pReloc) const {
// If not PIC object, no relocation type is invalid
if (!config().isCodeIndep())
return;
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_ARM_RELATIVE:
case llvm::ELF::R_ARM_COPY:
case llvm::ELF::R_ARM_GLOB_DAT:
@@ -454,14 +399,14 @@
break;
default:
- error(diag::non_pic_relocation) << (int)pReloc.type()
+ error(diag::non_pic_relocation) << getName(pReloc.type())
<< pReloc.symInfo()->name();
break;
}
}
-bool ARMRelocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool ARMRelocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
switch (pReloc.type()) {
case llvm::ELF::R_ARM_PC24:
case llvm::ELF::R_ARM_THM_CALL:
@@ -477,26 +422,21 @@
case llvm::ELF::R_ARM_THM_JUMP8: {
return false;
}
- default: {
- return true;
- }
+ default: { return true; }
}
}
-void
-ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
-{
+void ARMRelocator::scanLocalReloc(Relocation& pReloc,
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
-
+ switch (pReloc.type()) {
// Set R_ARM_TARGET1 to R_ARM_ABS32
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET1 should be set by option --target1-rel
// or --target1-rel
case llvm::ELF::R_ARM_TARGET1:
- pReloc.setType(llvm::ELF::R_ARM_ABS32);
+ pReloc.setType(llvm::ELF::R_ARM_ABS32);
case llvm::ELF::R_ARM_ABS32:
case llvm::ELF::R_ARM_ABS32_NOI: {
// If buiding PIC object (shared library or PIC executable),
@@ -522,7 +462,7 @@
case llvm::ELF::R_ARM_THM_MOVT_ABS: {
// PIC code should not contain these kinds of relocation
if (config().isCodeIndep()) {
- error(diag::non_pic_relocation) << (int)pReloc.type()
+ error(diag::non_pic_relocation) << getName(pReloc.type())
<< pReloc.symInfo()->name();
}
return;
@@ -534,7 +474,6 @@
}
// Set R_ARM_TARGET2 to R_ARM_GOT_PREL
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET2 should be set by option --target2
case llvm::ELF::R_ARM_TARGET2:
pReloc.setType(llvm::ELF::R_ARM_GOT_PREL);
@@ -548,9 +487,9 @@
// If building PIC object, a dynamic relocation with
// type RELATIVE is needed to relocate this GOT entry.
if (config().isCodeIndep())
- helper_GOT_init(pReloc, true, *this);
+ helper_GOT_init(pReloc, true, *this);
else
- helper_GOT_init(pReloc, false, *this);
+ helper_GOT_init(pReloc, false, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -560,7 +499,8 @@
// FIXME: Currently we only support R_ARM_BASE_PREL against
// symbol _GLOBAL_OFFSET_TABLE_
if (rsym != getTarget().getGOTSymbol()->resolveInfo())
- fatal(diag::base_relocation) << (int)pReloc.type() << rsym->name()
+ fatal(diag::base_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name()
<< "mclinker@googlegroups.com";
return;
}
@@ -570,26 +510,21 @@
case llvm::ELF::R_ARM_RELATIVE: {
// These are relocation type for dynamic linker, shold not
// appear in object file.
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
}
- default: {
- break;
- }
- } // end switch
+ default: { break; }
+ } // end switch
}
void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
-
+ switch (pReloc.type()) {
// Set R_ARM_TARGET1 to R_ARM_ABS32
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET1 should be set by option --target1-rel
// or --target1-rel
case llvm::ELF::R_ARM_TARGET1:
@@ -609,7 +544,7 @@
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need to reserve a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -619,13 +554,13 @@
}
}
- if (getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT), true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
checkValidReloc(pReloc);
// set Rel bit
if (helper_use_relative_reloc(*rsym, *this))
@@ -652,7 +587,8 @@
// FIXME: Currently we only support these relocations against
// symbol _GLOBAL_OFFSET_TABLE_
if (rsym != getTarget().getGOTSymbol()->resolveInfo()) {
- fatal(diag::base_relocation) << (int)pReloc.type() << rsym->name()
+ fatal(diag::base_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name()
<< "mclinker@googlegroups.com";
}
case llvm::ELF::R_ARM_REL32:
@@ -697,17 +633,17 @@
case llvm::ELF::R_ARM_MOVT_BREL:
case llvm::ELF::R_ARM_MOVW_BREL: {
// Relative addressing relocation, may needs dynamic relocation
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
// symbol needs dynamic relocation entry, reserve an entry in .rel.dyn
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
checkValidReloc(pReloc);
// set Rel bit
- //helper_DynRel_init(pReloc, pReloc.type(), *this);
+ helper_DynRel_init(pReloc, pReloc.type(), *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
}
@@ -755,7 +691,6 @@
}
// Set R_ARM_TARGET2 to R_ARM_GOT_PREL
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET2 should be set by option --target2
case llvm::ELF::R_ARM_TARGET2:
pReloc.setType(llvm::ELF::R_ARM_GOT_PREL);
@@ -783,28 +718,25 @@
case llvm::ELF::R_ARM_RELATIVE: {
// These are relocation type for dynamic linker, shold not
// appear in object file.
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
}
- default: {
- break;
- }
- } // end switch
+ default: { break; }
+ } // end switch
}
void ARMRelocator::scanRelocation(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if an GOT/PLT/Dynamic Relocation
@@ -825,19 +757,34 @@
issueUndefRef(pReloc, pSection, pInput);
}
+uint32_t ARMRelocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_ARM_ABS32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void ARMRelocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//=========================================//
// Each relocation function implementation //
//=========================================//
// R_ARM_NONE
-ARMRelocator::Result none(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result none(Relocation& pReloc, ARMRelocator& pParent) {
return Relocator::OK;
}
// R_ARM_ABS32: (S + A) | T
-ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = pReloc.target() + pReloc.addend();
@@ -845,10 +792,11 @@
if (T != 0x0)
helper_clear_thumb_bit(S);
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC &
- pReloc.targetRef().frag()->getParent()->getSection().flag())) {
+ if ((llvm::ELF::SHF_ALLOC &
+ pReloc.targetRef().frag()->getParent()->getSection().flag()) == 0) {
pReloc.target() = (S + A) | T;
return Relocator::OK;
}
@@ -857,7 +805,7 @@
if (!rsym->isLocal()) {
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0 ; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
// If we generate a dynamic relocation (except R_ARM_RELATIVE)
// for a place, we should not perform static relocation on it
@@ -873,12 +821,11 @@
}
// R_ARM_REL32: ((S + A) | T) - P
-ARMRelocator::Result rel32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result rel32(Relocation& pReloc, ARMRelocator& pParent) {
// perform static relocation
Relocator::Address S = pReloc.symValue();
- Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord T = getThumbBit(pReloc);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
// An external symbol may need PLT (this reloc is from a stub/veneer)
if (!pReloc.symInfo()->isLocal()) {
@@ -898,8 +845,7 @@
}
// R_ARM_BASE_PREL: B(S) + A - P
-ARMRelocator::Result base_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result base_prel(Relocation& pReloc, ARMRelocator& pParent) {
// perform static relocation
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = pReloc.symValue() + A - pReloc.place();
@@ -907,8 +853,7 @@
}
// R_ARM_GOTOFF32: ((S + A) | T) - GOT_ORG
-ARMRelocator::Result gotoff32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result gotoff32(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
@@ -921,50 +866,47 @@
}
// R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
-ARMRelocator::Result got_brel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result got_brel(Relocation& pReloc, ARMRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & ARMRelocator::ReserveGOT))
return Relocator::BadReloc;
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + A - GOT_ORG;
// setup got entry value if needed
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && ARMRelocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && ARMRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
return Relocator::OK;
}
// R_ARM_GOT_PREL: GOT(S) + A - P
-ARMRelocator::Result got_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result got_prel(Relocation& pReloc, ARMRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & ARMRelocator::ReserveGOT)) {
return Relocator::BadReloc;
}
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
- Relocator::Address P = pReloc.place();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address P = pReloc.place();
// Apply relocation.
pReloc.target() = GOT_S + A - P;
// setup got entry value if needed
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && ARMRelocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && ARMRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
return Relocator::OK;
}
// R_ARM_THM_JUMP8: S + A - P
-ARMRelocator::Result thm_jump8(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump8(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord P = pReloc.place();
- Relocator::DWord A = helper_sign_extend((pReloc.target() & 0x00ff) << 1, 8) +
- pReloc.addend();
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x00ff) << 1, 8) + pReloc.addend();
// S depends on PLT exists or not
Relocator::Address S = pReloc.symValue();
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)
@@ -979,11 +921,10 @@
}
// R_ARM_THM_JUMP11: S + A - P
-ARMRelocator::Result thm_jump11(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump11(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord P = pReloc.place();
- Relocator::DWord A = helper_sign_extend((pReloc.target() & 0x07ff) << 1, 11) +
- pReloc.addend();
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x07ff) << 1, 11) + pReloc.addend();
// S depends on PLT exists or not
Relocator::Address S = pReloc.symValue();
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)
@@ -998,31 +939,30 @@
}
// R_ARM_THM_JUMP19: ((S + A) | T) - P
-ARMRelocator::Result thm_jump19(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump19(Relocation& pReloc, ARMRelocator& pParent) {
// get lower and upper 16 bit instructions from relocation targetData
uint16_t upper_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()));
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A = helper_thumb32_cond_branch_offset(upper_inst,
- lower_inst);
+ Relocator::DWord A =
+ helper_thumb32_cond_branch_offset(upper_inst, lower_inst);
Relocator::Address P = pReloc.place();
Relocator::Address S;
// if symbol has plt
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
- }
- else {
+ } else {
S = pReloc.symValue();
if (T != 0x0)
helper_clear_thumb_bit(S);
}
- if (0x0 == T) {
+ if (T == 0x0) {
// FIXME: conditional branch to PLT in THUMB-2 not supported yet
- error(diag::unsupport_cond_branch_reloc) << (int)pReloc.type();
+ error(diag::unsupported_cond_branch_reloc)
+ << static_cast<int>(pReloc.type());
return Relocator::BadReloc;
}
@@ -1043,13 +983,11 @@
// R_ARM_PLT32: ((S + A) | T) - P
// R_ARM_JUMP24: ((S + A) | T) - P
// R_ARM_CALL: ((S + A) | T) - P
-ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)) {
// change target to NOP : mov r0, r0
@@ -1057,10 +995,10 @@
return Relocator::OK;
}
- Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A =
- helper_sign_extend((pReloc.target() & 0x00FFFFFFu) << 2, 26) +
- pReloc.addend();
+ Relocator::DWord T = getThumbBit(pReloc);
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x00FFFFFFu) << 2, 26) +
+ pReloc.addend();
Relocator::Address P = pReloc.place();
Relocator::Address S = pReloc.symValue();
if (T != 0x0)
@@ -1083,9 +1021,8 @@
if (pReloc.type() == llvm::ELF::R_ARM_PC24)
return Relocator::BadReloc;
- pReloc.target() = (pReloc.target() & 0xffffff) |
- 0xfa000000 |
- (((S + A - P) & 2) << 23);
+ pReloc.target() =
+ (pReloc.target() & 0xffffff) | 0xfa000000 | (((S + A - P) & 2) << 23);
}
Relocator::DWord X = ((S + A) | T) - P;
@@ -1099,13 +1036,11 @@
// R_ARM_THM_CALL: ((S + A) | T) - P
// R_ARM_THM_JUMP24: ((S + A) | T) - P
-ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)) {
pReloc.target() = (0xe000U << 16) | 0xbf00U;
@@ -1125,8 +1060,7 @@
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
- }
- else {
+ } else {
S = pReloc.symValue();
if (T != 0x0)
helper_clear_thumb_bit(S);
@@ -1148,8 +1082,7 @@
S = helper_bit_select(S, P, 0x2);
// rewrite instruction to BLX
lower_inst &= ~0x1000U;
- }
- else {
+ } else {
// otherwise, the instruction should be BL
lower_inst |= 0x1000U;
}
@@ -1171,13 +1104,12 @@
}
// R_ARM_MOVW_ABS_NC: (S + A) | T
-ARMRelocator::Result movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
if (T != 0x0)
helper_clear_thumb_bit(S);
@@ -1185,29 +1117,28 @@
// If the flag of target section is not ALLOC, we will not scan this
// relocation but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0 ; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
}
// perform static relocation
Relocator::DWord X = (S + A) | T;
- pReloc.target() = helper_insert_val_movw_movt_inst(
- pReloc.target() + pReloc.addend(), X);
+ pReloc.target() =
+ helper_insert_val_movw_movt_inst(pReloc.target() + pReloc.addend(), X);
return Relocator::OK;
}
// R_ARM_MOVW_PREL_NC: ((S + A) | T) - P
-ARMRelocator::Result movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
if (T != 0x0)
helper_clear_thumb_bit(S);
Relocator::DWord X = ((S + A) | T) - P;
@@ -1221,18 +1152,18 @@
}
// R_ARM_MOVT_ABS: S + A
-ARMRelocator::Result movt_abs(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movt_abs(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
@@ -1247,12 +1178,11 @@
}
// R_ARM_MOVT_PREL: S + A - P
-ARMRelocator::Result movt_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movt_prel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
Relocator::DWord X = S + A - P;
X >>= 16;
@@ -1261,8 +1191,8 @@
}
// R_ARM_THM_MOVW_ABS_NC: (S + A) | T
-ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc,
+ ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
@@ -1274,16 +1204,17 @@
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
}
Relocator::DWord X = (S + A) | T;
@@ -1296,8 +1227,8 @@
}
// R_ARM_THM_MOVW_PREL_NC: ((S + A) | T) - P
-ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc,
+ ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
@@ -1309,7 +1240,7 @@
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = ((S + A) | T) - P;
val = helper_insert_val_thumb_movw_movt_inst(val, X);
@@ -1321,8 +1252,7 @@
// R_ARM_THM_MOVW_BREL_NC: ((S + A) | T) - B(S)
// R_ARM_THM_MOVW_BREL: ((S + A) | T) - B(S)
-ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
@@ -1334,7 +1264,7 @@
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = ((S + A) | T) - P;
@@ -1346,8 +1276,7 @@
}
// R_ARM_THM_MOVT_ABS: S + A
-ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
@@ -1356,12 +1285,12 @@
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
// If the flag of target section is not ALLOC, we will not scan this
// relocation but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
@@ -1378,13 +1307,11 @@
*(reinterpret_cast<uint16_t*>(&pReloc.target())) = val >> 16;
*(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1) = val & 0xFFFFu;
return Relocator::OK;
-
}
// R_ARM_THM_MOVT_PREL: S + A - P
// R_ARM_THM_MOVT_BREL: S + A - B(S)
-ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
@@ -1393,7 +1320,7 @@
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = S + A - P;
X >>= 16;
@@ -1405,8 +1332,7 @@
}
// R_ARM_PREL31: ((S + A) | T) - P
-ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord target = pReloc.target();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = helper_sign_extend(target, 31) + pReloc.addend();
@@ -1416,7 +1342,7 @@
helper_clear_thumb_bit(S);
// if symbol has plt
- if ( pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
+ if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
}
@@ -1431,12 +1357,12 @@
// R_ARM_TLS_GD32: GOT(S) + A - P
// R_ARM_TLS_IE32: GOT(S) + A - P
// R_ARM_TLS_LE32: S + A - tp
-ARMRelocator::Result tls(Relocation& pReloc, ARMRelocator& pParent)
-{
- return Relocator::Unsupport;
+ARMRelocator::Result tls(Relocation& pReloc, ARMRelocator& pParent) {
+ return Relocator::Unsupported;
}
-ARMRelocator::Result unsupport(Relocation& pReloc, ARMRelocator& pParent)
-{
- return Relocator::Unsupport;
+ARMRelocator::Result unsupported(Relocation& pReloc, ARMRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMRelocator.h b/lib/Target/ARM/ARMRelocator.h
index 9c3156b..1be9ed4 100644
--- a/lib/Target/ARM/ARMRelocator.h
+++ b/lib/Target/ARM/ARMRelocator.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMRELOCATOR_H
-#define TARGET_ARM_ARMRELOCATOR_H
+#ifndef TARGET_ARM_ARMRELOCATOR_H_
+#define TARGET_ARM_ARMRELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "ARMLDBackend.h"
namespace mcld {
@@ -20,9 +20,8 @@
* \brief ARMRelocator creates and destroys the ARM relocations.
*
*/
-class ARMRelocator : public Relocator
-{
-public:
+class ARMRelocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, ARMGOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, ARMPLT1> SymPLTMap;
@@ -45,10 +44,10 @@
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -56,35 +55,30 @@
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
+ public:
ARMRelocator(ARMGNULDBackend& pParent, const LinkerConfig& pConfig);
~ARMRelocator();
Result applyRelocation(Relocation& pRelocation);
- ARMGNULDBackend& getTarget()
- { return m_Target; }
+ ARMGNULDBackend& getTarget() { return m_Target; }
- const ARMGNULDBackend& getTarget() const
- { return m_Target; }
+ const ARMGNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -98,12 +92,19 @@
LDSection& pSection,
Input& pInput);
-
/// mayHaveFunctionPointerAccess - check if the given reloc would possibly
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc, const LDSection& pSection);
void scanGlobalReloc(Relocation& pReloc,
@@ -122,14 +123,13 @@
LDSymbol& defineSymbolforCopyReloc(IRBuilder& pLinker,
const ResolveInfo& pSym);
-private:
+ private:
ARMGNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymPLTMap m_SymPLTMap;
SymGOTMap m_SymGOTPLTMap;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_ARM_ARMRELOCATOR_H_
diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp
deleted file mode 100644
index 25caa56..0000000
--- a/lib/Target/ARM/ARMTargetMachine.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- ARMTargetMachine.cpp -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMTargetMachine.h"
-#include "ARM.h"
-
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-ARMBaseTargetMachine::ARMBaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
-//===----------------------------------------------------------------------===//
-// Initialize MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeARMLDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::ARMBaseTargetMachine> X(mcld::TheARMTarget);
- mcld::RegisterTargetMachine<mcld::ARMBaseTargetMachine> Y(mcld::TheThumbTarget);
-}
-
diff --git a/lib/Target/ARM/ARMTargetMachine.h b/lib/Target/ARM/ARMTargetMachine.h
deleted file mode 100644
index ddcf73d..0000000
--- a/lib/Target/ARM/ARMTargetMachine.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- ARMTargetMachine.h -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMTARGETMACHINE_H
-#define TARGET_ARM_ARMTARGETMACHINE_H
-
-#include "ARM.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class ARMBaseTargetMachine : public MCLDTargetMachine
-{
-public:
- ARMBaseTargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/ARM/ARMToARMStub.cpp b/lib/Target/ARM/ARMToARMStub.cpp
index ba3acf4..1c4b976 100644
--- a/lib/Target/ARM/ARMToARMStub.cpp
+++ b/lib/Target/ARM/ARMToARMStub.cpp
@@ -10,36 +10,35 @@
#include "ARMToARMStub.h"
#include "ARMLDBackend.h"
-#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMToARMStub
//===----------------------------------------------------------------------===//
const uint32_t ARMToARMStub::PIC_TEMPLATE[] = {
- 0xe59fc000, // ldr r12, [pc]
- 0xe08ff00c, // add pc, pc, ip
- 0x0 // dcd R_ARM_REL32(X-4)
+ 0xe59fc000, // ldr r12, [pc]
+ 0xe08ff00c, // add pc, pc, ip
+ 0x0 // dcd R_ARM_REL32(X-4)
};
const uint32_t ARMToARMStub::TEMPLATE[] = {
- 0xe51ff004, // ldr pc, [pc, #-4]
- 0x0 // dcd R_ARM_ABS32(X)
+ 0xe51ff004, // ldr pc, [pc, #-4]
+ 0x0 // dcd R_ARM_ABS32(X)
};
ARMToARMStub::ARMToARMStub(bool pIsOutputPIC)
- : m_pData(NULL), m_Name("A2A_prototype"), m_Size(0x0)
-{
+ : m_pData(NULL), m_Name("A2A_prototype"), m_Size(0x0) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
addFixup(8u, -4, llvm::ELF::R_ARM_REL32);
- }
- else {
+ } else {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(4u, 0x0, llvm::ELF::R_ARM_ABS32);
@@ -51,20 +50,17 @@
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_pData(pData), m_Name("A2A_veneer"), m_Size(pSize)
-{
+ : m_pData(pData), m_Name("A2A_veneer"), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-ARMToARMStub::~ARMToARMStub()
-{
+ARMToARMStub::~ARMToARMStub() {
}
bool ARMToARMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is ARM
if ((pTargetSymValue & 0x1) == 0x0) {
@@ -78,7 +74,7 @@
int64_t branch_offset = static_cast<int64_t>(dest) - pSource;
if ((branch_offset > ARMGNULDBackend::ARM_MAX_FWD_BRANCH_OFFSET) ||
(branch_offset < ARMGNULDBackend::ARM_MAX_BWD_BRANCH_OFFSET)) {
- result = true;
+ result = true;
}
break;
}
@@ -89,27 +85,24 @@
return result;
}
-const std::string& ARMToARMStub::name() const
-{
+const std::string& ARMToARMStub::name() const {
return m_Name;
}
-const uint8_t* ARMToARMStub::getContent() const
-{
+const uint8_t* ARMToARMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t ARMToARMStub::size() const
-{
+size_t ARMToARMStub::size() const {
return m_Size;
}
-size_t ARMToARMStub::alignment() const
-{
+size_t ARMToARMStub::alignment() const {
return 4u;
}
-Stub* ARMToARMStub::doClone()
-{
+Stub* ARMToARMStub::doClone() {
return new ARMToARMStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMToARMStub.h b/lib/Target/ARM/ARMToARMStub.h
index afb26a8..2dc6acc 100644
--- a/lib/Target/ARM/ARMToARMStub.h
+++ b/lib/Target/ARM/ARMToARMStub.h
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMTOARMSTUB_H_
+#define TARGET_ARM_ARMTOARMSTUB_H_
-#ifndef TARGET_ARM_ARMTOARMSTUB_H
-#define TARGET_ARM_ARMTOARMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class ARMToARMStub : public Stub
-{
-public:
- ARMToARMStub(bool pIsOutputPIC);
+class ARMToARMStub : public Stub {
+ public:
+ explicit ARMToARMStub(bool pIsOutputPIC);
~ARMToARMStub();
@@ -46,7 +43,7 @@
size_t alignment() const;
-private:
+ private:
ARMToARMStub(const ARMToARMStub&);
ARMToARMStub& operator=(const ARMToARMStub&);
@@ -60,7 +57,7 @@
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -68,6 +65,6 @@
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMTOARMSTUB_H_
diff --git a/lib/Target/ARM/ARMToTHMStub.cpp b/lib/Target/ARM/ARMToTHMStub.cpp
index a46a0c8..b53c747 100644
--- a/lib/Target/ARM/ARMToTHMStub.cpp
+++ b/lib/Target/ARM/ARMToTHMStub.cpp
@@ -10,38 +10,37 @@
#include "ARMToTHMStub.h"
#include "ARMLDBackend.h"
-#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMToTHMStub
//===----------------------------------------------------------------------===//
const uint32_t ARMToTHMStub::PIC_TEMPLATE[] = {
- 0xe59fc004, // ldr r12, [pc, #4]
- 0xe08fc00c, // add ip, pc, ip
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_REL32(X)
+ 0xe59fc004, // ldr r12, [pc, #4]
+ 0xe08fc00c, // add ip, pc, ip
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t ARMToTHMStub::TEMPLATE[] = {
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_ABS32(X)
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_ABS32(X)
};
ARMToTHMStub::ARMToTHMStub(bool pIsOutputPIC)
- : m_pData(NULL), m_Name("A2T_prototype"), m_Size(0x0)
-{
+ : m_pData(NULL), m_Name("A2T_prototype"), m_Size(0x0) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
addFixup(12u, 0x0, llvm::ELF::R_ARM_REL32);
- }
- else {
+ } else {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(8u, 0x0, llvm::ELF::R_ARM_ABS32);
@@ -53,20 +52,17 @@
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_pData(pData), m_Name("A2T_veneer"), m_Size(pSize)
-{
+ : m_pData(pData), m_Name("A2T_veneer"), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-ARMToTHMStub::~ARMToTHMStub()
-{
+ARMToTHMStub::~ARMToTHMStub() {
}
bool ARMToTHMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is THUMB
if ((pTargetSymValue & 0x1) != 0x0) {
@@ -97,27 +93,24 @@
return result;
}
-const std::string& ARMToTHMStub::name() const
-{
+const std::string& ARMToTHMStub::name() const {
return m_Name;
}
-const uint8_t* ARMToTHMStub::getContent() const
-{
+const uint8_t* ARMToTHMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t ARMToTHMStub::size() const
-{
+size_t ARMToTHMStub::size() const {
return m_Size;
}
-size_t ARMToTHMStub::alignment() const
-{
+size_t ARMToTHMStub::alignment() const {
return 4u;
}
-Stub* ARMToTHMStub::doClone()
-{
+Stub* ARMToTHMStub::doClone() {
return new ARMToTHMStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMToTHMStub.h b/lib/Target/ARM/ARMToTHMStub.h
index e7a44bf..5521baf 100644
--- a/lib/Target/ARM/ARMToTHMStub.h
+++ b/lib/Target/ARM/ARMToTHMStub.h
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMTOTHMSTUB_H_
+#define TARGET_ARM_ARMTOTHMSTUB_H_
-#ifndef TARGET_ARM_ARMTOTHMSTUB_H
-#define TARGET_ARM_ARMTOTHMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class ARMToTHMStub : public Stub
-{
-public:
- ARMToTHMStub(bool pIsOutputPIC);
+class ARMToTHMStub : public Stub {
+ public:
+ explicit ARMToTHMStub(bool pIsOutputPIC);
~ARMToTHMStub();
@@ -46,7 +43,7 @@
size_t alignment() const;
-private:
+ private:
ARMToTHMStub(const ARMToTHMStub&);
ARMToTHMStub& operator=(const ARMToTHMStub&);
@@ -60,7 +57,7 @@
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -68,6 +65,6 @@
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMTOTHMSTUB_H_
diff --git a/lib/Target/ARM/Android.mk b/lib/Target/ARM/Android.mk
index 31fe7af..cd83704 100644
--- a/lib/Target/ARM/Android.mk
+++ b/lib/Target/ARM/Android.mk
@@ -4,14 +4,11 @@
ARMDiagnostic.cpp \
ARMELFAttributeData.cpp \
ARMELFDynamic.cpp \
- ARMELFMCLinker.cpp \
ARMEmulation.cpp \
ARMGOT.cpp \
ARMLDBackend.cpp \
- ARMMCLinker.cpp \
ARMPLT.cpp \
ARMRelocator.cpp \
- ARMTargetMachine.cpp \
ARMToARMStub.cpp \
ARMToTHMStub.cpp \
THMToARMStub.cpp \
diff --git a/lib/Target/ARM/THMToARMStub.cpp b/lib/Target/ARM/THMToARMStub.cpp
index 34e0cbf..c8c7951 100644
--- a/lib/Target/ARM/THMToARMStub.cpp
+++ b/lib/Target/ARM/THMToARMStub.cpp
@@ -10,35 +10,35 @@
#include "THMToARMStub.h"
#include "ARMLDBackend.h"
-#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// THMToARMStub
//===----------------------------------------------------------------------===//
const uint32_t THMToARMStub::PIC_TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe08cf00f, // add pc, ip, pc
- 0x0 // dcd R_ARM_REL32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe08cf00f, // add pc, ip, pc
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t THMToARMStub::TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe51ff004, // ldr pc, [pc, #-4]
- 0x0 // dcd R_ARM_ABS32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe51ff004, // ldr pc, [pc, #-4]
+ 0x0 // dcd R_ARM_ABS32(X)
};
THMToARMStub::THMToARMStub(bool pIsOutputPIC, bool pUsingThumb2)
- : m_pData(NULL),
- m_Name("T2A_prototype"),
- m_Size(0x0),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(NULL),
+ m_Name("T2A_prototype"),
+ m_Size(0x0),
+ m_bUsingThumb2(pUsingThumb2) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
@@ -56,23 +56,20 @@
const_fixup_iterator pBegin,
const_fixup_iterator pEnd,
bool pUsingThumb2)
- : m_pData(pData),
- m_Name("T2A_veneer"),
- m_Size(pSize),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(pData),
+ m_Name("T2A_veneer"),
+ m_Size(pSize),
+ m_bUsingThumb2(pUsingThumb2) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-THMToARMStub::~THMToARMStub()
-{
+THMToARMStub::~THMToARMStub() {
}
bool THMToARMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is ARM
if ((pTargetSymValue & 0x1) == 0x0) {
@@ -109,37 +106,30 @@
return result;
}
-const std::string& THMToARMStub::name() const
-{
+const std::string& THMToARMStub::name() const {
return m_Name;
}
-const uint8_t* THMToARMStub::getContent() const
-{
+const uint8_t* THMToARMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t THMToARMStub::size() const
-{
+size_t THMToARMStub::size() const {
return m_Size;
}
-size_t THMToARMStub::alignment() const
-{
+size_t THMToARMStub::alignment() const {
return 4u;
}
// for T bit of this stub
-uint64_t THMToARMStub::initSymValue() const
-{
+uint64_t THMToARMStub::initSymValue() const {
return 0x1;
}
-Stub* THMToARMStub::doClone()
-{
- return new THMToARMStub(m_pData,
- m_Size,
- fixup_begin(),
- fixup_end(),
- m_bUsingThumb2);
+Stub* THMToARMStub::doClone() {
+ return new THMToARMStub(
+ m_pData, m_Size, fixup_begin(), fixup_end(), m_bUsingThumb2);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/THMToARMStub.h b/lib/Target/ARM/THMToARMStub.h
index af5a926..3272810 100644
--- a/lib/Target/ARM/THMToARMStub.h
+++ b/lib/Target/ARM/THMToARMStub.h
@@ -6,16 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_THMTOARMSTUB_H_
+#define TARGET_ARM_THMTOARMSTUB_H_
-#ifndef TARGET_ARM_THMTOARMSTUB_H
-#define TARGET_ARM_THMTOARMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -24,9 +22,8 @@
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class THMToARMStub : public Stub
-{
-public:
+class THMToARMStub : public Stub {
+ public:
THMToARMStub(bool pIsOutputPIC, bool pUsingThumb2);
~THMToARMStub();
@@ -48,7 +45,7 @@
// for T bit of this stub
uint64_t initSymValue() const;
-private:
+ private:
THMToARMStub(const THMToARMStub&);
THMToARMStub& operator=(const THMToARMStub&);
@@ -63,7 +60,7 @@
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -72,6 +69,6 @@
bool m_bUsingThumb2;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_THMTOARMSTUB_H_
diff --git a/lib/Target/ARM/THMToTHMStub.cpp b/lib/Target/ARM/THMToTHMStub.cpp
index f167f28..acf35ed 100644
--- a/lib/Target/ARM/THMToTHMStub.cpp
+++ b/lib/Target/ARM/THMToTHMStub.cpp
@@ -10,37 +10,37 @@
#include "THMToTHMStub.h"
#include "ARMLDBackend.h"
-#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// THMToTHMStub
//===----------------------------------------------------------------------===//
const uint32_t THMToTHMStub::PIC_TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc004, // ldr r12, [pc, #4]
- 0xe08fc00c, // add ip, pc, ip
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_REL32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc004, // ldr r12, [pc, #4]
+ 0xe08fc00c, // add ip, pc, ip
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t THMToTHMStub::TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_ABS32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_ABS32(X)
};
THMToTHMStub::THMToTHMStub(bool pIsOutputPIC, bool pUsingThumb2)
- : m_pData(NULL),
- m_Name("T2T_prototype"),
- m_Size(0x0),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(NULL),
+ m_Name("T2T_prototype"),
+ m_Size(0x0),
+ m_bUsingThumb2(pUsingThumb2) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
@@ -58,23 +58,20 @@
const_fixup_iterator pBegin,
const_fixup_iterator pEnd,
bool pUsingThumb2)
- : m_pData(pData),
- m_Name("T2T_veneer"),
- m_Size(pSize),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(pData),
+ m_Name("T2T_veneer"),
+ m_Size(pSize),
+ m_bUsingThumb2(pUsingThumb2) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-THMToTHMStub::~THMToTHMStub()
-{
+THMToTHMStub::~THMToTHMStub() {
}
bool THMToTHMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is THUMB
if ((pTargetSymValue & 0x1) != 0x0) {
@@ -85,11 +82,11 @@
uint64_t dest = pTargetSymValue + pReloc.addend() + 4u;
int64_t branch_offset = static_cast<int64_t>(dest) - pSource;
if (m_bUsingThumb2) {
- if ((branch_offset > ARMGNULDBackend::THM2_MAX_FWD_BRANCH_OFFSET) ||
- (branch_offset < ARMGNULDBackend::THM2_MAX_BWD_BRANCH_OFFSET)) {
- result = true;
- break;
- }
+ if ((branch_offset > ARMGNULDBackend::THM2_MAX_FWD_BRANCH_OFFSET) ||
+ (branch_offset < ARMGNULDBackend::THM2_MAX_BWD_BRANCH_OFFSET)) {
+ result = true;
+ break;
+ }
} else {
if ((branch_offset > ARMGNULDBackend::THM_MAX_FWD_BRANCH_OFFSET) ||
(branch_offset < ARMGNULDBackend::THM_MAX_BWD_BRANCH_OFFSET)) {
@@ -106,36 +103,29 @@
return result;
}
-const std::string& THMToTHMStub::name() const
-{
+const std::string& THMToTHMStub::name() const {
return m_Name;
}
-const uint8_t* THMToTHMStub::getContent() const
-{
+const uint8_t* THMToTHMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t THMToTHMStub::size() const
-{
+size_t THMToTHMStub::size() const {
return m_Size;
}
-size_t THMToTHMStub::alignment() const
-{
+size_t THMToTHMStub::alignment() const {
return 4u;
}
-uint64_t THMToTHMStub::initSymValue() const
-{
+uint64_t THMToTHMStub::initSymValue() const {
return 0x1;
}
-Stub* THMToTHMStub::doClone()
-{
- return new THMToTHMStub(m_pData,
- m_Size,
- fixup_begin(),
- fixup_end(),
- m_bUsingThumb2);
+Stub* THMToTHMStub::doClone() {
+ return new THMToTHMStub(
+ m_pData, m_Size, fixup_begin(), fixup_end(), m_bUsingThumb2);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/THMToTHMStub.h b/lib/Target/ARM/THMToTHMStub.h
index 4f3f363..dc8ff90 100644
--- a/lib/Target/ARM/THMToTHMStub.h
+++ b/lib/Target/ARM/THMToTHMStub.h
@@ -6,16 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_THMTOTHMSTUB_H_
+#define TARGET_ARM_THMTOTHMSTUB_H_
-#ifndef TARGET_ARM_THMTOTHMSTUB_H
-#define TARGET_ARM_THMTOTHMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -24,9 +22,8 @@
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class THMToTHMStub : public Stub
-{
-public:
+class THMToTHMStub : public Stub {
+ public:
THMToTHMStub(bool pIsOutputPIC, bool pUsingThumb2);
~THMToTHMStub();
@@ -48,7 +45,7 @@
// for T bit of this stub
uint64_t initSymValue() const;
-private:
+ private:
THMToTHMStub(const THMToTHMStub&);
THMToTHMStub& operator=(const THMToTHMStub&);
@@ -63,7 +60,7 @@
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -72,6 +69,6 @@
bool m_bUsingThumb2;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_THMTOTHMSTUB_H_
diff --git a/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp b/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
index de43662..cc50932 100644
--- a/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
+++ b/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -20,5 +20,4 @@
mcld::RegisterTarget<llvm::Triple::thumb> Y(TheThumbTarget, "thumb");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/Android.mk b/lib/Target/Android.mk
index e46a09f..aaeb589 100644
--- a/lib/Target/Android.mk
+++ b/lib/Target/Android.mk
@@ -6,7 +6,6 @@
ELFAttributeValue.cpp \
ELFDynamic.cpp \
ELFEmulation.cpp \
- ELFMCLinker.cpp \
GNUInfo.cpp \
GNULDBackend.cpp \
GOT.cpp \
diff --git a/lib/Target/ELFAttribute.cpp b/lib/Target/ELFAttribute.cpp
index ccffab7..04976bb 100644
--- a/lib/Target/ELFAttribute.cpp
+++ b/lib/Target/ELFAttribute.cpp
@@ -6,38 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttribute.h>
+#include "mcld/Target/ELFAttribute.h"
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/LEB128.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/ELFAttributeValue.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/LEB128.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFAttributeValue.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/STLExtras.h>
#include <llvm/Support/Host.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFAttribute
//===----------------------------------------------------------------------===//
-ELFAttribute::~ELFAttribute()
-{
+ELFAttribute::~ELFAttribute() {
llvm::DeleteContainerPointers(m_Subsections);
return;
}
-bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
-{
+bool ELFAttribute::merge(const Input& pInput, LDSection& pInputAttrSectHdr) {
// Skip corrupt subsection
if (pInputAttrSectHdr.size() < MinimalELFAttributeSectionSize)
return true;
@@ -63,7 +61,7 @@
// [ <uint32: subsection-length> NTBS: vendor-name
// <bytes: vendor-data>
// ]*
- const char *attribute_data = region.begin();
+ const char* attribute_data = region.begin();
// format-version
if (attribute_data[0] != FormatVersion) {
@@ -76,13 +74,13 @@
// Iterate all subsections containing in this attribute section.
do {
- const char *subsection_data = region.begin() + subsection_offset;
+ const char* subsection_data = region.begin() + subsection_offset;
// subsection-length
uint32_t subsection_length =
*reinterpret_cast<const uint32_t*>(subsection_data);
- if(llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian())
+ if (llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian())
bswap32(subsection_length);
// vendor-name
@@ -95,19 +93,18 @@
return true;
// Select the attribute subsection.
- Subsection *subsection = getSubsection(vendor_name);
+ Subsection* subsection = getSubsection(vendor_name);
// Only process the subsections whose vendor can be recognized.
if (subsection == NULL) {
- warning(diag::warn_unrecognized_vendor_subsection)
- << vendor_name << pInput.name();
+ warning(diag::warn_unrecognized_vendor_subsection) << vendor_name
+ << pInput.name();
} else {
// vendor-data
- size_t vendor_data_offset = subsection_offset +
- SubsectionLengthFieldSize +
- vendor_name_length;
- size_t vendor_data_size = subsection_length - SubsectionLengthFieldSize -
- vendor_name_length;
+ size_t vendor_data_offset =
+ subsection_offset + SubsectionLengthFieldSize + vendor_name_length;
+ size_t vendor_data_size =
+ subsection_length - SubsectionLengthFieldSize - vendor_name_length;
ConstAddress vendor_data =
reinterpret_cast<ConstAddress>(region.begin()) + vendor_data_offset;
@@ -118,25 +115,26 @@
}
subsection_offset += subsection_length;
- } while ((subsection_offset + SubsectionLengthFieldSize) < pInputAttrSectHdr.size());
+ } while ((subsection_offset + SubsectionLengthFieldSize) <
+ pInputAttrSectHdr.size());
return true;
}
-size_t ELFAttribute::sizeOutput() const
-{
+size_t ELFAttribute::sizeOutput() const {
size_t total_size = FormatVersionFieldSize;
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
total_size += (*subsec_it)->sizeOutput();
}
return total_size;
}
-size_t ELFAttribute::emit(MemoryRegion &pRegion) const
-{
+size_t ELFAttribute::emit(MemoryRegion& pRegion) const {
// ARM [ABI-addenda], 2.2.3
uint64_t total_size = 0;
@@ -146,8 +144,10 @@
total_size += FormatVersionFieldSize;
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
// Write out subsection.
total_size += (*subsec_it)->emit(buffer + total_size);
}
@@ -155,21 +155,21 @@
return total_size;
}
-void ELFAttribute::registerAttributeData(ELFAttributeData& pAttrData)
-{
+void ELFAttribute::registerAttributeData(ELFAttributeData& pAttrData) {
assert((getSubsection(pAttrData.getVendorName()) == NULL) &&
"Multiple attribute data for a vendor!");
m_Subsections.push_back(new Subsection(*this, pAttrData));
return;
}
-ELFAttribute::Subsection *
-ELFAttribute::getSubsection(llvm::StringRef pVendorName) const
-{
+ELFAttribute::Subsection* ELFAttribute::getSubsection(
+ llvm::StringRef pVendorName) const {
// Search m_Subsections linearly.
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
Subsection* const subsection = *subsec_it;
if (subsection->isMyAttribute(pVendorName)) {
return subsection;
@@ -183,12 +183,11 @@
//===----------------------------------------------------------------------===//
// ELFAttribute::Subsection
//===----------------------------------------------------------------------===//
-bool ELFAttribute::Subsection::merge(const Input &pInput,
+bool ELFAttribute::Subsection::merge(const Input& pInput,
ConstAddress pData,
- size_t pSize)
-{
+ size_t pSize) {
const bool need_swap = (llvm::sys::IsLittleEndianHost !=
- m_Parent.config().targets().isLittleEndian());
+ m_Parent.config().targets().isLittleEndian());
// Read attribute sub-subsection from vendor data.
//
// ARM [ABI-addenda], 2.2.4:
@@ -197,7 +196,7 @@
// | Tag_Section (=2) <uint32: byte-size> <section number>* 0 <attribute>*
// | Tag_symbol (=3) <unit32: byte-size> <symbol number>* 0 <attribute>*
// ] +
- const char *subsubsection_data = reinterpret_cast<const char*>(pData);
+ const char* subsubsection_data = reinterpret_cast<const char*>(pData);
size_t remaining_size = pSize;
if (!m_AttrData.preMerge(pInput)) {
@@ -238,7 +237,7 @@
if (!ELFAttributeData::ReadTag(tag, attr_buf, attr_size))
break;
- ELFAttributeValue *out_attr;
+ ELFAttributeValue* out_attr;
bool is_newly_created;
std::tie(out_attr, is_newly_created) =
@@ -277,49 +276,44 @@
case ELFAttributeData::Tag_Section:
case ELFAttributeData::Tag_Symbol:
// Skip any unknown tags.
- default: {
- break;
- }
+ default: { break; }
}
// Update subsubsection_data and remaining_size for next.
subsubsection_data += subsubsection_length;
remaining_size -= subsubsection_length;
- } // while (remaining_size > ELFAttribute::MinimalELFAttributeSubsectionSize)
+ } // while (remaining_size > ELFAttribute::MinimalELFAttributeSubsectionSize)
return m_AttrData.postMerge(m_Parent.config(), pInput);
}
-size_t ELFAttribute::Subsection::sizeOutput() const
-{
+size_t ELFAttribute::Subsection::sizeOutput() const {
// ARM [ABI-addenda], 2.2.3 and 2.2.4
return ELFAttribute::SubsectionLengthFieldSize +
- m_AttrData.getVendorName().length() /* vendor-name */ +
- 1 /* NULL-terminator for vendor-name */ +
- 1 /* Tag_File */ +
- sizeof(uint32_t) /* length of sub-subsection */ +
- m_AttrData.sizeOutput();
+ m_AttrData.getVendorName().length() /* vendor-name */ +
+ 1 /* NULL-terminator for vendor-name */ + 1 /* Tag_File */ +
+ sizeof(uint32_t) /* length of sub-subsection */ +
+ m_AttrData.sizeOutput();
}
-size_t ELFAttribute::Subsection::emit(char *pBuf) const
-{
+size_t ELFAttribute::Subsection::emit(char* pBuf) const {
// ARM [ABI-addenda], 2.2.3 and 2.2.4
const bool need_swap = (llvm::sys::IsLittleEndianHost !=
- m_Parent.config().targets().isLittleEndian());
+ m_Parent.config().targets().isLittleEndian());
- char *buffer = pBuf;
+ char* buffer = pBuf;
// The subsection-length and byte-size field in sub-subsection will be patched
// later after writing out all attribute data.
- char *subsection_length_hole = NULL;
- char *subsubsection_length_hole = NULL;
+ char* subsection_length_hole = NULL;
+ char* subsubsection_length_hole = NULL;
// Reserve space for subsection-length.
subsection_length_hole = buffer;
buffer += 4;
// Write vendor-name.
- const std::string &vendor_name = m_AttrData.getVendorName();
+ const std::string& vendor_name = m_AttrData.getVendorName();
::memcpy(buffer, vendor_name.c_str(), vendor_name.length());
buffer += vendor_name.length();
@@ -348,13 +342,13 @@
// Patch subsubsection_length_hole.
assert(subsubsection_length_hole != NULL);
- if(need_swap)
+ if (need_swap)
bswap32(subsubsection_length);
::memcpy(subsubsection_length_hole, &subsubsection_length, sizeof(uint32_t));
// Write subsection-length in subsection_length_hole.
- if(need_swap)
+ if (need_swap)
bswap32(subsection_length);
assert(subsection_length_hole != NULL);
@@ -362,3 +356,5 @@
return subsection_length;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFAttributeData.cpp b/lib/Target/ELFAttributeData.cpp
index c41918b..4e3e279 100644
--- a/lib/Target/ELFAttributeData.cpp
+++ b/lib/Target/ELFAttributeData.cpp
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttributeData.h>
+#include "mcld/Target/ELFAttributeData.h"
-#include <mcld/Support/LEB128.h>
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Support/LEB128.h"
+#include "mcld/Target/ELFAttributeValue.h"
#include <cstring>
#include <cassert>
-using namespace mcld;
+namespace mcld {
-bool ELFAttributeData::ReadTag(TagType& pTag, const char* &pBuf,
- size_t &pBufSize)
-{
+bool ELFAttributeData::ReadTag(TagType& pTag,
+ const char*& pBuf,
+ size_t& pBufSize) {
size_t size = 0;
pTag = static_cast<ELFAttributeData::TagType>(
- leb128::decode<uint64_t>(pBuf, size));
+ leb128::decode<uint64_t>(pBuf, size));
if (size > pBufSize)
return false;
@@ -32,9 +32,9 @@
return true;
}
-bool ELFAttributeData::ReadValue(ELFAttributeValue& pValue, const char* &pBuf,
- size_t &pBufSize)
-{
+bool ELFAttributeData::ReadValue(ELFAttributeValue& pValue,
+ const char*& pBuf,
+ size_t& pBufSize) {
// An ULEB128-encoded value
if (pValue.isIntValue()) {
size_t size = 0;
@@ -63,8 +63,7 @@
bool ELFAttributeData::WriteAttribute(TagType pTag,
const ELFAttributeValue& pValue,
- char* &pBuf)
-{
+ char*& pBuf) {
// Write the attribute tag.
leb128::encode<uint32_t>(pBuf, pTag);
@@ -86,3 +85,5 @@
return true;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFAttributeValue.cpp b/lib/Target/ELFAttributeValue.cpp
index 0f99325..fff6c7d 100644
--- a/lib/Target/ELFAttributeValue.cpp
+++ b/lib/Target/ELFAttributeValue.cpp
@@ -7,16 +7,15 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Target/ELFAttributeValue.h"
#include <llvm/Support/ErrorHandling.h>
-#include <mcld/Support/LEB128.h>
+#include "mcld/Support/LEB128.h"
-using namespace mcld;
+namespace mcld {
-size_t ELFAttributeValue::getSize() const
-{
+size_t ELFAttributeValue::getSize() const {
size_t size = 0;
if (isIntValue())
@@ -32,8 +31,7 @@
return size;
}
-bool ELFAttributeValue::isDefaultValue() const
-{
+bool ELFAttributeValue::isDefaultValue() const {
if (isUninitialized()) {
// Uninitialized attribute means default value
return true;
@@ -51,8 +49,7 @@
// unreachable
}
-bool ELFAttributeValue::equals(const ELFAttributeValue& pValue) const
-{
+bool ELFAttributeValue::equals(const ELFAttributeValue& pValue) const {
if ((pValue.type() != m_Type) || isUninitialized())
return false;
@@ -64,3 +61,5 @@
return true;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFDynamic.cpp b/lib/Target/ELFDynamic.cpp
index 86de446..4318bfa 100644
--- a/lib/Target/ELFDynamic.cpp
+++ b/lib/Target/ELFDynamic.cpp
@@ -6,160 +6,151 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Host.h>
-#include <llvm/Support/ErrorHandling.h>
-#include <mcld/Target/ELFDynamic.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFDynamic.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/LinkerConfig.h"
-using namespace mcld;
-using namespace elf_dynamic;
+#include <llvm/Support/ErrorHandling.h>
+#include <llvm/Support/Host.h>
+
+namespace mcld {
+namespace elf_dynamic {
//===----------------------------------------------------------------------===//
// elf_dynamic::EntryIF
//===----------------------------------------------------------------------===//
-EntryIF::EntryIF()
-{
+EntryIF::EntryIF() {
}
-EntryIF::~EntryIF()
-{
+EntryIF::~EntryIF() {
}
+} // namespace elf_dynamic
+
//===----------------------------------------------------------------------===//
// ELFDynamic
//===----------------------------------------------------------------------===//
-ELFDynamic::ELFDynamic(const GNULDBackend& pParent,
- const LinkerConfig& pConfig)
- : m_pEntryFactory(NULL), m_Backend(pParent), m_Config(pConfig), m_Idx(0) {
+ELFDynamic::ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig)
+ : m_pEntryFactory(NULL), m_Backend(pParent), m_Config(pConfig), m_Idx(0) {
// FIXME: support big-endian machine.
if (m_Config.targets().is32Bits()) {
if (m_Config.targets().isLittleEndian())
- m_pEntryFactory = new Entry<32, true>();
+ m_pEntryFactory = new elf_dynamic::Entry<32, true>();
} else if (m_Config.targets().is64Bits()) {
if (m_Config.targets().isLittleEndian())
- m_pEntryFactory = new Entry<64, true>();
+ m_pEntryFactory = new elf_dynamic::Entry<64, true>();
} else {
fatal(diag::unsupported_bitclass) << m_Config.targets().triple().str()
<< m_Config.targets().bitclass();
}
}
-
-ELFDynamic::~ELFDynamic()
-{
- if (NULL != m_pEntryFactory)
+ELFDynamic::~ELFDynamic() {
+ if (m_pEntryFactory != NULL)
delete m_pEntryFactory;
EntryListType::iterator entry, entryEnd = m_EntryList.end();
for (entry = m_EntryList.begin(); entry != entryEnd; ++entry) {
- if (NULL != *entry)
+ if (*entry != NULL)
delete (*entry);
}
entryEnd = m_NeedList.end();
for (entry = m_NeedList.begin(); entry != entryEnd; ++entry) {
- if (NULL != *entry)
+ if (*entry != NULL)
delete (*entry);
}
}
-size_t ELFDynamic::size() const
-{
+size_t ELFDynamic::size() const {
return (m_NeedList.size() + m_EntryList.size());
}
-size_t ELFDynamic::numOfBytes() const
-{
- return size()*entrySize();
+size_t ELFDynamic::numOfBytes() const {
+ return size() * entrySize();
}
-size_t ELFDynamic::entrySize() const
-{
+size_t ELFDynamic::entrySize() const {
return m_pEntryFactory->size();
}
-void ELFDynamic::reserveOne(uint64_t pTag)
-{
- assert(NULL != m_pEntryFactory);
+void ELFDynamic::reserveOne(uint64_t pTag) {
+ assert(m_pEntryFactory != NULL);
m_EntryList.push_back(m_pEntryFactory->clone());
}
-void ELFDynamic::applyOne(uint64_t pTag, uint64_t pValue)
-{
+void ELFDynamic::applyOne(uint64_t pTag, uint64_t pValue) {
assert(m_Idx < m_EntryList.size());
m_EntryList[m_Idx]->setValue(pTag, pValue);
++m_Idx;
}
/// reserveEntries - reserve entries
-void ELFDynamic::reserveEntries(const ELFFileFormat& pFormat)
-{
+void ELFDynamic::reserveEntries(const ELFFileFormat& pFormat) {
if (LinkerConfig::DynObj == m_Config.codeGenType()) {
- reserveOne(llvm::ELF::DT_SONAME); // DT_SONAME
+ reserveOne(llvm::ELF::DT_SONAME);
if (m_Config.options().Bsymbolic())
- reserveOne(llvm::ELF::DT_SYMBOLIC); // DT_SYMBOLIC
+ reserveOne(llvm::ELF::DT_SYMBOLIC);
}
if (pFormat.hasInit())
- reserveOne(llvm::ELF::DT_INIT); // DT_INIT
+ reserveOne(llvm::ELF::DT_INIT);
if (pFormat.hasFini())
- reserveOne(llvm::ELF::DT_FINI); // DT_FINI
+ reserveOne(llvm::ELF::DT_FINI);
if (pFormat.hasPreInitArray()) {
- reserveOne(llvm::ELF::DT_PREINIT_ARRAY); // DT_PREINIT_ARRAY
- reserveOne(llvm::ELF::DT_PREINIT_ARRAYSZ); // DT_PREINIT_ARRAYSZ
+ reserveOne(llvm::ELF::DT_PREINIT_ARRAY);
+ reserveOne(llvm::ELF::DT_PREINIT_ARRAYSZ);
}
if (pFormat.hasInitArray()) {
- reserveOne(llvm::ELF::DT_INIT_ARRAY); // DT_INIT_ARRAY
- reserveOne(llvm::ELF::DT_INIT_ARRAYSZ); // DT_INIT_ARRAYSZ
+ reserveOne(llvm::ELF::DT_INIT_ARRAY);
+ reserveOne(llvm::ELF::DT_INIT_ARRAYSZ);
}
if (pFormat.hasFiniArray()) {
- reserveOne(llvm::ELF::DT_FINI_ARRAY); // DT_FINI_ARRAY
- reserveOne(llvm::ELF::DT_FINI_ARRAYSZ); // DT_FINI_ARRAYSZ
+ reserveOne(llvm::ELF::DT_FINI_ARRAY);
+ reserveOne(llvm::ELF::DT_FINI_ARRAYSZ);
}
if (pFormat.hasHashTab())
- reserveOne(llvm::ELF::DT_HASH); // DT_HASH
+ reserveOne(llvm::ELF::DT_HASH);
- // FIXME: use llvm enum constant
if (pFormat.hasGNUHashTab())
- reserveOne(0x6ffffef5); // DT_GNU_HASH
+ reserveOne(llvm::ELF::DT_GNU_HASH);
if (pFormat.hasDynSymTab()) {
- reserveOne(llvm::ELF::DT_SYMTAB); // DT_SYMTAB
- reserveOne(llvm::ELF::DT_SYMENT); // DT_SYMENT
+ reserveOne(llvm::ELF::DT_SYMTAB);
+ reserveOne(llvm::ELF::DT_SYMENT);
}
if (pFormat.hasDynStrTab()) {
- reserveOne(llvm::ELF::DT_STRTAB); // DT_STRTAB
- reserveOne(llvm::ELF::DT_STRSZ); // DT_STRSZ
+ reserveOne(llvm::ELF::DT_STRTAB);
+ reserveOne(llvm::ELF::DT_STRSZ);
}
- reserveTargetEntries(pFormat); // DT_PLTGOT
+ reserveTargetEntries(pFormat);
if (pFormat.hasRelPlt() || pFormat.hasRelaPlt()) {
- reserveOne(llvm::ELF::DT_PLTREL); // DT_PLTREL
- reserveOne(llvm::ELF::DT_JMPREL); // DT_JMPREL
- reserveOne(llvm::ELF::DT_PLTRELSZ); // DT_PLTRELSZ
+ reserveOne(llvm::ELF::DT_PLTREL);
+ reserveOne(llvm::ELF::DT_JMPREL);
+ reserveOne(llvm::ELF::DT_PLTRELSZ);
}
if (pFormat.hasRelDyn()) {
- reserveOne(llvm::ELF::DT_REL); // DT_REL
- reserveOne(llvm::ELF::DT_RELSZ); // DT_RELSZ
- reserveOne(llvm::ELF::DT_RELENT); // DT_RELENT
+ reserveOne(llvm::ELF::DT_REL);
+ reserveOne(llvm::ELF::DT_RELSZ);
+ reserveOne(llvm::ELF::DT_RELENT);
}
if (pFormat.hasRelaDyn()) {
- reserveOne(llvm::ELF::DT_RELA); // DT_RELA
- reserveOne(llvm::ELF::DT_RELASZ); // DT_RELASZ
- reserveOne(llvm::ELF::DT_RELAENT); // DT_RELAENT
+ reserveOne(llvm::ELF::DT_RELA);
+ reserveOne(llvm::ELF::DT_RELASZ);
+ reserveOne(llvm::ELF::DT_RELAENT);
}
uint64_t dt_flags = 0x0;
@@ -175,111 +166,96 @@
(LinkerConfig::DynObj == m_Config.codeGenType()))
dt_flags |= llvm::ELF::DF_STATIC_TLS;
- if ((m_Config.options().hasNewDTags() && 0x0 != dt_flags) ||
- 0 != (dt_flags & llvm::ELF::DF_STATIC_TLS))
- reserveOne(llvm::ELF::DT_FLAGS); // DT_FLAGS
+ if ((m_Config.options().hasNewDTags() && dt_flags != 0x0) ||
+ (dt_flags & llvm::ELF::DF_STATIC_TLS) != 0x0)
+ reserveOne(llvm::ELF::DT_FLAGS);
if (m_Backend.hasTextRel())
- reserveOne(llvm::ELF::DT_TEXTREL); // DT_TEXTREL
+ reserveOne(llvm::ELF::DT_TEXTREL);
- if (m_Config.options().hasNow() ||
- m_Config.options().hasLoadFltr() ||
- m_Config.options().hasOrigin() ||
- m_Config.options().hasInterPose() ||
- m_Config.options().hasNoDefaultLib() ||
- m_Config.options().hasNoDump() ||
- m_Config.options().Bgroup() ||
+ if (m_Config.options().hasNow() || m_Config.options().hasLoadFltr() ||
+ m_Config.options().hasOrigin() || m_Config.options().hasInterPose() ||
+ m_Config.options().hasNoDefaultLib() || m_Config.options().hasNoDump() ||
+ m_Config.options().Bgroup() ||
((LinkerConfig::DynObj == m_Config.codeGenType()) &&
- (m_Config.options().hasNoDelete() ||
- m_Config.options().hasInitFirst() ||
+ (m_Config.options().hasNoDelete() || m_Config.options().hasInitFirst() ||
m_Config.options().hasNoDLOpen()))) {
- reserveOne(llvm::ELF::DT_FLAGS_1); // DT_FLAGS_1
+ reserveOne(llvm::ELF::DT_FLAGS_1);
}
- reserveOne(llvm::ELF::DT_NULL); // for DT_NULL
+ reserveOne(llvm::ELF::DT_NULL);
}
/// applyEntries - apply entries
-void ELFDynamic::applyEntries(const ELFFileFormat& pFormat)
-{
+void ELFDynamic::applyEntries(const ELFFileFormat& pFormat) {
if (LinkerConfig::DynObj == m_Config.codeGenType() &&
m_Config.options().Bsymbolic()) {
- applyOne(llvm::ELF::DT_SYMBOLIC, 0x0); // DT_SYMBOLIC
+ applyOne(llvm::ELF::DT_SYMBOLIC, 0x0);
}
if (pFormat.hasInit())
- applyOne(llvm::ELF::DT_INIT, pFormat.getInit().addr()); // DT_INIT
+ applyOne(llvm::ELF::DT_INIT, pFormat.getInit().addr());
if (pFormat.hasFini())
- applyOne(llvm::ELF::DT_FINI, pFormat.getFini().addr()); // DT_FINI
+ applyOne(llvm::ELF::DT_FINI, pFormat.getFini().addr());
if (pFormat.hasPreInitArray()) {
- // DT_PREINIT_ARRAY
applyOne(llvm::ELF::DT_PREINIT_ARRAY, pFormat.getPreInitArray().addr());
- // DT_PREINIT_ARRAYSZ
applyOne(llvm::ELF::DT_PREINIT_ARRAYSZ, pFormat.getPreInitArray().size());
}
if (pFormat.hasInitArray()) {
- // DT_INIT_ARRAY
applyOne(llvm::ELF::DT_INIT_ARRAY, pFormat.getInitArray().addr());
-
- // DT_INIT_ARRAYSZ
applyOne(llvm::ELF::DT_INIT_ARRAYSZ, pFormat.getInitArray().size());
}
if (pFormat.hasFiniArray()) {
- // DT_FINI_ARRAY
applyOne(llvm::ELF::DT_FINI_ARRAY, pFormat.getFiniArray().addr());
-
- // DT_FINI_ARRAYSZ
applyOne(llvm::ELF::DT_FINI_ARRAYSZ, pFormat.getFiniArray().size());
}
if (pFormat.hasHashTab())
- applyOne(llvm::ELF::DT_HASH, pFormat.getHashTab().addr()); // DT_HASH
+ applyOne(llvm::ELF::DT_HASH, pFormat.getHashTab().addr());
- // FIXME: use llvm enum constant
if (pFormat.hasGNUHashTab())
- applyOne(0x6ffffef5, pFormat.getGNUHashTab().addr()); // DT_GNU_HASH
+ applyOne(llvm::ELF::DT_GNU_HASH, pFormat.getGNUHashTab().addr());
if (pFormat.hasDynSymTab()) {
- applyOne(llvm::ELF::DT_SYMTAB, pFormat.getDynSymTab().addr()); // DT_SYMTAB
- applyOne(llvm::ELF::DT_SYMENT, symbolSize()); // DT_SYMENT
+ applyOne(llvm::ELF::DT_SYMTAB, pFormat.getDynSymTab().addr());
+ applyOne(llvm::ELF::DT_SYMENT, symbolSize());
}
if (pFormat.hasDynStrTab()) {
- applyOne(llvm::ELF::DT_STRTAB, pFormat.getDynStrTab().addr()); // DT_STRTAB
- applyOne(llvm::ELF::DT_STRSZ, pFormat.getDynStrTab().size()); // DT_STRSZ
+ applyOne(llvm::ELF::DT_STRTAB, pFormat.getDynStrTab().addr());
+ applyOne(llvm::ELF::DT_STRSZ, pFormat.getDynStrTab().size());
}
- applyTargetEntries(pFormat); // DT_PLTGOT
+ applyTargetEntries(pFormat);
if (pFormat.hasRelPlt()) {
- applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_REL); // DT_PLTREL
- applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelPlt().addr()); // DT_JMPREL
- applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelPlt().size()); // DT_PLTRELSZ
- }
- else if (pFormat.hasRelaPlt()) {
- applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_RELA); // DT_PLTREL
- applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelaPlt().addr()); // DT_JMPREL
- applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelaPlt().size()); // DT_PLTRELSZ
+ applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_REL);
+ applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelPlt().addr());
+ applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelPlt().size());
+ } else if (pFormat.hasRelaPlt()) {
+ applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_RELA);
+ applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelaPlt().addr());
+ applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelaPlt().size());
}
if (pFormat.hasRelDyn()) {
- applyOne(llvm::ELF::DT_REL, pFormat.getRelDyn().addr()); // DT_REL
- applyOne(llvm::ELF::DT_RELSZ, pFormat.getRelDyn().size()); // DT_RELSZ
- applyOne(llvm::ELF::DT_RELENT, m_pEntryFactory->relSize()); // DT_RELENT
+ applyOne(llvm::ELF::DT_REL, pFormat.getRelDyn().addr());
+ applyOne(llvm::ELF::DT_RELSZ, pFormat.getRelDyn().size());
+ applyOne(llvm::ELF::DT_RELENT, m_pEntryFactory->relSize());
}
if (pFormat.hasRelaDyn()) {
- applyOne(llvm::ELF::DT_RELA, pFormat.getRelaDyn().addr()); // DT_RELA
- applyOne(llvm::ELF::DT_RELASZ, pFormat.getRelaDyn().size()); // DT_RELASZ
- applyOne(llvm::ELF::DT_RELAENT, m_pEntryFactory->relaSize()); // DT_RELAENT
+ applyOne(llvm::ELF::DT_RELA, pFormat.getRelaDyn().addr());
+ applyOne(llvm::ELF::DT_RELASZ, pFormat.getRelaDyn().size());
+ applyOne(llvm::ELF::DT_RELAENT, m_pEntryFactory->relaSize());
}
if (m_Backend.hasTextRel()) {
- applyOne(llvm::ELF::DT_TEXTREL, 0x0); // DT_TEXTREL
+ applyOne(llvm::ELF::DT_TEXTREL, 0x0);
if (m_Config.options().warnSharedTextrel() &&
LinkerConfig::DynObj == m_Config.codeGenType())
@@ -299,9 +275,9 @@
(LinkerConfig::DynObj == m_Config.codeGenType()))
dt_flags |= llvm::ELF::DF_STATIC_TLS;
- if ((m_Config.options().hasNewDTags() && 0x0 != dt_flags) ||
- 0 != (dt_flags & llvm::ELF::DF_STATIC_TLS))
- applyOne(llvm::ELF::DT_FLAGS, dt_flags); // DT_FLAGS
+ if ((m_Config.options().hasNewDTags() && dt_flags != 0x0) ||
+ (dt_flags & llvm::ELF::DF_STATIC_TLS) != 0)
+ applyOne(llvm::ELF::DT_FLAGS, dt_flags);
uint64_t dt_flags_1 = 0x0;
if (m_Config.options().hasNow())
@@ -326,33 +302,30 @@
if (m_Config.options().hasNoDLOpen())
dt_flags_1 |= llvm::ELF::DF_1_NOOPEN;
}
- if (0x0 != dt_flags_1)
- applyOne(llvm::ELF::DT_FLAGS_1, dt_flags_1); // DT_FLAGS_1
+ if (dt_flags_1 != 0x0)
+ applyOne(llvm::ELF::DT_FLAGS_1, dt_flags_1);
- applyOne(llvm::ELF::DT_NULL, 0x0); // for DT_NULL
+ applyOne(llvm::ELF::DT_NULL, 0x0);
}
/// symbolSize
-size_t ELFDynamic::symbolSize() const
-{
+size_t ELFDynamic::symbolSize() const {
return m_pEntryFactory->symbolSize();
}
/// reserveNeedEntry - reserve on DT_NEED entry.
-void ELFDynamic::reserveNeedEntry()
-{
+void ELFDynamic::reserveNeedEntry() {
m_NeedList.push_back(m_pEntryFactory->clone());
}
/// emit
-void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const
-{
+void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const {
if (pRegion.size() < pSection.size()) {
llvm::report_fatal_error(llvm::Twine("the given memory is smaller") +
llvm::Twine(" than the section's demaind.\n"));
}
- uint8_t* address = (uint8_t*)pRegion.begin();
+ uint8_t* address = reinterpret_cast<uint8_t*>(pRegion.begin());
EntryListType::const_iterator entry, entryEnd = m_NeedList.end();
for (entry = m_NeedList.begin(); entry != entryEnd; ++entry)
address += (*entry)->emit(address);
@@ -362,8 +335,8 @@
address += (*entry)->emit(address);
}
-void ELFDynamic::applySoname(uint64_t pStrTabIdx)
-{
- applyOne(llvm::ELF::DT_SONAME, pStrTabIdx); // DT_SONAME
+void ELFDynamic::applySoname(uint64_t pStrTabIdx) {
+ applyOne(llvm::ELF::DT_SONAME, pStrTabIdx);
}
+} // namespace mcld
diff --git a/lib/Target/ELFEmulation.cpp b/lib/Target/ELFEmulation.cpp
index a68e485..019c4ac 100644
--- a/lib/Target/ELFEmulation.cpp
+++ b/lib/Target/ELFEmulation.cpp
@@ -6,78 +6,76 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Script/InputSectDesc.h>
+#include "mcld/Target/ELFEmulation.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Script/InputSectDesc.h"
#include <llvm/Support/Host.h>
-using namespace mcld;
+namespace mcld {
struct NameMap {
- const char* from; ///< the prefix of the input string. (match FROM*)
- const char* to; ///< the output string.
- InputSectDesc::KeepPolicy policy; /// mark whether the input is kept in GC
+ const char* from; ///< the prefix of the input string. (match FROM*)
+ const char* to; ///< the output string.
+ InputSectDesc::KeepPolicy policy; /// mark whether the input is kept in GC
};
-static const NameMap map[] =
-{
- {".text*", ".text", InputSectDesc::NoKeep},
- {".rodata*", ".rodata", InputSectDesc::NoKeep},
- {".data.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
- {".data.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
- {".data*", ".data", InputSectDesc::NoKeep},
- {".bss*", ".bss", InputSectDesc::NoKeep},
- {".tdata*", ".tdata", InputSectDesc::NoKeep},
- {".tbss*", ".tbss", InputSectDesc::NoKeep},
- {".init", ".init", InputSectDesc::Keep},
- {".fini", ".fini", InputSectDesc::Keep},
- {".preinit_array*", ".preinit_array", InputSectDesc::Keep},
- {".init_array*", ".init_array", InputSectDesc::Keep},
- {".fini_array*", ".fini_array", InputSectDesc::Keep},
- // TODO: Support DT_INIT_ARRAY for all constructors?
- {".ctors*", ".ctors", InputSectDesc::Keep},
- {".dtors*", ".dtors", InputSectDesc::Keep},
- {".jcr", ".jcr", InputSectDesc::Keep},
- // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2
- // sections would be handled differently.
- {".sdata2*", ".sdata", InputSectDesc::NoKeep},
- {".sbss2*", ".sbss", InputSectDesc::NoKeep},
- {".sdata*", ".sdata", InputSectDesc::NoKeep},
- {".sbss*", ".sbss", InputSectDesc::NoKeep},
- {".lrodata*", ".lrodata", InputSectDesc::NoKeep},
- {".ldata*", ".ldata", InputSectDesc::NoKeep},
- {".lbss*", ".lbss", InputSectDesc::NoKeep},
- {".gcc_except_table*", ".gcc_except_table", InputSectDesc::Keep},
- {".gnu.linkonce.d.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
- {".gnu.linkonce.d.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
- {".gnu.linkonce.r*", ".rodata", InputSectDesc::NoKeep},
- {".gnu.linkonce.d*", ".data", InputSectDesc::NoKeep},
- {".gnu.linkonce.b*", ".bss", InputSectDesc::NoKeep},
- {".gnu.linkonce.sb2*", ".sbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.sb*", ".sbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.s2*", ".sdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.s*", ".sdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.wi*", ".debug_info", InputSectDesc::NoKeep},
- {".gnu.linkonce.td*", ".tdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.tb*", ".tbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.t*", ".text", InputSectDesc::NoKeep},
- {".gnu.linkonce.lr*", ".lrodata", InputSectDesc::NoKeep},
- {".gnu.linkonce.lb*", ".lbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.l*", ".ldata", InputSectDesc::NoKeep},
+static const NameMap map[] = {
+ {".text*", ".text", InputSectDesc::NoKeep},
+ {".rodata*", ".rodata", InputSectDesc::NoKeep},
+ {".data.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
+ {".data.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
+ {".data*", ".data", InputSectDesc::NoKeep},
+ {".bss*", ".bss", InputSectDesc::NoKeep},
+ {".tdata*", ".tdata", InputSectDesc::NoKeep},
+ {".tbss*", ".tbss", InputSectDesc::NoKeep},
+ {".init", ".init", InputSectDesc::Keep},
+ {".fini", ".fini", InputSectDesc::Keep},
+ {".preinit_array*", ".preinit_array", InputSectDesc::Keep},
+ {".init_array*", ".init_array", InputSectDesc::Keep},
+ {".fini_array*", ".fini_array", InputSectDesc::Keep},
+ // TODO: Support DT_INIT_ARRAY for all constructors?
+ {".ctors*", ".ctors", InputSectDesc::Keep},
+ {".dtors*", ".dtors", InputSectDesc::Keep},
+ {".jcr", ".jcr", InputSectDesc::Keep},
+ // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2
+ // sections would be handled differently.
+ {".sdata2*", ".sdata", InputSectDesc::NoKeep},
+ {".sbss2*", ".sbss", InputSectDesc::NoKeep},
+ {".sdata*", ".sdata", InputSectDesc::NoKeep},
+ {".sbss*", ".sbss", InputSectDesc::NoKeep},
+ {".lrodata*", ".lrodata", InputSectDesc::NoKeep},
+ {".ldata*", ".ldata", InputSectDesc::NoKeep},
+ {".lbss*", ".lbss", InputSectDesc::NoKeep},
+ {".gcc_except_table*", ".gcc_except_table", InputSectDesc::Keep},
+ {".gnu.linkonce.d.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep}, // NOLINT
+ {".gnu.linkonce.d.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
+ {".gnu.linkonce.r*", ".rodata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.d*", ".data", InputSectDesc::NoKeep},
+ {".gnu.linkonce.b*", ".bss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.sb2*", ".sbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.sb*", ".sbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.s2*", ".sdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.s*", ".sdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.wi*", ".debug_info", InputSectDesc::NoKeep},
+ {".gnu.linkonce.td*", ".tdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.tb*", ".tbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.t*", ".text", InputSectDesc::NoKeep},
+ {".gnu.linkonce.lr*", ".lrodata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.lb*", ".lbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.l*", ".ldata", InputSectDesc::NoKeep},
};
-bool mcld::MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig)
// FIXME: LinkerConfig& pConfig should be constant
-{
+bool MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig) {
// set up section map
if (pConfig.options().getScriptList().empty() &&
pConfig.codeGenType() != LinkerConfig::Object) {
- const unsigned int map_size = (sizeof(map) / sizeof(map[0]) );
+ const unsigned int map_size = (sizeof(map) / sizeof(map[0]));
for (unsigned int i = 0; i < map_size; ++i) {
std::pair<SectionMap::mapping, bool> res =
- pScript.sectionMap().insert(map[i].from, map[i].to, map[i].policy);
+ pScript.sectionMap().insert(map[i].from, map[i].to, map[i].policy);
if (!res.second)
return false;
}
@@ -94,7 +92,7 @@
case llvm::Triple::NetBSD:
pScript.directories().insert("=/usr/lib");
break;
- case llvm::Triple::MinGW32:
+ case llvm::Triple::Win32:
pScript.directories().insert("=/mingw/lib");
break;
default:
@@ -106,3 +104,4 @@
return true;
}
+} // namespace mcld
diff --git a/lib/Target/ELFMCLinker.cpp b/lib/Target/ELFMCLinker.cpp
deleted file mode 100644
index fae5c8c..0000000
--- a/lib/Target/ELFMCLinker.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- ELFMCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFMCLinker.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// ELFMCLinker
-//===----------------------------------------------------------------------===//
-ELFMCLinker::ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : MCLinker(pConfig, pModule, pFileHandle) {
-
-}
-
-ELFMCLinker::~ELFMCLinker()
-{
- // MCLinker will delete m_pLDBackend and m_pLDDriver;
-}
-
diff --git a/lib/Target/GNUInfo.cpp b/lib/Target/GNUInfo.cpp
index 75234b0..0ff1925 100644
--- a/lib/Target/GNUInfo.cpp
+++ b/lib/Target/GNUInfo.cpp
@@ -6,19 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/GNUInfo.h>
+#include "mcld/Target/GNUInfo.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GNUInfo
//===----------------------------------------------------------------------===//
-GNUInfo::GNUInfo(const llvm::Triple& pTriple)
- : m_Triple(pTriple) {
+GNUInfo::GNUInfo(const llvm::Triple& pTriple) : m_Triple(pTriple) {
}
-uint8_t GNUInfo::OSABI() const
-{
+uint8_t GNUInfo::OSABI() const {
switch (m_Triple.getOS()) {
case llvm::Triple::FreeBSD:
return llvm::ELF::ELFOSABI_FREEBSD;
@@ -29,3 +27,4 @@
}
}
+} // namespace mcld
diff --git a/lib/Target/GNULDBackend.cpp b/lib/Target/GNULDBackend.cpp
index 7021c5f..cc38e94 100644
--- a/lib/Target/GNULDBackend.cpp
+++ b/lib/Target/GNULDBackend.cpp
@@ -6,41 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/Target/GNULDBackend.h"
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/InputTree.h>
-#include <mcld/Config/Config.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/EhFrameHdr.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFObjectFileFormat.h>
-#include <mcld/LD/ELFDynObjFileFormat.h>
-#include <mcld/LD/ELFExecFileFormat.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/ELFDynamic.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/MC/Attribute.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/EhFrameHdr.h"
+#include "mcld/LD/ELFDynObjFileFormat.h"
+#include "mcld/LD/ELFExecFileFormat.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFObjectFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/OutputSectDesc.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/ELFDynamic.h"
+#include "mcld/Target/GNUInfo.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Host.h>
@@ -54,69 +54,67 @@
namespace {
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
static const std::string simple_c_identifier_allowed_chars =
- "0123456789"
- "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "_";
+ "0123456789"
+ "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "_";
/// isCIdentifier - return if the pName is a valid C identifier
-static bool isCIdentifier(const std::string& pName)
-{
- return (pName.find_first_not_of(simple_c_identifier_allowed_chars)
- == std::string::npos);
+static bool isCIdentifier(const std::string& pName) {
+ return (pName.find_first_not_of(simple_c_identifier_allowed_chars) ==
+ std::string::npos);
}
-} // anonymous namespace
+} // anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GNULDBackend
//===----------------------------------------------------------------------===//
GNULDBackend::GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo)
- : TargetLDBackend(pConfig),
- m_pObjectReader(NULL),
- m_pDynObjFileFormat(NULL),
- m_pExecFileFormat(NULL),
- m_pObjectFileFormat(NULL),
- m_pInfo(pInfo),
- m_pELFSegmentTable(NULL),
- m_pBRIslandFactory(NULL),
- m_pStubFactory(NULL),
- m_pEhFrameHdr(NULL),
- m_pAttribute(NULL),
- m_bHasTextRel(false),
- m_bHasStaticTLS(false),
- f_pPreInitArrayStart(NULL),
- f_pPreInitArrayEnd(NULL),
- f_pInitArrayStart(NULL),
- f_pInitArrayEnd(NULL),
- f_pFiniArrayStart(NULL),
- f_pFiniArrayEnd(NULL),
- f_pStack(NULL),
- f_pDynamic(NULL),
- f_pTDATA(NULL),
- f_pTBSS(NULL),
- f_pExecutableStart(NULL),
- f_pEText(NULL),
- f_p_EText(NULL),
- f_p__EText(NULL),
- f_pEData(NULL),
- f_p_EData(NULL),
- f_pBSSStart(NULL),
- f_pEnd(NULL),
- f_p_End(NULL) {
+ : TargetLDBackend(pConfig),
+ m_pObjectReader(NULL),
+ m_pDynObjFileFormat(NULL),
+ m_pExecFileFormat(NULL),
+ m_pObjectFileFormat(NULL),
+ m_pInfo(pInfo),
+ m_pELFSegmentTable(NULL),
+ m_pBRIslandFactory(NULL),
+ m_pStubFactory(NULL),
+ m_pEhFrameHdr(NULL),
+ m_pAttribute(NULL),
+ m_bHasTextRel(false),
+ m_bHasStaticTLS(false),
+ f_pPreInitArrayStart(NULL),
+ f_pPreInitArrayEnd(NULL),
+ f_pInitArrayStart(NULL),
+ f_pInitArrayEnd(NULL),
+ f_pFiniArrayStart(NULL),
+ f_pFiniArrayEnd(NULL),
+ f_pStack(NULL),
+ f_pDynamic(NULL),
+ f_pTDATA(NULL),
+ f_pTBSS(NULL),
+ f_pExecutableStart(NULL),
+ f_pEText(NULL),
+ f_p_EText(NULL),
+ f_p__EText(NULL),
+ f_pEData(NULL),
+ f_p_EData(NULL),
+ f_pBSSStart(NULL),
+ f_pEnd(NULL),
+ f_p_End(NULL) {
m_pELFSegmentTable = new ELFSegmentFactory();
m_pSymIndexMap = new HashTableType(1024);
m_pAttribute = new ELFAttribute(*this, pConfig);
}
-GNULDBackend::~GNULDBackend()
-{
+GNULDBackend::~GNULDBackend() {
delete m_pELFSegmentTable;
delete m_pInfo;
delete m_pDynObjFileFormat;
@@ -129,8 +127,7 @@
delete m_pStubFactory;
}
-size_t GNULDBackend::sectionStartOffset() const
-{
+size_t GNULDBackend::sectionStartOffset() const {
if (LinkerConfig::Binary == config().codeGenType())
return 0x0;
@@ -148,10 +145,9 @@
}
}
-uint64_t GNULDBackend::getSegmentStartAddr(const LinkerScript& pScript) const
-{
+uint64_t GNULDBackend::getSegmentStartAddr(const LinkerScript& pScript) const {
LinkerScript::AddressMap::const_iterator mapping =
- pScript.addressMap().find(".text");
+ pScript.addressMap().find(".text");
if (pScript.addressMap().end() != mapping)
return mapping.getEntry()->value();
else if (config().isCodeIndep())
@@ -160,39 +156,32 @@
return m_pInfo->defaultTextSegmentAddr();
}
-GNUArchiveReader*
-GNULDBackend::createArchiveReader(Module& pModule)
-{
- assert(NULL != m_pObjectReader);
+GNUArchiveReader* GNULDBackend::createArchiveReader(Module& pModule) {
+ assert(m_pObjectReader != NULL);
return new GNUArchiveReader(pModule, *m_pObjectReader);
}
-ELFObjectReader* GNULDBackend::createObjectReader(IRBuilder& pBuilder)
-{
+ELFObjectReader* GNULDBackend::createObjectReader(IRBuilder& pBuilder) {
m_pObjectReader = new ELFObjectReader(*this, pBuilder, config());
return m_pObjectReader;
}
-ELFDynObjReader* GNULDBackend::createDynObjReader(IRBuilder& pBuilder)
-{
+ELFDynObjReader* GNULDBackend::createDynObjReader(IRBuilder& pBuilder) {
return new ELFDynObjReader(*this, pBuilder, config());
}
-ELFBinaryReader* GNULDBackend::createBinaryReader(IRBuilder& pBuilder)
-{
+ELFBinaryReader* GNULDBackend::createBinaryReader(IRBuilder& pBuilder) {
return new ELFBinaryReader(pBuilder, config());
}
-ELFObjectWriter* GNULDBackend::createWriter()
-{
+ELFObjectWriter* GNULDBackend::createWriter() {
return new ELFObjectWriter(*this, config());
}
-bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder)
-{
+bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder) {
switch (config().codeGenType()) {
case LinkerConfig::DynObj: {
- if (NULL == m_pDynObjFileFormat)
+ if (m_pDynObjFileFormat == NULL)
m_pDynObjFileFormat = new ELFDynObjFileFormat();
m_pDynObjFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
@@ -200,14 +189,14 @@
}
case LinkerConfig::Exec:
case LinkerConfig::Binary: {
- if (NULL == m_pExecFileFormat)
+ if (m_pExecFileFormat == NULL)
m_pExecFileFormat = new ELFExecFileFormat();
m_pExecFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
return true;
}
case LinkerConfig::Object: {
- if (NULL == m_pObjectFileFormat)
+ if (m_pObjectFileFormat == NULL)
m_pObjectFileFormat = new ELFObjectFileFormat();
m_pObjectFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
@@ -221,15 +210,12 @@
/// initStandardSymbols - define and initialize standard symbols.
/// This function is called after section merging but before read relocations.
-bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder,
- Module& pModule)
-{
+bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder, Module& pModule) {
if (LinkerConfig::Object == config().codeGenType())
return true;
// GNU extension: define __start and __stop symbols for the sections whose
// name can be presented as C symbol
- // ref: GNU gold, Layout::define_section_symbols
Module::iterator iter, iterEnd = pModule.end();
for (iter = pModule.begin(); iter != iterEnd; ++iter) {
LDSection* section = *iter;
@@ -245,34 +231,35 @@
if (!section->hasSectionData())
continue;
break;
- } // end of switch
+ } // end of switch
if (isCIdentifier(section->name())) {
std::string start_name = "__start_" + section->name();
- FragmentRef* start_fragref = FragmentRef::Create(
- section->getSectionData()->front(), 0x0);
+ FragmentRef* start_fragref =
+ FragmentRef::Create(section->getSectionData()->front(), 0x0);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- start_name,
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- start_fragref, // FragRef
- ResolveInfo::Default);
+ start_name,
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ start_fragref, // FragRef
+ ResolveInfo::Default);
std::string stop_name = "__stop_" + section->name();
FragmentRef* stop_fragref = FragmentRef::Create(
- section->getSectionData()->front(), section->size());
+ section->getSectionData()->front(), section->size());
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- stop_name,
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- stop_fragref, // FragRef
- ResolveInfo::Default);
+ stop_name,
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ stop_fragref, // FragRef
+ ResolveInfo::Default);
}
}
@@ -283,402 +270,373 @@
FragmentRef* preinit_array = NULL;
if (file_format->hasPreInitArray()) {
preinit_array = FragmentRef::Create(
- file_format->getPreInitArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getPreInitArray().getSectionData()->front(), 0x0);
+ } else {
preinit_array = FragmentRef::Null();
}
+
f_pPreInitArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__preinit_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- preinit_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__preinit_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ preinit_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pPreInitArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__preinit_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__preinit_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// .init_array
FragmentRef* init_array = NULL;
if (file_format->hasInitArray()) {
init_array = FragmentRef::Create(
- file_format->getInitArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getInitArray().getSectionData()->front(), 0x0);
+ } else {
init_array = FragmentRef::Null();
}
f_pInitArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__init_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- init_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__init_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ init_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pInitArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__init_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- init_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__init_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ init_array, // FragRef
+ ResolveInfo::Hidden);
// .fini_array
FragmentRef* fini_array = NULL;
if (file_format->hasFiniArray()) {
fini_array = FragmentRef::Create(
- file_format->getFiniArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getFiniArray().getSectionData()->front(), 0x0);
+ } else {
fini_array = FragmentRef::Null();
}
f_pFiniArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__fini_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- fini_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__fini_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ fini_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pFiniArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__fini_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- fini_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__fini_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ fini_array, // FragRef
+ ResolveInfo::Hidden);
// .stack
FragmentRef* stack = NULL;
if (file_format->hasStack()) {
stack = FragmentRef::Create(
- file_format->getStack().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getStack().getSectionData()->front(), 0x0);
+ } else {
stack = FragmentRef::Null();
}
- f_pStack =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__stack",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- stack, // FragRef
- ResolveInfo::Hidden);
+ f_pStack = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__stack",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ stack, // FragRef
+ ResolveInfo::Hidden);
// _DYNAMIC
// TODO: add SectionData for .dynamic section, and then we can get the correct
// symbol section index for _DYNAMIC. Now it will be ABS.
- f_pDynamic =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_DYNAMIC",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ f_pDynamic = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_DYNAMIC",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// ----- segment symbols ----- //
f_pExecutableStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__executable_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_pEText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_p_EText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_p__EText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_pEData =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "edata",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__executable_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
- f_pEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_pEText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
+ f_p_EText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+ f_p__EText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+ f_pEData = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "edata",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
+ f_pEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// _edata is defined forcefully.
- // @ref Google gold linker: defstd.cc: 186
- f_p_EData =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_edata",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_p_EData = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "_edata",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// __bss_start is defined forcefully.
- // @ref Google gold linker: defstd.cc: 214
- f_pBSSStart =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "__bss_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_pBSSStart = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "__bss_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// _end is defined forcefully.
- // @ref Google gold linker: defstd.cc: 228
- f_p_End =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_p_End = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
return true;
}
-bool GNULDBackend::finalizeStandardSymbols()
-{
+bool GNULDBackend::finalizeStandardSymbols() {
if (LinkerConfig::Object == config().codeGenType())
return true;
ELFFileFormat* file_format = getOutputFormat();
// ----- section symbols ----- //
- if (NULL != f_pPreInitArrayStart) {
+ if (f_pPreInitArrayStart != NULL) {
if (!f_pPreInitArrayStart->hasFragRef()) {
f_pPreInitArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pPreInitArrayStart->setValue(0x0);
}
}
- if (NULL != f_pPreInitArrayEnd) {
+ if (f_pPreInitArrayEnd != NULL) {
if (f_pPreInitArrayEnd->hasFragRef()) {
f_pPreInitArrayEnd->setValue(f_pPreInitArrayEnd->value() +
file_format->getPreInitArray().size());
- }
- else {
+ } else {
f_pPreInitArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pPreInitArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pInitArrayStart) {
+ if (f_pInitArrayStart != NULL) {
if (!f_pInitArrayStart->hasFragRef()) {
f_pInitArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pInitArrayStart->setValue(0x0);
}
}
- if (NULL != f_pInitArrayEnd) {
+ if (f_pInitArrayEnd != NULL) {
if (f_pInitArrayEnd->hasFragRef()) {
f_pInitArrayEnd->setValue(f_pInitArrayEnd->value() +
file_format->getInitArray().size());
- }
- else {
+ } else {
f_pInitArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pInitArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pFiniArrayStart) {
+ if (f_pFiniArrayStart != NULL) {
if (!f_pFiniArrayStart->hasFragRef()) {
f_pFiniArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pFiniArrayStart->setValue(0x0);
}
}
- if (NULL != f_pFiniArrayEnd) {
+ if (f_pFiniArrayEnd != NULL) {
if (f_pFiniArrayEnd->hasFragRef()) {
f_pFiniArrayEnd->setValue(f_pFiniArrayEnd->value() +
file_format->getFiniArray().size());
- }
- else {
+ } else {
f_pFiniArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pFiniArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pStack) {
+ if (f_pStack != NULL) {
if (!f_pStack->hasFragRef()) {
f_pStack->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pStack->setValue(0x0);
}
}
- if (NULL != f_pDynamic) {
+ if (f_pDynamic != NULL) {
f_pDynamic->resolveInfo()->setBinding(ResolveInfo::Local);
f_pDynamic->setValue(file_format->getDynamic().addr());
f_pDynamic->setSize(file_format->getDynamic().size());
}
// ----- segment symbols ----- //
- if (NULL != f_pExecutableStart) {
+ if (f_pExecutableStart != NULL) {
ELFSegmentFactory::const_iterator exec_start =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
if (elfSegmentTable().end() != exec_start) {
if (ResolveInfo::ThreadLocal != f_pExecutableStart->type()) {
f_pExecutableStart->setValue(f_pExecutableStart->value() +
(*exec_start)->vaddr());
}
- }
- else
+ } else {
f_pExecutableStart->setValue(0x0);
+ }
}
- if (NULL != f_pEText || NULL != f_p_EText || NULL !=f_p__EText) {
- ELFSegmentFactory::const_iterator etext =
- elfSegmentTable().find(llvm::ELF::PT_LOAD,
- llvm::ELF::PF_X,
- llvm::ELF::PF_W);
+ if (f_pEText != NULL || f_p_EText != NULL || f_p__EText != NULL) {
+ ELFSegmentFactory::const_iterator etext = elfSegmentTable().find(
+ llvm::ELF::PT_LOAD, llvm::ELF::PF_X, llvm::ELF::PF_W);
if (elfSegmentTable().end() != etext) {
- if (NULL != f_pEText && ResolveInfo::ThreadLocal != f_pEText->type()) {
- f_pEText->setValue(f_pEText->value() +
- (*etext)->vaddr() +
+ if (f_pEText != NULL && ResolveInfo::ThreadLocal != f_pEText->type()) {
+ f_pEText->setValue(f_pEText->value() + (*etext)->vaddr() +
(*etext)->memsz());
}
- if (NULL != f_p_EText && ResolveInfo::ThreadLocal != f_p_EText->type()) {
- f_p_EText->setValue(f_p_EText->value() +
- (*etext)->vaddr() +
+ if (f_p_EText != NULL && ResolveInfo::ThreadLocal != f_p_EText->type()) {
+ f_p_EText->setValue(f_p_EText->value() + (*etext)->vaddr() +
(*etext)->memsz());
}
- if (NULL != f_p__EText && ResolveInfo::ThreadLocal != f_p__EText->type()) {
- f_p__EText->setValue(f_p__EText->value() +
- (*etext)->vaddr() +
- (*etext)->memsz());
+ if (f_p__EText != NULL &&
+ ResolveInfo::ThreadLocal != f_p__EText->type()) {
+ f_p__EText->setValue(f_p__EText->value() + (*etext)->vaddr() +
+ (*etext)->memsz());
}
- }
- else {
- if (NULL != f_pEText)
+ } else {
+ if (f_pEText != NULL)
f_pEText->setValue(0x0);
- if (NULL != f_p_EText)
+ if (f_p_EText != NULL)
f_p_EText->setValue(0x0);
- if (NULL != f_p__EText)
+ if (f_p__EText != NULL)
f_p__EText->setValue(0x0);
}
}
- if (NULL != f_pEData || NULL != f_p_EData || NULL != f_pBSSStart ||
- NULL != f_pEnd || NULL != f_p_End) {
+ if (f_pEData != NULL || f_p_EData != NULL || f_pBSSStart != NULL ||
+ f_pEnd != NULL || f_p_End != NULL) {
ELFSegmentFactory::const_iterator edata =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, llvm::ELF::PF_W, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, llvm::ELF::PF_W, 0x0);
if (elfSegmentTable().end() != edata) {
- if (NULL != f_pEData && ResolveInfo::ThreadLocal != f_pEData->type()) {
- f_pEData->setValue(f_pEData->value() +
- (*edata)->vaddr() +
+ if (f_pEData != NULL && ResolveInfo::ThreadLocal != f_pEData->type()) {
+ f_pEData->setValue(f_pEData->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_p_EData && ResolveInfo::ThreadLocal != f_p_EData->type()) {
- f_p_EData->setValue(f_p_EData->value() +
- (*edata)->vaddr() +
+ if (f_p_EData != NULL && ResolveInfo::ThreadLocal != f_p_EData->type()) {
+ f_p_EData->setValue(f_p_EData->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_pBSSStart && ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
- f_pBSSStart->setValue(f_pBSSStart->value() +
- (*edata)->vaddr() +
+ if (f_pBSSStart != NULL &&
+ ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
+ f_pBSSStart->setValue(f_pBSSStart->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_pEnd && ResolveInfo::ThreadLocal != f_pEnd->type()) {
- f_pEnd->setValue(f_pEnd->value() +
- (*edata)->vaddr() +
+ if (f_pEnd != NULL && ResolveInfo::ThreadLocal != f_pEnd->type()) {
+ f_pEnd->setValue(f_pEnd->value() + (*edata)->vaddr() +
(*edata)->memsz());
}
- if (NULL != f_p_End && ResolveInfo::ThreadLocal != f_p_End->type()) {
- f_p_End->setValue(f_p_End->value() +
- (*edata)->vaddr() +
+ if (f_p_End != NULL && ResolveInfo::ThreadLocal != f_p_End->type()) {
+ f_p_End->setValue(f_p_End->value() + (*edata)->vaddr() +
(*edata)->memsz());
}
- }
- else {
- if (NULL != f_pEData)
+ } else {
+ if (f_pEData != NULL)
f_pEData->setValue(0x0);
- if (NULL != f_p_EData)
+ if (f_p_EData != NULL)
f_p_EData->setValue(0x0);
- if (NULL != f_pBSSStart)
+ if (f_pBSSStart != NULL)
f_pBSSStart->setValue(0x0);
- if (NULL != f_pEnd)
+ if (f_pEnd != NULL)
f_pEnd->setValue(0x0);
- if (NULL != f_p_End)
+ if (f_p_End != NULL)
f_p_End->setValue(0x0);
}
}
@@ -686,34 +644,32 @@
return true;
}
-bool GNULDBackend::finalizeTLSSymbol(LDSymbol& pSymbol)
-{
+bool GNULDBackend::finalizeTLSSymbol(LDSymbol& pSymbol) {
// ignore if symbol has no fragRef
if (!pSymbol.hasFragRef())
return true;
// the value of a TLS symbol is the offset to the TLS segment
ELFSegmentFactory::iterator tls_seg =
- elfSegmentTable().find(llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
assert(tls_seg != elfSegmentTable().end());
uint64_t value = pSymbol.fragRef()->getOutputOffset();
- uint64_t addr = pSymbol.fragRef()->frag()->getParent()->getSection().addr();
+ uint64_t addr = pSymbol.fragRef()->frag()->getParent()->getSection().addr();
pSymbol.setValue(value + addr - (*tls_seg)->vaddr());
return true;
}
-ELFFileFormat* GNULDBackend::getOutputFormat()
-{
+ELFFileFormat* GNULDBackend::getOutputFormat() {
switch (config().codeGenType()) {
case LinkerConfig::DynObj:
- assert(NULL != m_pDynObjFileFormat);
+ assert(m_pDynObjFileFormat != NULL);
return m_pDynObjFileFormat;
case LinkerConfig::Exec:
case LinkerConfig::Binary:
- assert(NULL != m_pExecFileFormat);
+ assert(m_pExecFileFormat != NULL);
return m_pExecFileFormat;
case LinkerConfig::Object:
- assert(NULL != m_pObjectFileFormat);
+ assert(m_pObjectFileFormat != NULL);
return m_pObjectFileFormat;
default:
fatal(diag::unrecognized_output_file) << config().codeGenType();
@@ -721,18 +677,17 @@
}
}
-const ELFFileFormat* GNULDBackend::getOutputFormat() const
-{
+const ELFFileFormat* GNULDBackend::getOutputFormat() const {
switch (config().codeGenType()) {
case LinkerConfig::DynObj:
- assert(NULL != m_pDynObjFileFormat);
+ assert(m_pDynObjFileFormat != NULL);
return m_pDynObjFileFormat;
case LinkerConfig::Exec:
case LinkerConfig::Binary:
- assert(NULL != m_pExecFileFormat);
+ assert(m_pExecFileFormat != NULL);
return m_pExecFileFormat;
case LinkerConfig::Object:
- assert(NULL != m_pObjectFileFormat);
+ assert(m_pObjectFileFormat != NULL);
return m_pObjectFileFormat;
default:
fatal(diag::unrecognized_output_file) << config().codeGenType();
@@ -741,35 +696,33 @@
}
/// sizeShstrtab - compute the size of .shstrtab
-void GNULDBackend::sizeShstrtab(Module& pModule)
-{
+void GNULDBackend::sizeShstrtab(Module& pModule) {
size_t shstrtab = 0;
// compute the size of .shstrtab section.
Module::const_iterator sect, sectEnd = pModule.end();
for (sect = pModule.begin(); sect != sectEnd; ++sect) {
shstrtab += (*sect)->name().size() + 1;
- } // end of for
+ } // end of for
getOutputFormat()->getShStrTab().setSize(shstrtab);
}
/// sizeNamePools - compute the size of regular name pools
/// In ELF executable files, regular name pools are .symtab, .strtab,
/// .dynsym, .dynstr, .hash and .shstrtab.
-void GNULDBackend::sizeNamePools(Module& pModule)
-{
+void GNULDBackend::sizeNamePools(Module& pModule) {
assert(LinkerConfig::Unset != config().codePosition());
// number of entries in symbol tables starts from 1 to hold the special entry
// at index 0 (STN_UNDEF). See ELF Spec Book I, p1-21.
size_t symtab = 1;
- size_t dynsym = config().isCodeStatic()? 0 : 1;
+ size_t dynsym = config().isCodeStatic() ? 0 : 1;
// size of string tables starts from 1 to hold the null character in their
// first byte
- size_t strtab = 1;
- size_t dynstr = config().isCodeStatic()? 0 : 1;
- size_t hash = 0;
- size_t gnuhash = 0;
+ size_t strtab = 1;
+ size_t dynstr = config().isCodeStatic() ? 0 : 1;
+ size_t hash = 0;
+ size_t gnuhash = 0;
// number of local symbol in the .symtab and .dynsym
size_t symtab_local_cnt = 0;
@@ -799,11 +752,11 @@
symbols.numOfLocalDyns();
break;
}
- } // end of switch
+ } // end of switch
ELFFileFormat* file_format = getOutputFormat();
- switch(config().codeGenType()) {
+ switch (config().codeGenType()) {
case LinkerConfig::DynObj: {
// soname
dynstr += config().options().soname().size() + 1;
@@ -822,7 +775,7 @@
dynsym_local_cnt = 1 + symbols.numOfLocalDyns();
// compute .gnu.hash
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle()) {
// count the number of dynsym to hash
size_t hashed_sym_cnt = 0;
@@ -862,9 +815,9 @@
if (!config().options().getRpathList().empty()) {
dynamic().reserveNeedEntry();
GeneralOptions::const_rpath_iterator rpath,
- rpathEnd = config().options().rpath_end();
- for (rpath = config().options().rpath_begin();
- rpath != rpathEnd; ++rpath)
+ rpathEnd = config().options().rpath_end();
+ for (rpath = config().options().rpath_begin(); rpath != rpathEnd;
+ ++rpath)
dynstr += (*rpath).size() + 1;
}
@@ -894,9 +847,9 @@
/* fall through */
case LinkerConfig::Object: {
if (config().targets().is32Bits())
- file_format->getSymTab().setSize(symtab*sizeof(llvm::ELF::Elf32_Sym));
+ file_format->getSymTab().setSize(symtab * sizeof(llvm::ELF::Elf32_Sym));
else
- file_format->getSymTab().setSize(symtab*sizeof(llvm::ELF::Elf64_Sym));
+ file_format->getSymTab().setSize(symtab * sizeof(llvm::ELF::Elf64_Sym));
file_format->getStrTab().setSize(strtab);
// set .symtab sh_info to one greater than the symbol table
@@ -911,7 +864,7 @@
default:
fatal(diag::fatal_illegal_codegen_type) << pModule.name();
break;
- } // end of switch
+ } // end of switch
}
/// emitSymbol32 - emit an ELF32 symbol
@@ -919,22 +872,20 @@
LDSymbol& pSymbol,
char* pStrtab,
size_t pStrtabsize,
- size_t pSymtabIdx)
-{
- // FIXME: check the endian between host and target
- // write out symbol
- if (hasEntryInStrTab(pSymbol)) {
- pSym.st_name = pStrtabsize;
- strcpy((pStrtab + pStrtabsize), pSymbol.name());
- }
- else {
- pSym.st_name = 0;
- }
- pSym.st_value = pSymbol.value();
- pSym.st_size = getSymbolSize(pSymbol);
- pSym.st_info = getSymbolInfo(pSymbol);
- pSym.st_other = pSymbol.visibility();
- pSym.st_shndx = getSymbolShndx(pSymbol);
+ size_t pSymtabIdx) {
+ // FIXME: check the endian between host and target
+ // write out symbol
+ if (hasEntryInStrTab(pSymbol)) {
+ pSym.st_name = pStrtabsize;
+ ::memcpy((pStrtab + pStrtabsize), pSymbol.name(), pSymbol.nameSize());
+ } else {
+ pSym.st_name = 0;
+ }
+ pSym.st_value = pSymbol.value();
+ pSym.st_size = getSymbolSize(pSymbol);
+ pSym.st_info = getSymbolInfo(pSymbol);
+ pSym.st_other = pSymbol.visibility();
+ pSym.st_shndx = getSymbolShndx(pSymbol);
}
/// emitSymbol64 - emit an ELF64 symbol
@@ -942,22 +893,20 @@
LDSymbol& pSymbol,
char* pStrtab,
size_t pStrtabsize,
- size_t pSymtabIdx)
-{
- // FIXME: check the endian between host and target
- // write out symbol
- if (hasEntryInStrTab(pSymbol)) {
- pSym.st_name = pStrtabsize;
- strcpy((pStrtab + pStrtabsize), pSymbol.name());
- }
- else {
- pSym.st_name = 0;
- }
- pSym.st_value = pSymbol.value();
- pSym.st_size = getSymbolSize(pSymbol);
- pSym.st_info = getSymbolInfo(pSymbol);
- pSym.st_other = pSymbol.visibility();
- pSym.st_shndx = getSymbolShndx(pSymbol);
+ size_t pSymtabIdx) {
+ // FIXME: check the endian between host and target
+ // write out symbol
+ if (hasEntryInStrTab(pSymbol)) {
+ pSym.st_name = pStrtabsize;
+ ::memcpy((pStrtab + pStrtabsize), pSymbol.name(), pSymbol.nameSize());
+ } else {
+ pSym.st_name = 0;
+ }
+ pSym.st_value = pSymbol.value();
+ pSym.st_size = getSymbolSize(pSymbol);
+ pSym.st_info = getSymbolInfo(pSymbol);
+ pSym.st_other = pSymbol.visibility();
+ pSym.st_shndx = getSymbolShndx(pSymbol);
}
/// emitRegNamePools - emit regular name pools - .symtab, .strtab
@@ -965,8 +914,7 @@
/// the size of these tables should be computed before layout
/// layout should computes the start offset of these tables
void GNULDBackend::emitRegNamePools(const Module& pModule,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasSymTab())
return;
@@ -974,10 +922,10 @@
LDSection& symtab_sect = file_format->getSymTab();
LDSection& strtab_sect = file_format->getStrTab();
- MemoryRegion symtab_region = pOutput.request(symtab_sect.offset(),
- symtab_sect.size());
- MemoryRegion strtab_region = pOutput.request(strtab_sect.offset(),
- strtab_sect.size());
+ MemoryRegion symtab_region =
+ pOutput.request(symtab_sect.offset(), symtab_sect.size());
+ MemoryRegion strtab_region =
+ pOutput.request(strtab_sect.offset(), strtab_sect.size());
// set up symtab_region
llvm::ELF::Elf32_Sym* symtab32 = NULL;
@@ -992,7 +940,7 @@
}
// set up strtab_region
- char* strtab = (char*)strtab_region.begin();
+ char* strtab = reinterpret_cast<char*>(strtab_region.begin());
// emit the first ELF symbol
if (config().targets().is32Bits())
@@ -1033,11 +981,10 @@
///
/// the size of these tables should be computed before layout
/// layout should computes the start offset of these tables
-void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
-{
+void GNULDBackend::emitDynNamePools(Module& pModule,
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
- if (!file_format->hasDynSymTab() ||
- !file_format->hasDynStrTab() ||
+ if (!file_format->hasDynSymTab() || !file_format->hasDynStrTab() ||
!file_format->hasDynamic())
return;
@@ -1046,14 +993,13 @@
LDSection& symtab_sect = file_format->getDynSymTab();
LDSection& strtab_sect = file_format->getDynStrTab();
- LDSection& dyn_sect = file_format->getDynamic();
+ LDSection& dyn_sect = file_format->getDynamic();
- MemoryRegion symtab_region = pOutput.request(symtab_sect.offset(),
- symtab_sect.size());
- MemoryRegion strtab_region = pOutput.request(strtab_sect.offset(),
- strtab_sect.size());
- MemoryRegion dyn_region = pOutput.request(dyn_sect.offset(),
- dyn_sect.size());
+ MemoryRegion symtab_region =
+ pOutput.request(symtab_sect.offset(), symtab_sect.size());
+ MemoryRegion strtab_region =
+ pOutput.request(strtab_sect.offset(), strtab_sect.size());
+ MemoryRegion dyn_region = pOutput.request(dyn_sect.offset(), dyn_sect.size());
// set up symtab_region
llvm::ELF::Elf32_Sym* symtab32 = NULL;
llvm::ELF::Elf64_Sym* symtab64 = NULL;
@@ -1067,7 +1013,7 @@
}
// set up strtab_region
- char* strtab = (char*)strtab_region.begin();
+ char* strtab = reinterpret_cast<char*>(strtab_region.begin());
// emit the first ELF symbol
if (config().targets().is32Bits())
@@ -1080,7 +1026,7 @@
Module::SymbolTable& symbols = pModule.getSymbolTable();
// emit .gnu.hash
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle())
emitGNUHashTab(symbols, pOutput);
@@ -1111,7 +1057,9 @@
Module::const_lib_iterator lib, libEnd = pModule.lib_end();
for (lib = pModule.lib_begin(); lib != libEnd; ++lib) {
if (!(*lib)->attribute()->isAsNeeded() || (*lib)->isNeeded()) {
- strcpy((strtab + strtabsize), (*lib)->name().c_str());
+ ::memcpy((strtab + strtabsize),
+ (*lib)->name().c_str(),
+ (*lib)->name().size());
(*dt_need)->setValue(llvm::ELF::DT_NEEDED, strtabsize);
strtabsize += (*lib)->name().size() + 1;
++dt_need;
@@ -1126,7 +1074,7 @@
++dt_need;
GeneralOptions::const_rpath_iterator rpath,
- rpathEnd = config().options().rpath_end();
+ rpathEnd = config().options().rpath_end();
for (rpath = config().options().rpath_begin(); rpath != rpathEnd; ++rpath) {
memcpy((strtab + strtabsize), (*rpath).data(), (*rpath).size());
strtabsize += (*rpath).size();
@@ -1144,36 +1092,37 @@
// emit soname
if (LinkerConfig::DynObj == config().codeGenType()) {
- strcpy((strtab + strtabsize), config().options().soname().c_str());
+ ::memcpy((strtab + strtabsize),
+ config().options().soname().c_str(),
+ config().options().soname().size());
strtabsize += config().options().soname().size() + 1;
}
}
/// emitELFHashTab - emit .hash
void GNULDBackend::emitELFHashTab(const Module::SymbolTable& pSymtab,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasHashTab())
return;
LDSection& hash_sect = file_format->getHashTab();
- MemoryRegion hash_region = pOutput.request(hash_sect.offset(),
- hash_sect.size());
+ MemoryRegion hash_region =
+ pOutput.request(hash_sect.offset(), hash_sect.size());
// both 32 and 64 bits hash table use 32-bit entry
// set up hash_region
- uint32_t* word_array = (uint32_t*)hash_region.begin();
+ uint32_t* word_array = reinterpret_cast<uint32_t*>(hash_region.begin());
uint32_t& nbucket = word_array[0];
- uint32_t& nchain = word_array[1];
+ uint32_t& nchain = word_array[1];
size_t dynsymSize = 1 + pSymtab.numOfLocalDyns() + pSymtab.numOfDynamics();
nbucket = getHashBucketCount(dynsymSize, false);
- nchain = dynsymSize;
+ nchain = dynsymSize;
uint32_t* bucket = (word_array + 2);
- uint32_t* chain = (bucket + nbucket);
+ uint32_t* chain = (bucket + nbucket);
// initialize bucket
- memset((void*)bucket, 0, nbucket);
+ memset(reinterpret_cast<void*>(bucket), 0, nbucket);
hash::StringHash<hash::ELF> hash_func;
@@ -1190,55 +1139,55 @@
/// emitGNUHashTab - emit .gnu.hash
void GNULDBackend::emitGNUHashTab(Module::SymbolTable& pSymtab,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasGNUHashTab())
return;
MemoryRegion gnuhash_region =
- pOutput.request(file_format->getGNUHashTab().offset(),
- file_format->getGNUHashTab().size());
+ pOutput.request(file_format->getGNUHashTab().offset(),
+ file_format->getGNUHashTab().size());
- uint32_t* word_array = (uint32_t*)gnuhash_region.begin();
+ uint32_t* word_array = reinterpret_cast<uint32_t*>(gnuhash_region.begin());
// fixed-length fields
- uint32_t& nbucket = word_array[0];
- uint32_t& symidx = word_array[1];
+ uint32_t& nbucket = word_array[0];
+ uint32_t& symidx = word_array[1];
uint32_t& maskwords = word_array[2];
- uint32_t& shift2 = word_array[3];
+ uint32_t& shift2 = word_array[3];
// variable-length fields
- uint8_t* bitmask = (uint8_t*)(word_array + 4);
- uint32_t* bucket = NULL;
- uint32_t* chain = NULL;
+ uint8_t* bitmask = reinterpret_cast<uint8_t*>(word_array + 4);
+ uint32_t* bucket = NULL;
+ uint32_t* chain = NULL;
// count the number of dynsym to hash
size_t unhashed_sym_cnt = pSymtab.numOfLocalDyns();
- size_t hashed_sym_cnt = pSymtab.numOfDynamics();
+ size_t hashed_sym_cnt = pSymtab.numOfDynamics();
Module::const_sym_iterator symbol, symEnd = pSymtab.dynamicEnd();
for (symbol = pSymtab.dynamicBegin(); symbol != symEnd; ++symbol) {
if (DynsymCompare().needGNUHash(**symbol))
break;
- ++unhashed_sym_cnt;
- --hashed_sym_cnt;
+ ++unhashed_sym_cnt;
+ --hashed_sym_cnt;
}
// special case for the empty hash table
if (hashed_sym_cnt == 0) {
- nbucket = 1; // one empty bucket
- symidx = 1 + unhashed_sym_cnt; // symidx above unhashed symbols
- maskwords = 1; // bitmask length
- shift2 = 0; // bloom filter
+ nbucket = 1; // one empty bucket
+ symidx = 1 + unhashed_sym_cnt; // symidx above unhashed symbols
+ maskwords = 1; // bitmask length
+ shift2 = 0; // bloom filter
if (config().targets().is32Bits()) {
- uint32_t* maskval = (uint32_t*)bitmask;
- *maskval = 0; // no valid hashes
+ uint32_t* maskval = reinterpret_cast<uint32_t*>(bitmask);
+ *maskval = 0; // no valid hashes
} else {
// must be 64
- uint64_t* maskval = (uint64_t*)bitmask;
- *maskval = 0; // no valid hashes
+ uint64_t* maskval = reinterpret_cast<uint64_t*>(bitmask);
+ *maskval = 0; // no valid hashes
}
- bucket = (uint32_t*)(bitmask + config().targets().bitclass() / 8);
- *bucket = 0; // no hash in the only bucket
+ bucket = reinterpret_cast<uint32_t*>(bitmask +
+ config().targets().bitclass() / 8);
+ *bucket = 0; // no hash in the only bucket
return;
}
@@ -1247,22 +1196,21 @@
uint32_t shift1 = config().targets().is32Bits() ? 5 : 6;
uint32_t mask = (1u << shift1) - 1;
- nbucket = getHashBucketCount(hashed_sym_cnt, true);
- symidx = 1 + unhashed_sym_cnt;
+ nbucket = getHashBucketCount(hashed_sym_cnt, true);
+ symidx = 1 + unhashed_sym_cnt;
maskwords = 1 << (maskbitslog2 - shift1);
- shift2 = maskbitslog2;
+ shift2 = maskbitslog2;
// setup bucket and chain
- bucket = (uint32_t*)(bitmask + maskbits / 8);
- chain = (bucket + nbucket);
+ bucket = reinterpret_cast<uint32_t*>(bitmask + maskbits / 8);
+ chain = (bucket + nbucket);
// build the gnu style hash table
- typedef std::multimap<uint32_t,
- std::pair<LDSymbol*, uint32_t> > SymMapType;
+ typedef std::multimap<uint32_t, std::pair<LDSymbol*, uint32_t> > SymMapType;
SymMapType symmap;
symEnd = pSymtab.dynamicEnd();
for (symbol = pSymtab.localDynBegin() + symidx - 1; symbol != symEnd;
- ++symbol) {
+ ++symbol) {
hash::StringHash<hash::DJB> hasher;
uint32_t djbhash = hasher((*symbol)->name());
uint32_t hash = djbhash % nbucket;
@@ -1276,7 +1224,7 @@
size_t count = 0;
std::pair<SymMapType::iterator, SymMapType::iterator> ret;
ret = symmap.equal_range(idx);
- for (SymMapType::iterator it = ret.first; it != ret.second; ) {
+ for (SymMapType::iterator it = ret.first; it != ret.second;) {
// rearrange the hashed symbol ordering
*(pSymtab.localDynBegin() + hashedidx - 1) = it->second.first;
uint32_t djbhash = it->second.second;
@@ -1303,20 +1251,19 @@
// write the bitmasks
if (config().targets().is32Bits()) {
- uint32_t* maskval = (uint32_t*)bitmask;
+ uint32_t* maskval = reinterpret_cast<uint32_t*>(bitmask);
for (size_t i = 0; i < maskwords; ++i)
std::memcpy(maskval + i, &bitmasks[i], 4);
} else {
// must be 64
- uint64_t* maskval = (uint64_t*)bitmask;
+ uint64_t* maskval = reinterpret_cast<uint64_t*>(bitmask);
for (size_t i = 0; i < maskwords; ++i)
std::memcpy(maskval + i, &bitmasks[i], 8);
}
}
/// sizeInterp - compute the size of the .interp section
-void GNULDBackend::sizeInterp()
-{
+void GNULDBackend::sizeInterp() {
const char* dyld_name;
if (config().options().hasDyld())
dyld_name = config().options().dyld().c_str();
@@ -1328,8 +1275,7 @@
}
/// emitInterp - emit the .interp
-void GNULDBackend::emitInterp(FileOutputBuffer& pOutput)
-{
+void GNULDBackend::emitInterp(FileOutputBuffer& pOutput) {
if (getOutputFormat()->hasInterp()) {
const LDSection& interp = getOutputFormat()->getInterp();
MemoryRegion region = pOutput.request(interp.offset(), interp.size());
@@ -1343,27 +1289,24 @@
}
}
-bool GNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const
-{
+bool GNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const {
return ResolveInfo::Section != pSym.type();
}
-void GNULDBackend::orderSymbolTable(Module& pModule)
-{
+void GNULDBackend::orderSymbolTable(Module& pModule) {
Module::SymbolTable& symbols = pModule.getSymbolTable();
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle())
// Currently we may add output symbols after sizeNamePools(), and a
// non-stable sort is used in SymbolCategory::arrange(), so we just
// sort .dynsym right before emitting .gnu.hash
- std::stable_sort(symbols.dynamicBegin(), symbols.dynamicEnd(),
- DynsymCompare());
+ std::stable_sort(
+ symbols.dynamicBegin(), symbols.dynamicEnd(), DynsymCompare());
}
/// getSectionOrder
-unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
// NULL section should be the "1st" section
@@ -1401,8 +1344,15 @@
&pSectHdr == &file_format->getJCR() ||
&pSectHdr == &file_format->getDataRelRo())
return SHO_RELRO;
+
if (&pSectHdr == &file_format->getDataRelRoLocal())
return SHO_RELRO_LOCAL;
+
+ // Make special sections that end with .rel.ro suffix as RELRO.
+ llvm::StringRef name(pSectHdr.name());
+ if (name.endswith(".rel.ro")) {
+ return SHO_RELRO;
+ }
}
if ((pSectHdr.flag() & llvm::ELF::SHF_TLS) != 0x0) {
return SHO_TLS_DATA;
@@ -1449,15 +1399,14 @@
case LDFileFormat::MetaData:
case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
default:
return SHO_UNDEFINED;
}
}
/// getSymbolSize
-uint64_t GNULDBackend::getSymbolSize(const LDSymbol& pSymbol) const
-{
- // @ref Google gold linker: symtab.cc: 2780
+uint64_t GNULDBackend::getSymbolSize(const LDSymbol& pSymbol) const {
// undefined and dynamic symbols should have zero size.
if (pSymbol.isDyn() || pSymbol.desc() == ResolveInfo::Undefined)
return 0x0;
@@ -1465,8 +1414,7 @@
}
/// getSymbolInfo
-uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const {
// set binding
uint8_t bind = 0x0;
if (pSymbol.resolveInfo()->isLocal())
@@ -1482,7 +1430,7 @@
if (config().codeGenType() != LinkerConfig::Object &&
(pSymbol.visibility() == llvm::ELF::STV_INTERNAL ||
- pSymbol.visibility() == llvm::ELF::STV_HIDDEN))
+ pSymbol.visibility() == llvm::ELF::STV_HIDDEN))
bind = llvm::ELF::STB_LOCAL;
uint32_t type = pSymbol.resolveInfo()->type();
@@ -1494,8 +1442,7 @@
}
/// getSymbolValue - this function is called after layout()
-uint64_t GNULDBackend::getSymbolValue(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolValue(const LDSymbol& pSymbol) const {
if (pSymbol.isDyn())
return 0x0;
@@ -1503,9 +1450,7 @@
}
/// getSymbolShndx - this function is called after layout()
-uint64_t
-GNULDBackend::getSymbolShndx(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolShndx(const LDSymbol& pSymbol) const {
if (pSymbol.resolveInfo()->isAbsolute())
return llvm::ELF::SHN_ABS;
if (pSymbol.resolveInfo()->isCommon())
@@ -1516,21 +1461,22 @@
if (pSymbol.resolveInfo()->isDefine() && !pSymbol.hasFragRef())
return llvm::ELF::SHN_ABS;
- assert(pSymbol.hasFragRef() && "symbols must have fragment reference to get its index");
+ assert(pSymbol.hasFragRef() &&
+ "symbols must have fragment reference to get its index");
return pSymbol.fragRef()->frag()->getParent()->getSection().index();
}
/// getSymbolIdx - called by emitRelocation to get the ouput symbol table index
-size_t GNULDBackend::getSymbolIdx(const LDSymbol* pSymbol) const
-{
- HashTableType::iterator entry = m_pSymIndexMap->find(const_cast<LDSymbol *>(pSymbol));
- assert(entry != m_pSymIndexMap->end() && "symbol not found in the symbol table");
- return entry.getEntry()->value();
+size_t GNULDBackend::getSymbolIdx(const LDSymbol* pSymbol) const {
+ HashTableType::iterator entry =
+ m_pSymIndexMap->find(const_cast<LDSymbol*>(pSymbol));
+ assert(entry != m_pSymIndexMap->end() &&
+ "symbol not found in the symbol table");
+ return entry.getEntry()->value();
}
/// isTemporary - Whether pSymbol is a local label.
-bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const
-{
+bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const {
if (ResolveInfo::Local != pSymbol.binding())
return false;
@@ -1542,13 +1488,11 @@
return true;
// UnixWare 2.1 cc generate DWARF debugging symbols with `..' prefix.
- // @ref Google gold linker, target.cc:39 @@ Target::do_is_local_label_name()
if (name[0] == '.' && name[1] == '.')
return true;
// Work arround for gcc's bug
// gcc sometimes generate symbols with '_.L_' prefix.
- // @ref Google gold linker, target.cc:39 @@ Target::do_is_local_label_name()
if (pSymbol.nameSize() < 4)
return false;
@@ -1560,10 +1504,7 @@
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is executed at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
-bool
-GNULDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool GNULDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyFiles() &&
@@ -1594,7 +1535,7 @@
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -1612,16 +1553,13 @@
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -1641,16 +1579,13 @@
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -1664,16 +1599,11 @@
/// updateSectionFlags - update pTo's flags when merging pFrom
/// update the output section flags based on input section flags.
-/// @ref The Google gold linker:
-/// output.cc: 2809: Output_section::update_flags_for_input_section
-bool GNULDBackend::updateSectionFlags(LDSection& pTo, const LDSection& pFrom)
-{
+bool GNULDBackend::updateSectionFlags(LDSection& pTo, const LDSection& pFrom) {
// union the flags from input
uint32_t flags = pTo.flag();
- flags |= (pFrom.flag() &
- (llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_EXECINSTR));
+ flags |= (pFrom.flag() & (llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC |
+ llvm::ELF::SHF_EXECINSTR));
// if there is an input section is not SHF_MERGE, clean this flag
if (0 == (pFrom.flag() & llvm::ELF::SHF_MERGE))
@@ -1691,16 +1621,14 @@
bool GNULDBackend::readRelocation(const llvm::ELF::Elf32_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint32_t& pOffset) const
-{
+ uint32_t& pOffset) const {
uint32_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap32(pRel.r_offset);
- r_info = mcld::bswap32(pRel.r_info);
+ r_info = mcld::bswap32(pRel.r_info);
}
pType = static_cast<unsigned char>(r_info);
@@ -1713,17 +1641,15 @@
Relocation::Type& pType,
uint32_t& pSymIdx,
uint32_t& pOffset,
- int32_t& pAddend) const
-{
- uint32_t r_info = 0x0;
+ int32_t& pAddend) const {
+ uint32_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap32(pRel.r_offset);
- r_info = mcld::bswap32(pRel.r_info);
+ r_info = mcld::bswap32(pRel.r_info);
pAddend = mcld::bswap32(pRel.r_addend);
}
@@ -1734,18 +1660,16 @@
/// readRelocation - read ELF64_Rel entry
bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rel& pRel,
- Relocation::Type& pType,
- uint32_t& pSymIdx,
- uint64_t& pOffset) const
-{
+ Relocation::Type& pType,
+ uint32_t& pSymIdx,
+ uint64_t& pOffset) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
}
pType = static_cast<uint32_t>(r_info);
@@ -1755,20 +1679,18 @@
/// readRel - read ELF64_Rela entry
bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rela& pRel,
- Relocation::Type& pType,
- uint32_t& pSymIdx,
- uint64_t& pOffset,
- int64_t& pAddend) const
-{
+ Relocation::Type& pType,
+ uint32_t& pSymIdx,
+ uint64_t& pOffset,
+ int64_t& pAddend) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
pAddend = mcld::bswap64(pRel.r_addend);
}
@@ -1781,8 +1703,7 @@
void GNULDBackend::emitRelocation(llvm::ELF::Elf32_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint32_t pOffset) const
-{
+ uint32_t pOffset) const {
pRel.r_offset = pOffset;
pRel.setSymbolAndType(pSymIdx, pType);
}
@@ -1792,8 +1713,7 @@
Relocation::Type pType,
uint32_t pSymIdx,
uint32_t pOffset,
- int32_t pAddend) const
-{
+ int32_t pAddend) const {
pRel.r_offset = pOffset;
pRel.r_addend = pAddend;
pRel.setSymbolAndType(pSymIdx, pType);
@@ -1803,8 +1723,7 @@
void GNULDBackend::emitRelocation(llvm::ELF::Elf64_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint64_t pOffset) const
-{
+ uint64_t pOffset) const {
pRel.r_offset = pOffset;
pRel.setSymbolAndType(pSymIdx, pType);
}
@@ -1814,17 +1733,15 @@
Relocation::Type pType,
uint32_t pSymIdx,
uint64_t pOffset,
- int64_t pAddend) const
-{
+ int64_t pAddend) const {
pRel.r_offset = pOffset;
pRel.r_addend = pAddend;
pRel.setSymbolAndType(pSymIdx, pType);
}
/// createProgramHdrs - base on output sections to create the program headers
-void GNULDBackend::createProgramHdrs(Module& pModule)
-{
- ELFFileFormat *file_format = getOutputFormat();
+void GNULDBackend::createProgramHdrs(Module& pModule) {
+ ELFFileFormat* file_format = getOutputFormat();
// make PT_INTERP
if (file_format->hasInterp()) {
@@ -1839,7 +1756,7 @@
ELFSegment* load_seg = NULL;
// make possible PT_LOAD segments
LinkerScript& ldscript = pModule.getScript();
- LinkerScript::AddressMap::iterator addrEnd= ldscript.addressMap().end();
+ LinkerScript::AddressMap::iterator addrEnd = ldscript.addressMap().end();
SectionMap::iterator out, prev, outBegin, outEnd;
outBegin = ldscript.sectionMap().begin();
outEnd = ldscript.sectionMap().end();
@@ -1860,28 +1777,23 @@
if (LDFileFormat::Null == sect->kind()) {
// 1. create text segment
createPT_LOAD = true;
- }
- else if (!config().options().omagic() &&
- (prev_flag & llvm::ELF::PF_W) ^ (cur_flag & llvm::ELF::PF_W)) {
+ } else if (!config().options().omagic() &&
+ (prev_flag & llvm::ELF::PF_W) ^ (cur_flag & llvm::ELF::PF_W)) {
// 2. create data segment if w/o omagic set
createPT_LOAD = true;
- }
- else if (sect->kind() == LDFileFormat::BSS &&
- load_seg->isDataSegment() &&
- addrEnd != ldscript.addressMap().find(".bss")) {
+ } else if (sect->kind() == LDFileFormat::BSS && load_seg->isDataSegment() &&
+ addrEnd != ldscript.addressMap().find(".bss")) {
// 3. create bss segment if w/ -Tbss and there is a data segment
createPT_LOAD = true;
- }
- else if ((sect != &(file_format->getText())) &&
- (sect != &(file_format->getData())) &&
- (sect != &(file_format->getBSS())) &&
- (addrEnd != ldscript.addressMap().find(sect->name()))) {
+ } else if ((sect != &(file_format->getText())) &&
+ (sect != &(file_format->getData())) &&
+ (sect != &(file_format->getBSS())) &&
+ (addrEnd != ldscript.addressMap().find(sect->name()))) {
// 4. create PT_LOAD for sections in address map except for text, data,
// and bss
createPT_LOAD = true;
- }
- else if (LDFileFormat::Null == (*prev)->getSection()->kind() &&
- !config().options().getScriptList().empty()) {
+ } else if (LDFileFormat::Null == (*prev)->getSection()->kind() &&
+ !config().options().getScriptList().empty()) {
// 5. create PT_LOAD to hold NULL section if there is a default ldscript
createPT_LOAD = true;
}
@@ -1893,7 +1805,7 @@
load_seg->setAlign(abiPageSize());
}
- assert(NULL != load_seg);
+ assert(load_seg != NULL);
load_seg->append(sect);
if (cur_flag != prev_flag)
load_seg->updateFlag(cur_flag);
@@ -1903,9 +1815,8 @@
// make PT_DYNAMIC
if (file_format->hasDynamic()) {
- ELFSegment* dyn_seg = elfSegmentTable().produce(llvm::ELF::PT_DYNAMIC,
- llvm::ELF::PF_R |
- llvm::ELF::PF_W);
+ ELFSegment* dyn_seg = elfSegmentTable().produce(
+ llvm::ELF::PT_DYNAMIC, llvm::ELF::PF_R | llvm::ELF::PF_W);
dyn_seg->append(&file_format->getDynamic());
}
@@ -1913,15 +1824,17 @@
// make PT_GNU_RELRO
ELFSegment* relro_seg = elfSegmentTable().produce(llvm::ELF::PT_GNU_RELRO);
for (ELFSegmentFactory::iterator seg = elfSegmentTable().begin(),
- segEnd = elfSegmentTable().end(); seg != segEnd; ++seg) {
+ segEnd = elfSegmentTable().end();
+ seg != segEnd;
+ ++seg) {
if (llvm::ELF::PT_LOAD != (*seg)->type())
continue;
- for (ELFSegment::iterator sect = (*seg)->begin(),
- sectEnd = (*seg)->end(); sect != sectEnd; ++sect) {
+ for (ELFSegment::iterator sect = (*seg)->begin(), sectEnd = (*seg)->end();
+ sect != sectEnd;
+ ++sect) {
unsigned int order = getSectionOrder(**sect);
- if (SHO_RELRO_LOCAL == order ||
- SHO_RELRO == order ||
+ if (SHO_RELRO_LOCAL == order || SHO_RELRO == order ||
SHO_RELRO_LAST == order) {
relro_seg->append(*sect);
}
@@ -1946,14 +1859,13 @@
// make PT_GNU_STACK
if (file_format->hasStackNote()) {
+ uint32_t flag = getSegmentFlag(file_format->getStackNote().flag());
elfSegmentTable().produce(llvm::ELF::PT_GNU_STACK,
- llvm::ELF::PF_R |
- llvm::ELF::PF_W |
- getSegmentFlag(file_format->getStackNote().flag()));
+ llvm::ELF::PF_R | llvm::ELF::PF_W | flag);
}
// make PT_NOTE
- ELFSegment *note_seg = NULL;
+ ELFSegment* note_seg = NULL;
prev_flag = 0x0;
Module::iterator sect, sectBegin, sectEnd;
sectBegin = pModule.begin();
@@ -1979,21 +1891,20 @@
}
/// setupProgramHdrs - set up the attributes of segments
-void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
-{
+void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript) {
// update segment info
for (ELFSegmentFactory::iterator seg = elfSegmentTable().begin(),
- segEnd = elfSegmentTable().end(); seg != segEnd; ++seg) {
-
+ segEnd = elfSegmentTable().end();
+ seg != segEnd;
+ ++seg) {
// bypass if there is no section in this segment (e.g., PT_GNU_STACK)
if ((*seg)->size() == 0)
continue;
// bypass the PT_LOAD that only has NULL section now
if ((*seg)->type() == llvm::ELF::PT_LOAD &&
- (*seg)->front()->kind() == LDFileFormat::Null &&
- (*seg)->size() == 1)
- continue;
+ (*seg)->front()->kind() == LDFileFormat::Null && (*seg)->size() == 1)
+ continue;
(*seg)->setOffset((*seg)->front()->offset());
if ((*seg)->type() == llvm::ELF::PT_LOAD &&
@@ -2012,22 +1923,19 @@
break;
}
if (sect != sectREnd) {
- (*seg)->setFilesz((*sect)->offset() +
- (*sect)->size() -
- (*seg)->offset());
+ (*seg)->setFilesz((*sect)->offset() + (*sect)->size() - (*seg)->offset());
} else {
(*seg)->setFilesz(0x0);
}
- (*seg)->setMemsz((*seg)->back()->addr() +
- (*seg)->back()->size() -
+ (*seg)->setMemsz((*seg)->back()->addr() + (*seg)->back()->size() -
(*seg)->vaddr());
- } // end of for
+ } // end of for
// handle the case if text segment only has NULL section
LDSection* null_sect = &getOutputFormat()->getNULLSection();
ELFSegmentFactory::iterator null_seg =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
if ((*null_seg)->size() == 1) {
// find 2nd PT_LOAD
@@ -2053,20 +1961,17 @@
}
}
if (sect == sectEnd) {
- (*seg)->setFilesz((*seg)->back()->offset() +
- (*seg)->back()->size() -
+ (*seg)->setFilesz((*seg)->back()->offset() + (*seg)->back()->size() -
(*seg)->offset());
} else if (*sect != (*seg)->front()) {
--sect;
- (*seg)->setFilesz((*sect)->offset() +
- (*sect)->size() -
+ (*seg)->setFilesz((*sect)->offset() + (*sect)->size() -
(*seg)->offset());
} else {
(*seg)->setFilesz(0x0);
}
- (*seg)->setMemsz((*seg)->back()->addr() +
- (*seg)->back()->size() -
+ (*seg)->setMemsz((*seg)->back()->addr() + (*seg)->back()->size() -
(*seg)->vaddr());
(*seg)->insert((*seg)->begin(), null_sect);
@@ -2087,11 +1992,11 @@
// set up PT_PHDR
ELFSegmentFactory::iterator phdr =
- elfSegmentTable().find(llvm::ELF::PT_PHDR, llvm::ELF::PF_R, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_PHDR, llvm::ELF::PF_R, 0x0);
if (phdr != elfSegmentTable().end()) {
ELFSegmentFactory::iterator null_seg =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
if (null_seg != elfSegmentTable().end()) {
uint64_t offset = 0x0, phdr_size = 0x0;
if (config().targets().is32Bits()) {
@@ -2115,8 +2020,7 @@
/// getSegmentFlag - give a section flag and return the corresponding segment
/// flag
-uint32_t GNULDBackend::getSegmentFlag(const uint32_t pSectionFlag)
-{
+uint32_t GNULDBackend::getSegmentFlag(const uint32_t pSectionFlag) {
uint32_t flag = 0x0;
if ((pSectionFlag & llvm::ELF::SHF_ALLOC) != 0x0)
flag |= llvm::ELF::PF_R;
@@ -2128,16 +2032,13 @@
}
/// setupGNUStackInfo - setup the section flag of .note.GNU-stack in output
-/// @ref gold linker: layout.cc:2608
-void GNULDBackend::setupGNUStackInfo(Module& pModule)
-{
+void GNULDBackend::setupGNUStackInfo(Module& pModule) {
uint32_t flag = 0x0;
if (config().options().hasStackSet()) {
// 1. check the command line option (-z execstack or -z noexecstack)
if (config().options().hasExecStack())
flag = llvm::ELF::SHF_EXECINSTR;
- }
- else {
+ } else {
// 2. check the stack info from the input objects
// FIXME: since we alway emit .note.GNU-stack in output now, we may be able
// to check this from the output .note.GNU-stack directly after section
@@ -2147,7 +2048,7 @@
for (obj = pModule.obj_begin(); obj != objEnd; ++obj) {
++object_count;
const LDSection* sect = (*obj)->context()->getSection(".note.GNU-stack");
- if (NULL != sect) {
+ if (sect != NULL) {
++stack_note_count;
// 2.1 found a stack note that is set as executable
if (0 != (llvm::ELF::SHF_EXECINSTR & sect->flag())) {
@@ -2174,8 +2075,7 @@
}
/// setOutputSectionOffset - helper function to set output sections' offset.
-void GNULDBackend::setOutputSectionOffset(Module& pModule)
-{
+void GNULDBackend::setOutputSectionOffset(Module& pModule) {
LinkerScript& script = pModule.getScript();
uint64_t offset = 0x0;
LDSection* cur = NULL;
@@ -2191,15 +2091,15 @@
}
switch (prev->kind()) {
- case LDFileFormat::Null:
- offset = sectionStartOffset();
- break;
- case LDFileFormat::BSS:
- offset = prev->offset();
- break;
- default:
- offset = prev->offset() + prev->size();
- break;
+ case LDFileFormat::Null:
+ offset = sectionStartOffset();
+ break;
+ case LDFileFormat::BSS:
+ offset = prev->offset();
+ break;
+ default:
+ offset = prev->offset() + prev->size();
+ break;
}
alignAddress(offset, cur->align());
cur->setOffset(offset);
@@ -2207,8 +2107,7 @@
}
/// setOutputSectionAddress - helper function to set output sections' address.
-void GNULDBackend::setOutputSectionAddress(Module& pModule)
-{
+void GNULDBackend::setOutputSectionAddress(Module& pModule) {
RpnEvaluator evaluator(pModule, *this);
LinkerScript& script = pModule.getScript();
uint64_t vma = 0x0, offset = 0x0;
@@ -2230,7 +2129,9 @@
// process dot assignments between 2 output sections
for (SectionMap::Output::dot_iterator it = (*out)->dot_begin(),
- ie = (*out)->dot_end(); it != ie; ++it) {
+ ie = (*out)->dot_end();
+ it != ie;
+ ++it) {
(*it).assign(evaluator);
}
@@ -2292,8 +2193,7 @@
// check if current is the first non-relro section
SectionMap::iterator relro_last = out - 1;
- if (relro_last != outEnd &&
- (*relro_last)->order() <= SHO_RELRO_LAST &&
+ if (relro_last != outEnd && (*relro_last)->order() <= SHO_RELRO_LAST &&
(*out)->order() > SHO_RELRO_LAST) {
// align the first non-relro section to page boundary
alignAddress(vma, abiPageSize());
@@ -2311,20 +2211,20 @@
got.setOffset(got.offset() + diff);
}
}
- } // end of if - for relro processing
+ } // end of if - for relro processing
cur->setAddr(vma);
switch (prev->kind()) {
- case LDFileFormat::Null:
- offset = sectionStartOffset();
- break;
- case LDFileFormat::BSS:
- offset = prev->offset();
- break;
- default:
- offset = prev->offset() + prev->size();
- break;
+ case LDFileFormat::Null:
+ offset = sectionStartOffset();
+ break;
+ case LDFileFormat::BSS:
+ offset = prev->offset();
+ break;
+ default:
+ offset = prev->offset() + prev->size();
+ break;
}
alignAddress(offset, cur->align());
// in p75, http://www.sco.com/developers/devspecs/gabi41.pdf
@@ -2336,8 +2236,7 @@
// output!
if ((cur->flag() & llvm::ELF::SHF_ALLOC) != 0 &&
(vma & (abiPageSize() - 1)) != (offset & (abiPageSize() - 1))) {
- uint64_t padding = abiPageSize() +
- (vma & (abiPageSize() - 1)) -
+ uint64_t padding = abiPageSize() + (vma & (abiPageSize() - 1)) -
(offset & (abiPageSize() - 1));
offset += padding;
}
@@ -2348,8 +2247,9 @@
bool changed = false;
Fragment* invalid = NULL;
for (SectionMap::Output::iterator in = (*out)->begin(),
- inEnd = (*out)->end(); in != inEnd; ++in) {
-
+ inEnd = (*out)->end();
+ in != inEnd;
+ ++in) {
if (invalid != NULL && !(*in)->dotAssignments().empty()) {
while (invalid != (*in)->dotAssignments().front().first) {
Fragment* prev = invalid->getPrevNode();
@@ -2360,7 +2260,9 @@
}
for (SectionMap::Input::dot_iterator it = (*in)->dot_begin(),
- ie = (*in)->dot_end(); it != ie; ++it) {
+ ie = (*in)->dot_end();
+ it != ie;
+ ++it) {
(*it).second.assign(evaluator);
if ((*it).first != NULL) {
uint64_t new_offset = (*it).second.symbol().value() - vma;
@@ -2370,8 +2272,8 @@
changed = true;
}
}
- } // for each dot assignment
- } // for each input description
+ } // for each dot assignment
+ } // for each input description
if (changed) {
while (invalid != NULL) {
@@ -2383,73 +2285,72 @@
cur->setSize(cur->getSectionData()->back().getOffset() +
cur->getSectionData()->back().size());
}
-
- } // for each output section description
+ } // for each output section description
}
/// placeOutputSections - place output sections based on SectionMap
-void GNULDBackend::placeOutputSections(Module& pModule)
-{
+void GNULDBackend::placeOutputSections(Module& pModule) {
typedef std::vector<LDSection*> Orphans;
Orphans orphans;
SectionMap& sectionMap = pModule.getScript().sectionMap();
for (Module::iterator it = pModule.begin(), ie = pModule.end(); it != ie;
- ++it) {
+ ++it) {
bool wanted = false;
switch ((*it)->kind()) {
- // take NULL and StackNote directly
- case LDFileFormat::Null:
- case LDFileFormat::StackNote:
- wanted = true;
- break;
- // ignore if section size is 0
- case LDFileFormat::EhFrame:
- if (((*it)->size() != 0) ||
- ((*it)->hasEhFrame() &&
- config().codeGenType() == LinkerConfig::Object))
+ // take NULL and StackNote directly
+ case LDFileFormat::Null:
+ case LDFileFormat::StackNote:
wanted = true;
- break;
- case LDFileFormat::Relocation:
- if (((*it)->size() != 0) ||
- ((*it)->hasRelocData() &&
- config().codeGenType() == LinkerConfig::Object))
- wanted = true;
- break;
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Target:
- case LDFileFormat::MetaData:
- case LDFileFormat::BSS:
- case LDFileFormat::Debug:
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::Note:
- case LDFileFormat::NamePool:
- case LDFileFormat::EhFrameHdr:
- if (((*it)->size() != 0) ||
- ((*it)->hasSectionData() &&
- config().codeGenType() == LinkerConfig::Object))
- wanted = true;
- break;
- case LDFileFormat::Group:
- if (LinkerConfig::Object == config().codeGenType()) {
- //TODO: support incremental linking
- ;
- }
- break;
- case LDFileFormat::Version:
- if ((*it)->size() != 0) {
- wanted = true;
- warning(diag::warn_unsupported_symbolic_versioning) << (*it)->name();
- }
- break;
- default:
- if ((*it)->size() != 0) {
- error(diag::err_unsupported_section) << (*it)->name() << (*it)->kind();
- }
- break;
- } // end of switch
+ break;
+ // ignore if section size is 0
+ case LDFileFormat::EhFrame:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasEhFrame() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::Relocation:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasRelocData() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Target:
+ case LDFileFormat::MetaData:
+ case LDFileFormat::BSS:
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::Note:
+ case LDFileFormat::NamePool:
+ case LDFileFormat::EhFrameHdr:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasSectionData() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::Group:
+ if (LinkerConfig::Object == config().codeGenType()) {
+ // TODO: support incremental linking
+ }
+ break;
+ case LDFileFormat::Version:
+ if ((*it)->size() != 0) {
+ wanted = true;
+ warning(diag::warn_unsupported_symbolic_versioning) << (*it)->name();
+ }
+ break;
+ default:
+ if ((*it)->size() != 0) {
+ error(diag::err_unsupported_section) << (*it)->name()
+ << (*it)->kind();
+ }
+ break;
+ } // end of switch
if (wanted) {
SectionMap::iterator out, outBegin, outEnd;
@@ -2459,21 +2360,21 @@
bool matched = false;
if ((*it)->name().compare((*out)->name()) == 0) {
switch ((*out)->prolog().constraint()) {
- case OutputSectDesc::NO_CONSTRAINT:
- matched = true;
- break;
- case OutputSectDesc::ONLY_IF_RO:
- matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) == 0;
- break;
- case OutputSectDesc::ONLY_IF_RW:
- matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) != 0;
- break;
- } // end of switch
+ case OutputSectDesc::NO_CONSTRAINT:
+ matched = true;
+ break;
+ case OutputSectDesc::ONLY_IF_RO:
+ matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) == 0;
+ break;
+ case OutputSectDesc::ONLY_IF_RW:
+ matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) != 0;
+ break;
+ } // end of switch
if (matched)
break;
}
- } // for each output section description
+ } // for each output section description
if (out != outEnd) {
// set up the section
@@ -2483,14 +2384,16 @@
orphans.push_back(*it);
}
}
- } // for each section in Module
+ } // for each section in Module
// set up sections in SectionMap but do not exist at all.
uint32_t flag = 0x0;
unsigned int order = SHO_UNDEFINED;
OutputSectDesc::Type type = OutputSectDesc::LOAD;
for (SectionMap::reverse_iterator out = sectionMap.rbegin(),
- outEnd = sectionMap.rend(); out != outEnd; ++out) {
+ outEnd = sectionMap.rend();
+ out != outEnd;
+ ++out) {
if ((*out)->hasContent() ||
(*out)->getSection()->kind() == LDFileFormat::Null ||
(*out)->getSection()->kind() == LDFileFormat::StackNote) {
@@ -2502,11 +2405,11 @@
(*out)->setOrder(order);
(*out)->prolog().setType(type);
}
- } // for each output section description
+ } // for each output section description
// place orphan sections
for (Orphans::iterator it = orphans.begin(), ie = orphans.end(); it != ie;
- ++it) {
+ ++it) {
size_t order = getSectionOrder(**it);
SectionMap::iterator out, outBegin, outEnd;
outBegin = sectionMap.begin();
@@ -2522,13 +2425,12 @@
out = sectionMap.insert(out, *it);
}
(*out)->setOrder(order);
- } // for each orphan section
+ } // for each orphan section
// sort output section orders if there is no default ldscript
if (config().options().getScriptList().empty()) {
- std::stable_sort(sectionMap.begin(),
- sectionMap.end(),
- SectionMap::SHOCompare());
+ std::stable_sort(
+ sectionMap.begin(), sectionMap.end(), SectionMap::SHOCompare());
}
// when section ordering is fixed, now we can make sure dot assignments are
@@ -2537,8 +2439,7 @@
}
/// layout - layout method
-void GNULDBackend::layout(Module& pModule)
-{
+void GNULDBackend::layout(Module& pModule) {
// 1. place output sections based on SectionMap from SECTIONS command
placeOutputSections(pModule);
@@ -2546,7 +2447,8 @@
SectionMap& sectionMap = pModule.getScript().sectionMap();
pModule.getSectionTable().clear();
for (SectionMap::iterator out = sectionMap.begin(), outEnd = sectionMap.end();
- out != outEnd; ++out) {
+ out != outEnd;
+ ++out) {
if ((*out)->hasContent() ||
(*out)->getSection()->kind() == LDFileFormat::Null ||
(*out)->getSection()->kind() == LDFileFormat::StackNote ||
@@ -2554,7 +2456,7 @@
(*out)->getSection()->setIndex(pModule.size());
pModule.getSectionTable().push_back((*out)->getSection());
}
- } // for each output section description
+ } // for each output section description
// 3. update the size of .shstrtab
sizeShstrtab(pModule);
@@ -2571,42 +2473,38 @@
setOutputSectionOffset(pModule);
}
-void GNULDBackend::createAndSizeEhFrameHdr(Module& pModule)
-{
+void GNULDBackend::createAndSizeEhFrameHdr(Module& pModule) {
if (LinkerConfig::Object != config().codeGenType() &&
config().options().hasEhFrameHdr() && getOutputFormat()->hasEhFrame()) {
// init EhFrameHdr and size the output section
ELFFileFormat* format = getOutputFormat();
- m_pEhFrameHdr = new EhFrameHdr(format->getEhFrameHdr(),
- format->getEhFrame());
+ m_pEhFrameHdr =
+ new EhFrameHdr(format->getEhFrameHdr(), format->getEhFrame());
m_pEhFrameHdr->sizeOutput();
}
}
/// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe
/// function pointer access
-bool GNULDBackend::mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection)
- const
-{
+bool GNULDBackend::mayHaveUnsafeFunctionPointerAccess(
+ const LDSection& pSection) const {
llvm::StringRef name(pSection.name());
return !name.startswith(".rodata._ZTV") &&
!name.startswith(".data.rel.ro._ZTV") &&
!name.startswith(".rodata._ZTC") &&
- !name.startswith(".data.rel.ro._ZTC") &&
- !name.startswith(".eh_frame");
+ !name.startswith(".data.rel.ro._ZTC") && !name.startswith(".eh_frame");
}
/// preLayout - Backend can do any needed modification before layout
-void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder) {
// prelayout target first
doPreLayout(pBuilder);
// change .tbss and .tdata section symbol from Local to LocalDyn category
- if (NULL != f_pTDATA)
+ if (f_pTDATA != NULL)
pModule.getSymbolTable().changeToDynamic(*f_pTDATA);
- if (NULL != f_pTBSS)
+ if (f_pTBSS != NULL)
pModule.getSymbolTable().changeToDynamic(*f_pTBSS);
// To merge input's relocation sections into output's relocation sections.
@@ -2618,14 +2516,11 @@
for (input = pModule.obj_begin(); input != inEnd; ++input) {
LDContext::sect_iterator rs, rsEnd = (*input)->context()->relocSectEnd();
for (rs = (*input)->context()->relocSectBegin(); rs != rsEnd; ++rs) {
-
// get the output relocation LDSection with identical name.
LDSection* output_sect = pModule.getSection((*rs)->name());
- if (NULL == output_sect) {
- output_sect = LDSection::Create((*rs)->name(),
- (*rs)->kind(),
- (*rs)->type(),
- (*rs)->flag());
+ if (output_sect == NULL) {
+ output_sect = LDSection::Create(
+ (*rs)->name(), (*rs)->kind(), (*rs)->type(), (*rs)->flag());
output_sect->setAlign((*rs)->align());
pModule.getSectionTable().push_back(output_sect);
@@ -2633,11 +2528,11 @@
// set output relocation section link
const LDSection* input_link = (*rs)->getLink();
- assert(NULL != input_link && "Illegal input relocation section.");
+ assert(input_link != NULL && "Illegal input relocation section.");
// get the linked output section
LDSection* output_link = pModule.getSection(input_link->name());
- assert(NULL != output_link);
+ assert(output_link != NULL);
output_sect->setLink(output_link);
@@ -2649,9 +2544,9 @@
// move relocations from input's to output's RelcoationData
RelocData::RelocationListType& out_list =
- out_reloc_data->getRelocationList();
+ out_reloc_data->getRelocationList();
RelocData::RelocationListType& in_list =
- (*rs)->getRelocData()->getRelocationList();
+ (*rs)->getRelocData()->getRelocationList();
out_list.splice(out_list.end(), in_list);
// size output
@@ -2663,17 +2558,16 @@
fatal(diag::unknown_reloc_section_type) << output_sect->type()
<< output_sect->name();
}
- } // end of for each relocation section
- } // end of for each input
- } // end of if
+ } // end of for each relocation section
+ } // end of for each input
+ } // end of if
// set up the section flag of .note.GNU-stack section
setupGNUStackInfo(pModule);
}
/// postLayout - Backend can do any needed modification after layout
-void GNULDBackend::postLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void GNULDBackend::postLayout(Module& pModule, IRBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
// do relaxation
relax(pModule, pBuilder);
@@ -2684,8 +2578,7 @@
doPostLayout(pModule, pBuilder);
}
-void GNULDBackend::postProcessing(FileOutputBuffer& pOutput)
-{
+void GNULDBackend::postProcessing(FileOutputBuffer& pOutput) {
if (LinkerConfig::Object != config().codeGenType() &&
config().options().hasEhFrameHdr() && getOutputFormat()->hasEhFrame()) {
// emit eh_frame_hdr
@@ -2694,15 +2587,11 @@
}
/// getHashBucketCount - calculate hash bucket count.
-/// @ref Google gold linker, dynobj.cc:791
unsigned GNULDBackend::getHashBucketCount(unsigned pNumOfSymbols,
- bool pIsGNUStyle)
-{
- // @ref Google gold, dynobj.cc:loc 791
- static const unsigned int buckets[] =
- {
- 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
- 16411, 32771, 65537, 131101, 262147
+ bool pIsGNUStyle) {
+ static const unsigned int buckets[] = {
+ 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209, 16411,
+ 32771, 65537, 131101, 262147
};
const unsigned buckets_count = sizeof buckets / sizeof buckets[0];
@@ -2720,11 +2609,9 @@
}
/// getGNUHashMaskbitslog2 - calculate the number of mask bits in log2
-/// @ref binutils gold, dynobj.cc:1165
-unsigned GNULDBackend::getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const
-{
+unsigned GNULDBackend::getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const {
uint32_t maskbitslog2 = 1;
- for (uint32_t x = pNumOfSymbols >> 1; x != 0; x >>=1)
+ for (uint32_t x = pNumOfSymbols >> 1; x != 0; x >>= 1)
++maskbitslog2;
if (maskbitslog2 < 3)
@@ -2741,9 +2628,7 @@
}
/// isDynamicSymbol
-/// @ref Google gold linker: symtab.cc:311
-bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const
-{
+bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const {
// If a local symbol is in the LDContext's symbol table, it's a real local
// symbol. We should not add it
if (pSymbol.binding() == ResolveInfo::Local)
@@ -2752,7 +2637,7 @@
// If we are building shared object, and the visibility is external, we
// need to add it.
if (LinkerConfig::DynObj == config().codeGenType() ||
- LinkerConfig::Exec == config().codeGenType() ||
+ LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()) {
if (pSymbol.resolveInfo()->visibility() == ResolveInfo::Default ||
pSymbol.resolveInfo()->visibility() == ResolveInfo::Protected)
@@ -2762,9 +2647,7 @@
}
/// isDynamicSymbol
-/// @ref Google gold linker: symtab.cc:311
-bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const
-{
+bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const {
// If a local symbol is in the LDContext's symbol table, it's a real local
// symbol. We should not add it
if (pResolveInfo.binding() == ResolveInfo::Local)
@@ -2773,7 +2656,7 @@
// If we are building shared object, and the visibility is external, we
// need to add it.
if (LinkerConfig::DynObj == config().codeGenType() ||
- LinkerConfig::Exec == config().codeGenType() ||
+ LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()) {
if (pResolveInfo.visibility() == ResolveInfo::Default ||
pResolveInfo.visibility() == ResolveInfo::Protected)
@@ -2783,23 +2666,19 @@
}
/// elfSegmentTable - return the reference of the elf segment table
-ELFSegmentFactory& GNULDBackend::elfSegmentTable()
-{
+ELFSegmentFactory& GNULDBackend::elfSegmentTable() {
assert(m_pELFSegmentTable != NULL && "Do not create ELFSegmentTable!");
return *m_pELFSegmentTable;
}
/// elfSegmentTable - return the reference of the elf segment table
-const ELFSegmentFactory& GNULDBackend::elfSegmentTable() const
-{
+const ELFSegmentFactory& GNULDBackend::elfSegmentTable() const {
assert(m_pELFSegmentTable != NULL && "Do not create ELFSegmentTable!");
return *m_pELFSegmentTable;
}
/// commonPageSize - the common page size of the target machine.
-/// @ref gold linker: target.h:135
-uint64_t GNULDBackend::commonPageSize() const
-{
+uint64_t GNULDBackend::commonPageSize() const {
if (config().options().commPageSize() > 0)
return std::min(config().options().commPageSize(), abiPageSize());
else
@@ -2807,9 +2686,7 @@
}
/// abiPageSize - the abi page size of the target machine.
-/// @ref gold linker: target.h:125
-uint64_t GNULDBackend::abiPageSize() const
-{
+uint64_t GNULDBackend::abiPageSize() const {
if (config().options().maxPageSize() > 0)
return config().options().maxPageSize();
else
@@ -2818,9 +2695,7 @@
/// isSymbolPreemtible - whether the symbol can be preemted by other
/// link unit
-/// @ref Google gold linker, symtab.h:551
-bool GNULDBackend::isSymbolPreemptible(const ResolveInfo& pSym) const
-{
+bool GNULDBackend::isSymbolPreemptible(const ResolveInfo& pSym) const {
if (pSym.other() != ResolveInfo::Default)
return false;
@@ -2846,16 +2721,13 @@
}
/// symbolNeedsDynRel - return whether the symbol needs a dynamic relocation
-/// @ref Google gold linker, symtab.h:645
bool GNULDBackend::symbolNeedsDynRel(const ResolveInfo& pSym,
bool pSymHasPLT,
- bool isAbsReloc) const
-{
+ bool isAbsReloc) const {
// an undefined reference in the executables should be statically
// resolved to 0 and no need a dynamic relocation
- if (pSym.isUndef() &&
- !pSym.isDyn() &&
- (LinkerConfig::Exec == config().codeGenType() ||
+ if (pSym.isUndef() && !pSym.isDyn() &&
+ (LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()))
return false;
@@ -2871,19 +2743,15 @@
return false;
if (!config().isCodeIndep() && pSymHasPLT)
return false;
- if (pSym.isDyn() || pSym.isUndef() ||
- isSymbolPreemptible(pSym))
+ if (pSym.isDyn() || pSym.isUndef() || isSymbolPreemptible(pSym))
return true;
return false;
}
/// symbolNeedsPLT - return whether the symbol needs a PLT entry
-/// @ref Google gold linker, symtab.h:596
-bool GNULDBackend::symbolNeedsPLT(const ResolveInfo& pSym) const
-{
- if (pSym.isUndef() &&
- !pSym.isDyn() &&
+bool GNULDBackend::symbolNeedsPLT(const ResolveInfo& pSym) const {
+ if (pSym.isUndef() && !pSym.isDyn() &&
LinkerConfig::DynObj != config().codeGenType())
return false;
@@ -2900,16 +2768,12 @@
if (config().options().isPIE())
return false;
- return (pSym.isDyn() ||
- pSym.isUndef() ||
- isSymbolPreemptible(pSym));
+ return (pSym.isDyn() || pSym.isUndef() || isSymbolPreemptible(pSym));
}
/// symbolHasFinalValue - return true if the symbol's value can be decided at
/// link time
-/// @ref Google gold linker, Symbol::final_value_is_known
-bool GNULDBackend::symbolFinalValueIsKnown(const ResolveInfo& pSym) const
-{
+bool GNULDBackend::symbolFinalValueIsKnown(const ResolveInfo& pSym) const {
// if the output is pic code or if not executables, symbols' value may change
// at runtime
// FIXME: CodeIndep() || LinkerConfig::Relocatable == CodeGenType
@@ -2935,14 +2799,11 @@
/// symbolNeedsCopyReloc - return whether the symbol needs a copy relocation
bool GNULDBackend::symbolNeedsCopyReloc(const Relocation& pReloc,
- const ResolveInfo& pSym) const
-{
+ const ResolveInfo& pSym) const {
// only the reference from dynamic executable to non-function symbol in
// the dynamic objects may need copy relocation
- if (config().isCodeIndep() ||
- !pSym.isDyn() ||
- pSym.type() == ResolveInfo::Function ||
- pSym.size() == 0)
+ if (config().isCodeIndep() || !pSym.isDyn() ||
+ pSym.type() == ResolveInfo::Function || pSym.size() == 0)
return false;
// check if the option -z nocopyreloc is given
@@ -2958,40 +2819,34 @@
return false;
}
-LDSymbol& GNULDBackend::getTDATASymbol()
-{
- assert(NULL != f_pTDATA);
+LDSymbol& GNULDBackend::getTDATASymbol() {
+ assert(f_pTDATA != NULL);
return *f_pTDATA;
}
-const LDSymbol& GNULDBackend::getTDATASymbol() const
-{
- assert(NULL != f_pTDATA);
+const LDSymbol& GNULDBackend::getTDATASymbol() const {
+ assert(f_pTDATA != NULL);
return *f_pTDATA;
}
-LDSymbol& GNULDBackend::getTBSSSymbol()
-{
- assert(NULL != f_pTBSS);
+LDSymbol& GNULDBackend::getTBSSSymbol() {
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
-const LDSymbol& GNULDBackend::getTBSSSymbol() const
-{
- assert(NULL != f_pTBSS);
+const LDSymbol& GNULDBackend::getTBSSSymbol() const {
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
-llvm::StringRef GNULDBackend::getEntry(const Module& pModule) const
-{
+llvm::StringRef GNULDBackend::getEntry(const Module& pModule) const {
if (pModule.getScript().hasEntry())
return pModule.getScript().entry();
else
return getInfo().entry();
}
-void GNULDBackend::checkAndSetHasTextRel(const LDSection& pSection)
-{
+void GNULDBackend::checkAndSetHasTextRel(const LDSection& pSection) {
if (m_bHasTextRel)
return;
@@ -3006,47 +2861,43 @@
/// sortRelocation - sort the dynamic relocations to let dynamic linker
/// process relocations more efficiently
-void GNULDBackend::sortRelocation(LDSection& pSection)
-{
+void GNULDBackend::sortRelocation(LDSection& pSection) {
if (!config().options().hasCombReloc())
return;
assert(pSection.kind() == LDFileFormat::Relocation);
switch (config().codeGenType()) {
- case LinkerConfig::DynObj:
- case LinkerConfig::Exec:
- if (&pSection == &getOutputFormat()->getRelDyn() ||
- &pSection == &getOutputFormat()->getRelaDyn()) {
- if (pSection.hasRelocData())
- pSection.getRelocData()->sort(RelocCompare(*this));
- }
- default:
- return;
+ case LinkerConfig::DynObj:
+ case LinkerConfig::Exec:
+ if (&pSection == &getOutputFormat()->getRelDyn() ||
+ &pSection == &getOutputFormat()->getRelaDyn()) {
+ if (pSection.hasRelocData())
+ pSection.getRelocData()->sort(RelocCompare(*this));
+ }
+ default:
+ return;
}
}
/// initBRIslandFactory - initialize the branch island factory for relaxation
-bool GNULDBackend::initBRIslandFactory()
-{
- if (NULL == m_pBRIslandFactory) {
- m_pBRIslandFactory = new BranchIslandFactory(maxFwdBranchOffset(),
- maxBwdBranchOffset());
+bool GNULDBackend::initBRIslandFactory() {
+ if (m_pBRIslandFactory == NULL) {
+ m_pBRIslandFactory =
+ new BranchIslandFactory(maxFwdBranchOffset(), maxBwdBranchOffset());
}
return true;
}
/// initStubFactory - initialize the stub factory for relaxation
-bool GNULDBackend::initStubFactory()
-{
- if (NULL == m_pStubFactory) {
+bool GNULDBackend::initStubFactory() {
+ if (m_pStubFactory == NULL) {
m_pStubFactory = new StubFactory();
}
return true;
}
-bool GNULDBackend::relax(Module& pModule, IRBuilder& pBuilder)
-{
+bool GNULDBackend::relax(Module& pModule, IRBuilder& pBuilder) {
if (!mayRelax())
return true;
@@ -3062,8 +2913,7 @@
return true;
}
-bool GNULDBackend::DynsymCompare::needGNUHash(const LDSymbol& X) const
-{
+bool GNULDBackend::DynsymCompare::needGNUHash(const LDSymbol& X) const {
// FIXME: in bfd and gold linker, an undefined symbol might be hashed
// when the ouput is not PIC, if the symbol is referred by a non pc-relative
// reloc, and its value is set to the addr of the plt entry.
@@ -3071,14 +2921,12 @@
}
bool GNULDBackend::DynsymCompare::operator()(const LDSymbol* X,
- const LDSymbol* Y) const
-{
+ const LDSymbol* Y) const {
return !needGNUHash(*X) && needGNUHash(*Y);
}
bool GNULDBackend::RelocCompare::operator()(const Relocation* X,
- const Relocation* Y) const
-{
+ const Relocation* Y) const {
// 1. compare if relocation is relative
if (X->symInfo() == NULL) {
if (Y->symInfo() != NULL)
@@ -3115,3 +2963,5 @@
return false;
}
+
+} // namespace mcld
diff --git a/lib/Target/GOT.cpp b/lib/Target/GOT.cpp
index a441775..0e08c8b 100644
--- a/lib/Target/GOT.cpp
+++ b/lib/Target/GOT.cpp
@@ -6,32 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GOT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/IRBuilder.h>
+#include <llvm/Support/Casting.h>
#include <cstring>
#include <cstdlib>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GOT
//===----------------------------------------------------------------------===//
-GOT::GOT(LDSection& pSection)
- : m_Section(pSection) {
+GOT::GOT(LDSection& pSection) : m_Section(pSection) {
m_SectionData = IRBuilder::CreateSectionData(pSection);
}
-GOT::~GOT()
-{
+GOT::~GOT() {
}
-void GOT::finalizeSectionSize()
-{
+void GOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::iterator frag, fragEnd = m_SectionData->end();
for (frag = m_SectionData->begin(); frag != fragEnd; ++frag) {
@@ -42,3 +39,4 @@
m_Section.setSize(offset);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/Hexagon.h b/lib/Target/Hexagon/Hexagon.h
index 437a839..78e333a 100644
--- a/lib/Target/Hexagon/Hexagon.h
+++ b/lib/Target/Hexagon/Hexagon.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGON_H
-#define TARGET_HEXAGON_HEXAGON_H
+#ifndef TARGET_HEXAGON_HEXAGON_H_
+#define TARGET_HEXAGON_HEXAGON_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -21,10 +21,9 @@
extern mcld::Target TheHexagonTarget;
-TargetLDBackend*
-createHexagonLDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createHexagonLDBackend(const llvm::Target&,
+ const std::string&);
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_HEXAGON_HEXAGON_H_
diff --git a/lib/Target/Hexagon/HexagonAbsoluteStub.cpp b/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
index 38c1a3c..3ddf08b 100644
--- a/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
+++ b/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
@@ -1,4 +1,4 @@
-//===- HexagonAbsoluteStub.cpp ---------------------------------------------------===//
+//===- HexagonAbsoluteStub.cpp --------------------------------------------===//
//
// The MCLinker Project
//
@@ -10,34 +10,34 @@
#include "HexagonAbsoluteStub.h"
#include "HexagonLDBackend.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Fragment/Relocation.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/MathExtras.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonAbsoluteStub
//===----------------------------------------------------------------------===//
const uint32_t HexagonAbsoluteStub::TEMPLATE[] = {
- 0xbffd7f1d, /* { sp = add (sp, #-8) */
- 0xa79dfcfe, /* memw (sp + #-8) = r28 } */
- 0x723cc000, /* r28.h = #HI (foo) */
- 0x713cc000, /* r28.l = #LO (foo) */
- 0xb01d411d, /* { sp = add (sp, #8) */
- 0x529c4000, /* jumpr r28 */
- 0x919dc01c /* r28 = memw (sp) } */
+ 0xbffd7f1d, /* { sp = add (sp, #-8) */
+ 0xa79dfcfe, /* memw (sp + #-8) = r28 } */
+ 0x723cc000, /* r28.h = #HI (foo) */
+ 0x713cc000, /* r28.l = #LO (foo) */
+ 0xb01d411d, /* { sp = add (sp, #8) */
+ 0x529c4000, /* jumpr r28 */
+ 0x919dc01c /* r28 = memw (sp) } */
};
#define FITS_IN_NBITS(D, B) \
- ( llvm::abs64(D) < (~(~(int64_t) 0 << ((B) - 1)) & -(4 * 4)))
+ (llvm::abs64(D) < (~(~(int64_t)0 << ((B)-1)) & -(4 * 4)))
HexagonAbsoluteStub::HexagonAbsoluteStub(bool pIsOutputPIC)
- : Stub(), m_Name("HexagonTrampoline"), m_pData(NULL), m_Size(0x0)
-{
+ : Stub(), m_Name("HexagonTrampoline"), m_pData(NULL), m_Size(0x0) {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(8u, 0x0, llvm::ELF::R_HEX_HI16);
@@ -49,20 +49,17 @@
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : Stub(), m_Name("AbsVeneer"), m_pData(pData), m_Size(pSize)
-{
+ : Stub(), m_Name("AbsVeneer"), m_pData(pData), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-HexagonAbsoluteStub::~HexagonAbsoluteStub()
-{
+HexagonAbsoluteStub::~HexagonAbsoluteStub() {
}
bool HexagonAbsoluteStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
int nbits = 0;
switch (pReloc.type()) {
case llvm::ELF::R_HEX_B22_PCREL:
@@ -92,27 +89,24 @@
return true;
}
-const std::string& HexagonAbsoluteStub::name() const
-{
+const std::string& HexagonAbsoluteStub::name() const {
return m_Name;
}
-const uint8_t* HexagonAbsoluteStub::getContent() const
-{
+const uint8_t* HexagonAbsoluteStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t HexagonAbsoluteStub::size() const
-{
+size_t HexagonAbsoluteStub::size() const {
return m_Size;
}
-size_t HexagonAbsoluteStub::alignment() const
-{
+size_t HexagonAbsoluteStub::alignment() const {
return 4u;
}
-Stub* HexagonAbsoluteStub::doClone()
-{
+Stub* HexagonAbsoluteStub::doClone() {
return new HexagonAbsoluteStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonAbsoluteStub.h b/lib/Target/Hexagon/HexagonAbsoluteStub.h
index f3ba2e5..c7d8267 100644
--- a/lib/Target/Hexagon/HexagonAbsoluteStub.h
+++ b/lib/Target/Hexagon/HexagonAbsoluteStub.h
@@ -1,4 +1,4 @@
-//===- HexagonAbsoluteStub.h -----------------------------------------------===//
+//===- HexagonAbsoluteStub.h ----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
+#define TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
-#ifndef TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H
-#define TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@
* \brief Hexagon stub for abs long call from source to target
*
*/
-class HexagonAbsoluteStub : public Stub
-{
-public:
- HexagonAbsoluteStub(bool pIsOutputPIC);
+class HexagonAbsoluteStub : public Stub {
+ public:
+ explicit HexagonAbsoluteStub(bool pIsOutputPIC);
~HexagonAbsoluteStub();
@@ -46,27 +43,27 @@
size_t alignment() const;
-private:
+ private:
HexagonAbsoluteStub(const HexagonAbsoluteStub&);
HexagonAbsoluteStub& operator=(const HexagonAbsoluteStub&);
/// for doClone
HexagonAbsoluteStub(const uint32_t* pData,
- size_t pSize,
- const_fixup_iterator pBegin,
- const_fixup_iterator pEnd);
+ size_t pSize,
+ const_fixup_iterator pBegin,
+ const_fixup_iterator pEnd);
/// doClone
Stub* doClone();
-private:
+ private:
std::string m_Name;
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
diff --git a/lib/Target/Hexagon/HexagonDiagnostic.cpp b/lib/Target/Hexagon/HexagonDiagnostic.cpp
index 7fd58c0..4122daa 100644
--- a/lib/Target/Hexagon/HexagonDiagnostic.cpp
+++ b/lib/Target/Hexagon/HexagonDiagnostic.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "Hexagon.h"
namespace mcld {
@@ -16,22 +16,18 @@
// createHexagonDiagnostic - the help function to create corresponding
// HexagonDiagnostic
//===----------------------------------------------------------------------===//
-DiagnosticLineInfo*
-createHexagonDiagLineInfo(const Target& pTarget, const std::string &pTriple)
-{
+DiagnosticLineInfo* createHexagonDiagLineInfo(const Target& pTarget,
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
-
-using namespace mcld;
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeHexagonDiagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeHexagonDiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheHexagonTarget,
- createHexagonDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(
+ mcld::TheHexagonTarget, mcld::createHexagonDiagLineInfo);
}
-
diff --git a/lib/Target/Hexagon/HexagonELFDynamic.cpp b/lib/Target/Hexagon/HexagonELFDynamic.cpp
index 96534cc..8fe17d9 100644
--- a/lib/Target/Hexagon/HexagonELFDynamic.cpp
+++ b/lib/Target/Hexagon/HexagonELFDynamic.cpp
@@ -8,30 +8,28 @@
//===----------------------------------------------------------------------===//
#include "HexagonELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
HexagonELFDynamic::HexagonELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig) {
+ : ELFDynamic(pParent, pConfig) {
}
-HexagonELFDynamic::~HexagonELFDynamic()
-{
+HexagonELFDynamic::~HexagonELFDynamic() {
}
-void HexagonELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void HexagonELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void HexagonELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void HexagonELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonELFDynamic.h b/lib/Target/Hexagon/HexagonELFDynamic.h
index d1d43dc..97c826a 100644
--- a/lib/Target/Hexagon/HexagonELFDynamic.h
+++ b/lib/Target/Hexagon/HexagonELFDynamic.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONELFDYNAMIC_H
-#define TARGET_HEXAGON_HEXAGONELFDYNAMIC_H
+#ifndef TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
+#define TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
-class HexagonELFDynamic : public ELFDynamic
-{
-public:
+class HexagonELFDynamic : public ELFDynamic {
+ public:
HexagonELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~HexagonELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
diff --git a/lib/Target/Hexagon/HexagonELFMCLinker.cpp b/lib/Target/Hexagon/HexagonELFMCLinker.cpp
deleted file mode 100644
index bf5f7d7..0000000
--- a/lib/Target/Hexagon/HexagonELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- HexagonELFMCLinker.cpp ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "HexagonELFMCLinker.h"
-
-using namespace mcld;
-
-HexagonELFMCLinker::HexagonELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-HexagonELFMCLinker::~HexagonELFMCLinker()
-{
-}
-
diff --git a/lib/Target/Hexagon/HexagonELFMCLinker.h b/lib/Target/Hexagon/HexagonELFMCLinker.h
deleted file mode 100644
index 777420d..0000000
--- a/lib/Target/Hexagon/HexagonELFMCLinker.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//===- HexagonELFMCLinker.h -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONELFMCLINKER_H
-#define TARGET_HEXAGON_HEXAGONELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class HexagonELFMCLinker
- * \brief HexagonELFMCLinker sets up the environment for linking.
- *
- * \see
- */
-class HexagonELFMCLinker : public ELFMCLinker
-{
-public:
- HexagonELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~HexagonELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Hexagon/HexagonEmulation.cpp b/lib/Target/Hexagon/HexagonEmulation.cpp
index 8a77cf7..d14c082 100644
--- a/lib/Target/Hexagon/HexagonEmulation.cpp
+++ b/lib/Target/Hexagon/HexagonEmulation.cpp
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateHexagonELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateHexagonELF(LinkerScript& pScript,
+ LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -38,8 +38,7 @@
//===----------------------------------------------------------------------===//
// emulateHexagonLD - the help function to emulate Hexagon ld
//===----------------------------------------------------------------------===//
-bool emulateHexagonLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateHexagonLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -52,7 +51,7 @@
return MCLDEmulateHexagonELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// HexagonEmulation
@@ -62,4 +61,3 @@
mcld::TargetRegistry::RegisterEmulation(mcld::TheHexagonTarget,
mcld::emulateHexagonLD);
}
-
diff --git a/lib/Target/Hexagon/HexagonEncodings.h b/lib/Target/Hexagon/HexagonEncodings.h
index 2a2e9db..a9d056d 100644
--- a/lib/Target/Hexagon/HexagonEncodings.h
+++ b/lib/Target/Hexagon/HexagonEncodings.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONENCODINGS_H
-#define TARGET_HEXAGON_HEXAGONENCODINGS_H
+#ifndef TARGET_HEXAGON_HEXAGONENCODINGS_H_
+#define TARGET_HEXAGON_HEXAGONENCODINGS_H_
Instruction insn_encodings[] = {
{ "if (Pv4) memb(Rs32+#u6:0)=Rt32",
@@ -3558,4 +3558,4 @@
},
};
-#endif
+#endif // TARGET_HEXAGON_HEXAGONENCODINGS_H_
diff --git a/lib/Target/Hexagon/HexagonGNUInfo.cpp b/lib/Target/Hexagon/HexagonGNUInfo.cpp
index ad4cd34..05eb0cc 100644
--- a/lib/Target/Hexagon/HexagonGNUInfo.cpp
+++ b/lib/Target/Hexagon/HexagonGNUInfo.cpp
@@ -11,21 +11,21 @@
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/StringSwitch.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGNUInfo
//===----------------------------------------------------------------------===//
HexagonGNUInfo::HexagonGNUInfo(const TargetOptions& pTargetOptions)
- : GNUInfo(pTargetOptions.triple()), m_Options(pTargetOptions) {
+ : GNUInfo(pTargetOptions.triple()), m_Options(pTargetOptions) {
}
/// flags - the value of ElfXX_Ehdr::e_flags
-uint64_t HexagonGNUInfo::flags() const
-{
+uint64_t HexagonGNUInfo::flags() const {
return llvm::StringSwitch<uint64_t>(m_Options.getTargetCPU())
- .Case("hexagonv4", V4)
- .Case("hexagonv5", V5)
- .Default(V4);
+ .Case("hexagonv4", V4)
+ .Case("hexagonv5", V5)
+ .Default(V4);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGNUInfo.h b/lib/Target/Hexagon/HexagonGNUInfo.h
index 0173e65..d43d95c 100644
--- a/lib/Target/Hexagon/HexagonGNUInfo.h
+++ b/lib/Target/Hexagon/HexagonGNUInfo.h
@@ -6,26 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGNUINFO_H
-#define TARGET_HEXAGON_HEXAGONGNUINFO_H
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/TargetOptions.h>
+#ifndef TARGET_HEXAGON_HEXAGONGNUINFO_H_
+#define TARGET_HEXAGON_HEXAGONGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/TargetOptions.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class HexagonGNUInfo : public GNUInfo
-{
-public:
- enum CPUType {
- V3 = 0x2,
- V4 = 0x3,
- V5
- };
+class HexagonGNUInfo : public GNUInfo {
+ public:
+ enum CPUType { V3 = 0x2, V4 = 0x3, V5 };
-public:
- HexagonGNUInfo(const TargetOptions& pTargetOptions);
+ public:
+ explicit HexagonGNUInfo(const TargetOptions& pTargetOptions);
uint32_t machine() const { return llvm::ELF::EM_HEXAGON; }
@@ -34,11 +29,10 @@
/// flags - the value of ElfXX_Ehdr::e_flags
uint64_t flags() const;
-private:
+ private:
const TargetOptions& m_Options;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_HEXAGON_HEXAGONGNUINFO_H_
diff --git a/lib/Target/Hexagon/HexagonGOT.cpp b/lib/Target/Hexagon/HexagonGOT.cpp
index eaa2669..bcfc468 100644
--- a/lib/Target/Hexagon/HexagonGOT.cpp
+++ b/lib/Target/Hexagon/HexagonGOT.cpp
@@ -8,27 +8,24 @@
//===----------------------------------------------------------------------===//
#include "HexagonGOT.h"
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGOT
//===----------------------------------------------------------------------===//
-HexagonGOT::HexagonGOT(LDSection& pSection)
- : GOT(pSection)
-{
+HexagonGOT::HexagonGOT(LDSection& pSection) : GOT(pSection) {
}
-HexagonGOT::~HexagonGOT()
-{
+HexagonGOT::~HexagonGOT() {
}
-HexagonGOTEntry* HexagonGOT::create()
-{
+HexagonGOTEntry* HexagonGOT::create() {
return new HexagonGOTEntry(0, m_SectionData);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGOT.h b/lib/Target/Hexagon/HexagonGOT.h
index ac94c11..6fa9fab 100644
--- a/lib/Target/Hexagon/HexagonGOT.h
+++ b/lib/Target/Hexagon/HexagonGOT.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGOT_H
-#define TARGET_HEXAGON_HEXAGONGOT_H
+#ifndef TARGET_HEXAGON_HEXAGONGOT_H_
+#define TARGET_HEXAGON_HEXAGONGOT_H_
-#include <mcld/Target/GOT.h>
+#include "mcld/Target/GOT.h"
namespace mcld {
@@ -19,29 +19,25 @@
/** \class HexagonGOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class HexagonGOTEntry : public GOT::Entry<4>
-{
-public:
+class HexagonGOTEntry : public GOT::Entry<4> {
+ public:
HexagonGOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class HexagonGOT
* \brief Hexagon Global Offset Table.
*/
-class HexagonGOT : public GOT
-{
-public:
- HexagonGOT(LDSection& pSection);
+class HexagonGOT : public GOT {
+ public:
+ explicit HexagonGOT(LDSection& pSection);
~HexagonGOT();
HexagonGOTEntry* create();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_HEXAGON_HEXAGONGOT_H_
diff --git a/lib/Target/Hexagon/HexagonGOTPLT.cpp b/lib/Target/Hexagon/HexagonGOTPLT.cpp
index cfceff5..0601a70 100644
--- a/lib/Target/Hexagon/HexagonGOTPLT.cpp
+++ b/lib/Target/Hexagon/HexagonGOTPLT.cpp
@@ -1,4 +1,4 @@
-//===- HexagonGOTPLT.cpp ------------------------------------------------------===//
+//===- HexagonGOTPLT.cpp --------------------------------------------------===//
//
// The MCLinker Project
//
@@ -9,20 +9,18 @@
#include "HexagonGOTPLT.h"
#include "HexagonPLT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGOTPLT
//===----------------------------------------------------------------------===//
-HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection)
- : HexagonGOT(pSection)
-{
+HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection) : HexagonGOT(pSection) {
// Skip GOT0 entries
for (size_t i = 0; i < HexagonGOTPLT0Num; ++i) {
create();
@@ -30,24 +28,20 @@
pSection.setAlign(8);
}
-HexagonGOTPLT::~HexagonGOTPLT()
-{
+HexagonGOTPLT::~HexagonGOTPLT() {
}
// Check if we really have GOT PLT entries ?
-bool HexagonGOTPLT::hasGOT1() const
-{
+bool HexagonGOTPLT::hasGOT1() const {
return (m_SectionData->size() > HexagonGOTPLT0Num);
}
-void HexagonGOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<HexagonGOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void HexagonGOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<HexagonGOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT)
-{
+void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < HexagonGOTPLT0Num; ++i)
@@ -55,9 +49,9 @@
// Set the initial value of the GOT entry to the address
// of PLT0, the stub calculates the index of the caller directly from
// the address where the call arised
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<HexagonGOTEntry>(*it).setValue(pPLT.addr());
}
}
-}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGOTPLT.h b/lib/Target/Hexagon/HexagonGOTPLT.h
index fa68bff..e692cd9 100644
--- a/lib/Target/Hexagon/HexagonGOTPLT.h
+++ b/lib/Target/Hexagon/HexagonGOTPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGOTPLT_H
-#define TARGET_HEXAGON_HEXAGONGOTPLT_H
+#ifndef TARGET_HEXAGON_HEXAGONGOTPLT_H_
+#define TARGET_HEXAGON_HEXAGONGOTPLT_H_
-#include <llvm/ADT/DenseMap.h>
#include "HexagonGOT.h"
+#include <llvm/ADT/DenseMap.h>
namespace mcld {
@@ -23,10 +23,9 @@
/** \class HexagonGOTPLT
* \brief Hexagon .got.plt section.
*/
-class HexagonGOTPLT : public HexagonGOT
-{
-public:
- HexagonGOTPLT(LDSection &pSection);
+class HexagonGOTPLT : public HexagonGOT {
+ public:
+ explicit HexagonGOTPLT(LDSection& pSection);
~HexagonGOTPLT();
@@ -38,6 +37,6 @@
void applyAllGOTPLT(const HexagonPLT& pPLT);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONGOTPLT_H_
diff --git a/lib/Target/Hexagon/HexagonLDBackend.cpp b/lib/Target/Hexagon/HexagonLDBackend.cpp
index eb3458b..5d4d4dc 100644
--- a/lib/Target/Hexagon/HexagonLDBackend.cpp
+++ b/lib/Target/Hexagon/HexagonLDBackend.cpp
@@ -13,49 +13,48 @@
#include "HexagonGNUInfo.h"
#include "HexagonAbsoluteStub.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonLDBackend
//===----------------------------------------------------------------------===//
HexagonLDBackend::HexagonLDBackend(const LinkerConfig& pConfig,
HexagonGNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pGOTPLT(NULL),
- m_pPLT(NULL),
- m_pRelaDyn(NULL),
- m_pRelaPLT(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_CopyRel(llvm::ELF::R_HEX_COPY) {
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL),
+ m_pPLT(NULL),
+ m_pRelaDyn(NULL),
+ m_pRelaPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_CopyRel(llvm::ELF::R_HEX_COPY) {
}
-HexagonLDBackend::~HexagonLDBackend()
-{
+HexagonLDBackend::~HexagonLDBackend() {
delete m_pRelocator;
delete m_pGOT;
delete m_pPLT;
@@ -64,30 +63,26 @@
delete m_pDynamic;
}
-bool HexagonLDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool HexagonLDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new HexagonRelocator(*this, config());
}
return true;
}
-const Relocator* HexagonLDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* HexagonLDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* HexagonLDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* HexagonLDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new HexagonELFDynamic(*this, config());
// set .got.plt and .got sizes
@@ -102,14 +97,16 @@
// set .rela.dyn size
if (!m_pRelaDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelaDynSize();
}
// set .rela.plt size
if (!m_pRelaPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelaPLTSize();
}
}
@@ -118,29 +115,25 @@
SetSDataSection();
}
-void HexagonLDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void HexagonLDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-HexagonELFDynamic& HexagonLDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+HexagonELFDynamic& HexagonLDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const HexagonELFDynamic& HexagonLDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const HexagonELFDynamic& HexagonLDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
if (!pRegion.size())
return 0;
@@ -151,7 +144,6 @@
if ((LinkerConfig::Object != config().codeGenType()) &&
(!config().isCodeStatic())) {
if (FileFormat->hasPLT() && (&pSection == &(FileFormat->getPLT()))) {
-
unsigned char* buffer = pRegion.begin();
m_pPLT->applyPLT0();
@@ -173,13 +165,11 @@
++it;
}
return RegionSize;
- }
- else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
+ } else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
RegionSize += emitGOTSectionData(pRegion);
return RegionSize;
- }
- else if (FileFormat->hasGOTPLT() &&
- (&pSection == &(FileFormat->getGOTPLT()))) {
+ } else if (FileFormat->hasGOTPLT() &&
+ (&pSection == &(FileFormat->getGOTPLT()))) {
RegionSize += emitGOTPLTSectionData(pRegion, FileFormat);
return RegionSize;
}
@@ -190,11 +180,10 @@
uint8_t* out_offset = pRegion.begin();
for (frag_iter = sect_data->begin(); frag_iter != frag_end; ++frag_iter) {
size_t size = frag_iter->size();
- switch(frag_iter->getKind()) {
+ switch (frag_iter->getKind()) {
case Fragment::Fillment: {
- const FillFragment& fill_frag =
- llvm::cast<FillFragment>(*frag_iter);
- if (0 == fill_frag.getValueSize()) {
+ const FillFragment& fill_frag = llvm::cast<FillFragment>(*frag_iter);
+ if (fill_frag.getValueSize() == 0) {
// virtual fillment, ignore it.
break;
}
@@ -203,7 +192,7 @@
}
case Fragment::Region: {
const RegionFragment& region_frag =
- llvm::cast<RegionFragment>(*frag_iter);
+ llvm::cast<RegionFragment>(*frag_iter);
const char* start = region_frag.getRegion().begin();
memcpy(out_offset, start, size);
break;
@@ -217,9 +206,9 @@
break;
default:
llvm::report_fatal_error(
- "unsupported value size for align fragment emission yet.\n");
+ "unsupported value size for align fragment emission yet.\n");
break;
- } // end switch
+ } // end switch
break;
}
case Fragment::Null: {
@@ -229,93 +218,79 @@
default:
llvm::report_fatal_error("unsupported fragment type.\n");
break;
- } // end switch
+ } // end switch
out_offset += size;
- } // end for
+ } // end for
return pRegion.size();
}
-HexagonGOT& HexagonLDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+HexagonGOT& HexagonLDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const HexagonGOT& HexagonLDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const HexagonGOT& HexagonLDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-HexagonPLT& HexagonLDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+HexagonPLT& HexagonLDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const HexagonPLT& HexagonLDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const HexagonPLT& HexagonLDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& HexagonLDBackend::getRelaDyn()
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+OutputRelocSection& HexagonLDBackend::getRelaDyn() {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-const OutputRelocSection& HexagonLDBackend::getRelaDyn() const
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+const OutputRelocSection& HexagonLDBackend::getRelaDyn() const {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-OutputRelocSection& HexagonLDBackend::getRelaPLT()
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+OutputRelocSection& HexagonLDBackend::getRelaPLT() {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-const OutputRelocSection& HexagonLDBackend::getRelaPLT() const
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+const OutputRelocSection& HexagonLDBackend::getRelaPLT() const {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-HexagonGOTPLT& HexagonLDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+HexagonGOTPLT& HexagonLDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const HexagonGOTPLT& HexagonLDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const HexagonGOTPLT& HexagonLDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-void HexagonLDBackend::setRelaDynSize()
-{
+void HexagonLDBackend::setRelaDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaDyn().setSize
- (m_pRelaDyn->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaDyn().setSize(m_pRelaDyn->numOfRelocs() *
+ getRelaEntrySize());
}
-void HexagonLDBackend::setRelaPLTSize()
-{
+void HexagonLDBackend::setRelaPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaPlt().setSize
- (m_pRelaPLT->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaPlt().setSize(m_pRelaPLT->numOfRelocs() *
+ getRelaEntrySize());
}
-void HexagonLDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void HexagonLDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -325,9 +300,7 @@
m_pGOT->finalizeSectionSize();
}
-uint64_t
-HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
@@ -336,8 +309,8 @@
unsigned int EntrySize = HexagonGOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (HexagonGOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (HexagonGOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<HexagonGOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -346,38 +319,36 @@
return RegionSize;
}
-void HexagonLDBackend::defineGOTSymbol(IRBuilder& pBuilder,
- Fragment& pFrag)
-{
+void HexagonLDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag) {
// define symbol _GLOBAL_OFFSET_TABLE_
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
}
}
-uint64_t HexagonLDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
- assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
+uint64_t HexagonLDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
+ assert(m_pGOTPLT != NULL &&
+ "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -387,8 +358,9 @@
unsigned int EntrySize = HexagonGOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (HexagonGOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (HexagonGOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<HexagonGOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -397,9 +369,8 @@
return RegionSize;
}
-unsigned int
-HexagonLDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int HexagonLDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (LinkerConfig::Object != config().codeGenType()) {
@@ -429,9 +400,7 @@
}
void HexagonLDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
-
+ ObjectBuilder& pBuilder) {
if ((LinkerConfig::Object != config().codeGenType()) &&
(!config().isCodeStatic())) {
ELFFileFormat* file_format = getOutputFormat();
@@ -445,9 +414,7 @@
// initialize .plt
LDSection& plt = file_format->getPLT();
- m_pPLT = new HexagonPLT(plt,
- *m_pGOTPLT,
- config());
+ m_pPLT = new HexagonPLT(plt, *m_pGOTPLT, config());
// initialize .rela.plt
LDSection& relaplt = file_format->getRelaPlt();
@@ -457,39 +424,42 @@
// initialize .rela.dyn
LDSection& reladyn = file_format->getRelaDyn();
m_pRelaDyn = new OutputRelocSection(pModule, reladyn);
-
}
m_psdata = pBuilder.CreateSection(".sdata",
LDFileFormat::Target,
llvm::ELF::SHT_PROGBITS,
llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4*1024);
- m_pscommon_1 = pBuilder.CreateSection(".scommon.1",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 1);
+ 4 * 1024);
+ m_pscommon_1 =
+ pBuilder.CreateSection(".scommon.1",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 1);
IRBuilder::CreateSectionData(*m_pscommon_1);
- m_pscommon_2 = pBuilder.CreateSection(".scommon.2",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 2);
+ m_pscommon_2 =
+ pBuilder.CreateSection(".scommon.2",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 2);
IRBuilder::CreateSectionData(*m_pscommon_2);
- m_pscommon_4 = pBuilder.CreateSection(".scommon.4",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4);
+ m_pscommon_4 =
+ pBuilder.CreateSection(".scommon.4",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 4);
IRBuilder::CreateSectionData(*m_pscommon_4);
- m_pscommon_8 = pBuilder.CreateSection(".scommon.8",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 8);
+ m_pscommon_8 =
+ pBuilder.CreateSection(".scommon.8",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 8);
IRBuilder::CreateSectionData(*m_pscommon_8);
m_pstart = pBuilder.CreateSection(".start",
@@ -500,84 +470,81 @@
IRBuilder::CreateSectionData(*m_pstart);
}
-void HexagonLDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void HexagonLDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
if (config().codeGenType() == LinkerConfig::Object)
return;
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
- m_psdabase =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_SDA_BASE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
+ m_psdabase = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_SDA_BASE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__sbss_start",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "__sbss_start",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__sbss_end",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "__sbss_end",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
-bool HexagonLDBackend::initTargetStubs()
-{
- if (NULL != getStubFactory()) {
- getStubFactory()->addPrototype
- (new HexagonAbsoluteStub(config().isCodeIndep()));
+bool HexagonLDBackend::initTargetStubs() {
+ if (getStubFactory() != NULL) {
+ getStubFactory()->addPrototype(
+ new HexagonAbsoluteStub(config().isCodeIndep()));
return true;
}
return false;
}
-bool HexagonLDBackend::initBRIslandFactory()
-{
- if (NULL == m_pBRIslandFactory) {
- m_pBRIslandFactory = new BranchIslandFactory(maxFwdBranchOffset(),
- maxBwdBranchOffset(),
- 0);
+bool HexagonLDBackend::initBRIslandFactory() {
+ if (m_pBRIslandFactory == NULL) {
+ m_pBRIslandFactory =
+ new BranchIslandFactory(maxFwdBranchOffset(), maxBwdBranchOffset(), 0);
}
return true;
}
-bool HexagonLDBackend::initStubFactory()
-{
- if (NULL == m_pStubFactory) {
+bool HexagonLDBackend::initStubFactory() {
+ if (m_pStubFactory == NULL) {
m_pStubFactory = new StubFactory();
}
return true;
}
-bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
- bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool HexagonLDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
ELFFileFormat* file_format = getOutputFormat();
// check branch relocs and create the related stubs if needed
@@ -601,15 +568,15 @@
if (symbol->hasFragRef()) {
uint64_t value = symbol->fragRef()->getOutputOffset();
uint64_t addr =
- symbol->fragRef()->frag()->getParent()->getSection().addr();
+ symbol->fragRef()->frag()->getParent()->getSection().addr();
sym_value = addr + value;
}
- Stub* stub = getStubFactory()->create(*relocation, // relocation
- sym_value, //symbol value
+ Stub* stub = getStubFactory()->create(*relocation, // relocation
+ sym_value, // symbol value
pBuilder,
*getBRIslandFactory());
- if (NULL != stub) {
- assert(NULL != stub->symInfo());
+ if (stub != NULL) {
+ assert(stub->symInfo() != NULL);
// increase the size of .symtab and .strtab
LDSection& symtab = file_format->getSymTab();
LDSection& strtab = file_format->getStrTab();
@@ -617,8 +584,7 @@
strtab.setSize(strtab.size() + stub->symInfo()->nameSize() + 1);
isRelaxed = true;
}
- }
- break;
+ } break;
default:
break;
@@ -631,8 +597,9 @@
Fragment* invalid = NULL;
pFinished = true;
for (BranchIslandFactory::iterator island = getBRIslandFactory()->begin(),
- island_end = getBRIslandFactory()->end(); island != island_end; ++island)
- {
+ island_end = getBRIslandFactory()->end();
+ island != island_end;
+ ++island) {
if ((*island).end() == file_format->getText().getSectionData()->end())
break;
@@ -645,7 +612,7 @@
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -654,42 +621,37 @@
// reset the size of .text
if (isRelaxed) {
file_format->getText().setSize(
- file_format->getText().getSectionData()->back().getOffset() +
- file_format->getText().getSectionData()->back().size());
+ file_format->getText().getSectionData()->back().getOffset() +
+ file_format->getText().getSectionData()->back().size());
}
return isRelaxed;
}
/// finalizeSymbol - finalize the symbol value
-bool HexagonLDBackend::finalizeTargetSymbols()
-{
+bool HexagonLDBackend::finalizeTargetSymbols() {
if (config().codeGenType() == LinkerConfig::Object)
return true;
if (m_psdabase)
m_psdabase->setValue(m_psdata->addr());
- ELFSegmentFactory::const_iterator edata =
- elfSegmentTable().find(llvm::ELF::PT_LOAD,
- llvm::ELF::PF_W,
- llvm::ELF::PF_X);
+ ELFSegmentFactory::const_iterator edata = elfSegmentTable().find(
+ llvm::ELF::PT_LOAD, llvm::ELF::PF_W, llvm::ELF::PF_X);
if (elfSegmentTable().end() != edata) {
- if (NULL != f_pEData && ResolveInfo::ThreadLocal != f_pEData->type()) {
+ if (f_pEData != NULL && ResolveInfo::ThreadLocal != f_pEData->type()) {
f_pEData->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_p_EData && ResolveInfo::ThreadLocal != f_p_EData->type()) {
+ if (f_p_EData != NULL && ResolveInfo::ThreadLocal != f_p_EData->type()) {
f_p_EData->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_pBSSStart &&
+ if (f_pBSSStart != NULL &&
ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
f_pBSSStart->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_pEnd && ResolveInfo::ThreadLocal != f_pEnd->type()) {
- f_pEnd->setValue((((*edata)->vaddr() +
- (*edata)->memsz()) + 7) & ~7);
+ if (f_pEnd != NULL && ResolveInfo::ThreadLocal != f_pEnd->type()) {
+ f_pEnd->setValue((((*edata)->vaddr() + (*edata)->memsz()) + 7) & ~7);
}
- if (NULL != f_p_End && ResolveInfo::ThreadLocal != f_p_End->type()) {
- f_p_End->setValue((((*edata)->vaddr() +
- (*edata)->memsz()) + 7) & ~7);
+ if (f_p_End != NULL && ResolveInfo::ThreadLocal != f_p_End->type()) {
+ f_p_End->setValue((((*edata)->vaddr() + (*edata)->memsz()) + 7) & ~7);
}
}
return true;
@@ -698,20 +660,18 @@
/// merge Input Sections
bool HexagonLDBackend::mergeSection(Module& pModule,
const Input& pInputFile,
- LDSection& pInputSection)
-{
+ LDSection& pInputSection) {
if ((pInputSection.flag() & llvm::ELF::SHF_HEX_GPREL) ||
(pInputSection.kind() == LDFileFormat::LinkOnce) ||
(pInputSection.kind() == LDFileFormat::Target)) {
- SectionData *sd = NULL;
+ SectionData* sd = NULL;
if (!m_psdata->hasSectionData()) {
sd = IRBuilder::CreateSectionData(*m_psdata);
m_psdata->setSectionData(sd);
}
sd = m_psdata->getSectionData();
MoveSectionDataAndSort(*pInputSection.getSectionData(), *sd);
- }
- else {
+ } else {
ObjectBuilder builder(pModule);
builder.MergeSection(pInputFile, pInputSection);
}
@@ -719,7 +679,7 @@
}
bool HexagonLDBackend::SetSDataSection() {
- SectionData *pTo = (m_psdata->getSectionData());
+ SectionData* pTo = (m_psdata->getSectionData());
if (pTo) {
MoveCommonData(*m_pscommon_1->getSectionData(), *pTo);
@@ -741,7 +701,8 @@
SectionData::FragmentListType& newlist = pTo->getFragmentList();
for (fragTo = newlist.begin(), fragToEnd = newlist.end();
- fragTo != fragToEnd; ++fragTo) {
+ fragTo != fragToEnd;
+ ++fragTo) {
fragTo->setParent(pTo);
}
}
@@ -751,9 +712,7 @@
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is called at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
-bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool HexagonLDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyLocals()) {
@@ -784,7 +743,7 @@
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -800,55 +759,48 @@
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
- switch((*com_sym)->size()) {
- case 1:
- if (maxGPSize <= 0)
+ switch ((*com_sym)->size()) {
+ case 1:
+ if (maxGPSize <= 0)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_1->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 2:
+ if (maxGPSize <= 1)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_2->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 4:
+ if (maxGPSize <= 3)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_4->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 8:
+ if (maxGPSize <= 7)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_8->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ default:
break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_1->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 2:
- if (maxGPSize <= 1)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_2->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 4:
- if (maxGPSize <= 3)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_4->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 8:
- if (maxGPSize <= 7)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_8->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- default:
- break;
}
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
}
@@ -865,55 +817,48 @@
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
- switch((*com_sym)->size()) {
- case 1:
- if (maxGPSize <= 0)
+ switch ((*com_sym)->size()) {
+ case 1:
+ if (maxGPSize <= 0)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_1->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 2:
+ if (maxGPSize <= 1)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_2->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 4:
+ if (maxGPSize <= 3)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_4->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 8:
+ if (maxGPSize <= 7)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_8->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ default:
break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_1->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 2:
- if (maxGPSize <= 1)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_2->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 4:
- if (maxGPSize <= 3)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_4->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 8:
- if (maxGPSize <= 7)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_8->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- default:
- break;
}
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
}
@@ -925,8 +870,7 @@
return true;
}
-bool HexagonLDBackend::MoveCommonData(SectionData &pFrom, SectionData &pTo)
-{
+bool HexagonLDBackend::MoveCommonData(SectionData& pFrom, SectionData& pTo) {
SectionData::FragmentListType& to_list = pTo.getFragmentList();
SectionData::FragmentListType::iterator frag, fragEnd = to_list.end();
@@ -953,11 +897,11 @@
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
pFrom.getFragmentList().push_front(align);
}
if (found)
@@ -968,23 +912,20 @@
return true;
}
-bool HexagonLDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool HexagonLDBackend::readSection(Input& pInput, SectionData& pSD) {
Fragment* frag = NULL;
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
if (pSD.getSection().type() == llvm::ELF::SHT_NOBITS) {
frag = new FillFragment(0x0, 1, size);
- }
- else {
+ } else {
llvm::StringRef region = pInput.memArea()->request(offset, size);
if (region.size() == 0) {
// If the input section's size is zero, we got a NULL region.
// use a virtual fill fragment
frag = new FillFragment(0x0, 0, 0);
- }
- else {
+ } else {
frag = new RegionFragment(region);
}
}
@@ -994,8 +935,8 @@
}
/// MoveSectionData - move the fragments of pTO section data to pTo
-bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom, SectionData& pTo)
-{
+bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom,
+ SectionData& pTo) {
assert(&pFrom != &pTo && "Cannot move section data to itself!");
SectionData::FragmentListType& to_list = pTo.getFragmentList();
SectionData::FragmentListType::iterator frag, fragEnd = to_list.end();
@@ -1023,11 +964,11 @@
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
pFrom.getFragmentList().push_front(align);
}
if (found)
@@ -1054,18 +995,14 @@
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void HexagonLDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void HexagonLDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createHexagonLDBackend - the help funtion to create corresponding
/// HexagonLDBackend
-TargetLDBackend* createHexagonLDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createHexagonLDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -1085,13 +1022,13 @@
return new HexagonLDBackend(pConfig, new HexagonGNUInfo(pConfig.targets()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeHexagonLDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheHexagonTarget,
- createHexagonLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheHexagonTarget,
+ mcld::createHexagonLDBackend);
}
diff --git a/lib/Target/Hexagon/HexagonLDBackend.h b/lib/Target/Hexagon/HexagonLDBackend.h
index 0fc909c..89aea83 100644
--- a/lib/Target/Hexagon/HexagonLDBackend.h
+++ b/lib/Target/Hexagon/HexagonLDBackend.h
@@ -6,31 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONLDBACKEND_H
-#define TARGET_HEXAGON_HEXAGONLDBACKEND_H
+#ifndef TARGET_HEXAGON_HEXAGONLDBACKEND_H_
+#define TARGET_HEXAGON_HEXAGONLDBACKEND_H_
#include "HexagonELFDynamic.h"
#include "HexagonGOT.h"
#include "HexagonPLT.h"
#include "HexagonGOTPLT.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
-class LinkerConfig;
class HexagonGNUInfo;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
/// HexagonLDBackend - linker backend of Hexagon target of GNU ELF format
///
-class HexagonLDBackend : public GNULDBackend
-{
-public:
+class HexagonLDBackend : public GNULDBackend {
+ public:
HexagonLDBackend(const LinkerConfig& pConfig, HexagonGNUInfo* pInfo);
~HexagonLDBackend();
@@ -86,8 +85,7 @@
const Relocator* getRelocator() const;
Relocator* getRelocator();
- ResolveInfo::Desc getSymDesc(uint16_t shndx) const
- {
+ ResolveInfo::Desc getSymDesc(uint16_t shndx) const {
if (shndx >= llvm::ELF::SHN_HEXAGON_SCOMMON &&
shndx <= llvm::ELF::SHN_HEXAGON_SCOMMON_8)
return ResolveInfo::Common;
@@ -132,7 +130,7 @@
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
- bool MoveCommonData(SectionData &pFrom, SectionData &pTo);
+ bool MoveCommonData(SectionData& pFrom, SectionData& pTo);
bool MoveSectionDataAndSort(SectionData& pFrom, SectionData& pTo);
@@ -140,24 +138,19 @@
uint32_t getGP() { return m_psdata->addr(); }
- Relocation::Type getCopyRelType() const { return m_CopyRel; }
+ Relocation::Type getCopyRelType() const { return m_CopyRel; }
- virtual uint32_t getGOTSymbolAddr() {
- return m_pGOTSymbol->value();
- }
+ virtual uint32_t getGOTSymbolAddr() { return m_pGOTSymbol->value(); }
-
-protected:
+ protected:
void defineGOTSymbol(IRBuilder& pBuilder, Fragment&);
-private:
+ private:
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelEntrySize()
- { return 0; }
+ size_t getRelEntrySize() { return 0; }
/// getRelaEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return 12; }
+ size_t getRelaEntrySize() { return 12; }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
@@ -176,7 +169,7 @@
virtual void setRelaDynSize();
virtual void setRelaPLTSize();
-private:
+ private:
Relocator* m_pRelocator;
HexagonGOT* m_pGOT;
HexagonGOTPLT* m_pGOTPLT;
@@ -200,7 +193,7 @@
LDSymbol* m_pBSSEnd;
Relocation::Type m_CopyRel;
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONLDBACKEND_H_
diff --git a/lib/Target/Hexagon/HexagonMCLinker.cpp b/lib/Target/Hexagon/HexagonMCLinker.cpp
deleted file mode 100644
index 770ae94..0000000
--- a/lib/Target/Hexagon/HexagonMCLinker.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//===- HexagonMCLinker.cpp ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "Hexagon.h"
-#include "HexagonELFMCLinker.h"
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <llvm/ADT/Triple.h>
-
-using namespace mcld;
-
-namespace mcld {
-
-/// createHexagonMCLinker - the help funtion to create corresponding
-/// HexagonMCLinker
-MCLinker* createHexagonMCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- if (theTriple.isArch32Bit())
- return new HexagonELFMCLinker(pConfig, pModule, pFileHandle);
-
- assert(0 && "Hexagon_64 has not supported yet");
- return NULL;
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// HexagonMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeHexagonMCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheHexagonTarget,
- createHexagonMCLinker);
-}
-
diff --git a/lib/Target/Hexagon/HexagonPLT.cpp b/lib/Target/Hexagon/HexagonPLT.cpp
index 3d692fd..ca9352a 100644
--- a/lib/Target/Hexagon/HexagonPLT.cpp
+++ b/lib/Target/Hexagon/HexagonPLT.cpp
@@ -9,55 +9,48 @@
#include "HexagonPLT.h"
#include "HexagonRelocationFunctions.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// PLT entry data
//===----------------------------------------------------------------------===//
HexagonPLT0::HexagonPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(hexagon_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(hexagon_plt0)>(pParent) {
}
HexagonPLT1::HexagonPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(hexagon_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(hexagon_plt1)>(pParent) {
}
//===----------------------------------------------------------------------===//
// HexagonPLT
//===----------------------------------------------------------------------===//
HexagonPLT::HexagonPLT(LDSection& pSection,
- HexagonGOTPLT &pGOTPLT,
- const LinkerConfig& pConfig)
- : PLT(pSection),
- m_GOTPLT(pGOTPLT),
- m_Config(pConfig)
-{
+ HexagonGOTPLT& pGOTPLT,
+ const LinkerConfig& pConfig)
+ : PLT(pSection), m_GOTPLT(pGOTPLT), m_Config(pConfig) {
assert(LinkerConfig::DynObj == m_Config.codeGenType() ||
- LinkerConfig::Exec == m_Config.codeGenType() ||
+ LinkerConfig::Exec == m_Config.codeGenType() ||
LinkerConfig::Binary == m_Config.codeGenType());
m_PLT0 = hexagon_plt0;
- m_PLT0Size = sizeof (hexagon_plt0);
+ m_PLT0Size = sizeof(hexagon_plt0);
// create PLT0
new HexagonPLT0(*m_pSectionData);
pSection.setAlign(16);
}
-HexagonPLT::~HexagonPLT()
-{
+HexagonPLT::~HexagonPLT() {
}
-PLTEntryBase* HexagonPLT::getPLT0() const
-{
+PLTEntryBase* HexagonPLT::getPLT0() const {
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -68,8 +61,7 @@
return plt0;
}
-void HexagonPLT::finalizeSectionSize()
-{
+void HexagonPLT::finalizeSectionSize() {
uint64_t size = 0;
// plt0 size
size = getPLT0()->size();
@@ -92,18 +84,15 @@
}
}
-bool HexagonPLT::hasPLT1() const
-{
+bool HexagonPLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-HexagonPLT1* HexagonPLT::create()
-{
+HexagonPLT1* HexagonPLT::create() {
return new HexagonPLT1(*m_pSectionData);
}
-void HexagonPLT::applyPLT0()
-{
+void HexagonPLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
uint64_t pltBase = m_Section.addr();
@@ -116,8 +105,8 @@
memcpy(data, m_PLT0, plt0->size());
uint32_t gotpltAddr = m_GOTPLT.addr();
- int32_t *dest = (int32_t *)data;
- int32_t result = ((gotpltAddr - pltBase ) >> 6);
+ int32_t* dest = reinterpret_cast<int32_t*>(data);
+ int32_t result = ((gotpltAddr - pltBase) >> 6);
*dest |= ApplyMask<int32_t>(0xfff3fff, result);
dest = dest + 1;
// Already calculated using pltBase
@@ -128,7 +117,6 @@
}
void HexagonPLT::applyPLT1() {
-
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -140,13 +128,12 @@
assert(it != ie && "FragmentList is empty, applyPLT1 failed!");
uint32_t GOTEntrySize = HexagonGOTEntry::EntrySize;
- uint32_t GOTEntryAddress =
- got_base + GOTEntrySize * 4;
+ uint32_t GOTEntryAddress = got_base + GOTEntrySize * 4;
uint64_t PLTEntryAddress =
- plt_base + HexagonPLT0::EntrySize; //Offset of PLT0
+ plt_base + HexagonPLT0::EntrySize; // Offset of PLT0
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint64_t PLT1EntrySize = HexagonPLT1::EntrySize;
HexagonPLT1* plt1 = NULL;
@@ -160,8 +147,8 @@
memcpy(Out, hexagon_plt1, plt1->size());
- int32_t *dest = (int32_t *)Out;
- int32_t result = ((GOTEntryAddress - PLTEntryAddress ) >> 6);
+ int32_t* dest = reinterpret_cast<int32_t*>(Out);
+ int32_t result = ((GOTEntryAddress - PLTEntryAddress) >> 6);
*dest |= ApplyMask<int32_t>(0xfff3fff, result);
dest = dest + 1;
result = (GOTEntryAddress - PLTEntryAddress);
@@ -178,13 +165,14 @@
}
}
-uint64_t HexagonPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t HexagonPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
unsigned char* buffer = pRegion.begin();
- memcpy(buffer, llvm::cast<HexagonPLT0>((*it)).getValue(), HexagonPLT0::EntrySize);
+ memcpy(buffer,
+ llvm::cast<HexagonPLT0>((*it)).getValue(),
+ HexagonPLT0::EntrySize);
result += HexagonPLT0::EntrySize;
++it;
@@ -199,3 +187,4 @@
return result;
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonPLT.h b/lib/Target/Hexagon/HexagonPLT.h
index 4acce49..22f580e 100644
--- a/lib/Target/Hexagon/HexagonPLT.h
+++ b/lib/Target/Hexagon/HexagonPLT.h
@@ -6,53 +6,48 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONPLT_H
-#define TARGET_HEXAGON_HEXAGONPLT_H
+#ifndef TARGET_HEXAGON_HEXAGONPLT_H_
+#define TARGET_HEXAGON_HEXAGONPLT_H_
#include "HexagonGOT.h"
#include "HexagonGOTPLT.h"
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Support/MemoryRegion.h"
const uint8_t hexagon_plt0[] = {
- 0x00, 0x40, 0x00, 0x00, // { immext (#0)
- 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0
- 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa
- 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2
- 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) }# dynamic link at GOT1
- 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn
- 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x00, 0x40, 0x00, 0x00, // { immext (#0)
+ 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0 // NOLINT
+ 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa // NOLINT
+ 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2
+ 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) } # dynamic link at GOT1
+ 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn
+ 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
};
const uint8_t hexagon_plt1[] = {
- 0x00, 0x40, 0x00, 0x00, // { immext (#0)
- 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn
- 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn
- 0x00, 0xc0, 0x9c, 0x52 // jumpr r28 # call it
+ 0x00, 0x40, 0x00, 0x00, // { immext (#0)
+ 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn // NOLINT
+ 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn // NOLINT
+ 0x00, 0xc0, 0x9c, 0x52 // jumpr r28 # call it
};
-} // anonymous namespace
-
namespace mcld {
class GOTEntry;
-class LinkerConfig;
class HexagonPLT1;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
// HexagonPLT Entry
//===----------------------------------------------------------------------===//
-class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)>
-{
-public:
+class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)> {
+ public:
HexagonPLT0(SectionData& pParent);
};
@@ -62,9 +57,8 @@
/** \class HexagonPLT
* \brief Hexagon Procedure Linkage Table
*/
-class HexagonPLT : public PLT
-{
-public:
+class HexagonPLT : public PLT {
+ public:
HexagonPLT(LDSection& pSection,
HexagonGOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -86,22 +80,20 @@
PLTEntryBase* getPLT0() const;
-private:
+ private:
HexagonGOTPLT& m_GOTPLT;
- const uint8_t *m_PLT0;
+ const uint8_t* m_PLT0;
unsigned int m_PLT0Size;
const LinkerConfig& m_Config;
};
-class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)>
-{
-public:
+class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)> {
+ public:
HexagonPLT1(SectionData& pParent);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_HEXAGON_HEXAGONPLT_H_
diff --git a/lib/Target/Hexagon/HexagonRelocationFunctions.h b/lib/Target/Hexagon/HexagonRelocationFunctions.h
index 6c60954..7b6783d 100644
--- a/lib/Target/Hexagon/HexagonRelocationFunctions.h
+++ b/lib/Target/Hexagon/HexagonRelocationFunctions.h
@@ -6,8 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
+#define TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
+
typedef struct {
- const char *insnSyntax;
+ const char* insnSyntax;
uint32_t insnMask;
uint32_t insnCmpMask;
uint32_t insnBitMask;
@@ -33,104 +36,106 @@
return result;
}
-#define DECL_HEXAGON_APPLY_RELOC_FUNC(Name) \
-static HexagonRelocator::Result Name (Relocation& pEntry, \
- HexagonRelocator& pParent);
+#define DECL_HEXAGON_APPLY_RELOC_FUNC(Name) \
+ static HexagonRelocator::Result Name(Relocation& pEntry, \
+ HexagonRelocator& pParent);
-#define DECL_HEXAGON_APPLY_RELOC_FUNCS \
-DECL_HEXAGON_APPLY_RELOC_FUNC(none) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocPCREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGPREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocAbs) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocPLTB22PCREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOTREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOT) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(unsupport)
+#define DECL_HEXAGON_APPLY_RELOC_FUNCS \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(none) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocPCREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGPREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocAbs) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocPLTB22PCREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOTREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOT) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(unsupported)
-#define DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_HEX_NONE" }, \
- { &relocPCREL, 1, "R_HEX_B22_PCREL" }, \
- { &relocPCREL, 2, "R_HEX_B15_PCREL" }, \
- { &relocPCREL, 3, "R_HEX_B7_PCREL" }, \
- { &relocAbs, 4, "R_HEX_LO16" }, \
- { &relocAbs, 5, "R_HEX_HI16" }, \
- { &relocAbs, 6, "R_HEX_32" }, \
- { &relocAbs, 7, "R_HEX_16" }, \
- { &relocAbs, 8, "R_HEX_8" }, \
- { &relocGPREL, 9, "R_HEX_GPREL16_0" }, \
- { &relocGPREL, 10, "R_HEX_GPREL16_1" }, \
- { &relocGPREL, 11, "R_HEX_GPREL16_2" }, \
- { &relocGPREL, 12, "R_HEX_GPREL16_3" }, \
- { &unsupport, 13, "R_HEX_HL16" }, \
- { &relocPCREL, 14, "R_HEX_B13_PCREL" }, \
- { &relocPCREL, 15, "R_HEX_B9_PCREL" }, \
- { &relocPCREL, 16, "R_HEX_B32_PCREL_X" }, \
- { &relocAbs, 17, "R_HEX_32_6_X" }, \
- { &relocPCREL, 18, "R_HEX_B22_PCREL_X" }, \
- { &relocPCREL, 19, "R_HEX_B15_PCREL_X" }, \
- { &relocPCREL, 20, "R_HEX_B13_PCREL_X" }, \
- { &relocPCREL, 21, "R_HEX_B9_PCREL_X" }, \
- { &relocPCREL, 22, "R_HEX_B7_PCREL_X" }, \
- { &relocAbs, 23, "R_HEX_16_X" }, \
- { &relocAbs, 24, "R_HEX_12_X" }, \
- { &relocAbs, 25, "R_HEX_11_X" }, \
- { &relocAbs, 26, "R_HEX_10_X" }, \
- { &relocAbs, 27, "R_HEX_9_X" }, \
- { &relocAbs, 28, "R_HEX_8_X" }, \
- { &relocAbs, 29, "R_HEX_7_X" }, \
- { &relocAbs, 30, "R_HEX_6_X" }, \
- { &relocPCREL, 31, "R_HEX_32_PCREL" }, \
- { &none, 32, "R_HEX_COPY" }, \
- { &none, 33, "R_HEX_GLOB_DAT" }, \
- { &none, 34, "R_HEX_JMP_SLOT" }, \
- { &none, 35, "R_HEX_RELATIVE" }, \
- { &relocPLTB22PCREL, 36, "R_HEX_PLT_B22_PCREL" }, \
- { &relocGOTREL, 37, "R_HEX_GOTREL_LO16" }, \
- { &relocGOTREL, 38, "R_HEX_GOTREL_HI16" }, \
- { &relocGOTREL, 39, "R_HEX_GOTREL_32" }, \
- { &relocGOT, 40, "R_HEX_GOT_LO16" }, \
- { &relocGOT, 41, "R_HEX_GOT_HI16" }, \
- { &relocGOT, 42, "R_HEX_GOT_32" }, \
- { &relocGOT, 43, "R_HEX_GOT_16" }, \
- { &unsupport, 44, "R_HEX_DTPMOD_32" }, \
- { &unsupport, 45, "R_HEX_DTPREL_LO16" }, \
- { &unsupport, 46, "R_HEX_DTPREL_HI16" }, \
- { &unsupport, 47, "R_HEX_DTPREL_32" }, \
- { &unsupport, 48, "R_HEX_DTPREL_16" }, \
- { &unsupport, 49, "R_HEX_GD_PLT_B22_PCREL" }, \
- { &unsupport, 50, "R_HEX_GD_GOT_LO16" }, \
- { &unsupport, 51, "R_HEX_GD_GOT_HI16" }, \
- { &unsupport, 52, "R_HEX_GD_GOT_32" }, \
- { &unsupport, 53, "R_HEX_GD_GOT_16" }, \
- { &unsupport, 54, "R_HEX_IE_LO16" }, \
- { &unsupport, 55, "R_HEX_IE_HI16" }, \
- { &unsupport, 56, "R_HEX_IE_32" }, \
- { &unsupport, 57, "R_HEX_IE_GOT_LO16" }, \
- { &unsupport, 58, "R_HEX_IE_GOT_HI16" }, \
- { &unsupport, 59, "R_HEX_IE_GOT_32" }, \
- { &unsupport, 60, "R_HEX_IE_GOT_16" }, \
- { &unsupport, 61, "R_HEX_TPREL_LO16" }, \
- { &unsupport, 62, "R_HEX_TPREL_HI16" }, \
- { &unsupport, 63, "R_HEX_TPREL_32" }, \
- { &unsupport, 64, "R_HEX_TPREL_16" }, \
- { &relocPCREL, 65, "R_HEX_6_PCREL_X" }, \
- { &relocGOTREL, 66, "R_HEX_GOTREL_32_6_X" }, \
- { &relocGOTREL, 67, "R_HEX_GOTREL_16_X" }, \
- { &relocGOTREL, 68, "R_HEX_GOTREL_11_X" }, \
- { &relocGOT, 69, "R_HEX_GOT_32_6_X" }, \
- { &relocGOT, 70, "R_HEX_GOT_16_X" }, \
- { &relocGOT, 71, "R_HEX_GOT_11_X" }, \
- { &unsupport, 72, "R_HEX_DTPREL_32_6_X" }, \
- { &unsupport, 73, "R_HEX_DTPREL_16_X" }, \
- { &unsupport, 74, "R_HEX_DTPREL_11_X" }, \
- { &unsupport, 75, "R_HEX_GD_GOT_32_6_X" }, \
- { &unsupport, 76, "R_HEX_GD_GOT_16_X" }, \
- { &unsupport, 77, "R_HEX_GD_GOT_11_X" }, \
- { &unsupport, 78, "R_HEX_IE_32_6_X" }, \
- { &unsupport, 79, "R_HEX_IE_16_X" }, \
- { &unsupport, 80, "R_HEX_IE_GOT_32_6_X" }, \
- { &unsupport, 81, "R_HEX_IE_GOT_16_X" }, \
- { &unsupport, 82, "R_HEX_IE_GOT_11_X" }, \
- { &unsupport, 83, "R_HEX_TPREL_32_6_X" }, \
- { &unsupport, 84, "R_HEX_TPREL_16_X" }, \
- { &unsupport, 85, "R_HEX_TPREL_11_X" }
+#define DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_HEX_NONE" }, \
+ { &relocPCREL, 1, "R_HEX_B22_PCREL" }, \
+ { &relocPCREL, 2, "R_HEX_B15_PCREL" }, \
+ { &relocPCREL, 3, "R_HEX_B7_PCREL" }, \
+ { &relocAbs, 4, "R_HEX_LO16" }, \
+ { &relocAbs, 5, "R_HEX_HI16" }, \
+ { &relocAbs, 6, "R_HEX_32" }, \
+ { &relocAbs, 7, "R_HEX_16" }, \
+ { &relocAbs, 8, "R_HEX_8" }, \
+ { &relocGPREL, 9, "R_HEX_GPREL16_0" }, \
+ { &relocGPREL, 10, "R_HEX_GPREL16_1" }, \
+ { &relocGPREL, 11, "R_HEX_GPREL16_2" }, \
+ { &relocGPREL, 12, "R_HEX_GPREL16_3" }, \
+ { &unsupported, 13, "R_HEX_HL16" }, \
+ { &relocPCREL, 14, "R_HEX_B13_PCREL" }, \
+ { &relocPCREL, 15, "R_HEX_B9_PCREL" }, \
+ { &relocPCREL, 16, "R_HEX_B32_PCREL_X" }, \
+ { &relocAbs, 17, "R_HEX_32_6_X" }, \
+ { &relocPCREL, 18, "R_HEX_B22_PCREL_X" }, \
+ { &relocPCREL, 19, "R_HEX_B15_PCREL_X" }, \
+ { &relocPCREL, 20, "R_HEX_B13_PCREL_X" }, \
+ { &relocPCREL, 21, "R_HEX_B9_PCREL_X" }, \
+ { &relocPCREL, 22, "R_HEX_B7_PCREL_X" }, \
+ { &relocAbs, 23, "R_HEX_16_X" }, \
+ { &relocAbs, 24, "R_HEX_12_X" }, \
+ { &relocAbs, 25, "R_HEX_11_X" }, \
+ { &relocAbs, 26, "R_HEX_10_X" }, \
+ { &relocAbs, 27, "R_HEX_9_X" }, \
+ { &relocAbs, 28, "R_HEX_8_X" }, \
+ { &relocAbs, 29, "R_HEX_7_X" }, \
+ { &relocAbs, 30, "R_HEX_6_X" }, \
+ { &relocPCREL, 31, "R_HEX_32_PCREL" }, \
+ { &none, 32, "R_HEX_COPY" }, \
+ { &none, 33, "R_HEX_GLOB_DAT" }, \
+ { &none, 34, "R_HEX_JMP_SLOT" }, \
+ { &none, 35, "R_HEX_RELATIVE" }, \
+ { &relocPLTB22PCREL, 36, "R_HEX_PLT_B22_PCREL" }, \
+ { &relocGOTREL, 37, "R_HEX_GOTREL_LO16" }, \
+ { &relocGOTREL, 38, "R_HEX_GOTREL_HI16" }, \
+ { &relocGOTREL, 39, "R_HEX_GOTREL_32" }, \
+ { &relocGOT, 40, "R_HEX_GOT_LO16" }, \
+ { &relocGOT, 41, "R_HEX_GOT_HI16" }, \
+ { &relocGOT, 42, "R_HEX_GOT_32" }, \
+ { &relocGOT, 43, "R_HEX_GOT_16" }, \
+ { &unsupported, 44, "R_HEX_DTPMOD_32" }, \
+ { &unsupported, 45, "R_HEX_DTPREL_LO16" }, \
+ { &unsupported, 46, "R_HEX_DTPREL_HI16" }, \
+ { &unsupported, 47, "R_HEX_DTPREL_32" }, \
+ { &unsupported, 48, "R_HEX_DTPREL_16" }, \
+ { &unsupported, 49, "R_HEX_GD_PLT_B22_PCREL" }, \
+ { &unsupported, 50, "R_HEX_GD_GOT_LO16" }, \
+ { &unsupported, 51, "R_HEX_GD_GOT_HI16" }, \
+ { &unsupported, 52, "R_HEX_GD_GOT_32" }, \
+ { &unsupported, 53, "R_HEX_GD_GOT_16" }, \
+ { &unsupported, 54, "R_HEX_IE_LO16" }, \
+ { &unsupported, 55, "R_HEX_IE_HI16" }, \
+ { &unsupported, 56, "R_HEX_IE_32" }, \
+ { &unsupported, 57, "R_HEX_IE_GOT_LO16" }, \
+ { &unsupported, 58, "R_HEX_IE_GOT_HI16" }, \
+ { &unsupported, 59, "R_HEX_IE_GOT_32" }, \
+ { &unsupported, 60, "R_HEX_IE_GOT_16" }, \
+ { &unsupported, 61, "R_HEX_TPREL_LO16" }, \
+ { &unsupported, 62, "R_HEX_TPREL_HI16" }, \
+ { &unsupported, 63, "R_HEX_TPREL_32" }, \
+ { &unsupported, 64, "R_HEX_TPREL_16" }, \
+ { &relocPCREL, 65, "R_HEX_6_PCREL_X" }, \
+ { &relocGOTREL, 66, "R_HEX_GOTREL_32_6_X" }, \
+ { &relocGOTREL, 67, "R_HEX_GOTREL_16_X" }, \
+ { &relocGOTREL, 68, "R_HEX_GOTREL_11_X" }, \
+ { &relocGOT, 69, "R_HEX_GOT_32_6_X" }, \
+ { &relocGOT, 70, "R_HEX_GOT_16_X" }, \
+ { &relocGOT, 71, "R_HEX_GOT_11_X" }, \
+ { &unsupported, 72, "R_HEX_DTPREL_32_6_X" }, \
+ { &unsupported, 73, "R_HEX_DTPREL_16_X" }, \
+ { &unsupported, 74, "R_HEX_DTPREL_11_X" }, \
+ { &unsupported, 75, "R_HEX_GD_GOT_32_6_X" }, \
+ { &unsupported, 76, "R_HEX_GD_GOT_16_X" }, \
+ { &unsupported, 77, "R_HEX_GD_GOT_11_X" }, \
+ { &unsupported, 78, "R_HEX_IE_32_6_X" }, \
+ { &unsupported, 79, "R_HEX_IE_16_X" }, \
+ { &unsupported, 80, "R_HEX_IE_GOT_32_6_X" }, \
+ { &unsupported, 81, "R_HEX_IE_GOT_16_X" }, \
+ { &unsupported, 82, "R_HEX_IE_GOT_11_X" }, \
+ { &unsupported, 83, "R_HEX_TPREL_32_6_X" }, \
+ { &unsupported, 84, "R_HEX_TPREL_16_X" }, \
+ { &unsupported, 85, "R_HEX_TPREL_11_X" }
+
+#endif // TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/Hexagon/HexagonRelocator.cpp b/lib/Target/Hexagon/HexagonRelocator.cpp
index d02b640..c05d76f 100644
--- a/lib/Target/Hexagon/HexagonRelocator.cpp
+++ b/lib/Target/Hexagon/HexagonRelocator.cpp
@@ -9,30 +9,31 @@
#include "HexagonRelocator.h"
#include "HexagonRelocationFunctions.h"
#include "HexagonEncodings.h"
+
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// Relocation Helper Functions
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static Relocation &helper_DynRel_init(ResolveInfo *pSym,
- Fragment &pFrag,
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
uint64_t pOffset,
Relocator::Type pType,
- HexagonRelocator &pParent) {
- HexagonLDBackend &ld_backend = pParent.getTarget();
- Relocation &rela_entry = *ld_backend.getRelaDyn().create();
+ HexagonRelocator& pParent) {
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ Relocation& rela_entry = *ld_backend.getRelaDyn().create();
rela_entry.setType(pType);
rela_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_HEX_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_HEX_RELATIVE || pSym == NULL)
rela_entry.setSymInfo(0);
else
rela_entry.setSymInfo(pSym);
@@ -42,8 +43,8 @@
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_HEX_RELATIVE
-static bool helper_use_relative_reloc(const ResolveInfo &pSym,
- const HexagonRelocator &pFactory) {
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const HexagonRelocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
@@ -51,60 +52,58 @@
return true;
}
-static HexagonGOTEntry &helper_GOT_init(Relocation &pReloc,
+static HexagonGOTEntry& helper_GOT_init(Relocation& pReloc,
bool pHasRel,
- HexagonRelocator &pParent) {
+ HexagonRelocator& pParent) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
- HexagonGOTEntry *got_entry = ld_backend.getGOT().create();
+ HexagonGOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(HexagonRelocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_HEX_RELATIVE,
- pParent);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_HEX_RELATIVE, pParent);
got_entry->setValue(HexagonRelocator::SymVal);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_HEX_GLOB_DAT,
- pParent);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_HEX_GLOB_DAT, pParent);
got_entry->setValue(0);
}
}
return *got_entry;
}
-static Relocator::Address helper_get_GOT_address(ResolveInfo &pSym,
- HexagonRelocator &pParent) {
- HexagonGOTEntry *got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+static Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
+ HexagonRelocator& pParent) {
+ HexagonGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static PLTEntryBase &helper_PLT_init(Relocation &pReloc,
- HexagonRelocator &pParent) {
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ HexagonRelocator& pParent) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
- PLTEntryBase *plt_entry = ld_backend.getPLT().create();
+ PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
- HexagonGOTEntry *gotplt_entry = ld_backend.getGOTPLT().create();
+ HexagonGOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
// init the corresponding rel entry in .rela.plt
- Relocation &rela_entry = *ld_backend.getRelaPLT().create();
+ Relocation& rela_entry = *ld_backend.getRelaPLT().create();
rela_entry.setType(llvm::ELF::R_HEX_JMP_SLOT);
rela_entry.targetRef().assign(*gotplt_entry);
rela_entry.setSymInfo(rsym);
@@ -113,9 +112,9 @@
}
static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- HexagonRelocator &pParent) {
- PLTEntryBase *plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ HexagonRelocator& pParent) {
+ PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
@@ -125,24 +124,24 @@
DECL_HEXAGON_APPLY_RELOC_FUNCS
/// the prototype of applying function
-typedef Relocator::Result (*ApplyFunctionType)(Relocation &pReloc,
- HexagonRelocator &pParent);
+typedef Relocator::Result (*ApplyFunctionType)(Relocation& pReloc,
+ HexagonRelocator& pParent);
// the table entry of applying functions
struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
- const char *name;
+ const char* name;
};
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS};
-static uint32_t findBitMask(uint32_t insn, Instruction *encodings,
+static uint32_t findBitMask(uint32_t insn,
+ Instruction* encodings,
int32_t numInsns) {
- for (int32_t i = 0; i < numInsns; i++) {
+ for (int32_t i = 0; i < numInsns; ++i) {
if (((insn & 0xc000) == 0) && !(encodings[i].isDuplex))
continue;
@@ -158,23 +157,26 @@
return -1;
}
-#define FINDBITMASK(INSN) \
- findBitMask((uint32_t) INSN, insn_encodings, \
+#define FINDBITMASK(INSN) \
+ findBitMask((uint32_t)INSN, \
+ insn_encodings, \
sizeof(insn_encodings) / sizeof(Instruction))
//===--------------------------------------------------------------------===//
// HexagonRelocator
//===--------------------------------------------------------------------===//
-HexagonRelocator::HexagonRelocator(HexagonLDBackend &pParent,
- const LinkerConfig &pConfig)
- : Relocator(pConfig), m_Target(pParent) {}
+HexagonRelocator::HexagonRelocator(HexagonLDBackend& pParent,
+ const LinkerConfig& pConfig)
+ : Relocator(pConfig), m_Target(pParent) {
+}
-HexagonRelocator::~HexagonRelocator() {}
+HexagonRelocator::~HexagonRelocator() {
+}
-Relocator::Result HexagonRelocator::applyRelocation(Relocation &pRelocation) {
+Relocator::Result HexagonRelocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type > 85) { // 86-255 relocs do not exists for Hexagon
+ if (type > 85) { // 86-255 relocs do not exists for Hexagon
return Relocator::Unknown;
}
@@ -182,7 +184,7 @@
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char *HexagonRelocator::getName(Relocation::Type pType) const {
+const char* HexagonRelocator::getName(Relocation::Type pType) const {
return ApplyFunctions[pType].name;
}
@@ -190,26 +192,29 @@
return 32;
}
-void HexagonRelocator::scanRelocation(Relocation &pReloc, IRBuilder &pLinker,
- Module &pModule, LDSection &pSection, Input &pInput) {
+void HexagonRelocator::scanRelocation(Relocation& pReloc,
+ IRBuilder& pLinker,
+ Module& pModule,
+ LDSection& pSection,
+ Input& pInput) {
if (LinkerConfig::Object == config().codeGenType())
return;
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ ResolveInfo* rsym = pReloc.symInfo();
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
if (config().isCodeStatic())
return;
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
- if (rsym->isLocal()) // rsym is local
+ if (rsym->isLocal()) // rsym is local
scanLocalReloc(pReloc, pLinker, pModule, pSection);
- else // rsym is external
+ else // rsym is external
scanGlobalReloc(pReloc, pLinker, pModule, pSection);
// check if we should issue undefined reference for the relocation target
@@ -218,176 +223,179 @@
issueUndefRef(pReloc, pSection, pInput);
}
-void HexagonRelocator::addCopyReloc(ResolveInfo &pSym,
- HexagonLDBackend &pTarget) {
- Relocation &rel_entry = *pTarget.getRelaDyn().create();
+void HexagonRelocator::addCopyReloc(ResolveInfo& pSym,
+ HexagonLDBackend& pTarget) {
+ Relocation& rel_entry = *pTarget.getRelaDyn().create();
rel_entry.setType(pTarget.getCopyRelType());
assert(pSym.outSymbol()->hasFragRef());
rel_entry.targetRef().assign(*pSym.outSymbol()->fragRef());
rel_entry.setSymInfo(&pSym);
}
-void HexagonRelocator::scanLocalReloc(Relocation &pReloc, IRBuilder &pBuilder,
- Module &pModule, LDSection &pSection) {
+void HexagonRelocator::scanLocalReloc(Relocation& pReloc,
+ IRBuilder& pBuilder,
+ Module& pModule,
+ LDSection& pSection) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
+ ResolveInfo* rsym = pReloc.symInfo();
switch (pReloc.type()) {
+ case llvm::ELF::R_HEX_LO16:
+ case llvm::ELF::R_HEX_HI16:
+ case llvm::ELF::R_HEX_16:
+ case llvm::ELF::R_HEX_8:
+ case llvm::ELF::R_HEX_32_6_X:
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_12_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ assert(!(rsym->reserved() & ReserveRel) &&
+ "Cannot apply this relocation for read only section");
+ return;
- case llvm::ELF::R_HEX_LO16:
- case llvm::ELF::R_HEX_HI16:
- case llvm::ELF::R_HEX_16:
- case llvm::ELF::R_HEX_8:
- case llvm::ELF::R_HEX_32_6_X:
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_12_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- assert(!(rsym->reserved() & ReserveRel) &&
- "Cannot apply this relocation for read only section");
- return;
-
- case llvm::ELF::R_HEX_32:
- // If buiding PIC object (shared library or PIC executable),
- // a dynamic relocations with RELATIVE type to this location is needed.
- // Reserve an entry in .rel.dyn
- if (config().isCodeIndep()) {
- Relocation &reloc = helper_DynRel_init(rsym,
- *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_HEX_RELATIVE,
- *this);
- // we need to set up the relocation addend at apply relocation, record the
- // relocation
- getRelRelMap().record(pReloc, reloc);
-
- // set Rel bit
- rsym->setReserved(rsym->reserved() | ReserveRel);
- getTarget().checkAndSetHasTextRel(*pSection.getLink());
- }
- return;
-
- default:
- return;
- }
-}
-
-void HexagonRelocator::scanGlobalReloc(Relocation &pReloc, IRBuilder &pBuilder,
- Module &pModule, LDSection &pSection) {
- // rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = getTarget();
-
- switch (pReloc.type()) {
- case llvm::ELF::R_HEX_LO16:
- case llvm::ELF::R_HEX_HI16:
- case llvm::ELF::R_HEX_16:
- case llvm::ELF::R_HEX_8:
- case llvm::ELF::R_HEX_32_6_X:
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_12_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- assert(!(rsym->reserved() & ReserveRel) &&
- "Cannot apply this relocation for read only section");
- return;
-
- case llvm::ELF::R_HEX_32:
- if (ld_backend.symbolNeedsPLT(*rsym)) {
- //create PLT for this symbol if it does not have.
- if (!(rsym->reserved() & ReservePLT)) {
- helper_PLT_init(pReloc, *this);
- rsym->setReserved(rsym->reserved() | ReservePLT);
- }
- }
-
- if (ld_backend.symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
- if (ld_backend.symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol &cpy_sym =
- defineSymbolforCopyReloc(pBuilder, *rsym, ld_backend);
- addCopyReloc(*cpy_sym.resolveInfo(), ld_backend);
- }
- else {
- Relocation &reloc = helper_DynRel_init(rsym,
+ case llvm::ELF::R_HEX_32:
+ // If buiding PIC object (shared library or PIC executable),
+ // a dynamic relocations with RELATIVE type to this location is needed.
+ // Reserve an entry in .rel.dyn
+ if (config().isCodeIndep()) {
+ Relocation& reloc = helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
llvm::ELF::R_HEX_RELATIVE,
*this);
- // we need to set up the relocation addend at apply relocation, record the
+ // we need to set up the relocation addend at apply relocation, record
+ // the
// relocation
getRelRelMap().record(pReloc, reloc);
+
+ // set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
- ld_backend.checkAndSetHasTextRel(*pSection.getLink());
+ getTarget().checkAndSetHasTextRel(*pSection.getLink());
}
- }
- return;
-
- case llvm::ELF::R_HEX_GOTREL_LO16:
- case llvm::ELF::R_HEX_GOTREL_HI16:
- case llvm::ELF::R_HEX_GOTREL_32:
- case llvm::ELF::R_HEX_GOTREL_32_6_X:
- case llvm::ELF::R_HEX_GOTREL_16_X:
- case llvm::ELF::R_HEX_GOTREL_11_X:
- // This assumes that GOT exists
- return;
-
- case llvm::ELF::R_HEX_GOT_LO16:
- case llvm::ELF::R_HEX_GOT_HI16:
- case llvm::ELF::R_HEX_GOT_32:
- case llvm::ELF::R_HEX_GOT_16:
- case llvm::ELF::R_HEX_GOT_32_6_X:
- case llvm::ELF::R_HEX_GOT_16_X:
- case llvm::ELF::R_HEX_GOT_11_X:
- // Symbol needs GOT entry, reserve entry in .got
- // return if we already create GOT for this symbol
- if (rsym->reserved() & ReserveGOT)
return;
- // If the GOT is used in statically linked binaries,
- // the GOT entry is enough and no relocation is needed.
- if (config().isCodeStatic())
- helper_GOT_init(pReloc, false, *this);
- else
- helper_GOT_init(pReloc, true, *this);
- // set GOT bit
- rsym->setReserved(rsym->reserved() | ReserveGOT);
- return;
- case llvm::ELF::R_HEX_B22_PCREL:
- case llvm::ELF::R_HEX_B15_PCREL:
- case llvm::ELF::R_HEX_B7_PCREL:
- case llvm::ELF::R_HEX_B13_PCREL:
- case llvm::ELF::R_HEX_B9_PCREL:
- case llvm::ELF::R_HEX_B32_PCREL_X:
- case llvm::ELF::R_HEX_B22_PCREL_X:
- case llvm::ELF::R_HEX_B15_PCREL_X:
- case llvm::ELF::R_HEX_B13_PCREL_X:
- case llvm::ELF::R_HEX_B9_PCREL_X:
- case llvm::ELF::R_HEX_B7_PCREL_X:
- case llvm::ELF::R_HEX_32_PCREL:
- case llvm::ELF::R_HEX_6_PCREL_X:
- case llvm::ELF::R_HEX_PLT_B22_PCREL:
- if (rsym->reserved() & ReservePLT)
+ default:
return;
- if (ld_backend.symbolNeedsPLT(*rsym) ||
- pReloc.type() == llvm::ELF::R_HEX_PLT_B22_PCREL) {
- helper_PLT_init(pReloc, *this);
- rsym->setReserved(rsym->reserved() | ReservePLT);
- }
- return;
+ }
+}
- default:
- break;
+void HexagonRelocator::scanGlobalReloc(Relocation& pReloc,
+ IRBuilder& pBuilder,
+ Module& pModule,
+ LDSection& pSection) {
+ // rsym - The relocation target symbol
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = getTarget();
- } // end of switch
+ switch (pReloc.type()) {
+ case llvm::ELF::R_HEX_LO16:
+ case llvm::ELF::R_HEX_HI16:
+ case llvm::ELF::R_HEX_16:
+ case llvm::ELF::R_HEX_8:
+ case llvm::ELF::R_HEX_32_6_X:
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_12_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ assert(!(rsym->reserved() & ReserveRel) &&
+ "Cannot apply this relocation for read only section");
+ return;
+
+ case llvm::ELF::R_HEX_32:
+ if (ld_backend.symbolNeedsPLT(*rsym)) {
+ // create PLT for this symbol if it does not have.
+ if (!(rsym->reserved() & ReservePLT)) {
+ helper_PLT_init(pReloc, *this);
+ rsym->setReserved(rsym->reserved() | ReservePLT);
+ }
+ }
+
+ if (ld_backend.symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
+ if (ld_backend.symbolNeedsCopyReloc(pReloc, *rsym)) {
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, ld_backend);
+ addCopyReloc(*cpy_sym.resolveInfo(), ld_backend);
+ } else {
+ Relocation& reloc = helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_HEX_RELATIVE,
+ *this);
+ // we need to set up the relocation addend at apply relocation, record
+ // the
+ // relocation
+ getRelRelMap().record(pReloc, reloc);
+ rsym->setReserved(rsym->reserved() | ReserveRel);
+ ld_backend.checkAndSetHasTextRel(*pSection.getLink());
+ }
+ }
+ return;
+
+ case llvm::ELF::R_HEX_GOTREL_LO16:
+ case llvm::ELF::R_HEX_GOTREL_HI16:
+ case llvm::ELF::R_HEX_GOTREL_32:
+ case llvm::ELF::R_HEX_GOTREL_32_6_X:
+ case llvm::ELF::R_HEX_GOTREL_16_X:
+ case llvm::ELF::R_HEX_GOTREL_11_X:
+ // This assumes that GOT exists
+ return;
+
+ case llvm::ELF::R_HEX_GOT_LO16:
+ case llvm::ELF::R_HEX_GOT_HI16:
+ case llvm::ELF::R_HEX_GOT_32:
+ case llvm::ELF::R_HEX_GOT_16:
+ case llvm::ELF::R_HEX_GOT_32_6_X:
+ case llvm::ELF::R_HEX_GOT_16_X:
+ case llvm::ELF::R_HEX_GOT_11_X:
+ // Symbol needs GOT entry, reserve entry in .got
+ // return if we already create GOT for this symbol
+ if (rsym->reserved() & ReserveGOT)
+ return;
+ // If the GOT is used in statically linked binaries,
+ // the GOT entry is enough and no relocation is needed.
+ if (config().isCodeStatic())
+ helper_GOT_init(pReloc, false, *this);
+ else
+ helper_GOT_init(pReloc, true, *this);
+ // set GOT bit
+ rsym->setReserved(rsym->reserved() | ReserveGOT);
+ return;
+
+ case llvm::ELF::R_HEX_B22_PCREL:
+ case llvm::ELF::R_HEX_B15_PCREL:
+ case llvm::ELF::R_HEX_B7_PCREL:
+ case llvm::ELF::R_HEX_B13_PCREL:
+ case llvm::ELF::R_HEX_B9_PCREL:
+ case llvm::ELF::R_HEX_B32_PCREL_X:
+ case llvm::ELF::R_HEX_B22_PCREL_X:
+ case llvm::ELF::R_HEX_B15_PCREL_X:
+ case llvm::ELF::R_HEX_B13_PCREL_X:
+ case llvm::ELF::R_HEX_B9_PCREL_X:
+ case llvm::ELF::R_HEX_B7_PCREL_X:
+ case llvm::ELF::R_HEX_32_PCREL:
+ case llvm::ELF::R_HEX_6_PCREL_X:
+ case llvm::ELF::R_HEX_PLT_B22_PCREL:
+ if (rsym->reserved() & ReservePLT)
+ return;
+ if (ld_backend.symbolNeedsPLT(*rsym) ||
+ pReloc.type() == llvm::ELF::R_HEX_PLT_B22_PCREL) {
+ helper_PLT_init(pReloc, *this);
+ rsym->setReserved(rsym->reserved() | ReservePLT);
+ }
+ return;
+
+ default:
+ break;
+ } // end of switch
}
/// defineSymbolforCopyReloc
@@ -395,19 +403,21 @@
/// section and all other reference to this symbol should refer to this
/// copy.
/// @note This is executed at `scan relocation' stage.
-LDSymbol &HexagonRelocator::defineSymbolforCopyReloc(
- IRBuilder &pBuilder, const ResolveInfo &pSym, HexagonLDBackend &pTarget) {
+LDSymbol& HexagonRelocator::defineSymbolforCopyReloc(
+ IRBuilder& pBuilder,
+ const ResolveInfo& pSym,
+ HexagonLDBackend& pTarget) {
// get or create corresponding BSS LDSection
- LDSection *bss_sect_hdr = NULL;
- ELFFileFormat *file_format = pTarget.getOutputFormat();
+ LDSection* bss_sect_hdr = NULL;
+ ELFFileFormat* file_format = pTarget.getOutputFormat();
if (ResolveInfo::ThreadLocal == pSym.type())
bss_sect_hdr = &file_format->getTBSS();
else
bss_sect_hdr = &file_format->getBSS();
// get or create corresponding BSS SectionData
- assert(NULL != bss_sect_hdr);
- SectionData *bss_section = NULL;
+ assert(bss_sect_hdr != NULL);
+ SectionData* bss_section = NULL;
if (bss_sect_hdr->hasSectionData())
bss_section = bss_sect_hdr->getSectionData();
else
@@ -418,36 +428,43 @@
uint32_t addralign = config().targets().bitclass() / 8;
// allocate space in BSS for the copy symbol
- Fragment *frag = new FillFragment(0x0, 1, pSym.size());
+ Fragment* frag = new FillFragment(0x0, 1, pSym.size());
uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_section, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
- ResolveInfo::Binding binding = (ResolveInfo::Binding) pSym.binding();
+ ResolveInfo::Binding binding = (ResolveInfo::Binding)pSym.binding();
if (binding == ResolveInfo::Weak)
binding = ResolveInfo::Global;
// Define the copy symbol in the bss section and resolve it
- LDSymbol *cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(), (ResolveInfo::Type) pSym.type(), ResolveInfo::Define,
- binding, pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0), (ResolveInfo::Visibility) pSym.other());
+ LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// output all other alias symbols if any
- Module &pModule = pBuilder.getModule();
- Module::AliasList *alias_list = pModule.getAliasList(pSym);
- if (NULL != alias_list) {
+ Module& pModule = pBuilder.getModule();
+ Module::AliasList* alias_list = pModule.getAliasList(pSym);
+ if (alias_list != NULL) {
Module::alias_iterator it, it_e = alias_list->end();
for (it = alias_list->begin(); it != it_e; ++it) {
- const ResolveInfo *alias = *it;
+ const ResolveInfo* alias = *it;
if (alias != &pSym && alias->isDyn()) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- alias->name(), (ResolveInfo::Type) alias->type(),
- ResolveInfo::Define, binding, alias->size(), // size
- 0x0, // value
+ alias->name(),
+ (ResolveInfo::Type)alias->type(),
+ ResolveInfo::Define,
+ binding,
+ alias->size(), // size
+ 0x0, // value
FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility) alias->other());
+ (ResolveInfo::Visibility)alias->other());
}
}
}
@@ -455,20 +472,19 @@
return *cpy_sym;
}
-void HexagonRelocator::partialScanRelocation(Relocation &pReloc,
- Module &pModule,
- const LDSection &pSection) {
+void HexagonRelocator::partialScanRelocation(Relocation& pReloc,
+ Module& pModule) {
pReloc.updateAddend();
// if we meet a section symbol
if (pReloc.symInfo()->type() == ResolveInfo::Section) {
- LDSymbol *input_sym = pReloc.symInfo()->outSymbol();
+ LDSymbol* input_sym = pReloc.symInfo()->outSymbol();
// 1. update the relocation target offset
assert(input_sym->hasFragRef());
// 2. get the output LDSection which the symbol defined in
- const LDSection &out_sect =
+ const LDSection& out_sect =
input_sym->fragRef()->frag()->getParent()->getSection();
- ResolveInfo *sym_info =
+ ResolveInfo* sym_info =
pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
// set relocation target symbol to the output section symbol's resolveInfo
pReloc.setSymInfo(sym_info);
@@ -480,14 +496,14 @@
//=========================================//
// R_HEX_NONE
-Relocator::Result none(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result none(Relocation& pReloc, HexagonRelocator& pParent) {
return Relocator::OK;
}
-//R_HEX_32 and its class of relocations use only addend and symbol value
+// R_HEX_32 and its class of relocations use only addend and symbol value
// S + A : result is unsigned truncate.
// Exception: R_HEX_32_6_X : unsigned verify
-Relocator::Result applyAbs(Relocation &pReloc) {
+Relocator::Result applyAbs(Relocation& pReloc) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
uint32_t result = (uint32_t)(S + A);
@@ -497,54 +513,53 @@
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_LO16:
- bitMask = 0x00c03fff;
- break;
+ case llvm::ELF::R_HEX_LO16:
+ bitMask = 0x00c03fff;
+ break;
- case llvm::ELF::R_HEX_HI16:
- shift = 16;
- bitMask = 0x00c03fff;
- break;
+ case llvm::ELF::R_HEX_HI16:
+ shift = 16;
+ bitMask = 0x00c03fff;
+ break;
- case llvm::ELF::R_HEX_32:
- bitMask = 0xffffffff;
- break;
+ case llvm::ELF::R_HEX_32:
+ bitMask = 0xffffffff;
+ break;
- case llvm::ELF::R_HEX_16:
- bitMask = 0x0000ffff;
- alignment = 2;
- break;
+ case llvm::ELF::R_HEX_16:
+ bitMask = 0x0000ffff;
+ alignment = 2;
+ break;
- case llvm::ELF::R_HEX_8:
- bitMask = 0x000000ff;
- alignment = 1;
- break;
+ case llvm::ELF::R_HEX_8:
+ bitMask = 0x000000ff;
+ alignment = 1;
+ break;
- case llvm::ELF::R_HEX_12_X:
- bitMask = 0x000007e0;
- break;
+ case llvm::ELF::R_HEX_12_X:
+ bitMask = 0x000007e0;
+ break;
- case llvm::ELF::R_HEX_32_6_X:
- bitMask = 0xfff3fff;
- shift = 6;
- effectiveBits = 26;
- break;
+ case llvm::ELF::R_HEX_32_6_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ effectiveBits = 26;
+ break;
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- bitMask = FINDBITMASK(pReloc.target());
- break;
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ break;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
-
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (result % alignment != 0))
@@ -562,11 +577,11 @@
return Relocator::OK;
}
-//R_HEX_B22_PCREL and its class of relocations, use
+// R_HEX_B22_PCREL and its class of relocations, use
// S + A - P : result is signed verify.
// Exception: R_HEX_B32_PCREL_X : signed truncate
// Another Exception: R_HEX_6_PCREL_X is unsigned truncate
-Relocator::Result applyRel(Relocation &pReloc, int64_t pResult) {
+Relocator::Result applyRel(Relocation& pReloc, int64_t pResult) {
uint32_t bitMask = 0;
uint32_t effectiveBits = 0;
uint32_t alignment = 1;
@@ -574,92 +589,92 @@
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_B22_PCREL:
- bitMask = 0x01ff3ffe;
- effectiveBits = 22;
- alignment = 4;
- shift = 2;
- break;
+ case llvm::ELF::R_HEX_B22_PCREL:
+ bitMask = 0x01ff3ffe;
+ effectiveBits = 22;
+ alignment = 4;
+ shift = 2;
+ break;
- case llvm::ELF::R_HEX_B15_PCREL:
- bitMask = 0x00df20fe;
- effectiveBits = 15;
- alignment = 4;
- shift = 2;
- break;
+ case llvm::ELF::R_HEX_B15_PCREL:
+ bitMask = 0x00df20fe;
+ effectiveBits = 15;
+ alignment = 4;
+ shift = 2;
+ break;
- case llvm::ELF::R_HEX_B7_PCREL:
- bitMask = 0x00001f18;
- effectiveBits = 7;
- alignment = 4;
- shift = 2;
- break;
+ case llvm::ELF::R_HEX_B7_PCREL:
+ bitMask = 0x00001f18;
+ effectiveBits = 7;
+ alignment = 4;
+ shift = 2;
+ break;
- case llvm::ELF::R_HEX_B13_PCREL:
- bitMask = 0x00202ffe;
- effectiveBits = 13;
- alignment = 4;
- shift = 2;
- break;
+ case llvm::ELF::R_HEX_B13_PCREL:
+ bitMask = 0x00202ffe;
+ effectiveBits = 13;
+ alignment = 4;
+ shift = 2;
+ break;
- case llvm::ELF::R_HEX_B9_PCREL:
- bitMask = 0x003000fe;
- effectiveBits = 9;
- alignment = 4;
- shift = 2;
- break;
+ case llvm::ELF::R_HEX_B9_PCREL:
+ bitMask = 0x003000fe;
+ effectiveBits = 9;
+ alignment = 4;
+ shift = 2;
+ break;
- case llvm::ELF::R_HEX_B32_PCREL_X:
- bitMask = 0xfff3fff;
- shift = 6;
- break;
+ case llvm::ELF::R_HEX_B32_PCREL_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ break;
- case llvm::ELF::R_HEX_B22_PCREL_X:
- bitMask = 0x01ff3ffe;
- effectiveBits = 22;
- pResult &= 0x3f;
- break;
+ case llvm::ELF::R_HEX_B22_PCREL_X:
+ bitMask = 0x01ff3ffe;
+ effectiveBits = 22;
+ pResult &= 0x3f;
+ break;
- case llvm::ELF::R_HEX_B15_PCREL_X:
- bitMask = 0x00df20fe;
- effectiveBits = 15;
- pResult &= 0x3f;
- break;
+ case llvm::ELF::R_HEX_B15_PCREL_X:
+ bitMask = 0x00df20fe;
+ effectiveBits = 15;
+ pResult &= 0x3f;
+ break;
- case llvm::ELF::R_HEX_B13_PCREL_X:
- bitMask = 0x00202ffe;
- effectiveBits = 13;
- pResult &= 0x3f;
- break;
+ case llvm::ELF::R_HEX_B13_PCREL_X:
+ bitMask = 0x00202ffe;
+ effectiveBits = 13;
+ pResult &= 0x3f;
+ break;
- case llvm::ELF::R_HEX_B9_PCREL_X:
- bitMask = 0x003000fe;
- effectiveBits = 9;
- pResult &= 0x3f;
- break;
+ case llvm::ELF::R_HEX_B9_PCREL_X:
+ bitMask = 0x003000fe;
+ effectiveBits = 9;
+ pResult &= 0x3f;
+ break;
- case llvm::ELF::R_HEX_B7_PCREL_X:
- bitMask = 0x00001f18;
- effectiveBits = 7;
- pResult &= 0x3f;
- break;
+ case llvm::ELF::R_HEX_B7_PCREL_X:
+ bitMask = 0x00001f18;
+ effectiveBits = 7;
+ pResult &= 0x3f;
+ break;
- case llvm::ELF::R_HEX_32_PCREL:
- bitMask = 0xffffffff;
- effectiveBits = 32;
- break;
+ case llvm::ELF::R_HEX_32_PCREL:
+ bitMask = 0xffffffff;
+ effectiveBits = 32;
+ break;
- case llvm::ELF::R_HEX_6_PCREL_X:
- // This is unique since it has a unsigned operand and its truncated
- bitMask = FINDBITMASK(pReloc.target());
- result = pReloc.addend() + pReloc.symValue() - pReloc.place();
- pReloc.target() |= ApplyMask<uint32_t>(bitMask, result);
- return Relocator::OK;
+ case llvm::ELF::R_HEX_6_PCREL_X:
+ // This is unique since it has a unsigned operand and its truncated
+ bitMask = FINDBITMASK(pReloc.target());
+ result = pReloc.addend() + pReloc.symValue() - pReloc.place();
+ pReloc.target() |= ApplyMask<uint32_t>(bitMask, result);
+ return Relocator::OK;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (pResult % alignment != 0))
@@ -673,17 +688,17 @@
return Relocator::Overflow;
}
- pReloc.target() |= (uint32_t) ApplyMask<int32_t>(bitMask, pResult);
+ pReloc.target() |= (uint32_t)ApplyMask<int32_t>(bitMask, pResult);
return Relocator::OK;
}
-Relocator::Result relocAbs(Relocation &pReloc, HexagonRelocator &pParent) {
- ResolveInfo *rsym = pReloc.symInfo();
+Relocator::Result relocAbs(Relocation& pReloc, HexagonRelocator& pParent) {
+ ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocation* rel_entry = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != rel_entry);
+ bool has_dyn_rel = (rel_entry != NULL);
// if the flag of target section is not ALLOC, we eprform only static
// relocation.
@@ -717,22 +732,22 @@
return applyAbs(pReloc);
}
-Relocator::Result relocPCREL(Relocation &pReloc, HexagonRelocator &pParent) {
- ResolveInfo *rsym = pReloc.symInfo();
+Relocator::Result relocPCREL(Relocation& pReloc, HexagonRelocator& pParent) {
+ ResolveInfo* rsym = pReloc.symInfo();
int64_t result;
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord P = pReloc.place();
- FragmentRef &target_fragref = pReloc.targetRef();
- Fragment *target_frag = target_fragref.frag();
- LDSection &target_sect = target_frag->getParent()->getSection();
+ FragmentRef& target_fragref = pReloc.targetRef();
+ Fragment* target_frag = target_fragref.frag();
+ LDSection& target_sect = target_frag->getParent()->getSection();
result = (int64_t)(S + A - P);
// for relocs inside non ALLOC, just apply
- if (0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0) {
return applyRel(pReloc, result);
}
@@ -749,7 +764,7 @@
}
// R_HEX_GPREL16_0 and its class : Unsigned Verify
-Relocator::Result relocGPREL(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGPREL(Relocation& pReloc, HexagonRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord GP = pParent.getTarget().getGP();
@@ -759,28 +774,28 @@
uint32_t alignment = 1;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GPREL16_0:
- break;
+ case llvm::ELF::R_HEX_GPREL16_0:
+ break;
- case llvm::ELF::R_HEX_GPREL16_1:
- shift = 1;
- alignment = 2;
- break;
+ case llvm::ELF::R_HEX_GPREL16_1:
+ shift = 1;
+ alignment = 2;
+ break;
- case llvm::ELF::R_HEX_GPREL16_2:
- shift = 2;
- alignment = 4;
- break;
+ case llvm::ELF::R_HEX_GPREL16_2:
+ shift = 2;
+ alignment = 4;
+ break;
- case llvm::ELF::R_HEX_GPREL16_3:
- shift = 3;
- alignment = 8;
- break;
+ case llvm::ELF::R_HEX_GPREL16_3:
+ shift = 3;
+ alignment = 8;
+ break;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
uint32_t range = 1 << 16;
@@ -799,8 +814,8 @@
}
// R_HEX_PLT_B22_PCREL: PLT(S) + A - P
-Relocator::Result relocPLTB22PCREL(Relocation &pReloc,
- HexagonRelocator &pParent) {
+Relocator::Result relocPLTB22PCREL(Relocation& pReloc,
+ HexagonRelocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & HexagonRelocator::ReservePLT))
@@ -814,22 +829,21 @@
return Relocator::OK;
}
-//R_HEX_GOT_LO16 and its class : (G) Signed Truncate
-//Exception: R_HEX_GOT_16(_X): signed verify
+// R_HEX_GOT_LO16 and its class : (G) Signed Truncate
+// Exception: R_HEX_GOT_16(_X): signed verify
// Exception: R_HEX_GOT_11_X : unsigned truncate
-Relocator::Result relocGOT(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGOT(Relocation& pReloc, HexagonRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & HexagonRelocator::ReserveGOT)) {
return Relocator::BadReloc;
}
// set got entry value if needed
- HexagonGOTEntry *got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ HexagonGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
+ assert(got_entry != NULL);
if (HexagonRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
- Relocator::Address GOT_S =
- helper_get_GOT_address(*pReloc.symInfo(), pParent);
+ Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
Relocator::Address GOT = pParent.getTarget().getGOTSymbolAddr();
int32_t result = (int32_t)(GOT_S - GOT);
uint32_t effectiveBits = 0;
@@ -839,45 +853,45 @@
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GOT_LO16:
- bitMask = 0x00c03fff;
- break;
+ case llvm::ELF::R_HEX_GOT_LO16:
+ bitMask = 0x00c03fff;
+ break;
- case llvm::ELF::R_HEX_GOT_HI16:
- bitMask = 0x00c03fff;
- shift = 16;
- alignment = 4;
- break;
+ case llvm::ELF::R_HEX_GOT_HI16:
+ bitMask = 0x00c03fff;
+ shift = 16;
+ alignment = 4;
+ break;
- case llvm::ELF::R_HEX_GOT_32:
- bitMask = 0xffffffff;
- break;
+ case llvm::ELF::R_HEX_GOT_32:
+ bitMask = 0xffffffff;
+ break;
- case llvm::ELF::R_HEX_GOT_16:
- bitMask = FINDBITMASK(pReloc.target());
- effectiveBits = 16;
- break;
+ case llvm::ELF::R_HEX_GOT_16:
+ bitMask = FINDBITMASK(pReloc.target());
+ effectiveBits = 16;
+ break;
- case llvm::ELF::R_HEX_GOT_32_6_X:
- bitMask = 0xfff3fff;
- shift = 6;
- break;
+ case llvm::ELF::R_HEX_GOT_32_6_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ break;
- case llvm::ELF::R_HEX_GOT_16_X:
- bitMask = FINDBITMASK(pReloc.target());
- effectiveBits = 6;
- break;
+ case llvm::ELF::R_HEX_GOT_16_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ effectiveBits = 6;
+ break;
- case llvm::ELF::R_HEX_GOT_11_X:
- bitMask = FINDBITMASK(pReloc.target());
- result_u = GOT_S - GOT;
- pReloc.target() |= ApplyMask<uint32_t>(bitMask, result_u);
- return Relocator::OK;
+ case llvm::ELF::R_HEX_GOT_11_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ result_u = GOT_S - GOT;
+ pReloc.target() |= ApplyMask<uint32_t>(bitMask, result_u);
+ return Relocator::OK;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (result % alignment != 0))
@@ -896,7 +910,7 @@
// R_HEX_GOTREL_LO16: and its class of relocs
// (S + A - GOT) : Signed Truncate
-Relocator::Result relocGOTREL(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGOTREL(Relocation& pReloc, HexagonRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::Address GOT = pParent.getTarget().getGOTSymbolAddr();
@@ -908,34 +922,34 @@
uint32_t result = (uint32_t)(S + A - GOT);
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GOTREL_LO16:
- bitMask = 0x00c03fff;
- break;
+ case llvm::ELF::R_HEX_GOTREL_LO16:
+ bitMask = 0x00c03fff;
+ break;
- case llvm::ELF::R_HEX_GOTREL_HI16:
- bitMask = 0x00c03fff;
- shift = 16;
- alignment = 4;
- break;
+ case llvm::ELF::R_HEX_GOTREL_HI16:
+ bitMask = 0x00c03fff;
+ shift = 16;
+ alignment = 4;
+ break;
- case llvm::ELF::R_HEX_GOTREL_32:
- bitMask = 0xffffffff;
- break;
+ case llvm::ELF::R_HEX_GOTREL_32:
+ bitMask = 0xffffffff;
+ break;
- case llvm::ELF::R_HEX_GOTREL_32_6_X:
- bitMask = 0x0fff3fff;
- shift = 6;
- break;
+ case llvm::ELF::R_HEX_GOTREL_32_6_X:
+ bitMask = 0x0fff3fff;
+ shift = 6;
+ break;
- case llvm::ELF::R_HEX_GOTREL_16_X:
- case llvm::ELF::R_HEX_GOTREL_11_X:
- bitMask = FINDBITMASK(pReloc.target());
- break;
+ case llvm::ELF::R_HEX_GOTREL_16_X:
+ case llvm::ELF::R_HEX_GOTREL_11_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ break;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if (result % alignment != 0)
@@ -947,6 +961,8 @@
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation &pReloc, HexagonRelocator &pParent) {
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, HexagonRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonRelocator.h b/lib/Target/Hexagon/HexagonRelocator.h
index 7f50f31..2a7ee54 100644
--- a/lib/Target/Hexagon/HexagonRelocator.h
+++ b/lib/Target/Hexagon/HexagonRelocator.h
@@ -6,33 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONRELOCATOR_H
-#define TARGET_HEXAGON_HEXAGONRELOCATOR_H
+#ifndef TARGET_HEXAGON_HEXAGONRELOCATOR_H_
+#define TARGET_HEXAGON_HEXAGONRELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "HexagonLDBackend.h"
namespace mcld {
-class ResolveInfo;
class LinkerConfig;
+class ResolveInfo;
/** \class HexagonRelocator
* \brief HexagonRelocator creates and destroys the Hexagon relocations.
*
*/
-class HexagonRelocator : public Relocator
-{
-public:
+class HexagonRelocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, PLTEntryBase> SymPLTMap;
typedef KeyEntryMap<ResolveInfo, HexagonGOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, HexagonGOTEntry> SymGOTPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
-public:
+ public:
/** \enum ReservedEntryType
* \brief The reserved entry type of reserved space in ResolveInfo.
*
@@ -52,10 +51,10 @@
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -63,10 +62,7 @@
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
HexagonRelocator(HexagonLDBackend& pParent, const LinkerConfig& pConfig);
~HexagonRelocator();
@@ -87,32 +83,37 @@
// Handle partial linking
void partialScanRelocation(Relocation& pReloc,
- Module& pModule,
- const LDSection& pSection);
+ Module& pModule);
- HexagonLDBackend& getTarget()
- { return m_Target; }
+ HexagonLDBackend& getTarget() { return m_Target; }
- const HexagonLDBackend& getTarget() const
- { return m_Target; }
+ const HexagonLDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
-protected:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const { return 0; }
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset) {}
+
+ protected:
/// addCopyReloc - add a copy relocation into .rela.dyn for pSym
/// @param pSym - A resolved copy symbol that defined in BSS section
void addCopyReloc(ResolveInfo& pSym, HexagonLDBackend& pTarget);
@@ -124,7 +125,7 @@
const ResolveInfo& pSym,
HexagonLDBackend& pTarget);
-private:
+ private:
virtual void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -142,7 +143,6 @@
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_HEXAGON_HEXAGONRELOCATOR_H_
diff --git a/lib/Target/Hexagon/HexagonTargetMachine.cpp b/lib/Target/Hexagon/HexagonTargetMachine.cpp
deleted file mode 100644
index 33067b9..0000000
--- a/lib/Target/Hexagon/HexagonTargetMachine.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- HexagonTargetMachine.cpp -------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "HexagonTargetMachine.h"
-#include "Hexagon.h"
-#include <mcld/Support/TargetRegistry.h>
-
-extern "C" void MCLDInitializeHexagonLDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::HexagonTargetMachine>
- X(mcld::TheHexagonTarget);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// HexagonTargetMachine
-//===----------------------------------------------------------------------===//
-HexagonTargetMachine::HexagonTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
diff --git a/lib/Target/Hexagon/HexagonTargetMachine.h b/lib/Target/Hexagon/HexagonTargetMachine.h
deleted file mode 100644
index 5ebf434..0000000
--- a/lib/Target/Hexagon/HexagonTargetMachine.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- HexagonTargetMachine.h ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
-#define TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
-#include "Hexagon.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class HexagonTargetMachine : public MCLDTargetMachine
-{
-public:
- HexagonTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string &pTriple);
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp b/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
index e0d660b..ef63225 100644
--- a/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
+++ b/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
@@ -1,4 +1,4 @@
-//===- HexagonTargetInfo.cpp -----------------------------------------------===//
+//===- HexagonTargetInfo.cpp ----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -18,5 +18,4 @@
mcld::RegisterTarget<llvm::Triple::hexagon> X(TheHexagonTarget, "hexagon");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/Mips/Android.mk b/lib/Target/Mips/Android.mk
index 541f5bb..0bb2d40 100644
--- a/lib/Target/Mips/Android.mk
+++ b/lib/Target/Mips/Android.mk
@@ -3,17 +3,14 @@
mcld_mips_target_SRC_FILES := \
MipsDiagnostic.cpp \
MipsELFDynamic.cpp \
- MipsELFMCLinker.cpp \
MipsEmulation.cpp \
MipsGNUInfo.cpp \
MipsGOT.cpp \
MipsGOTPLT.cpp \
MipsLA25Stub.cpp \
MipsLDBackend.cpp \
- MipsMCLinker.cpp \
MipsPLT.cpp \
- MipsRelocator.cpp \
- MipsTargetMachine.cpp
+ MipsRelocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/Mips/Mips.h b/lib/Target/Mips/Mips.h
index c3fe7a2..9841655 100644
--- a/lib/Target/Mips/Mips.h
+++ b/lib/Target/Mips/Mips.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPS_H
-#define TARGET_MIPS_MIPS_H
+#ifndef TARGET_MIPS_MIPS_H_
+#define TARGET_MIPS_MIPS_H_
namespace mcld {
@@ -16,6 +16,6 @@
extern Target TheMipselTarget;
extern Target TheMips64elTarget;
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPS_H_
diff --git a/lib/Target/Mips/MipsDiagnostic.cpp b/lib/Target/Mips/MipsDiagnostic.cpp
index e03ea3c..e4534f8 100644
--- a/lib/Target/Mips/MipsDiagnostic.cpp
+++ b/lib/Target/Mips/MipsDiagnostic.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "Mips.h"
namespace {
@@ -17,12 +17,11 @@
// MipsDiagnostic
//===----------------------------------------------------------------------===//
mcld::DiagnosticLineInfo* createMipsDiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new mcld::DWARFLineInfo();
}
-} // namespace of mcld
+} // anonymous namespace
//===----------------------------------------------------------------------===//
// InitializeMipsDiagnostic
diff --git a/lib/Target/Mips/MipsELFDynamic.cpp b/lib/Target/Mips/MipsELFDynamic.cpp
index b532b03..c732f36 100644
--- a/lib/Target/Mips/MipsELFDynamic.cpp
+++ b/lib/Target/Mips/MipsELFDynamic.cpp
@@ -6,27 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/ELF.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/Target/GNULDBackend.h"
#include "MipsELFDynamic.h"
#include "MipsLDBackend.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
MipsELFDynamic::MipsELFDynamic(const MipsGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig),
- m_pParent(pParent),
- m_pConfig(pConfig)
-{
+ : ELFDynamic(pParent, pConfig), m_pParent(pParent), m_pConfig(pConfig) {
}
-void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
@@ -41,8 +38,7 @@
reserveOne(llvm::ELF::DT_MIPS_PLTGOT);
}
-void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
@@ -57,8 +53,7 @@
applyOne(llvm::ELF::DT_MIPS_PLTGOT, pFormat.getGOTPLT().addr());
}
-size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const {
if (!pFormat.hasDynSymTab())
return 0;
@@ -66,29 +61,28 @@
return dynsym.size() / symbolSize();
}
-size_t MipsELFDynamic::getGotSym(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getGotSym(const ELFFileFormat& pFormat) const {
if (!pFormat.hasGOT())
return 0;
return getSymTabNum(pFormat) - m_pParent.getGOT().getGlobalNum();
}
-size_t MipsELFDynamic::getLocalGotNum(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getLocalGotNum(const ELFFileFormat& pFormat) const {
if (!pFormat.hasGOT())
return 0;
return m_pParent.getGOT().getLocalNum();
}
-uint64_t MipsELFDynamic::getBaseAddress()
-{
+uint64_t MipsELFDynamic::getBaseAddress() {
if (LinkerConfig::Exec != m_pConfig.codeGenType())
return 0;
ELFSegmentFactory::const_iterator baseSeg =
- m_pParent.elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
+ m_pParent.elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
return m_pParent.elfSegmentTable().end() == baseSeg ? 0 : (*baseSeg)->vaddr();
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsELFDynamic.h b/lib/Target/Mips/MipsELFDynamic.h
index ff0666e..f51d6bc 100644
--- a/lib/Target/Mips/MipsELFDynamic.h
+++ b/lib/Target/Mips/MipsELFDynamic.h
@@ -6,25 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSELFDYNAMIC_H
-#define TARGET_MIPS_MIPSELFDYNAMIC_H
+#ifndef TARGET_MIPS_MIPSELFDYNAMIC_H_
+#define TARGET_MIPS_MIPSELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class MipsGNULDBackend;
-class MipsELFDynamic : public ELFDynamic
-{
-public:
+class MipsELFDynamic : public ELFDynamic {
+ public:
MipsELFDynamic(const MipsGNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
const MipsGNULDBackend& m_pParent;
const LinkerConfig& m_pConfig;
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
@@ -34,6 +33,6 @@
uint64_t getBaseAddress();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSELFDYNAMIC_H_
diff --git a/lib/Target/Mips/MipsELFMCLinker.cpp b/lib/Target/Mips/MipsELFMCLinker.cpp
deleted file mode 100644
index 077177a..0000000
--- a/lib/Target/Mips/MipsELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- MipsELFMCLinker.cpp ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "MipsELFMCLinker.h"
-
-using namespace mcld;
-
-MipsELFMCLinker::MipsELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-MipsELFMCLinker::~MipsELFMCLinker()
-{
-}
-
diff --git a/lib/Target/Mips/MipsELFMCLinker.h b/lib/Target/Mips/MipsELFMCLinker.h
deleted file mode 100644
index c0a2dfa..0000000
--- a/lib/Target/Mips/MipsELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- MipsELFMCLinker.h --------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSELFMCLINKER_H
-#define TARGET_MIPS_MIPSELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class MipsELFMCLinker
- * \brief MipsELFMCLinker sets up the environment for linking.
- */
-class MipsELFMCLinker : public ELFMCLinker
-{
-public:
- MipsELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~MipsELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/Mips/MipsEmulation.cpp b/lib/Target/Mips/MipsEmulation.cpp
index 5e5d192..416e3d7 100644
--- a/lib/Target/Mips/MipsEmulation.cpp
+++ b/lib/Target/Mips/MipsEmulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -42,8 +41,7 @@
//===----------------------------------------------------------------------===//
// emulateMipsLD - the help function to emulate Mips ld
//===----------------------------------------------------------------------===//
-bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -56,7 +54,7 @@
return MCLDEmulateMipsELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// MipsEmulation
diff --git a/lib/Target/Mips/MipsGNUInfo.cpp b/lib/Target/Mips/MipsGNUInfo.cpp
index 521a800..132e9c3 100644
--- a/lib/Target/Mips/MipsGNUInfo.cpp
+++ b/lib/Target/Mips/MipsGNUInfo.cpp
@@ -14,41 +14,33 @@
// MipsGNUInfo
//===----------------------------------------------------------------------===//
MipsGNUInfo::MipsGNUInfo(const llvm::Triple& pTriple)
- : GNUInfo(pTriple),
- m_ABIVersion(0),
- m_PICFlags(0)
-{}
+ : GNUInfo(pTriple), m_ABIVersion(0), m_PICFlags(0) {
+}
-void MipsGNUInfo::setABIVersion(uint8_t ver)
-{
+void MipsGNUInfo::setABIVersion(uint8_t ver) {
m_ABIVersion = ver;
}
-void MipsGNUInfo::setPICFlags(uint64_t flags)
-{
+void MipsGNUInfo::setPICFlags(uint64_t flags) {
m_PICFlags = flags;
}
-uint32_t MipsGNUInfo::machine() const
-{
+uint32_t MipsGNUInfo::machine() const {
return llvm::ELF::EM_MIPS;
}
-uint8_t MipsGNUInfo::ABIVersion() const
-{
+uint8_t MipsGNUInfo::ABIVersion() const {
return m_ABIVersion;
}
-uint64_t MipsGNUInfo::defaultTextSegmentAddr() const
-{
+uint64_t MipsGNUInfo::defaultTextSegmentAddr() const {
if (m_Triple.isArch32Bit())
return 0x400000;
else
return 0x120000000ull;
}
-uint64_t MipsGNUInfo::flags() const
-{
+uint64_t MipsGNUInfo::flags() const {
uint64_t val = llvm::ELF::EF_MIPS_NOREORDER | m_PICFlags;
if (m_Triple.isArch32Bit())
@@ -59,19 +51,16 @@
return val;
}
-const char* MipsGNUInfo::entry() const
-{
+const char* MipsGNUInfo::entry() const {
return "__start";
}
-const char* MipsGNUInfo::dyld() const
-{
+const char* MipsGNUInfo::dyld() const {
return m_Triple.isArch32Bit() ? "/lib/ld.so.1" : "/lib64/ld.so.1";
}
-uint64_t MipsGNUInfo::abiPageSize() const
-{
+uint64_t MipsGNUInfo::abiPageSize() const {
return 0x10000;
}
-} // end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGNUInfo.h b/lib/Target/Mips/MipsGNUInfo.h
index 8b5d9b6..673c39a 100644
--- a/lib/Target/Mips/MipsGNUInfo.h
+++ b/lib/Target/Mips/MipsGNUInfo.h
@@ -6,17 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGNUINFO_H
-#define TARGET_MIPS_MIPSGNUINFO_H
-#include <llvm/Support/ELF.h>
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_MIPS_MIPSGNUINFO_H_
+#define TARGET_MIPS_MIPSGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
+#include <llvm/Support/ELF.h>
namespace mcld {
-class MipsGNUInfo : public GNUInfo
-{
-public:
- MipsGNUInfo(const llvm::Triple& pTriple);
+class MipsGNUInfo : public GNUInfo {
+ public:
+ explicit MipsGNUInfo(const llvm::Triple& pTriple);
void setABIVersion(uint8_t ver);
void setPICFlags(uint64_t flags);
@@ -30,11 +29,11 @@
const char* dyld() const;
uint64_t abiPageSize() const;
-private:
+ private:
uint8_t m_ABIVersion;
uint64_t m_PICFlags;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSGNUINFO_H_
diff --git a/lib/Target/Mips/MipsGOT.cpp b/lib/Target/Mips/MipsGOT.cpp
index dddf12b..85d89c7 100644
--- a/lib/Target/Mips/MipsGOT.cpp
+++ b/lib/Target/Mips/MipsGOT.cpp
@@ -7,55 +7,49 @@
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
-#include <llvm/Support/ELF.h>
-
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/OutputRelocSection.h"
#include "MipsGOT.h"
#include "MipsRelocator.h"
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
+
namespace {
- const uint32_t Mips32ModulePtr = 1 << 31;
- const uint64_t Mips64ModulePtr = 1ull << 63;
- const size_t MipsGOT0Num = 2;
- const size_t MipsGOTGpOffset = 0x7FF0;
- const size_t MipsGOTSize = MipsGOTGpOffset + 0x7FFF;
+const uint32_t Mips32ModulePtr = 1 << 31;
+const uint64_t Mips64ModulePtr = 1ull << 63;
+const size_t MipsGOT0Num = 2;
+const size_t MipsGOTGpOffset = 0x7FF0;
+const size_t MipsGOTSize = MipsGOTGpOffset + 0x7FFF;
}
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsGOT::GOTMultipart
//===----------------------------------------------------------------------===//
MipsGOT::GOTMultipart::GOTMultipart(size_t local, size_t global)
- : m_LocalNum(local),
- m_GlobalNum(global),
- m_ConsumedLocal(0),
- m_ConsumedGlobal(0),
- m_pLastLocal(NULL),
- m_pLastGlobal(NULL)
-{
+ : m_LocalNum(local),
+ m_GlobalNum(global),
+ m_ConsumedLocal(0),
+ m_ConsumedGlobal(0),
+ m_pLastLocal(NULL),
+ m_pLastGlobal(NULL) {
}
-bool MipsGOT::GOTMultipart::isConsumed() const
-{
- return m_LocalNum == m_ConsumedLocal &&
- m_GlobalNum == m_ConsumedGlobal;
+bool MipsGOT::GOTMultipart::isConsumed() const {
+ return m_LocalNum == m_ConsumedLocal && m_GlobalNum == m_ConsumedGlobal;
}
-void MipsGOT::GOTMultipart::consumeLocal()
-{
- assert(m_ConsumedLocal < m_LocalNum &&
- "Consumed too many local GOT entries");
+void MipsGOT::GOTMultipart::consumeLocal() {
+ assert(m_ConsumedLocal < m_LocalNum && "Consumed too many local GOT entries");
++m_ConsumedLocal;
m_pLastLocal = m_pLastLocal->getNextNode();
}
-void MipsGOT::GOTMultipart::consumeGlobal()
-{
+void MipsGOT::GOTMultipart::consumeGlobal() {
assert(m_ConsumedGlobal < m_GlobalNum &&
"Consumed too many global GOT entries");
++m_ConsumedGlobal;
@@ -66,15 +60,12 @@
// MipsGOT::LocalEntry
//===----------------------------------------------------------------------===//
MipsGOT::LocalEntry::LocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord addend, bool isGot16)
- : m_pInfo(pInfo),
- m_Addend(addend),
- m_IsGot16(isGot16)
-{
+ Relocation::DWord addend,
+ bool isGot16)
+ : m_pInfo(pInfo), m_Addend(addend), m_IsGot16(isGot16) {
}
-bool MipsGOT::LocalEntry::operator<(const LocalEntry &O) const
-{
+bool MipsGOT::LocalEntry::operator<(const LocalEntry& O) const {
if (m_pInfo != O.m_pInfo)
return m_pInfo < O.m_pInfo;
@@ -88,49 +79,42 @@
// MipsGOT
//===----------------------------------------------------------------------===//
MipsGOT::MipsGOT(LDSection& pSection)
- : GOT(pSection),
- m_pInput(NULL),
- m_CurrentGOTPart(0)
-{
+ : GOT(pSection), m_pInput(NULL), m_CurrentGOTPart(0) {
}
-uint64_t MipsGOT::getGPDispAddress() const
-{
+uint64_t MipsGOT::getGPDispAddress() const {
return addr() + MipsGOTGpOffset;
}
-void MipsGOT::reserve(size_t pNum)
-{
- for (size_t i = 0; i < pNum; i++)
+void MipsGOT::reserve(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
createEntry(0, m_SectionData);
}
-bool MipsGOT::hasGOT1() const
-{
+bool MipsGOT::hasGOT1() const {
return !m_MultipartList.empty();
}
-bool MipsGOT::hasMultipleGOT() const
-{
+bool MipsGOT::hasMultipleGOT() const {
return m_MultipartList.size() > 1;
}
-void MipsGOT::finalizeScanning(OutputRelocSection& pRelDyn)
-{
+void MipsGOT::finalizeScanning(OutputRelocSection& pRelDyn) {
for (MultipartListType::iterator it = m_MultipartList.begin();
- it != m_MultipartList.end(); ++it) {
+ it != m_MultipartList.end();
+ ++it) {
reserveHeader();
it->m_pLastLocal = &m_SectionData->back();
reserve(it->m_LocalNum);
it->m_pLastGlobal = &m_SectionData->back();
reserve(it->m_GlobalNum);
- if (it == m_MultipartList.begin())
+ if (it == m_MultipartList.begin()) {
// Reserve entries in the second part of the primary GOT.
// These entries correspond to the global symbols in all
// non-primary GOTs.
reserve(getGlobalNum() - it->m_GlobalNum);
- else {
+ } else {
// Reserve reldyn entries for R_MIPS_REL32 relocations
// for all global entries of secondary GOTs.
// FIXME: (simon) Do not count local entries for non-pic.
@@ -141,8 +125,7 @@
}
}
-bool MipsGOT::dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const
-{
+bool MipsGOT::dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const {
SymbolOrderMapType::const_iterator itX = m_SymbolOrderMap.find(pX);
SymbolOrderMapType::const_iterator itY = m_SymbolOrderMap.find(pY);
@@ -152,8 +135,7 @@
return itX == m_SymbolOrderMap.end() && itY != m_SymbolOrderMap.end();
}
-void MipsGOT::initGOTList()
-{
+void MipsGOT::initGOTList() {
m_SymbolOrderMap.clear();
m_MultipartList.clear();
@@ -167,29 +149,28 @@
m_InputLocalSymbols.clear();
}
-void MipsGOT::changeInput()
-{
+void MipsGOT::changeInput() {
m_MultipartList.back().m_Inputs.insert(m_pInput);
for (LocalSymbolSetType::iterator it = m_InputLocalSymbols.begin(),
end = m_InputLocalSymbols.end();
- it != end; ++it)
+ it != end;
+ ++it)
m_MergedLocalSymbols.insert(*it);
m_InputLocalSymbols.clear();
for (SymbolUniqueMapType::iterator it = m_InputGlobalSymbols.begin(),
end = m_InputGlobalSymbols.end();
- it != end; ++it)
+ it != end;
+ ++it)
m_MergedGlobalSymbols.insert(it->first);
m_InputGlobalSymbols.clear();
}
-bool MipsGOT::isGOTFull() const
-{
- uint64_t gotCount = MipsGOT0Num +
- m_MultipartList.back().m_LocalNum +
+bool MipsGOT::isGOTFull() const {
+ uint64_t gotCount = MipsGOT0Num + m_MultipartList.back().m_LocalNum +
m_MultipartList.back().m_GlobalNum;
gotCount += 1;
@@ -197,15 +178,15 @@
return gotCount * getEntrySize() > MipsGOTSize;
}
-void MipsGOT::split()
-{
+void MipsGOT::split() {
m_MergedLocalSymbols.clear();
m_MergedGlobalSymbols.clear();
size_t uniqueCount = 0;
for (SymbolUniqueMapType::const_iterator it = m_InputGlobalSymbols.begin(),
end = m_InputGlobalSymbols.end();
- it != end; ++it) {
+ it != end;
+ ++it) {
if (it->second)
++uniqueCount;
}
@@ -214,30 +195,27 @@
m_MultipartList.back().m_GlobalNum -= uniqueCount;
m_MultipartList.back().m_Inputs.erase(m_pInput);
- m_MultipartList.push_back(GOTMultipart(m_InputLocalSymbols.size(),
- m_InputGlobalSymbols.size()));
+ m_MultipartList.push_back(
+ GOTMultipart(m_InputLocalSymbols.size(), m_InputGlobalSymbols.size()));
m_MultipartList.back().m_Inputs.insert(m_pInput);
}
-void MipsGOT::initializeScan(const Input& pInput)
-{
+void MipsGOT::initializeScan(const Input& pInput) {
if (m_pInput == NULL) {
m_pInput = &pInput;
initGOTList();
- }
- else {
+ } else {
m_pInput = &pInput;
changeInput();
}
}
-void MipsGOT::finalizeScan(const Input& pInput)
-{
+void MipsGOT::finalizeScan(const Input& pInput) {
}
-bool MipsGOT::reserveLocalEntry(ResolveInfo& pInfo, int reloc,
- Relocation::DWord pAddend)
-{
+bool MipsGOT::reserveLocalEntry(ResolveInfo& pInfo,
+ int reloc,
+ Relocation::DWord pAddend) {
LocalEntry entry(&pInfo, pAddend, reloc == llvm::ELF::R_MIPS_GOT16);
if (m_InputLocalSymbols.count(entry))
@@ -261,8 +239,7 @@
return true;
}
-bool MipsGOT::reserveGlobalEntry(ResolveInfo& pInfo)
-{
+bool MipsGOT::reserveGlobalEntry(ResolveInfo& pInfo) {
if (m_InputGlobalSymbols.count(&pInfo))
return false;
@@ -285,14 +262,13 @@
return true;
}
-bool MipsGOT::isPrimaryGOTConsumed()
-{
+bool MipsGOT::isPrimaryGOTConsumed() {
return m_CurrentGOTPart > 0;
}
-Fragment* MipsGOT::consumeLocal()
-{
- assert(m_CurrentGOTPart < m_MultipartList.size() && "GOT number is out of range!");
+Fragment* MipsGOT::consumeLocal() {
+ assert(m_CurrentGOTPart < m_MultipartList.size() &&
+ "GOT number is out of range!");
if (m_MultipartList[m_CurrentGOTPart].isConsumed())
++m_CurrentGOTPart;
@@ -302,9 +278,9 @@
return m_MultipartList[m_CurrentGOTPart].m_pLastLocal;
}
-Fragment* MipsGOT::consumeGlobal()
-{
- assert(m_CurrentGOTPart < m_MultipartList.size() && "GOT number is out of range!");
+Fragment* MipsGOT::consumeGlobal() {
+ assert(m_CurrentGOTPart < m_MultipartList.size() &&
+ "GOT number is out of range!");
if (m_MultipartList[m_CurrentGOTPart].isConsumed())
++m_CurrentGOTPart;
@@ -314,11 +290,12 @@
return m_MultipartList[m_CurrentGOTPart].m_pLastGlobal;
}
-uint64_t MipsGOT::getGPAddr(const Input& pInput) const
-{
+uint64_t MipsGOT::getGPAddr(const Input& pInput) const {
uint64_t gotSize = 0;
- for (MultipartListType::const_iterator it = m_MultipartList.begin();
- it != m_MultipartList.end(); ++it) {
+ for (MultipartListType::const_iterator it = m_MultipartList.begin(),
+ ie = m_MultipartList.end();
+ it != ie;
+ ++it) {
if (it->m_Inputs.count(&pInput))
break;
@@ -331,13 +308,11 @@
}
uint64_t MipsGOT::getGPRelOffset(const Input& pInput,
- const Fragment& pEntry) const
-{
+ const Fragment& pEntry) const {
return addr() + pEntry.getOffset() - getGPAddr(pInput);
}
-void MipsGOT::recordGlobalEntry(const ResolveInfo* pInfo, Fragment* pEntry)
-{
+void MipsGOT::recordGlobalEntry(const ResolveInfo* pInfo, Fragment* pEntry) {
GotEntryKey key;
key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
@@ -345,10 +320,9 @@
m_GotGlobalEntriesMap[key] = pEntry;
}
-Fragment* MipsGOT::lookupGlobalEntry(const ResolveInfo* pInfo)
-{
+Fragment* MipsGOT::lookupGlobalEntry(const ResolveInfo* pInfo) {
GotEntryKey key;
- key.m_GOTPage= m_CurrentGOTPart;
+ key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
key.m_Addend = 0;
GotEntryMapType::iterator it = m_GotGlobalEntriesMap.find(key);
@@ -361,8 +335,7 @@
void MipsGOT::recordLocalEntry(const ResolveInfo* pInfo,
Relocation::DWord pAddend,
- Fragment* pEntry)
-{
+ Fragment* pEntry) {
GotEntryKey key;
key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
@@ -371,10 +344,9 @@
}
Fragment* MipsGOT::lookupLocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord pAddend)
-{
+ Relocation::DWord pAddend) {
GotEntryKey key;
- key.m_GOTPage= m_CurrentGOTPart;
+ key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
key.m_Addend = pAddend;
GotEntryMapType::iterator it = m_GotLocalEntriesMap.find(key);
@@ -385,31 +357,26 @@
return it->second;
}
-size_t MipsGOT::getLocalNum() const
-{
+size_t MipsGOT::getLocalNum() const {
assert(!m_MultipartList.empty() && "GOT is empty!");
return m_MultipartList[0].m_LocalNum + MipsGOT0Num;
}
-size_t MipsGOT::getGlobalNum() const
-{
+size_t MipsGOT::getGlobalNum() const {
return m_SymbolOrderMap.size();
}
//===----------------------------------------------------------------------===//
// Mips32GOT
//===----------------------------------------------------------------------===//
-Mips32GOT::Mips32GOT(LDSection& pSection)
- : MipsGOT(pSection)
-{}
+Mips32GOT::Mips32GOT(LDSection& pSection) : MipsGOT(pSection) {
+}
-void Mips32GOT::setEntryValue(Fragment* entry, uint64_t pValue)
-{
+void Mips32GOT::setEntryValue(Fragment* entry, uint64_t pValue) {
llvm::cast<Mips32GOTEntry>(entry)->setValue(pValue);
}
-uint64_t Mips32GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t Mips32GOT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
uint64_t result = 0;
@@ -421,18 +388,15 @@
return result;
}
-Fragment* Mips32GOT::createEntry(uint64_t pValue, SectionData* pParent)
-{
+Fragment* Mips32GOT::createEntry(uint64_t pValue, SectionData* pParent) {
return new Mips32GOTEntry(pValue, pParent);
}
-size_t Mips32GOT::getEntrySize() const
-{
+size_t Mips32GOT::getEntrySize() const {
return Mips32GOTEntry::EntrySize;
}
-void Mips32GOT::reserveHeader()
-{
+void Mips32GOT::reserveHeader() {
createEntry(0, m_SectionData);
createEntry(Mips32ModulePtr, m_SectionData);
}
@@ -440,17 +404,14 @@
//===----------------------------------------------------------------------===//
// Mips64GOT
//===----------------------------------------------------------------------===//
-Mips64GOT::Mips64GOT(LDSection& pSection)
- : MipsGOT(pSection)
-{}
+Mips64GOT::Mips64GOT(LDSection& pSection) : MipsGOT(pSection) {
+}
-void Mips64GOT::setEntryValue(Fragment* entry, uint64_t pValue)
-{
+void Mips64GOT::setEntryValue(Fragment* entry, uint64_t pValue) {
llvm::cast<Mips64GOTEntry>(entry)->setValue(pValue);
}
-uint64_t Mips64GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t Mips64GOT::emit(MemoryRegion& pRegion) {
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
uint64_t result = 0;
@@ -462,18 +423,17 @@
return result;
}
-Fragment* Mips64GOT::createEntry(uint64_t pValue, SectionData* pParent)
-{
+Fragment* Mips64GOT::createEntry(uint64_t pValue, SectionData* pParent) {
return new Mips64GOTEntry(pValue, pParent);
}
-size_t Mips64GOT::getEntrySize() const
-{
+size_t Mips64GOT::getEntrySize() const {
return Mips64GOTEntry::EntrySize;
}
-void Mips64GOT::reserveHeader()
-{
+void Mips64GOT::reserveHeader() {
createEntry(0, m_SectionData);
createEntry(Mips64ModulePtr, m_SectionData);
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGOT.h b/lib/Target/Mips/MipsGOT.h
index f5b213c..409347b 100644
--- a/lib/Target/Mips/MipsGOT.h
+++ b/lib/Target/Mips/MipsGOT.h
@@ -6,19 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGOT_H
-#define TARGET_MIPS_MIPSGOT_H
-#include <map>
-#include <vector>
+#ifndef TARGET_MIPS_MIPSGOT_H_
+#define TARGET_MIPS_MIPSGOT_H_
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
-
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Support/MemoryRegion.h>
#include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/DenseSet.h>
+
+#include <map>
#include <set>
+#include <vector>
namespace mcld {
@@ -30,10 +30,9 @@
/** \class MipsGOT
* \brief Mips Global Offset Table.
*/
-class MipsGOT : public GOT
-{
-public:
- MipsGOT(LDSection& pSection);
+class MipsGOT : public GOT {
+ public:
+ explicit MipsGOT(LDSection& pSection);
/// Assign value to the GOT entry.
virtual void setEntryValue(Fragment* entry, uint64_t pValue) = 0;
@@ -47,7 +46,8 @@
void initializeScan(const Input& pInput);
void finalizeScan(const Input& pInput);
- bool reserveLocalEntry(ResolveInfo& pInfo, int reloc,
+ bool reserveLocalEntry(ResolveInfo& pInfo,
+ int reloc,
Relocation::DWord pAddend);
bool reserveGlobalEntry(ResolveInfo& pInfo);
@@ -82,7 +82,7 @@
/// Compare two symbols to define order in the .dynsym.
bool dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const;
-protected:
+ protected:
/// Create GOT entry.
virtual Fragment* createEntry(uint64_t pValue, SectionData* pParent) = 0;
@@ -92,21 +92,20 @@
/// Reserve GOT header entries.
virtual void reserveHeader() = 0;
-private:
+ private:
/** \class GOTMultipart
* \brief GOTMultipart counts local and global entries in the GOT.
*/
- struct GOTMultipart
- {
- GOTMultipart(size_t local = 0, size_t global = 0);
+ struct GOTMultipart {
+ explicit GOTMultipart(size_t local = 0, size_t global = 0);
typedef llvm::DenseSet<const Input*> InputSetType;
- size_t m_LocalNum; ///< number of reserved local entries
- size_t m_GlobalNum; ///< number of reserved global entries
+ size_t m_LocalNum; ///< number of reserved local entries
+ size_t m_GlobalNum; ///< number of reserved global entries
- size_t m_ConsumedLocal; ///< consumed local entries
- size_t m_ConsumedGlobal; ///< consumed global entries
+ size_t m_ConsumedLocal; ///< consumed local entries
+ size_t m_ConsumedGlobal; ///< consumed global entries
Fragment* m_pLastLocal; ///< the last consumed local entry
Fragment* m_pLastGlobal; ///< the last consumed global entry
@@ -122,16 +121,16 @@
/** \class LocalEntry
* \brief LocalEntry local GOT entry descriptor.
*/
- struct LocalEntry
- {
+ struct LocalEntry {
const ResolveInfo* m_pInfo;
- Relocation::DWord m_Addend;
- bool m_IsGot16;
+ Relocation::DWord m_Addend;
+ bool m_IsGot16;
LocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord addend, bool isGot16);
+ Relocation::DWord addend,
+ bool isGot16);
- bool operator<(const LocalEntry &O) const;
+ bool operator<(const LocalEntry& O) const;
};
typedef std::vector<GOTMultipart> MultipartListType;
@@ -172,15 +171,13 @@
void split();
void reserve(size_t pNum);
-private:
- struct GotEntryKey
- {
+ private:
+ struct GotEntryKey {
size_t m_GOTPage;
const ResolveInfo* m_pInfo;
Relocation::DWord m_Addend;
- bool operator<(const GotEntryKey& key) const
- {
+ bool operator<(const GotEntryKey& key) const {
if (m_GOTPage != key.m_GOTPage)
return m_GOTPage < key.m_GOTPage;
@@ -199,12 +196,11 @@
/** \class Mips32GOT
* \brief Mips 32-bit Global Offset Table.
*/
-class Mips32GOT : public MipsGOT
-{
-public:
- Mips32GOT(LDSection& pSection);
+class Mips32GOT : public MipsGOT {
+ public:
+ explicit Mips32GOT(LDSection& pSection);
-private:
+ private:
typedef GOT::Entry<4> Mips32GOTEntry;
// MipsGOT
@@ -218,12 +214,11 @@
/** \class Mips64GOT
* \brief Mips 64-bit Global Offset Table.
*/
-class Mips64GOT : public MipsGOT
-{
-public:
- Mips64GOT(LDSection& pSection);
+class Mips64GOT : public MipsGOT {
+ public:
+ explicit Mips64GOT(LDSection& pSection);
-private:
+ private:
typedef GOT::Entry<8> Mips64GOTEntry;
// MipsGOT
@@ -234,7 +229,6 @@
virtual void reserveHeader();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_MIPS_MIPSGOT_H_
diff --git a/lib/Target/Mips/MipsGOTPLT.cpp b/lib/Target/Mips/MipsGOTPLT.cpp
index 1f65490..745b258 100644
--- a/lib/Target/Mips/MipsGOTPLT.cpp
+++ b/lib/Target/Mips/MipsGOTPLT.cpp
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
#include "MipsGOTPLT.h"
-namespace {
- typedef mcld::GOT::Entry<4> GOTPLTEntry;
+#include <llvm/Support/Casting.h>
- const size_t MipsGOTPLT0Num = 2;
+namespace {
+typedef mcld::GOT::Entry<4> GOTPLTEntry;
+
+const size_t MipsGOTPLT0Num = 2;
}
namespace mcld {
@@ -20,23 +21,19 @@
//===----------------------------------------------------------------------===//
// MipsGOTPLT
//===----------------------------------------------------------------------===//
-MipsGOTPLT::MipsGOTPLT(LDSection& pSection)
- : GOT(pSection)
-{
+MipsGOTPLT::MipsGOTPLT(LDSection& pSection) : GOT(pSection) {
// Create header's entries.
new GOTPLTEntry(0, m_SectionData);
new GOTPLTEntry(0, m_SectionData);
m_Last = ++m_SectionData->begin();
}
-void MipsGOTPLT::reserve(size_t pNum)
-{
- for (size_t i = 0; i < pNum; i++)
+void MipsGOTPLT::reserve(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
new GOTPLTEntry(0, m_SectionData);
}
-uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
uint64_t result = 0;
@@ -48,32 +45,28 @@
return result;
}
-Fragment* MipsGOTPLT::consume()
-{
+Fragment* MipsGOTPLT::consume() {
++m_Last;
assert(m_Last != m_SectionData->end() &&
"There is no reserved GOTPLT entries");
return &(*m_Last);
}
-bool MipsGOTPLT::hasGOT1() const
-{
+bool MipsGOTPLT::hasGOT1() const {
return m_SectionData->size() > MipsGOTPLT0Num;
}
-uint64_t MipsGOTPLT::getEntryAddr(size_t num) const
-{
+uint64_t MipsGOTPLT::getEntryAddr(size_t num) const {
return addr() + (MipsGOTPLT0Num + num) * GOTPLTEntry::EntrySize;
}
-void MipsGOTPLT::applyAllGOTPLT(uint64_t pltAddr)
-{
+void MipsGOTPLT::applyAllGOTPLT(uint64_t pltAddr) {
iterator it = begin();
- llvm::cast<GOTPLTEntry>(*it++).setValue(0); // PLT lazy resolver
- llvm::cast<GOTPLTEntry>(*it++).setValue(0); // Module pointer
+ llvm::cast<GOTPLTEntry>(*it++).setValue(0); // PLT lazy resolver
+ llvm::cast<GOTPLTEntry>(*it++).setValue(0); // Module pointer
for (; it != end(); ++it)
llvm::cast<GOTPLTEntry>(*it).setValue(pltAddr);
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGOTPLT.h b/lib/Target/Mips/MipsGOTPLT.h
index 94067fe..f5cd909 100644
--- a/lib/Target/Mips/MipsGOTPLT.h
+++ b/lib/Target/Mips/MipsGOTPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGOTPLT_H
-#define TARGET_MIPS_MIPSGOTPLT_H
+#ifndef TARGET_MIPS_MIPSGOTPLT_H_
+#define TARGET_MIPS_MIPSGOTPLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
namespace mcld {
@@ -20,10 +20,9 @@
/** \class MipsGOTPLT
* \brief Mips .got.plt section.
*/
-class MipsGOTPLT : public GOT
-{
-public:
- MipsGOTPLT(LDSection &pSection);
+class MipsGOTPLT : public GOT {
+ public:
+ explicit MipsGOTPLT(LDSection& pSection);
// hasGOT1 - return if this section has any GOT1 entry
bool hasGOT1() const;
@@ -36,15 +35,15 @@
void applyAllGOTPLT(uint64_t pltAddr);
-public:
+ public:
// GOT
void reserve(size_t pNum = 1);
-private:
+ private:
// the last consumed entry.
SectionData::iterator m_Last;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSGOTPLT_H_
diff --git a/lib/Target/Mips/MipsLA25Stub.cpp b/lib/Target/Mips/MipsLA25Stub.cpp
index fcbc011..3127b37 100644
--- a/lib/Target/Mips/MipsLA25Stub.cpp
+++ b/lib/Target/Mips/MipsLA25Stub.cpp
@@ -6,27 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ResolveInfo.h>
+#include "mcld/LD/ResolveInfo.h"
#include "MipsLA25Stub.h"
#include "MipsLDBackend.h"
namespace {
const uint32_t STUB[] = {
- 0x3c190000, // lui $25,%hi(func)
- 0x08000000, // j func
- 0x27390000, // add $25,$25,%lo(func)
- 0x00000000 // nop
+ 0x3c190000, // lui $25,%hi(func)
+ 0x08000000, // j func
+ 0x27390000, // add $25,$25,%lo(func)
+ 0x00000000 // nop
};
enum {
// Fake relocations for patching LA25 stubs.
R_MIPS_LA25_LUI = 200,
- R_MIPS_LA25_J = 201,
+ R_MIPS_LA25_J = 201,
R_MIPS_LA25_ADD = 202
};
-}
+} // anonymous namespace
namespace mcld {
@@ -35,11 +35,10 @@
//===----------------------------------------------------------------------===//
MipsLA25Stub::MipsLA25Stub(const MipsGNULDBackend& pTarget)
- : m_Target(pTarget),
- m_Name("MipsLA25_Prototype"),
- m_pData(STUB),
- m_Size(sizeof(STUB))
-{
+ : m_Target(pTarget),
+ m_Name("MipsLA25_Prototype"),
+ m_pData(STUB),
+ m_Size(sizeof(STUB)) {
addFixup(0, 0x0, R_MIPS_LA25_LUI);
addFixup(4, 0x0, R_MIPS_LA25_J);
addFixup(8, 0x0, R_MIPS_LA25_ADD);
@@ -50,19 +49,14 @@
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_Target(pTarget),
- m_Name("pic"),
- m_pData(pData),
- m_Size(pSize)
-{
+ : m_Target(pTarget), m_Name("pic"), m_pData(pData), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
bool MipsLA25Stub::isMyDuty(const Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
if (llvm::ELF::R_MIPS_26 != pReloc.type())
return false;
@@ -80,30 +74,25 @@
return true;
}
-const std::string& MipsLA25Stub::name() const
-{
+const std::string& MipsLA25Stub::name() const {
return m_Name;
}
-const uint8_t* MipsLA25Stub::getContent() const
-{
+const uint8_t* MipsLA25Stub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t MipsLA25Stub::size() const
-{
+size_t MipsLA25Stub::size() const {
return m_Size;
}
-size_t MipsLA25Stub::alignment() const
-{
+size_t MipsLA25Stub::alignment() const {
return 4;
}
-Stub* MipsLA25Stub::doClone()
-{
- return new MipsLA25Stub(m_Target, m_pData, m_Size,
- fixup_begin(), fixup_end());
+Stub* MipsLA25Stub::doClone() {
+ return new MipsLA25Stub(
+ m_Target, m_pData, m_Size, fixup_begin(), fixup_end());
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsLA25Stub.h b/lib/Target/Mips/MipsLA25Stub.h
index c74cd0d..0d43b87 100644
--- a/lib/Target/Mips/MipsLA25Stub.h
+++ b/lib/Target/Mips/MipsLA25Stub.h
@@ -6,13 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSLA25STUB_H
-#define TARGET_MIPS_MIPSLA25STUB_H
+#ifndef TARGET_MIPS_MIPSLA25STUB_H_
+#define TARGET_MIPS_MIPSLA25STUB_H_
-#include <mcld/Fragment/Stub.h>
+#include "mcld/Fragment/Stub.h"
-namespace mcld
-{
+namespace mcld {
class MipsGNULDBackend;
class Relocation;
@@ -23,12 +22,11 @@
/** \class MipsLA25Stub
* \brief Mips stub for a non-PIC interface to a PIC function.
*/
-class MipsLA25Stub : public Stub
-{
-public:
- MipsLA25Stub(const MipsGNULDBackend& pTarget);
+class MipsLA25Stub : public Stub {
+ public:
+ explicit MipsLA25Stub(const MipsGNULDBackend& pTarget);
-private:
+ private:
// Stub
Stub* doClone();
bool isMyDuty(const Relocation& pReloc,
@@ -39,7 +37,7 @@
size_t size() const;
size_t alignment() const;
-private:
+ private:
MipsLA25Stub(const MipsLA25Stub&);
MipsLA25Stub& operator=(const MipsLA25Stub&);
@@ -49,13 +47,13 @@
const_fixup_iterator pBegin,
const_fixup_iterator pEnd);
-private:
+ private:
const MipsGNULDBackend& m_Target;
const std::string m_Name;
const uint32_t* m_pData;
const size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSLA25STUB_H_
diff --git a/lib/Target/Mips/MipsLDBackend.cpp b/lib/Target/Mips/MipsLDBackend.cpp
index 9714e91..44156af 100644
--- a/lib/Target/Mips/MipsLDBackend.cpp
+++ b/lib/Target/Mips/MipsLDBackend.cpp
@@ -13,51 +13,49 @@
#include "MipsLDBackend.h"
#include "MipsRelocator.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/OutputRelocSection.h"
+
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Target/OutputRelocSection.h>
-#include <mcld/Object/ObjectBuilder.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsGNULDBackend
//===----------------------------------------------------------------------===//
MipsGNULDBackend::MipsGNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pPLT(NULL),
- m_pGOTPLT(NULL),
- m_pInfo(*pInfo),
- m_pRelPlt(NULL),
- m_pRelDyn(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_pPLTSymbol(NULL),
- m_pGpDispSymbol(NULL)
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pPLT(NULL),
+ m_pGOTPLT(NULL),
+ m_pInfo(*pInfo),
+ m_pRelPlt(NULL),
+ m_pRelDyn(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_pPLTSymbol(NULL),
+ m_pGpDispSymbol(NULL) {
}
-MipsGNULDBackend::~MipsGNULDBackend()
-{
+MipsGNULDBackend::~MipsGNULDBackend() {
delete m_pRelocator;
delete m_pPLT;
delete m_pRelPlt;
@@ -66,8 +64,7 @@
}
bool MipsGNULDBackend::needsLA25Stub(Relocation::Type pType,
- const mcld::ResolveInfo* pSym)
-{
+ const mcld::ResolveInfo* pSym) {
if (config().isCodeIndep())
return false;
@@ -80,19 +77,16 @@
return true;
}
-void MipsGNULDBackend::addNonPICBranchSym(ResolveInfo* rsym)
-{
+void MipsGNULDBackend::addNonPICBranchSym(ResolveInfo* rsym) {
m_HasNonPICBranchSyms.insert(rsym);
}
-bool MipsGNULDBackend::hasNonPICBranch(const ResolveInfo* rsym) const
-{
+bool MipsGNULDBackend::hasNonPICBranch(const ResolveInfo* rsym) const {
return m_HasNonPICBranchSyms.count(rsym);
}
void MipsGNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object == config().codeGenType())
return;
@@ -107,77 +101,73 @@
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
}
-void MipsGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void MipsGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// Define the symbol _PROCEDURE_LINKAGE_TABLE_ if there is a symbol with the
// same name in input
- m_pPLTSymbol =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ m_pPLTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
- m_pGpDispSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_gp_disp",
- ResolveInfo::Section,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ m_pGpDispSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_gp_disp",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
- "_gp",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ "_gp",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
}
-const Relocator* MipsGNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* MipsGNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* MipsGNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* MipsGNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void MipsGNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new MipsELFDynamic(*this, config());
// set .got size
// when building shared object, the .got section is must.
if (LinkerConfig::Object != config().codeGenType()) {
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeScanning(*m_pRelDyn);
m_pGOT->finalizeSectionSize();
@@ -197,33 +187,34 @@
// set .rel.plt size
if (!m_pRelPlt->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelPlt().setSize(
- m_pRelPlt->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelPlt().setSize(m_pRelPlt->numOfRelocs() *
+ getRelEntrySize());
}
// set .rel.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelDyn().setSize(
- m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
}
}
-void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *format = getOutputFormat();
+void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* format = getOutputFormat();
if (format->hasGOTPLT()) {
- assert(m_pGOTPLT && "doPostLayout failed, m_pGOTPLT is NULL!");
+ assert(m_pGOTPLT != NULL && "doPostLayout failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyAllGOTPLT(m_pPLT->addr());
}
if (format->hasPLT()) {
- assert(m_pPLT && "doPostLayout failed, m_pPLT is NULL!");
+ assert(m_pPLT != NULL && "doPostLayout failed, m_pPLT is NULL!");
m_pPLT->applyAllPLT(*m_pGOTPLT);
}
@@ -234,8 +225,7 @@
uint64_t picFlags = llvm::ELF::EF_MIPS_CPIC;
if (config().targets().triple().isArch64Bit()) {
picFlags |= llvm::ELF::EF_MIPS_PIC;
- }
- else {
+ } else {
if (LinkerConfig::DynObj == config().codeGenType())
picFlags |= llvm::ELF::EF_MIPS_PIC;
}
@@ -245,23 +235,20 @@
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-MipsELFDynamic& MipsGNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+MipsELFDynamic& MipsGNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const MipsELFDynamic& MipsGNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const MipsELFDynamic& MipsGNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t MipsGNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -278,38 +265,29 @@
return m_pGOTPLT->emit(pRegion);
}
- fatal(diag::unrecognized_output_sectoin)
- << pSection.name()
- << "mclinker@googlegroups.com";
+ fatal(diag::unrecognized_output_sectoin) << pSection.name()
+ << "mclinker@googlegroups.com";
return 0;
}
-bool MipsGNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const
-{
- return ResolveInfo::Section != pSym.type() ||
- m_pGpDispSymbol == &pSym;
+bool MipsGNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const {
+ return ResolveInfo::Section != pSym.type() || m_pGpDispSymbol == &pSym;
}
namespace {
- struct DynsymGOTCompare
- {
- const MipsGOT& m_pGOT;
+struct DynsymGOTCompare {
+ const MipsGOT& m_pGOT;
- DynsymGOTCompare(const MipsGOT& pGOT)
- : m_pGOT(pGOT)
- {
- }
+ explicit DynsymGOTCompare(const MipsGOT& pGOT) : m_pGOT(pGOT) {}
- bool operator()(const LDSymbol* X, const LDSymbol* Y) const
- {
- return m_pGOT.dynSymOrderCompare(X, Y);
- }
- };
-}
+ bool operator()(const LDSymbol* X, const LDSymbol* Y) const {
+ return m_pGOT.dynSymOrderCompare(X, Y);
+ }
+};
+} // anonymous namespace
-void MipsGNULDBackend::orderSymbolTable(Module& pModule)
-{
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+void MipsGNULDBackend::orderSymbolTable(Module& pModule) {
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle()) {
// The MIPS ABI and .gnu.hash require .dynsym to be sorted
// in different ways. The MIPS ABI requires a mapping between
@@ -320,57 +298,60 @@
Module::SymbolTable& symbols = pModule.getSymbolTable();
- std::stable_sort(symbols.dynamicBegin(), symbols.dynamicEnd(),
- DynsymGOTCompare(*m_pGOT));
+ std::stable_sort(
+ symbols.dynamicBegin(), symbols.dynamicEnd(), DynsymGOTCompare(*m_pGOT));
}
+} // namespace mcld
+
namespace llvm {
namespace ELF {
// SHT_MIPS_OPTIONS section's block descriptor.
struct Elf_Options {
- unsigned char kind; // Determines interpretation of variable
- // part of descriptor. See ODK_xxx enumeration.
- unsigned char size; // Byte size of descriptor, including this header.
- Elf64_Half section; // Section header index of section affected,
- // or 0 for global options.
- Elf64_Word info; // Kind-specific information.
+ unsigned char kind; // Determines interpretation of variable
+ // part of descriptor. See ODK_xxx enumeration.
+ unsigned char size; // Byte size of descriptor, including this header.
+ Elf64_Half section; // Section header index of section affected,
+ // or 0 for global options.
+ Elf64_Word info; // Kind-specific information.
};
// Type of SHT_MIPS_OPTIONS section's block.
enum {
- ODK_NULL = 0, // Undefined.
- ODK_REGINFO = 1, // Register usage and GP value.
- ODK_EXCEPTIONS = 2, // Exception processing information.
- ODK_PAD = 3, // Section padding information.
- ODK_HWPATCH = 4, // Hardware workarounds performed.
- ODK_FILL = 5, // Fill value used by the linker.
- ODK_TAGS = 6, // Reserved space for desktop tools.
- ODK_HWAND = 7, // Hardware workarounds, AND bits when merging.
- ODK_HWOR = 8, // Hardware workarounds, OR bits when merging.
- ODK_GP_GROUP = 9, // GP group to use for text/data sections.
- ODK_IDENT = 10 // ID information.
+ ODK_NULL = 0, // Undefined.
+ ODK_REGINFO = 1, // Register usage and GP value.
+ ODK_EXCEPTIONS = 2, // Exception processing information.
+ ODK_PAD = 3, // Section padding information.
+ ODK_HWPATCH = 4, // Hardware workarounds performed.
+ ODK_FILL = 5, // Fill value used by the linker.
+ ODK_TAGS = 6, // Reserved space for desktop tools.
+ ODK_HWAND = 7, // Hardware workarounds, AND bits when merging.
+ ODK_HWOR = 8, // Hardware workarounds, OR bits when merging.
+ ODK_GP_GROUP = 9, // GP group to use for text/data sections.
+ ODK_IDENT = 10 // ID information.
};
// Content of ODK_REGINFO block in SHT_MIPS_OPTIONS section on 32 bit ABI.
struct Elf32_RegInfo {
- Elf32_Word ri_gprmask; // Mask of general purpose registers used.
- Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
- Elf32_Addr ri_gp_value; // GP register value for this object file.
+ Elf32_Word ri_gprmask; // Mask of general purpose registers used.
+ Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
+ Elf32_Addr ri_gp_value; // GP register value for this object file.
};
// Content of ODK_REGINFO block in SHT_MIPS_OPTIONS section on 64 bit ABI.
struct Elf64_RegInfo {
- Elf32_Word ri_gprmask; // Mask of general purpose registers used.
- Elf32_Word ri_pad; // Padding.
- Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
- Elf64_Addr ri_gp_value; // GP register value for this object file.
+ Elf32_Word ri_gprmask; // Mask of general purpose registers used.
+ Elf32_Word ri_pad; // Padding.
+ Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
+ Elf64_Addr ri_gp_value; // GP register value for this object file.
};
-}
-}
+} // namespace ELF
+} // namespace llvm
-bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+namespace mcld {
+
+bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD) {
llvm::StringRef name(pSD.getSection().name());
if (name.startswith(".sdata")) {
@@ -389,11 +370,13 @@
llvm::StringRef region = pInput.memArea()->request(offset, size);
if (region.size() > 0) {
const llvm::ELF::Elf_Options* optb =
- reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin());
+ reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin());
const llvm::ELF::Elf_Options* opte =
- reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin() + size);
+ reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin() +
+ size);
- for (const llvm::ELF::Elf_Options* opt = optb; opt < opte; opt += opt->size) {
+ for (const llvm::ELF::Elf_Options* opt = optb; opt < opte;
+ opt += opt->size) {
switch (opt->kind) {
default:
// Nothing to do.
@@ -401,12 +384,11 @@
case llvm::ELF::ODK_REGINFO:
if (config().targets().triple().isArch32Bit()) {
const llvm::ELF::Elf32_RegInfo* reg =
- reinterpret_cast<const llvm::ELF::Elf32_RegInfo*>(opt + 1);
+ reinterpret_cast<const llvm::ELF::Elf32_RegInfo*>(opt + 1);
m_GP0Map[&pInput] = reg->ri_gp_value;
- }
- else {
+ } else {
const llvm::ELF::Elf64_RegInfo* reg =
- reinterpret_cast<const llvm::ELF::Elf64_RegInfo*>(opt + 1);
+ reinterpret_cast<const llvm::ELF::Elf64_RegInfo*>(opt + 1);
m_GP0Map[&pInput] = reg->ri_gp_value;
}
break;
@@ -420,69 +402,58 @@
return GNULDBackend::readSection(pInput, pSD);
}
-MipsGOT& MipsGNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+MipsGOT& MipsGNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const MipsGOT& MipsGNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const MipsGOT& MipsGNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-MipsPLT& MipsGNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT);
+MipsPLT& MipsGNULDBackend::getPLT() {
+ assert(m_pPLT != NULL);
return *m_pPLT;
}
-const MipsPLT& MipsGNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT);
+const MipsPLT& MipsGNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL);
return *m_pPLT;
}
-MipsGOTPLT& MipsGNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+MipsGOTPLT& MipsGNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const MipsGOTPLT& MipsGNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const MipsGOTPLT& MipsGNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-OutputRelocSection& MipsGNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPlt);
+OutputRelocSection& MipsGNULDBackend::getRelPLT() {
+ assert(m_pRelPlt != NULL);
return *m_pRelPlt;
}
-const OutputRelocSection& MipsGNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPlt);
+const OutputRelocSection& MipsGNULDBackend::getRelPLT() const {
+ assert(m_pRelPlt != NULL);
return *m_pRelPlt;
}
-OutputRelocSection& MipsGNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn);
+OutputRelocSection& MipsGNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL);
return *m_pRelDyn;
}
-const OutputRelocSection& MipsGNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn);
+const OutputRelocSection& MipsGNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL);
return *m_pRelDyn;
}
-unsigned int
-MipsGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int MipsGNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT()))
@@ -498,9 +469,8 @@
}
/// finalizeSymbol - finalize the symbol value
-bool MipsGNULDBackend::finalizeTargetSymbols()
-{
- if (NULL != m_pGpDispSymbol)
+bool MipsGNULDBackend::finalizeTargetSymbols() {
+ if (m_pGpDispSymbol != NULL)
m_pGpDispSymbol->setValue(m_pGOT->getGPDispAddress());
return true;
@@ -508,10 +478,8 @@
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is called at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
/// FIXME: Mips needs to allocate small common symbol
-bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyFiles() &&
@@ -542,7 +510,7 @@
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -560,17 +528,14 @@
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -590,17 +555,14 @@
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -612,79 +574,72 @@
return true;
}
-uint64_t MipsGNULDBackend::getGP0(const Input& pInput) const
-{
+uint64_t MipsGNULDBackend::getGP0(const Input& pInput) const {
return m_GP0Map.lookup(&pInput);
}
-void MipsGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// If we do not reserve any GOT entries, we do not need to re-define GOT
// symbol.
if (!m_pGOT->hasGOT1())
return;
// define symbol _GLOBAL_OFFSET_TABLE_
- if ( m_pGOTSymbol != NULL ) {
+ if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
-void MipsGNULDBackend::defineGOTPLTSymbol(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::defineGOTPLTSymbol(IRBuilder& pBuilder) {
// define symbol _PROCEDURE_LINKAGE_TABLE_
- if ( m_pPLTSymbol != NULL ) {
+ if (m_pPLTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pPLT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pPLTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pPLT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void MipsGNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void MipsGNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel)
-{
+bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel) {
uint64_t sym_value = 0x0;
LDSymbol* symbol = pRel.symInfo()->outSymbol();
@@ -694,13 +649,13 @@
sym_value = addr + value;
}
- Stub* stub =
- getStubFactory()->create(pRel, sym_value, pBuilder, *getBRIslandFactory());
+ Stub* stub = getStubFactory()->create(
+ pRel, sym_value, pBuilder, *getBRIslandFactory());
- if (NULL == stub)
+ if (stub == NULL)
return false;
- assert(NULL != stub->symInfo());
+ assert(stub->symInfo() != NULL);
// increase the size of .symtab and .strtab
LDSection& symtab = getOutputFormat()->getSymTab();
LDSection& strtab = getOutputFormat()->getStrTab();
@@ -710,26 +665,29 @@
return true;
}
-bool MipsGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
- bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool MipsGNULDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
for (Module::obj_iterator input = pModule.obj_begin();
- input != pModule.obj_end(); ++input) {
+ input != pModule.obj_end();
+ ++input) {
LDContext* context = (*input)->context();
for (LDContext::sect_iterator rs = context->relocSectBegin();
- rs != context->relocSectEnd(); ++rs) {
+ rs != context->relocSectEnd();
+ ++rs) {
LDSection* sec = *rs;
if (LDFileFormat::Ignore == sec->kind() || !sec->hasRelocData())
continue;
for (RelocData::iterator reloc = sec->getRelocData()->begin();
- reloc != sec->getRelocData()->end(); ++reloc) {
+ reloc != sec->getRelocData()->end();
+ ++reloc) {
if (llvm::ELF::R_MIPS_26 != reloc->type())
continue;
@@ -746,8 +704,8 @@
pFinished = true;
for (BranchIslandFactory::iterator ii = getBRIslandFactory()->begin(),
ie = getBRIslandFactory()->end();
- ii != ie; ++ii)
- {
+ ii != ie;
+ ++ii) {
BranchIsland& island = *ii;
if (island.end() == textData->end())
break;
@@ -761,7 +719,7 @@
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -775,9 +733,8 @@
return isRelaxed;
}
-bool MipsGNULDBackend::initTargetStubs()
-{
- if (NULL == getStubFactory())
+bool MipsGNULDBackend::initTargetStubs() {
+ if (getStubFactory() == NULL)
return false;
getStubFactory()->addPrototype(new MipsLA25Stub(*this));
@@ -787,8 +744,7 @@
bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf32_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint32_t& pOffset) const
-{
+ uint32_t& pOffset) const {
return GNULDBackend::readRelocation(pRel, pType, pSymIdx, pOffset);
}
@@ -796,24 +752,21 @@
Relocation::Type& pType,
uint32_t& pSymIdx,
uint32_t& pOffset,
- int32_t& pAddend) const
-{
+ int32_t& pAddend) const {
return GNULDBackend::readRelocation(pRel, pType, pSymIdx, pOffset, pAddend);
}
bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf64_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint64_t& pOffset) const
-{
+ uint64_t& pOffset) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
}
// MIPS 64 little endian (we do not support big endian now)
@@ -829,17 +782,15 @@
Relocation::Type& pType,
uint32_t& pSymIdx,
uint64_t& pOffset,
- int64_t& pAddend) const
-{
+ int64_t& pAddend) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
pAddend = mcld::bswap64(pRel.r_addend);
}
@@ -851,8 +802,7 @@
void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf32_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint32_t pOffset) const
-{
+ uint32_t pOffset) const {
GNULDBackend::emitRelocation(pRel, pType, pSymIdx, pOffset);
}
@@ -860,16 +810,14 @@
Relocation::Type pType,
uint32_t pSymIdx,
uint32_t pOffset,
- int32_t pAddend) const
-{
+ int32_t pAddend) const {
GNULDBackend::emitRelocation(pRel, pType, pSymIdx, pOffset, pAddend);
}
void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf64_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint64_t pOffset) const
-{
+ uint64_t pOffset) const {
uint64_t r_info = mcld::bswap32(pType);
r_info <<= 32;
r_info |= pSymIdx;
@@ -882,8 +830,7 @@
Relocation::Type pType,
uint32_t pSymIdx,
uint64_t pOffset,
- int64_t pAddend) const
-{
+ int64_t pAddend) const {
uint64_t r_info = mcld::bswap32(pType);
r_info <<= 32;
r_info |= pSymIdx;
@@ -898,20 +845,18 @@
//===----------------------------------------------------------------------===//
Mips32GNULDBackend::Mips32GNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : MipsGNULDBackend(pConfig, pInfo)
-{}
+ : MipsGNULDBackend(pConfig, pInfo) {
+}
-bool Mips32GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator)
+bool Mips32GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL)
m_pRelocator = new Mips32Relocator(*this, config());
return true;
}
void Mips32GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
MipsGNULDBackend::initTargetSections(pModule, pBuilder);
if (LinkerConfig::Object == config().codeGenType())
@@ -932,13 +877,11 @@
m_pPLT = new MipsPLT(plt);
}
-size_t Mips32GNULDBackend::getRelEntrySize()
-{
+size_t Mips32GNULDBackend::getRelEntrySize() {
return 8;
}
-size_t Mips32GNULDBackend::getRelaEntrySize()
-{
+size_t Mips32GNULDBackend::getRelaEntrySize() {
return 12;
}
@@ -947,20 +890,18 @@
//===----------------------------------------------------------------------===//
Mips64GNULDBackend::Mips64GNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : MipsGNULDBackend(pConfig, pInfo)
-{}
+ : MipsGNULDBackend(pConfig, pInfo) {
+}
-bool Mips64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator)
+bool Mips64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL)
m_pRelocator = new Mips64Relocator(*this, config());
return true;
}
void Mips64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
MipsGNULDBackend::initTargetSections(pModule, pBuilder);
if (LinkerConfig::Object == config().codeGenType())
@@ -981,21 +922,18 @@
m_pPLT = new MipsPLT(plt);
}
-size_t Mips64GNULDBackend::getRelEntrySize()
-{
+size_t Mips64GNULDBackend::getRelEntrySize() {
return 16;
}
-size_t Mips64GNULDBackend::getRelaEntrySize()
-{
+size_t Mips64GNULDBackend::getRelaEntrySize() {
return 24;
}
//===----------------------------------------------------------------------===//
/// createMipsLDBackend - the help funtion to create corresponding MipsLDBackend
///
-static TargetLDBackend* createMipsLDBackend(const LinkerConfig& pConfig)
-{
+static TargetLDBackend* createMipsLDBackend(const LinkerConfig& pConfig) {
const llvm::Triple& triple = pConfig.targets().triple();
if (triple.isOSDarwin()) {
@@ -1010,16 +948,18 @@
if (llvm::Triple::mips64el == arch)
return new Mips64GNULDBackend(pConfig, new MipsGNUInfo(triple));
- assert (arch == llvm::Triple::mipsel);
+ assert(arch == llvm::Triple::mipsel);
return new Mips32GNULDBackend(pConfig, new MipsGNUInfo(triple));
}
+} // namespace mcld
+
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeMipsLDBackend() {
mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheMipselTarget,
- createMipsLDBackend);
+ mcld::createMipsLDBackend);
mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheMips64elTarget,
- createMipsLDBackend);
+ mcld::createMipsLDBackend);
}
diff --git a/lib/Target/Mips/MipsLDBackend.h b/lib/Target/Mips/MipsLDBackend.h
index 991b3c4..2dbf8d1 100644
--- a/lib/Target/Mips/MipsLDBackend.h
+++ b/lib/Target/Mips/MipsLDBackend.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSLDBACKEND_H
-#define TARGET_MIPS_MIPSLDBACKEND_H
-#include <mcld/Target/GNULDBackend.h>
+#ifndef TARGET_MIPS_MIPSLDBACKEND_H_
+#define TARGET_MIPS_MIPSLDBACKEND_H_
+#include "mcld/Target/GNULDBackend.h"
#include "MipsELFDynamic.h"
#include "MipsGOT.h"
#include "MipsGOTPLT.h"
@@ -17,20 +17,19 @@
namespace mcld {
class LinkerConfig;
-class OutputRelocSection;
-class SectionMap;
class MemoryArea;
class MipsGNUInfo;
+class OutputRelocSection;
+class SectionMap;
/** \class MipsGNULDBackend
* \brief Base linker backend of Mips target of GNU ELF format.
*/
-class MipsGNULDBackend : public GNULDBackend
-{
-public:
+class MipsGNULDBackend : public GNULDBackend {
+ public:
typedef std::vector<LDSymbol*> SymbolListType;
-public:
+ public:
MipsGNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
~MipsGNULDBackend();
@@ -39,7 +38,7 @@
void addNonPICBranchSym(ResolveInfo* rsym);
bool hasNonPICBranch(const ResolveInfo* rsym) const;
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -105,13 +104,13 @@
OutputRelocSection& getRelDyn();
const OutputRelocSection& getRelDyn() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
- const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
- LDSymbol* getGpDispSymbol() { return m_pGpDispSymbol; }
- const LDSymbol* getGpDispSymbol() const { return m_pGpDispSymbol; }
+ LDSymbol* getGpDispSymbol() { return m_pGpDispSymbol; }
+ const LDSymbol* getGpDispSymbol() const { return m_pGpDispSymbol; }
- SymbolListType& getGlobalGOTSyms() { return m_GlobalGOTSyms; }
+ SymbolListType& getGlobalGOTSyms() { return m_GlobalGOTSyms; }
const SymbolListType& getGlobalGOTSyms() const { return m_GlobalGOTSyms; }
/// getTargetSectionOrder - compute the layout order of ARM target sections
@@ -128,7 +127,7 @@
/// in the specified input.
uint64_t getGP0(const Input& pInput) const;
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
void defineGOTPLTSymbol(IRBuilder& pBuilder);
@@ -209,21 +208,21 @@
uint64_t pOffset,
int64_t pAddend) const;
-private:
+ private:
typedef llvm::DenseSet<const ResolveInfo*> ResolveInfoSetType;
typedef llvm::DenseMap<const Input*, llvm::ELF::Elf64_Addr> GP0MapType;
-protected:
+ protected:
Relocator* m_pRelocator;
- MipsGOT* m_pGOT; // .got
- MipsPLT* m_pPLT; // .plt
- MipsGOTPLT* m_pGOTPLT; // .got.plt
+ MipsGOT* m_pGOT; // .got
+ MipsPLT* m_pPLT; // .plt
+ MipsGOTPLT* m_pGOTPLT; // .got.plt
-private:
+ private:
MipsGNUInfo& m_pInfo;
- OutputRelocSection* m_pRelPlt; // .rel.plt
- OutputRelocSection* m_pRelDyn; // .rel.dyn
+ OutputRelocSection* m_pRelPlt; // .rel.plt
+ OutputRelocSection* m_pRelDyn; // .rel.dyn
MipsELFDynamic* m_pDynamic;
LDSymbol* m_pGOTSymbol;
@@ -238,12 +237,11 @@
/** \class Mips32GNULDBackend
* \brief Base linker backend of Mips 32-bit target of GNU ELF format.
*/
-class Mips32GNULDBackend : public MipsGNULDBackend
-{
-public:
+class Mips32GNULDBackend : public MipsGNULDBackend {
+ public:
Mips32GNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
-private:
+ private:
// MipsGNULDBackend
bool initRelocator();
@@ -255,12 +253,11 @@
/** \class Mips64GNULDBackend
* \brief Base linker backend of Mips 64-bit target of GNU ELF format.
*/
-class Mips64GNULDBackend : public MipsGNULDBackend
-{
-public:
+class Mips64GNULDBackend : public MipsGNULDBackend {
+ public:
Mips64GNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
-private:
+ private:
// MipsGNULDBackend
bool initRelocator();
@@ -269,6 +266,6 @@
size_t getRelaEntrySize();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSLDBACKEND_H_
diff --git a/lib/Target/Mips/MipsMCLinker.cpp b/lib/Target/Mips/MipsMCLinker.cpp
deleted file mode 100644
index 49940b7..0000000
--- a/lib/Target/Mips/MipsMCLinker.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-//===- MipsMCLinker.cpp ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "Mips.h"
-#include "MipsELFMCLinker.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-namespace {
-
-//===----------------------------------------------------------------------===//
-/// createMipsMCLinker - the help funtion to create corresponding MipsMCLinker
-//===----------------------------------------------------------------------===//
-mcld::MCLinker* createMipsMCLinker(const std::string &pTriple,
- mcld::LinkerConfig& pConfig,
- mcld::Module& pModule,
- mcld::FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new mcld::MipsELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// MipsMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeMipsMCLinker() {
- mcld::TargetRegistry::RegisterMCLinker(mcld::TheMipselTarget,
- createMipsMCLinker);
- mcld::TargetRegistry::RegisterMCLinker(mcld::TheMips64elTarget,
- createMipsMCLinker);
-}
diff --git a/lib/Target/Mips/MipsPLT.cpp b/lib/Target/Mips/MipsPLT.cpp
index 81c05c0..aef25f9 100644
--- a/lib/Target/Mips/MipsPLT.cpp
+++ b/lib/Target/Mips/MipsPLT.cpp
@@ -8,70 +8,60 @@
//===----------------------------------------------------------------------===//
#include <llvm/Support/Casting.h>
#include <llvm/Support/ELF.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Support/MsgHandling.h"
#include "MipsGOTPLT.h"
#include "MipsPLT.h"
namespace {
const uint32_t PLT0[] = {
- 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
- 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
- 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
- 0x031cc023, // subu $24, $24, $28
- 0x03e07821, // move $15, $31
- 0x0018c082, // srl $24, $24, 2
- 0x0320f809, // jalr $25
- 0x2718fffe // subu $24, $24, 2
+ 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
+ 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
+ 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
+ 0x031cc023, // subu $24, $24, $28
+ 0x03e07821, // move $15, $31
+ 0x0018c082, // srl $24, $24, 2
+ 0x0320f809, // jalr $25
+ 0x2718fffe // subu $24, $24, 2
};
const uint32_t PLTA[] = {
- 0x3c0f0000, // lui $15, %hi(.got.plt entry)
- 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
- 0x03200008, // jr $25
- 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
+ 0x3c0f0000, // lui $15, %hi(.got.plt entry)
+ 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
+ 0x03200008, // jr $25
+ 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
};
-}
+} // anonymous namespace
namespace mcld {
//===----------------------------------------------------------------------===//
// MipsPLT0 Entry
//===----------------------------------------------------------------------===//
-class MipsPLT0 : public PLT::Entry<sizeof(PLT0)>
-{
-public:
- MipsPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(PLT0)>(pParent)
- {}
+class MipsPLT0 : public PLT::Entry<sizeof(PLT0)> {
+ public:
+ MipsPLT0(SectionData& pParent) : PLT::Entry<sizeof(PLT0)>(pParent) {}
};
//===----------------------------------------------------------------------===//
// MipsPLTA Entry
//===----------------------------------------------------------------------===//
-class MipsPLTA : public PLT::Entry<sizeof(PLTA)>
-{
-public:
- MipsPLTA(SectionData& pParent)
- : PLT::Entry<sizeof(PLTA)>(pParent)
- {}
+class MipsPLTA : public PLT::Entry<sizeof(PLTA)> {
+ public:
+ MipsPLTA(SectionData& pParent) : PLT::Entry<sizeof(PLTA)>(pParent) {}
};
//===----------------------------------------------------------------------===//
// MipsPLT
//===----------------------------------------------------------------------===//
-MipsPLT::MipsPLT(LDSection& pSection)
- : PLT(pSection)
-{
+MipsPLT::MipsPLT(LDSection& pSection) : PLT(pSection) {
new MipsPLT0(*m_pSectionData);
m_Last = m_pSectionData->begin();
}
-void MipsPLT::finalizeSectionSize()
-{
- uint64_t size = sizeof(PLT0) +
- (m_pSectionData->size() - 1) * sizeof(PLTA);
+void MipsPLT::finalizeSectionSize() {
+ uint64_t size = sizeof(PLT0) + (m_pSectionData->size() - 1) * sizeof(PLTA);
m_Section.setSize(size);
uint32_t offset = 0;
@@ -82,13 +72,11 @@
}
}
-bool MipsPLT::hasPLT1() const
-{
+bool MipsPLT::hasPLT1() const {
return m_pSectionData->size() > 1;
}
-uint64_t MipsPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t MipsPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
@@ -106,30 +94,28 @@
return result;
}
-void MipsPLT::reserveEntry(size_t pNum)
-{
+void MipsPLT::reserveEntry(size_t pNum) {
for (size_t i = 0; i < pNum; ++i) {
Fragment* entry = new (std::nothrow) MipsPLTA(*m_pSectionData);
- if (NULL == entry)
+ if (entry == NULL)
fatal(diag::fail_allocate_memory_plt);
}
}
-Fragment* MipsPLT::consume()
-{
+Fragment* MipsPLT::consume() {
++m_Last;
assert(m_Last != m_pSectionData->end() &&
"The number of PLT Entries and ResolveInfo doesn't match");
return &(*m_Last);
}
-void MipsPLT::applyAllPLT(MipsGOTPLT& pGOTPLT)
-{
+void MipsPLT::applyAllPLT(MipsGOTPLT& pGOTPLT) {
assert(m_Section.addr() && ".plt base address is NULL!");
size_t count = 0;
- for (iterator it = m_pSectionData->begin(); it != m_pSectionData->end(); ++it) {
+ for (iterator it = m_pSectionData->begin(); it != m_pSectionData->end();
+ ++it) {
PLTEntryBase* plt = &(llvm::cast<PLTEntryBase>(*it));
if (it == m_pSectionData->begin()) {
@@ -166,4 +152,4 @@
}
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsPLT.h b/lib/Target/Mips/MipsPLT.h
index a1d1b4a..7c26b8e 100644
--- a/lib/Target/Mips/MipsPLT.h
+++ b/lib/Target/Mips/MipsPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSPLT_H
-#define TARGET_MIPS_MIPSPLT_H
+#ifndef TARGET_MIPS_MIPSPLT_H_
+#define TARGET_MIPS_MIPSPLT_H_
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/PLT.h"
namespace mcld {
@@ -22,10 +22,9 @@
/** \class MipsPLT
* \brief Mips Procedure Linkage Table
*/
-class MipsPLT : public PLT
-{
-public:
- MipsPLT(LDSection& pSection);
+class MipsPLT : public PLT {
+ public:
+ explicit MipsPLT(LDSection& pSection);
// hasPLT1 - return if this PLT has any PLTA/PLTB entries
bool hasPLT1() const;
@@ -36,16 +35,16 @@
void applyAllPLT(MipsGOTPLT& pGOTPLT);
-public:
+ public:
// PLT
void reserveEntry(size_t pNum = 1);
void finalizeSectionSize();
-private:
+ private:
// the last consumed entry.
SectionData::iterator m_Last;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSPLT_H_
diff --git a/lib/Target/Mips/MipsRelocationFunctions.h b/lib/Target/Mips/MipsRelocationFunctions.h
index 3634686..06c9a0e 100644
--- a/lib/Target/Mips/MipsRelocationFunctions.h
+++ b/lib/Target/Mips/MipsRelocationFunctions.h
@@ -6,287 +6,291 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
+#define TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
-#define DECL_MIPS_APPLY_RELOC_FUNC(Name) \
-static MipsRelocator::Result Name(MipsRelocationInfo& pReloc, \
- MipsRelocator& pParent);
+#define DECL_MIPS_APPLY_RELOC_FUNC(Name) \
+ static MipsRelocator::Result Name(MipsRelocationInfo& pReloc, \
+ MipsRelocator& pParent);
-#define DECL_MIPS_APPLY_RELOC_FUNCS \
-DECL_MIPS_APPLY_RELOC_FUNC(none) \
-DECL_MIPS_APPLY_RELOC_FUNC(abs32) \
-DECL_MIPS_APPLY_RELOC_FUNC(rel26) \
-DECL_MIPS_APPLY_RELOC_FUNC(hi16) \
-DECL_MIPS_APPLY_RELOC_FUNC(lo16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gprel16) \
-DECL_MIPS_APPLY_RELOC_FUNC(got16) \
-DECL_MIPS_APPLY_RELOC_FUNC(call16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gprel32) \
-DECL_MIPS_APPLY_RELOC_FUNC(abs64) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotdisp) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotoff) \
-DECL_MIPS_APPLY_RELOC_FUNC(gothi16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotlo16) \
-DECL_MIPS_APPLY_RELOC_FUNC(sub) \
-DECL_MIPS_APPLY_RELOC_FUNC(jalr) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25lui) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25j) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25add) \
-DECL_MIPS_APPLY_RELOC_FUNC(pc32) \
-DECL_MIPS_APPLY_RELOC_FUNC(unsupport)
+#define DECL_MIPS_APPLY_RELOC_FUNCS \
+ DECL_MIPS_APPLY_RELOC_FUNC(none) \
+ DECL_MIPS_APPLY_RELOC_FUNC(abs32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(rel26) \
+ DECL_MIPS_APPLY_RELOC_FUNC(hi16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(lo16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gprel16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(got16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(call16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gprel32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(abs64) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotdisp) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotoff) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gothi16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotlo16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(sub) \
+ DECL_MIPS_APPLY_RELOC_FUNC(jalr) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25lui) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25j) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25add) \
+ DECL_MIPS_APPLY_RELOC_FUNC(pc32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(unsupported)
#define DECL_MIPS_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_MIPS_NONE", 0}, \
- { &unsupport, 1, "R_MIPS_16", 16}, \
- { &abs32, 2, "R_MIPS_32", 32}, \
- { &unsupport, 3, "R_MIPS_REL32", 32}, \
- { &rel26, 4, "R_MIPS_26", 26}, \
- { &hi16, 5, "R_MIPS_HI16", 16}, \
- { &lo16, 6, "R_MIPS_LO16", 16}, \
- { &gprel16, 7, "R_MIPS_GPREL16", 16}, \
- { &unsupport, 8, "R_MIPS_LITERAL", 16}, \
- { &got16, 9, "R_MIPS_GOT16", 16}, \
- { &unsupport, 10, "R_MIPS_PC16", 16}, \
- { &call16, 11, "R_MIPS_CALL16", 16}, \
- { &gprel32, 12, "R_MIPS_GPREL32", 32}, \
- { &none, 13, "R_MIPS_UNUSED1", 0}, \
- { &none, 14, "R_MIPS_UNUSED2", 0}, \
- { &none, 15, "R_MIPS_UNUSED3", 0}, \
- { &unsupport, 16, "R_MIPS_SHIFT5", 32}, \
- { &unsupport, 17, "R_MIPS_SHIFT6", 32}, \
- { &abs64, 18, "R_MIPS_64", 64}, \
- { &gotdisp, 19, "R_MIPS_GOT_DISP", 16}, \
- { &gotdisp, 20, "R_MIPS_GOT_PAGE", 16}, \
- { &gotoff, 21, "R_MIPS_GOT_OFST", 16}, \
- { &gothi16, 22, "R_MIPS_GOT_HI16", 16}, \
- { &gotlo16, 23, "R_MIPS_GOT_LO16", 16}, \
- { &sub, 24, "R_MIPS_SUB", 64}, \
- { &unsupport, 25, "R_MIPS_INSERT_A", 0}, \
- { &unsupport, 26, "R_MIPS_INSERT_B", 0}, \
- { &unsupport, 27, "R_MIPS_DELETE", 0}, \
- { &unsupport, 28, "R_MIPS_HIGHER", 16}, \
- { &unsupport, 29, "R_MIPS_HIGHEST", 16}, \
- { &gothi16, 30, "R_MIPS_CALL_HI16", 16}, \
- { &gotlo16, 31, "R_MIPS_CALL_LO16", 16}, \
- { &unsupport, 32, "R_MIPS_SCN_DISP", 32}, \
- { &unsupport, 33, "R_MIPS_REL16", 0}, \
- { &unsupport, 34, "R_MIPS_ADD_IMMEDIATE", 0}, \
- { &unsupport, 35, "R_MIPS_PJUMP", 0}, \
- { &unsupport, 36, "R_MIPS_RELGOT", 0}, \
- { &jalr, 37, "R_MIPS_JALR", 32}, \
- { &unsupport, 38, "R_MIPS_TLS_DTPMOD32", 32}, \
- { &unsupport, 39, "R_MIPS_TLS_DTPREL32", 32}, \
- { &unsupport, 40, "R_MIPS_TLS_DTPMOD64", 0}, \
- { &unsupport, 41, "R_MIPS_TLS_DTPREL64", 0}, \
- { &unsupport, 42, "R_MIPS_TLS_GD", 16}, \
- { &unsupport, 43, "R_MIPS_TLS_LDM", 16}, \
- { &unsupport, 44, "R_MIPS_TLS_DTPREL_HI16", 16}, \
- { &unsupport, 45, "R_MIPS_TLS_DTPREL_LO16", 16}, \
- { &unsupport, 46, "R_MIPS_TLS_GOTTPREL", 16}, \
- { &unsupport, 47, "R_MIPS_TLS_TPREL32", 32}, \
- { &unsupport, 48, "R_MIPS_TLS_TPREL64", 0}, \
- { &unsupport, 49, "R_MIPS_TLS_TPREL_HI16", 16}, \
- { &unsupport, 50, "R_MIPS_TLS_TPREL_LO16", 16}, \
- { &unsupport, 51, "R_MIPS_GLOB_DAT", 0}, \
- { &unsupport, 52, "", 0}, \
- { &unsupport, 53, "", 0}, \
- { &unsupport, 54, "", 0}, \
- { &unsupport, 55, "", 0}, \
- { &unsupport, 56, "", 0}, \
- { &unsupport, 57, "", 0}, \
- { &unsupport, 58, "", 0}, \
- { &unsupport, 59, "", 0}, \
- { &unsupport, 60, "", 0}, \
- { &unsupport, 61, "", 0}, \
- { &unsupport, 62, "", 0}, \
- { &unsupport, 63, "", 0}, \
- { &unsupport, 64, "", 0}, \
- { &unsupport, 65, "", 0}, \
- { &unsupport, 66, "", 0}, \
- { &unsupport, 67, "", 0}, \
- { &unsupport, 68, "", 0}, \
- { &unsupport, 69, "", 0}, \
- { &unsupport, 70, "", 0}, \
- { &unsupport, 71, "", 0}, \
- { &unsupport, 72, "", 0}, \
- { &unsupport, 73, "", 0}, \
- { &unsupport, 74, "", 0}, \
- { &unsupport, 75, "", 0}, \
- { &unsupport, 76, "", 0}, \
- { &unsupport, 77, "", 0}, \
- { &unsupport, 78, "", 0}, \
- { &unsupport, 79, "", 0}, \
- { &unsupport, 80, "", 0}, \
- { &unsupport, 81, "", 0}, \
- { &unsupport, 82, "", 0}, \
- { &unsupport, 83, "", 0}, \
- { &unsupport, 84, "", 0}, \
- { &unsupport, 85, "", 0}, \
- { &unsupport, 86, "", 0}, \
- { &unsupport, 87, "", 0}, \
- { &unsupport, 88, "", 0}, \
- { &unsupport, 89, "", 0}, \
- { &unsupport, 90, "", 0}, \
- { &unsupport, 91, "", 0}, \
- { &unsupport, 92, "", 0}, \
- { &unsupport, 93, "", 0}, \
- { &unsupport, 94, "", 0}, \
- { &unsupport, 95, "", 0}, \
- { &unsupport, 96, "", 0}, \
- { &unsupport, 97, "", 0}, \
- { &unsupport, 98, "", 0}, \
- { &unsupport, 99, "", 0}, \
- { &unsupport, 100, "R_MIPS16_26", 0}, \
- { &unsupport, 101, "R_MIPS16_GPREL", 0}, \
- { &unsupport, 102, "R_MIPS16_GOT16", 0}, \
- { &unsupport, 103, "R_MIPS16_CALL16", 0}, \
- { &unsupport, 104, "R_MIPS16_HI16", 0}, \
- { &unsupport, 105, "R_MIPS16_LO16", 0}, \
- { &unsupport, 106, "R_MIPS16_TLS_GD", 0}, \
- { &unsupport, 107, "R_MIPS16_TLS_LDM", 0}, \
- { &unsupport, 108, "R_MIPS16_TLS_DTPREL_HI16", 0}, \
- { &unsupport, 109, "R_MIPS16_TLS_DTPREL_LO16", 0}, \
- { &unsupport, 110, "R_MIPS16_TLS_GOTTPREL", 0}, \
- { &unsupport, 111, "R_MIPS16_TLS_TPREL_HI16", 0}, \
- { &unsupport, 112, "R_MIPS16_TLS_TPREL_LO16", 0}, \
- { &unsupport, 113, "", 0}, \
- { &unsupport, 114, "", 0}, \
- { &unsupport, 115, "", 0}, \
- { &unsupport, 116, "", 0}, \
- { &unsupport, 117, "", 0}, \
- { &unsupport, 118, "", 0}, \
- { &unsupport, 119, "", 0}, \
- { &unsupport, 120, "", 0}, \
- { &unsupport, 121, "", 0}, \
- { &unsupport, 122, "", 0}, \
- { &unsupport, 123, "", 0}, \
- { &unsupport, 124, "", 0}, \
- { &unsupport, 125, "", 0}, \
- { &unsupport, 126, "R_MIPS_COPY", 0}, \
- { &unsupport, 127, "R_MIPS_JUMP_SLOT", 0}, \
- { &unsupport, 128, "", 0}, \
- { &unsupport, 129, "", 0}, \
- { &unsupport, 130, "", 0}, \
- { &unsupport, 131, "", 0}, \
- { &unsupport, 132, "", 0}, \
- { &unsupport, 133, "R_MICROMIPS_26_S1", 0}, \
- { &unsupport, 134, "R_MICROMIPS_HI16", 0}, \
- { &unsupport, 135, "R_MICROMIPS_LO16", 0}, \
- { &unsupport, 136, "R_MICROMIPS_GPREL16", 0}, \
- { &unsupport, 137, "R_MICROMIPS_LITERAL", 0}, \
- { &unsupport, 138, "R_MICROMIPS_GOT16", 0}, \
- { &unsupport, 139, "R_MICROMIPS_PC7_S1", 0}, \
- { &unsupport, 140, "R_MICROMIPS_PC10_S1", 0}, \
- { &unsupport, 141, "R_MICROMIPS_PC16_S1", 0}, \
- { &unsupport, 142, "R_MICROMIPS_CALL16", 0}, \
- { &unsupport, 143, "R_MICROMIPS_GOT_DISP", 0}, \
- { &unsupport, 144, "R_MICROMIPS_GOT_PAGE", 0}, \
- { &unsupport, 145, "R_MICROMIPS_GOT_OFST", 0}, \
- { &unsupport, 146, "R_MICROMIPS_GOT_HI16", 0}, \
- { &unsupport, 147, "R_MICROMIPS_GOT_LO16", 0}, \
- { &unsupport, 148, "R_MICROMIPS_SUB", 0}, \
- { &unsupport, 149, "R_MICROMIPS_HIGHER", 0}, \
- { &unsupport, 150, "R_MICROMIPS_HIGHEST", 0}, \
- { &unsupport, 151, "R_MICROMIPS_CALL_HI16", 0}, \
- { &unsupport, 152, "R_MICROMIPS_CALL_LO16", 0}, \
- { &unsupport, 153, "R_MICROMIPS_SCN_DISP", 0}, \
- { &unsupport, 154, "R_MICROMIPS_JALR", 0}, \
- { &unsupport, 155, "R_MICROMIPS_HI0_LO16", 0}, \
- { &unsupport, 156, "", 0}, \
- { &unsupport, 157, "", 0}, \
- { &unsupport, 158, "", 0}, \
- { &unsupport, 159, "", 0}, \
- { &unsupport, 160, "", 0}, \
- { &unsupport, 161, "", 0}, \
- { &unsupport, 162, "R_MICROMIPS_TLS_GD", 0}, \
- { &unsupport, 163, "R_MICROMIPS_TLS_LDM", 0}, \
- { &unsupport, 164, "R_MICROMIPS_TLS_DTPREL_HI16", 0}, \
- { &unsupport, 165, "R_MICROMIPS_TLS_DTPREL_LO16", 0}, \
- { &unsupport, 166, "R_MICROMIPS_TLS_GOTTPREL", 0}, \
- { &unsupport, 167, "", 0}, \
- { &unsupport, 168, "", 0}, \
- { &unsupport, 169, "R_MICROMIPS_TLS_TPREL_HI16", 0}, \
- { &unsupport, 170, "R_MICROMIPS_TLS_TPREL_LO16", 0}, \
- { &unsupport, 171, "", 0}, \
- { &unsupport, 172, "R_MICROMIPS_GPREL7_S2", 0}, \
- { &unsupport, 173, "R_MICROMIPS_PC23_S2", 0}, \
- { &unsupport, 174, "", 0}, \
- { &unsupport, 175, "", 0}, \
- { &unsupport, 176, "", 0}, \
- { &unsupport, 177, "", 0}, \
- { &unsupport, 178, "", 0}, \
- { &unsupport, 179, "", 0}, \
- { &unsupport, 180, "", 0}, \
- { &unsupport, 181, "", 0}, \
- { &unsupport, 182, "", 0}, \
- { &unsupport, 183, "", 0}, \
- { &unsupport, 184, "", 0}, \
- { &unsupport, 185, "", 0}, \
- { &unsupport, 186, "", 0}, \
- { &unsupport, 187, "", 0}, \
- { &unsupport, 188, "", 0}, \
- { &unsupport, 189, "", 0}, \
- { &unsupport, 190, "", 0}, \
- { &unsupport, 191, "", 0}, \
- { &unsupport, 192, "", 0}, \
- { &unsupport, 193, "", 0}, \
- { &unsupport, 194, "", 0}, \
- { &unsupport, 195, "", 0}, \
- { &unsupport, 196, "", 0}, \
- { &unsupport, 197, "", 0}, \
- { &unsupport, 198, "", 0}, \
- { &unsupport, 199, "", 0}, \
- { &la25lui, 200, "R_MIPS_LA25_LUI", 16}, \
- { &la25j, 201, "R_MIPS_LA25_J", 26}, \
- { &la25add, 202, "R_MIPS_LA25_ADD", 16}, \
- { &unsupport, 203, "", 0}, \
- { &unsupport, 204, "", 0}, \
- { &unsupport, 205, "", 0}, \
- { &unsupport, 206, "", 0}, \
- { &unsupport, 207, "", 0}, \
- { &unsupport, 208, "", 0}, \
- { &unsupport, 209, "", 0}, \
- { &unsupport, 210, "", 0}, \
- { &unsupport, 211, "", 0}, \
- { &unsupport, 212, "", 0}, \
- { &unsupport, 213, "", 0}, \
- { &unsupport, 214, "", 0}, \
- { &unsupport, 215, "", 0}, \
- { &unsupport, 216, "", 0}, \
- { &unsupport, 217, "", 0}, \
- { &unsupport, 218, "", 0}, \
- { &unsupport, 219, "", 0}, \
- { &unsupport, 220, "", 0}, \
- { &unsupport, 221, "", 0}, \
- { &unsupport, 222, "", 0}, \
- { &unsupport, 223, "", 0}, \
- { &unsupport, 224, "", 0}, \
- { &unsupport, 225, "", 0}, \
- { &unsupport, 226, "", 0}, \
- { &unsupport, 227, "", 0}, \
- { &unsupport, 228, "", 0}, \
- { &unsupport, 229, "", 0}, \
- { &unsupport, 230, "", 0}, \
- { &unsupport, 231, "", 0}, \
- { &unsupport, 232, "", 0}, \
- { &unsupport, 233, "", 0}, \
- { &unsupport, 234, "", 0}, \
- { &unsupport, 235, "", 0}, \
- { &unsupport, 236, "", 0}, \
- { &unsupport, 237, "", 0}, \
- { &unsupport, 238, "", 0}, \
- { &unsupport, 239, "", 0}, \
- { &unsupport, 240, "", 0}, \
- { &unsupport, 241, "", 0}, \
- { &unsupport, 242, "", 0}, \
- { &unsupport, 243, "", 0}, \
- { &unsupport, 244, "", 0}, \
- { &unsupport, 245, "", 0}, \
- { &unsupport, 246, "", 0}, \
- { &unsupport, 247, "", 0}, \
- { &pc32, 248, "R_MIPS_PC32", 0}, \
- { &unsupport, 249, "", 0}, \
- { &unsupport, 250, "R_MIPS_GNU_REL16_S2", 0}, \
- { &unsupport, 251, "", 0}, \
- { &unsupport, 252, "", 0}, \
- { &unsupport, 253, "R_MIPS_GNU_VTINHERIT", 0}, \
- { &unsupport, 254, "R_MIPS_GNU_VTENTRY", 0}
+ { &none, 0, "R_MIPS_NONE", 0}, \
+ { &unsupported, 1, "R_MIPS_16", 16}, \
+ { &abs32, 2, "R_MIPS_32", 32}, \
+ { &unsupported, 3, "R_MIPS_REL32", 32}, \
+ { &rel26, 4, "R_MIPS_26", 26}, \
+ { &hi16, 5, "R_MIPS_HI16", 16}, \
+ { &lo16, 6, "R_MIPS_LO16", 16}, \
+ { &gprel16, 7, "R_MIPS_GPREL16", 16}, \
+ { &unsupported, 8, "R_MIPS_LITERAL", 16}, \
+ { &got16, 9, "R_MIPS_GOT16", 16}, \
+ { &unsupported, 10, "R_MIPS_PC16", 16}, \
+ { &call16, 11, "R_MIPS_CALL16", 16}, \
+ { &gprel32, 12, "R_MIPS_GPREL32", 32}, \
+ { &none, 13, "R_MIPS_UNUSED1", 0}, \
+ { &none, 14, "R_MIPS_UNUSED2", 0}, \
+ { &none, 15, "R_MIPS_UNUSED3", 0}, \
+ { &unsupported, 16, "R_MIPS_SHIFT5", 32}, \
+ { &unsupported, 17, "R_MIPS_SHIFT6", 32}, \
+ { &abs64, 18, "R_MIPS_64", 64}, \
+ { &gotdisp, 19, "R_MIPS_GOT_DISP", 16}, \
+ { &gotdisp, 20, "R_MIPS_GOT_PAGE", 16}, \
+ { &gotoff, 21, "R_MIPS_GOT_OFST", 16}, \
+ { &gothi16, 22, "R_MIPS_GOT_HI16", 16}, \
+ { &gotlo16, 23, "R_MIPS_GOT_LO16", 16}, \
+ { &sub, 24, "R_MIPS_SUB", 64}, \
+ { &unsupported, 25, "R_MIPS_INSERT_A", 0}, \
+ { &unsupported, 26, "R_MIPS_INSERT_B", 0}, \
+ { &unsupported, 27, "R_MIPS_DELETE", 0}, \
+ { &unsupported, 28, "R_MIPS_HIGHER", 16}, \
+ { &unsupported, 29, "R_MIPS_HIGHEST", 16}, \
+ { &gothi16, 30, "R_MIPS_CALL_HI16", 16}, \
+ { &gotlo16, 31, "R_MIPS_CALL_LO16", 16}, \
+ { &unsupported, 32, "R_MIPS_SCN_DISP", 32}, \
+ { &unsupported, 33, "R_MIPS_REL16", 0}, \
+ { &unsupported, 34, "R_MIPS_ADD_IMMEDIATE", 0}, \
+ { &unsupported, 35, "R_MIPS_PJUMP", 0}, \
+ { &unsupported, 36, "R_MIPS_RELGOT", 0}, \
+ { &jalr, 37, "R_MIPS_JALR", 32}, \
+ { &unsupported, 38, "R_MIPS_TLS_DTPMOD32", 32}, \
+ { &unsupported, 39, "R_MIPS_TLS_DTPREL32", 32}, \
+ { &unsupported, 40, "R_MIPS_TLS_DTPMOD64", 0}, \
+ { &unsupported, 41, "R_MIPS_TLS_DTPREL64", 0}, \
+ { &unsupported, 42, "R_MIPS_TLS_GD", 16}, \
+ { &unsupported, 43, "R_MIPS_TLS_LDM", 16}, \
+ { &unsupported, 44, "R_MIPS_TLS_DTPREL_HI16", 16}, \
+ { &unsupported, 45, "R_MIPS_TLS_DTPREL_LO16", 16}, \
+ { &unsupported, 46, "R_MIPS_TLS_GOTTPREL", 16}, \
+ { &unsupported, 47, "R_MIPS_TLS_TPREL32", 32}, \
+ { &unsupported, 48, "R_MIPS_TLS_TPREL64", 0}, \
+ { &unsupported, 49, "R_MIPS_TLS_TPREL_HI16", 16}, \
+ { &unsupported, 50, "R_MIPS_TLS_TPREL_LO16", 16}, \
+ { &unsupported, 51, "R_MIPS_GLOB_DAT", 0}, \
+ { &unsupported, 52, "", 0}, \
+ { &unsupported, 53, "", 0}, \
+ { &unsupported, 54, "", 0}, \
+ { &unsupported, 55, "", 0}, \
+ { &unsupported, 56, "", 0}, \
+ { &unsupported, 57, "", 0}, \
+ { &unsupported, 58, "", 0}, \
+ { &unsupported, 59, "", 0}, \
+ { &unsupported, 60, "", 0}, \
+ { &unsupported, 61, "", 0}, \
+ { &unsupported, 62, "", 0}, \
+ { &unsupported, 63, "", 0}, \
+ { &unsupported, 64, "", 0}, \
+ { &unsupported, 65, "", 0}, \
+ { &unsupported, 66, "", 0}, \
+ { &unsupported, 67, "", 0}, \
+ { &unsupported, 68, "", 0}, \
+ { &unsupported, 69, "", 0}, \
+ { &unsupported, 70, "", 0}, \
+ { &unsupported, 71, "", 0}, \
+ { &unsupported, 72, "", 0}, \
+ { &unsupported, 73, "", 0}, \
+ { &unsupported, 74, "", 0}, \
+ { &unsupported, 75, "", 0}, \
+ { &unsupported, 76, "", 0}, \
+ { &unsupported, 77, "", 0}, \
+ { &unsupported, 78, "", 0}, \
+ { &unsupported, 79, "", 0}, \
+ { &unsupported, 80, "", 0}, \
+ { &unsupported, 81, "", 0}, \
+ { &unsupported, 82, "", 0}, \
+ { &unsupported, 83, "", 0}, \
+ { &unsupported, 84, "", 0}, \
+ { &unsupported, 85, "", 0}, \
+ { &unsupported, 86, "", 0}, \
+ { &unsupported, 87, "", 0}, \
+ { &unsupported, 88, "", 0}, \
+ { &unsupported, 89, "", 0}, \
+ { &unsupported, 90, "", 0}, \
+ { &unsupported, 91, "", 0}, \
+ { &unsupported, 92, "", 0}, \
+ { &unsupported, 93, "", 0}, \
+ { &unsupported, 94, "", 0}, \
+ { &unsupported, 95, "", 0}, \
+ { &unsupported, 96, "", 0}, \
+ { &unsupported, 97, "", 0}, \
+ { &unsupported, 98, "", 0}, \
+ { &unsupported, 99, "", 0}, \
+ { &unsupported, 100, "R_MIPS16_26", 0}, \
+ { &unsupported, 101, "R_MIPS16_GPREL", 0}, \
+ { &unsupported, 102, "R_MIPS16_GOT16", 0}, \
+ { &unsupported, 103, "R_MIPS16_CALL16", 0}, \
+ { &unsupported, 104, "R_MIPS16_HI16", 0}, \
+ { &unsupported, 105, "R_MIPS16_LO16", 0}, \
+ { &unsupported, 106, "R_MIPS16_TLS_GD", 0}, \
+ { &unsupported, 107, "R_MIPS16_TLS_LDM", 0}, \
+ { &unsupported, 108, "R_MIPS16_TLS_DTPREL_HI16", 0}, \
+ { &unsupported, 109, "R_MIPS16_TLS_DTPREL_LO16", 0}, \
+ { &unsupported, 110, "R_MIPS16_TLS_GOTTPREL", 0}, \
+ { &unsupported, 111, "R_MIPS16_TLS_TPREL_HI16", 0}, \
+ { &unsupported, 112, "R_MIPS16_TLS_TPREL_LO16", 0}, \
+ { &unsupported, 113, "", 0}, \
+ { &unsupported, 114, "", 0}, \
+ { &unsupported, 115, "", 0}, \
+ { &unsupported, 116, "", 0}, \
+ { &unsupported, 117, "", 0}, \
+ { &unsupported, 118, "", 0}, \
+ { &unsupported, 119, "", 0}, \
+ { &unsupported, 120, "", 0}, \
+ { &unsupported, 121, "", 0}, \
+ { &unsupported, 122, "", 0}, \
+ { &unsupported, 123, "", 0}, \
+ { &unsupported, 124, "", 0}, \
+ { &unsupported, 125, "", 0}, \
+ { &unsupported, 126, "R_MIPS_COPY", 0}, \
+ { &unsupported, 127, "R_MIPS_JUMP_SLOT", 0}, \
+ { &unsupported, 128, "", 0}, \
+ { &unsupported, 129, "", 0}, \
+ { &unsupported, 130, "", 0}, \
+ { &unsupported, 131, "", 0}, \
+ { &unsupported, 132, "", 0}, \
+ { &unsupported, 133, "R_MICROMIPS_26_S1", 0}, \
+ { &unsupported, 134, "R_MICROMIPS_HI16", 0}, \
+ { &unsupported, 135, "R_MICROMIPS_LO16", 0}, \
+ { &unsupported, 136, "R_MICROMIPS_GPREL16", 0}, \
+ { &unsupported, 137, "R_MICROMIPS_LITERAL", 0}, \
+ { &unsupported, 138, "R_MICROMIPS_GOT16", 0}, \
+ { &unsupported, 139, "R_MICROMIPS_PC7_S1", 0}, \
+ { &unsupported, 140, "R_MICROMIPS_PC10_S1", 0}, \
+ { &unsupported, 141, "R_MICROMIPS_PC16_S1", 0}, \
+ { &unsupported, 142, "R_MICROMIPS_CALL16", 0}, \
+ { &unsupported, 143, "R_MICROMIPS_GOT_DISP", 0}, \
+ { &unsupported, 144, "R_MICROMIPS_GOT_PAGE", 0}, \
+ { &unsupported, 145, "R_MICROMIPS_GOT_OFST", 0}, \
+ { &unsupported, 146, "R_MICROMIPS_GOT_HI16", 0}, \
+ { &unsupported, 147, "R_MICROMIPS_GOT_LO16", 0}, \
+ { &unsupported, 148, "R_MICROMIPS_SUB", 0}, \
+ { &unsupported, 149, "R_MICROMIPS_HIGHER", 0}, \
+ { &unsupported, 150, "R_MICROMIPS_HIGHEST", 0}, \
+ { &unsupported, 151, "R_MICROMIPS_CALL_HI16", 0}, \
+ { &unsupported, 152, "R_MICROMIPS_CALL_LO16", 0}, \
+ { &unsupported, 153, "R_MICROMIPS_SCN_DISP", 0}, \
+ { &unsupported, 154, "R_MICROMIPS_JALR", 0}, \
+ { &unsupported, 155, "R_MICROMIPS_HI0_LO16", 0}, \
+ { &unsupported, 156, "", 0}, \
+ { &unsupported, 157, "", 0}, \
+ { &unsupported, 158, "", 0}, \
+ { &unsupported, 159, "", 0}, \
+ { &unsupported, 160, "", 0}, \
+ { &unsupported, 161, "", 0}, \
+ { &unsupported, 162, "R_MICROMIPS_TLS_GD", 0}, \
+ { &unsupported, 163, "R_MICROMIPS_TLS_LDM", 0}, \
+ { &unsupported, 164, "R_MICROMIPS_TLS_DTPREL_HI16", 0}, \
+ { &unsupported, 165, "R_MICROMIPS_TLS_DTPREL_LO16", 0}, \
+ { &unsupported, 166, "R_MICROMIPS_TLS_GOTTPREL", 0}, \
+ { &unsupported, 167, "", 0}, \
+ { &unsupported, 168, "", 0}, \
+ { &unsupported, 169, "R_MICROMIPS_TLS_TPREL_HI16", 0}, \
+ { &unsupported, 170, "R_MICROMIPS_TLS_TPREL_LO16", 0}, \
+ { &unsupported, 171, "", 0}, \
+ { &unsupported, 172, "R_MICROMIPS_GPREL7_S2", 0}, \
+ { &unsupported, 173, "R_MICROMIPS_PC23_S2", 0}, \
+ { &unsupported, 174, "", 0}, \
+ { &unsupported, 175, "", 0}, \
+ { &unsupported, 176, "", 0}, \
+ { &unsupported, 177, "", 0}, \
+ { &unsupported, 178, "", 0}, \
+ { &unsupported, 179, "", 0}, \
+ { &unsupported, 180, "", 0}, \
+ { &unsupported, 181, "", 0}, \
+ { &unsupported, 182, "", 0}, \
+ { &unsupported, 183, "", 0}, \
+ { &unsupported, 184, "", 0}, \
+ { &unsupported, 185, "", 0}, \
+ { &unsupported, 186, "", 0}, \
+ { &unsupported, 187, "", 0}, \
+ { &unsupported, 188, "", 0}, \
+ { &unsupported, 189, "", 0}, \
+ { &unsupported, 190, "", 0}, \
+ { &unsupported, 191, "", 0}, \
+ { &unsupported, 192, "", 0}, \
+ { &unsupported, 193, "", 0}, \
+ { &unsupported, 194, "", 0}, \
+ { &unsupported, 195, "", 0}, \
+ { &unsupported, 196, "", 0}, \
+ { &unsupported, 197, "", 0}, \
+ { &unsupported, 198, "", 0}, \
+ { &unsupported, 199, "", 0}, \
+ { &la25lui, 200, "R_MIPS_LA25_LUI", 16}, \
+ { &la25j, 201, "R_MIPS_LA25_J", 26}, \
+ { &la25add, 202, "R_MIPS_LA25_ADD", 16}, \
+ { &unsupported, 203, "", 0}, \
+ { &unsupported, 204, "", 0}, \
+ { &unsupported, 205, "", 0}, \
+ { &unsupported, 206, "", 0}, \
+ { &unsupported, 207, "", 0}, \
+ { &unsupported, 208, "", 0}, \
+ { &unsupported, 209, "", 0}, \
+ { &unsupported, 210, "", 0}, \
+ { &unsupported, 211, "", 0}, \
+ { &unsupported, 212, "", 0}, \
+ { &unsupported, 213, "", 0}, \
+ { &unsupported, 214, "", 0}, \
+ { &unsupported, 215, "", 0}, \
+ { &unsupported, 216, "", 0}, \
+ { &unsupported, 217, "", 0}, \
+ { &unsupported, 218, "", 0}, \
+ { &unsupported, 219, "", 0}, \
+ { &unsupported, 220, "", 0}, \
+ { &unsupported, 221, "", 0}, \
+ { &unsupported, 222, "", 0}, \
+ { &unsupported, 223, "", 0}, \
+ { &unsupported, 224, "", 0}, \
+ { &unsupported, 225, "", 0}, \
+ { &unsupported, 226, "", 0}, \
+ { &unsupported, 227, "", 0}, \
+ { &unsupported, 228, "", 0}, \
+ { &unsupported, 229, "", 0}, \
+ { &unsupported, 230, "", 0}, \
+ { &unsupported, 231, "", 0}, \
+ { &unsupported, 232, "", 0}, \
+ { &unsupported, 233, "", 0}, \
+ { &unsupported, 234, "", 0}, \
+ { &unsupported, 235, "", 0}, \
+ { &unsupported, 236, "", 0}, \
+ { &unsupported, 237, "", 0}, \
+ { &unsupported, 238, "", 0}, \
+ { &unsupported, 239, "", 0}, \
+ { &unsupported, 240, "", 0}, \
+ { &unsupported, 241, "", 0}, \
+ { &unsupported, 242, "", 0}, \
+ { &unsupported, 243, "", 0}, \
+ { &unsupported, 244, "", 0}, \
+ { &unsupported, 245, "", 0}, \
+ { &unsupported, 246, "", 0}, \
+ { &unsupported, 247, "", 0}, \
+ { &pc32, 248, "R_MIPS_PC32", 0}, \
+ { &unsupported, 249, "", 0}, \
+ { &unsupported, 250, "R_MIPS_GNU_REL16_S2", 0}, \
+ { &unsupported, 251, "", 0}, \
+ { &unsupported, 252, "", 0}, \
+ { &unsupported, 253, "R_MIPS_GNU_VTINHERIT", 0}, \
+ { &unsupported, 254, "R_MIPS_GNU_VTENTRY", 0}
+
+#endif // TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/Mips/MipsRelocator.cpp b/lib/Target/Mips/MipsRelocator.cpp
index 7da4dfd..d8039b7 100644
--- a/lib/Target/Mips/MipsRelocator.cpp
+++ b/lib/Target/Mips/MipsRelocator.cpp
@@ -9,12 +9,12 @@
#include "MipsRelocator.h"
#include "MipsRelocationFunctions.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/OutputRelocSection.h>
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/OutputRelocSection.h"
+#include "mcld/LD/ELFFileFormat.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/ELF.h>
@@ -25,28 +25,27 @@
// FIXME: Consider upstream these relocation types to LLVM.
enum {
R_MIPS_LA25_LUI = 200,
- R_MIPS_LA25_J = 201,
+ R_MIPS_LA25_J = 201,
R_MIPS_LA25_ADD = 202,
};
-} // end namespace ELF
-} // end namespace llvm
+} // namespace ELF
+} // namespace llvm
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsRelocationInfo
//===----------------------------------------------------------------------===//
-class mcld::MipsRelocationInfo
-{
-public:
- static bool HasSubType(const Relocation& pParent, Relocation::Type pType)
- {
+class MipsRelocationInfo {
+ public:
+ static bool HasSubType(const Relocation& pParent, Relocation::Type pType) {
if (llvm::ELF::R_MIPS_NONE == pType)
return true;
for (Relocation::Type type = pParent.type();
- llvm::ELF::R_MIPS_NONE != (type & 0xff); type >>= 8) {
+ llvm::ELF::R_MIPS_NONE != (type & 0xff);
+ type >>= 8) {
if ((type & 0xff) == pType)
return true;
}
@@ -55,12 +54,11 @@
}
MipsRelocationInfo(Relocation& pParent, bool pIsRel)
- : m_Parent(&pParent),
- m_Type(pParent.type()),
- m_Addend(0),
- m_Symbol(pParent.symValue()),
- m_Result(pParent.target())
- {
+ : m_Parent(&pParent),
+ m_Type(pParent.type()),
+ m_Addend(0),
+ m_Symbol(pParent.symValue()),
+ m_Result(pParent.target()) {
if (pIsRel && (type() < llvm::ELF::R_MIPS_LA25_LUI ||
type() > llvm::ELF::R_MIPS_LA25_ADD))
m_Addend = pParent.target();
@@ -68,81 +66,49 @@
m_Addend = pParent.addend();
}
- bool isNone() const
- {
- return llvm::ELF::R_MIPS_NONE == type();
- }
+ bool isNone() const { return llvm::ELF::R_MIPS_NONE == type(); }
- bool isLast() const
- {
- return llvm::ELF::R_MIPS_NONE == (m_Type >> 8);
- }
+ bool isLast() const { return llvm::ELF::R_MIPS_NONE == (m_Type >> 8); }
- MipsRelocationInfo next() const
- {
+ MipsRelocationInfo next() const {
return MipsRelocationInfo(*m_Parent, m_Type >> 8, result(), result(), 0);
}
- const Relocation& parent() const
- {
- return *m_Parent;
- }
+ const Relocation& parent() const { return *m_Parent; }
- Relocation& parent()
- {
- return *m_Parent;
- }
+ Relocation& parent() { return *m_Parent; }
- Relocation::Type type() const
- {
- return m_Type & 0xff;
- }
+ Relocation::Type type() const { return m_Type & 0xff; }
- Relocation::DWord A() const
- {
- return m_Addend;
- }
+ Relocation::DWord A() const { return m_Addend; }
- Relocation::DWord S() const
- {
- return m_Symbol;
- }
+ Relocation::DWord S() const { return m_Symbol; }
- Relocation::DWord P() const
- {
- return parent().place();
- }
+ Relocation::DWord P() const { return parent().place(); }
- Relocation::DWord result() const
- {
- return m_Result;
- }
+ Relocation::DWord result() const { return m_Result; }
- Relocation::DWord& result()
- {
- return m_Result;
- }
+ Relocation::DWord& result() { return m_Result; }
-private:
+ private:
Relocation* m_Parent;
Relocation::Type m_Type;
Relocation::DWord m_Addend;
Relocation::DWord m_Symbol;
Relocation::DWord m_Result;
- MipsRelocationInfo(Relocation& pParent, Relocation::Type pType,
+ MipsRelocationInfo(Relocation& pParent,
+ Relocation::Type pType,
Relocation::DWord pResult,
- Relocation::DWord pAddend, Relocation::DWord pSymbol)
- : m_Parent(&pParent),
- m_Type(pType),
- m_Addend(pAddend),
- m_Symbol(pSymbol),
- m_Result(pResult)
- {}
+ Relocation::DWord pAddend,
+ Relocation::DWord pSymbol)
+ : m_Parent(&pParent),
+ m_Type(pType),
+ m_Addend(pAddend),
+ m_Symbol(pSymbol),
+ m_Result(pResult) {}
- bool isFirst() const {
- return m_Type == parent().type();
- }
+ bool isFirst() const { return m_Type == parent().type(); }
};
//===----------------------------------------------------------------------===//
@@ -154,10 +120,8 @@
typedef Relocator::Result (*ApplyFunctionType)(MipsRelocationInfo&,
MipsRelocator& pParent);
-
// the table entry of applying functions
-struct ApplyFunctionTriple
-{
+struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -166,38 +130,34 @@
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_MIPS_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_MIPS_APPLY_RELOC_FUNC_PTRS};
//===----------------------------------------------------------------------===//
// MipsRelocator
//===----------------------------------------------------------------------===//
MipsRelocator::MipsRelocator(MipsGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent),
- m_pApplyingInput(NULL),
- m_CurrentLo16Reloc(NULL)
-{
+ : Relocator(pConfig),
+ m_Target(pParent),
+ m_pApplyingInput(NULL),
+ m_CurrentLo16Reloc(NULL) {
}
-Relocator::Result
-MipsRelocator::applyRelocation(Relocation& pReloc)
-{
+Relocator::Result MipsRelocator::applyRelocation(Relocation& pReloc) {
// If m_CurrentLo16Reloc is not NULL we are processing
// postponed relocation. Otherwise check relocation type
// and postpone it for later handling.
- if (NULL == m_CurrentLo16Reloc && isPostponed(pReloc)) {
+ if (m_CurrentLo16Reloc == NULL && isPostponed(pReloc)) {
postponeRelocation(pReloc);
return OK;
}
- for (MipsRelocationInfo info(pReloc, isRel());
- !info.isNone(); info = info.next()) {
+ for (MipsRelocationInfo info(pReloc, isRel()); !info.isNone();
+ info = info.next()) {
if (info.type() >= sizeof(ApplyFunctions) / sizeof(ApplyFunctions[0]))
return Unknown;
- const ApplyFunctionTriple & triple = ApplyFunctions[info.type()];
+ const ApplyFunctionTriple& triple = ApplyFunctions[info.type()];
Result res = triple.func(info, *this);
if (OK != res)
@@ -213,13 +173,11 @@
return OK;
}
-const char* MipsRelocator::getName(Relocation::Type pType) const
-{
+const char* MipsRelocator::getName(Relocation::Type pType) const {
return ApplyFunctions[pType & 0xff].name;
}
-Relocator::Size MipsRelocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size MipsRelocator::getSize(Relocation::Type pType) const {
return ApplyFunctions[pType & 0xff].size;
}
@@ -227,23 +185,23 @@
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym && "ResolveInfo of relocation not set while scanRelocation");
+ assert(rsym != NULL &&
+ "ResolveInfo of relocation not set while scanRelocation");
// Skip relocation against _gp_disp
- if (NULL != getTarget().getGpDispSymbol() &&
+ if (getTarget().getGpDispSymbol() != NULL &&
rsym == getTarget().getGpDispSymbol()->resolveInfo())
return;
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
- for (MipsRelocationInfo info(pReloc, isRel());
- !info.isNone(); info = info.next()) {
+ for (MipsRelocationInfo info(pReloc, isRel()); !info.isNone();
+ info = info.next()) {
// We test isLocal or if pInputSym is not a dynamic symbol
// We assume -Bsymbolic to bind all symbols internaly via !rsym->isDyn()
// Don't put undef symbols into local entries.
@@ -262,39 +220,34 @@
issueUndefRef(pReloc, pSection, pInput);
}
-bool MipsRelocator::initializeScan(Input& pInput)
-{
+bool MipsRelocator::initializeScan(Input& pInput) {
if (LinkerConfig::Object != config().codeGenType())
getTarget().getGOT().initializeScan(pInput);
return true;
}
-bool MipsRelocator::finalizeScan(Input& pInput)
-{
+bool MipsRelocator::finalizeScan(Input& pInput) {
if (LinkerConfig::Object != config().codeGenType())
getTarget().getGOT().finalizeScan(pInput);
return true;
}
-bool MipsRelocator::initializeApply(Input& pInput)
-{
+bool MipsRelocator::initializeApply(Input& pInput) {
m_pApplyingInput = &pInput;
return true;
}
-bool MipsRelocator::finalizeApply(Input& pInput)
-{
+bool MipsRelocator::finalizeApply(Input& pInput) {
m_pApplyingInput = NULL;
return true;
}
void MipsRelocator::scanLocalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- switch (pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_MIPS_NONE:
case llvm::ELF::R_MIPS_16:
break;
@@ -342,8 +295,9 @@
case llvm::ELF::R_MIPS_GOT_DISP:
case llvm::ELF::R_MIPS_GOT_PAGE:
case llvm::ELF::R_MIPS_GOT_OFST:
- if (getTarget().getGOT().reserveLocalEntry(*rsym,
- pReloc.type(), pReloc.A())) {
+ if (getTarget()
+ .getGOT()
+ .reserveLocalEntry(*rsym, pReloc.type(), pReloc.A())) {
if (getTarget().getGOT().hasMultipleGOT())
getTarget().checkAndSetHasTextRel(*pSection.getLink());
}
@@ -369,17 +323,17 @@
case llvm::ELF::R_MIPS_PC32:
break;
default:
- fatal(diag::unknown_relocation) << (int)pReloc.type() << rsym->name();
+ fatal(diag::unknown_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name();
}
}
void MipsRelocator::scanGlobalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- switch (pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_MIPS_NONE:
case llvm::ELF::R_MIPS_INSERT_A:
case llvm::ELF::R_MIPS_INSERT_B:
@@ -401,8 +355,7 @@
if (getTarget().symbolNeedsCopyReloc(pReloc.parent(), *rsym)) {
LDSymbol& cpySym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpySym.resolveInfo());
- }
- else {
+ } else {
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -425,7 +378,7 @@
break;
case llvm::ELF::R_MIPS_LITERAL:
case llvm::ELF::R_MIPS_GPREL32:
- fatal(diag::invalid_global_relocation) << (int)pReloc.type()
+ fatal(diag::invalid_global_relocation) << static_cast<int>(pReloc.type())
<< rsym->name();
break;
case llvm::ELF::R_MIPS_GPREL16:
@@ -467,15 +420,15 @@
case llvm::ELF::R_MIPS_COPY:
case llvm::ELF::R_MIPS_GLOB_DAT:
case llvm::ELF::R_MIPS_JUMP_SLOT:
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
default:
- fatal(diag::unknown_relocation) << (int)pReloc.type() << rsym->name();
+ fatal(diag::unknown_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name();
}
}
-bool MipsRelocator::isPostponed(const Relocation& pReloc) const
-{
+bool MipsRelocator::isPostponed(const Relocation& pReloc) const {
if (MipsRelocationInfo::HasSubType(pReloc, llvm::ELF::R_MIPS_HI16))
return true;
@@ -486,8 +439,7 @@
return false;
}
-void MipsRelocator::addCopyReloc(ResolveInfo& pSym)
-{
+void MipsRelocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& relEntry = *getTarget().getRelDyn().consumeEntry();
relEntry.setType(llvm::ELF::R_MIPS_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -496,18 +448,17 @@
}
LDSymbol& MipsRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+ const ResolveInfo& pSym) {
// Get or create corresponding BSS LDSection
ELFFileFormat* fileFormat = getTarget().getOutputFormat();
- LDSection* bssSectHdr =
- ResolveInfo::ThreadLocal == pSym.type() ? &fileFormat->getTBSS()
- : &fileFormat->getBSS();
+ LDSection* bssSectHdr = ResolveInfo::ThreadLocal == pSym.type()
+ ? &fileFormat->getTBSS()
+ : &fileFormat->getBSS();
// Get or create corresponding BSS SectionData
- SectionData* bssData =
- bssSectHdr->hasSectionData() ? bssSectHdr->getSectionData()
- : IRBuilder::CreateSectionData(*bssSectHdr);
+ SectionData* bssData = bssSectHdr->hasSectionData()
+ ? bssSectHdr->getSectionData()
+ : IRBuilder::CreateSectionData(*bssSectHdr);
// Determine the alignment by the symbol value
// FIXME: here we use the largest alignment
@@ -525,22 +476,23 @@
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpySym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// Output all other alias symbols if any
Module::AliasList* alias_list = pBuilder.getModule().getAliasList(pSym);
- if (NULL == alias_list)
+ if (alias_list == NULL)
return *cpySym;
for (Module::alias_iterator it = alias_list->begin(), ie = alias_list->end();
- it != ie; ++it) {
+ it != ie;
+ ++it) {
const ResolveInfo* alias = *it;
if (alias == &pSym || !alias->isDyn())
continue;
@@ -559,19 +511,17 @@
return *cpySym;
}
-void MipsRelocator::postponeRelocation(Relocation& pReloc)
-{
+void MipsRelocator::postponeRelocation(Relocation& pReloc) {
ResolveInfo* rsym = pReloc.symInfo();
m_PostponedRelocs[rsym].insert(&pReloc);
}
-void MipsRelocator::applyPostponedRelocations(MipsRelocationInfo& pLo16Reloc)
-{
+void MipsRelocator::applyPostponedRelocations(MipsRelocationInfo& pLo16Reloc) {
m_CurrentLo16Reloc = &pLo16Reloc;
ResolveInfo* rsym = pLo16Reloc.parent().symInfo();
- RelocationSet & relocs = m_PostponedRelocs[rsym];
+ RelocationSet& relocs = m_PostponedRelocs[rsym];
for (RelocationSet::iterator it = relocs.begin(); it != relocs.end(); ++it)
(*it)->apply(*this);
@@ -580,39 +530,31 @@
m_CurrentLo16Reloc = NULL;
}
-bool MipsRelocator::isGpDisp(const Relocation& pReloc) const
-{
- return 0 == strcmp("_gp_disp", pReloc.symInfo()->name());
+bool MipsRelocator::isGpDisp(const Relocation& pReloc) const {
+ return strcmp("_gp_disp", pReloc.symInfo()->name()) == 0;
}
-bool MipsRelocator::isRel() const
-{
+bool MipsRelocator::isRel() const {
return config().targets().is32Bits();
}
-bool MipsRelocator::isLocalReloc(ResolveInfo& pSym) const
-{
+bool MipsRelocator::isLocalReloc(ResolveInfo& pSym) const {
if (pSym.isUndef())
return false;
- return pSym.isLocal() ||
- !getTarget().isDynamicSymbol(pSym) ||
- !pSym.isDyn();
+ return pSym.isLocal() || !getTarget().isDynamicSymbol(pSym) || !pSym.isDyn();
}
-Relocator::Address MipsRelocator::getGPAddress()
-{
+Relocator::Address MipsRelocator::getGPAddress() {
return getTarget().getGOT().getGPAddr(getApplyingInput());
}
-Relocator::Address MipsRelocator::getGP0()
-{
+Relocator::Address MipsRelocator::getGP0() {
return getTarget().getGP0(getApplyingInput());
}
Fragment& MipsRelocator::getLocalGOTEntry(MipsRelocationInfo& pReloc,
- Relocation::DWord entryValue)
-{
+ Relocation::DWord entryValue) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -623,7 +565,7 @@
Fragment* got_entry = got.lookupLocalEntry(rsym, entryValue);
// Found a mapping, then return the mapped entry immediately.
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Not found.
@@ -639,8 +581,7 @@
return *got_entry;
}
-Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc)
-{
+Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -651,7 +592,7 @@
Fragment* got_entry = got.lookupGlobalEntry(rsym);
// Found a mapping, then return the mapped entry immediately.
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Not found.
@@ -667,8 +608,7 @@
return *got_entry;
}
-Relocator::Address MipsRelocator::getGOTOffset(MipsRelocationInfo& pReloc)
-{
+Relocator::Address MipsRelocator::getGOTOffset(MipsRelocationInfo& pReloc) {
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -680,14 +620,12 @@
return got.getGPRelOffset(getApplyingInput(),
getLocalGOTEntry(pReloc, value));
- }
- else {
+ } else {
return got.getGPRelOffset(getApplyingInput(), getGlobalGOTEntry(pReloc));
}
}
-void MipsRelocator::createDynRel(MipsRelocationInfo& pReloc)
-{
+void MipsRelocator::createDynRel(MipsRelocationInfo& pReloc) {
Relocator::DWord A = pReloc.A();
Relocator::DWord S = pReloc.S();
@@ -696,17 +634,15 @@
if (isLocalReloc(*rsym)) {
setupRelDynEntry(pReloc.parent().targetRef(), NULL);
pReloc.result() = A + S;
- }
- else {
+ } else {
setupRelDynEntry(pReloc.parent().targetRef(), rsym);
// Don't add symbol value that will be resolved by the dynamic linker.
pReloc.result() = A;
}
}
-uint64_t MipsRelocator::calcAHL(const MipsRelocationInfo& pHiReloc)
-{
- assert(NULL != m_CurrentLo16Reloc &&
+uint64_t MipsRelocator::calcAHL(const MipsRelocationInfo& pHiReloc) {
+ assert(m_CurrentLo16Reloc != NULL &&
"There is no saved R_MIPS_LO16 relocation");
uint64_t AHI = pHiReloc.A() & 0xFFFF;
@@ -716,13 +652,11 @@
return AHL;
}
-bool MipsRelocator::isN64ABI() const
-{
+bool MipsRelocator::isN64ABI() const {
return config().targets().is64Bits();
}
-uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym)
-{
+uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym) {
assert((rsym.reserved() & MipsRelocator::ReservePLT) &&
"Symbol does not require a PLT entry");
@@ -732,8 +666,7 @@
if (it != m_SymPLTMap.end()) {
plt = it->second.first;
- }
- else {
+ } else {
plt = getTarget().getPLT().consume();
Fragment* got = getTarget().getGOTPLT().consume();
@@ -749,16 +682,33 @@
return getTarget().getPLT().addr() + plt->getOffset();
}
+uint32_t MipsRelocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_MIPS_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void MipsRelocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
+
//===----------------------------------------------------------------------===//
// Mips32Relocator
//===----------------------------------------------------------------------===//
Mips32Relocator::Mips32Relocator(Mips32GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : MipsRelocator(pParent, pConfig)
-{}
+ : MipsRelocator(pParent, pConfig) {
+}
-void Mips32Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
-{
+void Mips32Relocator::setupRelDynEntry(FragmentRef& pFragRef,
+ ResolveInfo* pSym) {
Relocation& relEntry = *getTarget().getRelDyn().consumeEntry();
relEntry.setType(llvm::ELF::R_MIPS_REL32);
relEntry.targetRef() = pFragRef;
@@ -770,13 +720,12 @@
//===----------------------------------------------------------------------===//
Mips64Relocator::Mips64Relocator(Mips64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : MipsRelocator(pParent, pConfig)
-{}
+ : MipsRelocator(pParent, pConfig) {
+}
-void Mips64Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
-{
- Relocation::Type type = llvm::ELF::R_MIPS_REL32 |
- llvm::ELF::R_MIPS_64 << 8;
+void Mips64Relocator::setupRelDynEntry(FragmentRef& pFragRef,
+ ResolveInfo* pSym) {
+ Relocation::Type type = llvm::ELF::R_MIPS_REL32 | llvm::ELF::R_MIPS_64 << 8;
// FIXME (simon): Fix dynamic relocations.
type = llvm::ELF::R_MIPS_NONE;
@@ -791,27 +740,26 @@
//=========================================//
// R_MIPS_NONE and those unsupported/deprecated relocation type
-static
-MipsRelocator::Result none(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result none(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
// R_MIPS_32: S + A
-static
-MipsRelocator::Result abs32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result abs32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
ResolveInfo* rsym = pReloc.parent().symInfo();
Relocator::DWord A = pReloc.A();
Relocator::DWord S = pReloc.S();
LDSection& target_sect =
- pReloc.parent().targetRef().frag()->getParent()->getSection();
+ pReloc.parent().targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.result() = S + A;
return Relocator::OK;
}
@@ -829,12 +777,11 @@
// R_MIPS_26:
// local : ((A | ((P + 4) & 0x3F000000)) + S) >> 2
// external: (sign–extend(A) + S) >> 2
-static
-MipsRelocator::Result rel26(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result rel26(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- int32_t A = ((pReloc.parent().target() & 0x03FFFFFF) << 2);
+ int32_t A = pParent.isN64ABI() ? pReloc.A() : (pReloc.A() & 0x03FFFFFF) << 2;
int32_t P = pReloc.P();
int32_t S = rsym->reserved() & MipsRelocator::ReservePLT
? pParent.getPLTAddress(*rsym)
@@ -843,7 +790,7 @@
if (rsym->isLocal())
pReloc.result() = A | ((P + 4) & 0x3F000000);
else
- pReloc.result() = mcld::signExtend<28>(A);
+ pReloc.result() = signExtend<28>(A);
pReloc.result() = (pReloc.result() + S) >> 2;
@@ -853,17 +800,15 @@
// R_MIPS_HI16:
// local/external: ((AHL + S) - (short)(AHL + S)) >> 16
// _gp_disp : ((AHL + GP - P) - (short)(AHL + GP - P)) >> 16
-static
-MipsRelocator::Result hi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result hi16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
uint64_t AHL = pParent.calcAHL(pReloc);
if (pParent.isGpDisp(pReloc.parent())) {
int32_t P = pReloc.P();
int32_t GP = pParent.getGPAddress();
pReloc.result() = ((AHL + GP - P) - (int16_t)(AHL + GP - P)) >> 16;
- }
- else {
+ } else {
int32_t S = pReloc.S();
if (pParent.isN64ABI())
pReloc.result() = (pReloc.A() + S + 0x8000ull) >> 16;
@@ -877,9 +822,8 @@
// R_MIPS_LO16:
// local/external: AHL + S
// _gp_disp : AHL + GP - P + 4
-static
-MipsRelocator::Result lo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result lo16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// AHL is a combination of HI16 and LO16 addends. But R_MIPS_LO16
// uses low 16 bits of the AHL. That is why we do not need R_MIPS_HI16
// addend here.
@@ -889,8 +833,7 @@
int32_t P = pReloc.P();
int32_t GP = pParent.getGPAddress();
pReloc.result() = AHL + GP - P + 4;
- }
- else {
+ } else {
int32_t S = pReloc.S();
pReloc.result() = AHL + S;
}
@@ -903,9 +846,8 @@
// R_MIPS_GPREL16:
// external: sign–extend(A) + S - GP
// local : sign–extend(A) + S + GP0 – GP
-static
-MipsRelocator::Result gprel16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gprel16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// Remember to add the section offset to A.
uint64_t A = pReloc.A();
uint64_t S = pReloc.S();
@@ -924,9 +866,8 @@
// R_MIPS_GOT16:
// local : G (calculate AHL and put high 16 bit to GOT)
// external: G
-static
-MipsRelocator::Result got16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result got16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
if (pReloc.parent().symInfo()->isLocal()) {
int32_t AHL = pParent.calcAHL(pReloc);
int32_t S = pReloc.S();
@@ -937,8 +878,7 @@
Fragment& got_entry = pParent.getLocalGOTEntry(pReloc, res);
pReloc.result() = got.getGPRelOffset(pParent.getApplyingInput(), got_entry);
- }
- else {
+ } else {
pReloc.result() = pParent.getGOTOffset(pReloc);
}
@@ -947,9 +887,8 @@
// R_MIPS_GOTHI16:
// external: (G - (short)G) >> 16 + A
-static
-MipsRelocator::Result gothi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gothi16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
Relocator::Address G = pParent.getGOTOffset(pReloc);
int32_t A = pReloc.A();
@@ -960,9 +899,8 @@
// R_MIPS_GOTLO16:
// external: G & 0xffff
-static
-MipsRelocator::Result gotlo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotlo16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc) & 0xffff;
return Relocator::OK;
@@ -970,9 +908,8 @@
// R_MIPS_SUB:
// external/local: S - A
-static
-MipsRelocator::Result sub(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result sub(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
uint64_t S = pReloc.S();
uint64_t A = pReloc.A();
@@ -982,18 +919,16 @@
}
// R_MIPS_CALL16: G
-static
-MipsRelocator::Result call16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result call16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc);
return Relocator::OK;
}
// R_MIPS_GPREL32: A + S + GP0 - GP
-static
-MipsRelocator::Result gprel32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gprel32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// Remember to add the section offset to A.
uint64_t A = pReloc.A();
uint64_t S = pReloc.S();
@@ -1006,9 +941,8 @@
}
// R_MIPS_64: S + A
-static
-MipsRelocator::Result abs64(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result abs64(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// FIXME (simon): Consider to merge with abs32() or use the same function
// but with another mask size.
ResolveInfo* rsym = pReloc.parent().symInfo();
@@ -1017,9 +951,10 @@
Relocator::DWord S = pReloc.S();
LDSection& target_sect =
- pReloc.parent().targetRef().frag()->getParent()->getSection();
+ pReloc.parent().targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
pReloc.result() = S + A;
@@ -1037,33 +972,29 @@
}
// R_MIPS_GOT_DISP / R_MIPS_GOT_PAGE: G
-static
-MipsRelocator::Result gotdisp(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotdisp(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc);
return Relocator::OK;
}
// R_MIPS_GOT_OFST:
-static
-MipsRelocator::Result gotoff(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotoff(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// FIXME (simon): Needs to be implemented.
return Relocator::OK;
}
// R_MIPS_JALR:
-static
-MipsRelocator::Result jalr(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result jalr(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
// R_MIPS_LA25_LUI
-static
-MipsRelocator::Result la25lui(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25lui(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
int32_t S = pReloc.S();
pReloc.result() = (S + 0x8000) >> 16;
@@ -1072,9 +1003,8 @@
}
// R_MIPS_LA25_J
-static
-MipsRelocator::Result la25j(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25j(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
int32_t S = pReloc.S();
pReloc.result() = S >> 2;
@@ -1083,23 +1013,22 @@
}
// R_MIPS_LA25_ADD
-static
-MipsRelocator::Result la25add(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25add(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pReloc.S();
return Relocator::OK;
}
// R_MIPS_PC32:
-static
-MipsRelocator::Result pc32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result pc32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
-static
-MipsRelocator::Result unsupport(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
- return Relocator::Unsupport;
+static MipsRelocator::Result unsupported(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsRelocator.h b/lib/Target/Mips/MipsRelocator.h
index 5456a9f..27d5896 100644
--- a/lib/Target/Mips/MipsRelocator.h
+++ b/lib/Target/Mips/MipsRelocator.h
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSRELOCATOR_H
-#define TARGET_MIPS_MIPSRELOCATOR_H
+#ifndef TARGET_MIPS_MIPSRELOCATOR_H_
+#define TARGET_MIPS_MIPSRELOCATOR_H_
+
+#include "mcld/LD/Relocator.h"
+#include "mcld/Support/GCFactory.h"
+#include "MipsLDBackend.h"
#include <llvm/ADT/DenseMapInfo.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/Support/GCFactory.h>
-#include "MipsLDBackend.h"
namespace mcld {
@@ -21,17 +22,16 @@
/** \class MipsRelocator
* \brief MipsRelocator creates and destroys the Mips relocations.
*/
-class MipsRelocator : public Relocator
-{
-public:
+class MipsRelocator : public Relocator {
+ public:
enum ReservedEntryType {
- None = 0, // no reserved entry
- ReserveRel = 1, // reserve a dynamic relocation entry
- ReserveGot = 2, // reserve a GOT entry
- ReservePLT = 4 // reserve a PLT entry
+ None = 0, // no reserved entry
+ ReserveRel = 1, // reserve a dynamic relocation entry
+ ReserveGot = 2, // reserve a GOT entry
+ ReservePLT = 4 // reserve a PLT entry
};
-public:
+ public:
MipsRelocator(MipsGNULDBackend& pParent, const LinkerConfig& pConfig);
/// scanRelocation - determine the empty entries are needed or not and
@@ -61,14 +61,19 @@
Result applyRelocation(Relocation& pReloc);
- const Input& getApplyingInput() const
- { return *m_pApplyingInput; }
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
- MipsGNULDBackend& getTarget()
- { return m_Target; }
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
- const MipsGNULDBackend& getTarget() const
- { return m_Target; }
+ const Input& getApplyingInput() const { return *m_pApplyingInput; }
+
+ MipsGNULDBackend& getTarget() { return m_Target; }
+
+ const MipsGNULDBackend& getTarget() const { return m_Target; }
/// postponeRelocation - save R_MIPS_LO16 paired relocations
/// like R_MISP_HI16 and R_MIPS_GOT16 for a future processing.
@@ -118,27 +123,27 @@
Size getSize(Relocation::Type pType) const;
-protected:
+ protected:
/// setupRelDynEntry - create dynamic relocation entry.
virtual void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym) = 0;
/// isLocalReloc - handle relocation as a local symbol
bool isLocalReloc(ResolveInfo& pSym) const;
-private:
+ private:
typedef std::pair<Fragment*, Fragment*> PLTDescriptor;
typedef llvm::DenseMap<const ResolveInfo*, PLTDescriptor> SymPLTMap;
typedef llvm::DenseSet<Relocation*> RelocationSet;
typedef llvm::DenseMap<const ResolveInfo*, RelocationSet> SymRelocSetMap;
-private:
+ private:
MipsGNULDBackend& m_Target;
SymPLTMap m_SymPLTMap;
Input* m_pApplyingInput;
SymRelocSetMap m_PostponedRelocs;
MipsRelocationInfo* m_CurrentLo16Reloc;
-private:
+ private:
void scanLocalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
const LDSection& pSection);
@@ -167,12 +172,11 @@
/** \class Mips32Relocator
* \brief Mips32Relocator creates and destroys the Mips 32-bit relocations.
*/
-class Mips32Relocator : public MipsRelocator
-{
-public:
+class Mips32Relocator : public MipsRelocator {
+ public:
Mips32Relocator(Mips32GNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
// MipsRelocator
void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym);
};
@@ -180,16 +184,15 @@
/** \class Mips64Relocator
* \brief Mips64Relocator creates and destroys the Mips 64-bit relocations.
*/
-class Mips64Relocator : public MipsRelocator
-{
-public:
+class Mips64Relocator : public MipsRelocator {
+ public:
Mips64Relocator(Mips64GNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
// MipsRelocator
void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSRELOCATOR_H_
diff --git a/lib/Target/Mips/MipsTargetMachine.cpp b/lib/Target/Mips/MipsTargetMachine.cpp
deleted file mode 100644
index 2e57868..0000000
--- a/lib/Target/Mips/MipsTargetMachine.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- MipsTargetMachine.cpp ----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "MipsTargetMachine.h"
-#include "Mips.h"
-#include <mcld/Support/TargetRegistry.h>
-
-typedef mcld::RegisterTargetMachine<mcld::MipsBaseTargetMachine> RegMipsTarget;
-
-extern "C" void MCLDInitializeMipsLDTarget() {
- RegMipsTarget X1(mcld::TheMipselTarget);
- RegMipsTarget X2(mcld::TheMips64elTarget);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// MipsBaseTargetMachine
-//===----------------------------------------------------------------------===//
-MipsBaseTargetMachine::MipsBaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
diff --git a/lib/Target/Mips/MipsTargetMachine.h b/lib/Target/Mips/MipsTargetMachine.h
deleted file mode 100644
index 955d10a..0000000
--- a/lib/Target/Mips/MipsTargetMachine.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- MipsTargetMachine.h ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSTARGETMACHINE_H
-#define TARGET_MIPS_MIPSTARGETMACHINE_H
-
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class MipsBaseTargetMachine : public MCLDTargetMachine
-{
-public:
- MipsBaseTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string &pTriple);
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp b/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
index 4ae7a61..43aac3e 100644
--- a/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
+++ b/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -15,10 +15,9 @@
mcld::Target TheMips64elTarget;
extern "C" void MCLDInitializeMipsLDTargetInfo() {
- mcld::RegisterTarget<llvm::Triple::mipsel>
- X1(TheMipselTarget, "mipsel");
- mcld::RegisterTarget<llvm::Triple::mips64el>
- X2(TheMips64elTarget, "mips64el");
+ mcld::RegisterTarget<llvm::Triple::mipsel> X1(TheMipselTarget, "mipsel");
+ mcld::RegisterTarget<llvm::Triple::mips64el> X2(TheMips64elTarget,
+ "mips64el");
}
-} // namespace of mcld
+} // namespace mcld
diff --git a/lib/Target/OutputRelocSection.cpp b/lib/Target/OutputRelocSection.cpp
index 07670a3..40b7b8d 100644
--- a/lib/Target/OutputRelocSection.cpp
+++ b/lib/Target/OutputRelocSection.cpp
@@ -6,58 +6,54 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/Target/OutputRelocSection.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/Module.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Module.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputRelocSection
//===----------------------------------------------------------------------===//
OutputRelocSection::OutputRelocSection(Module& pModule, LDSection& pSection)
- : m_Module(pModule),
- m_pRelocData(NULL),
- m_isVisit(false),
- m_ValidEntryIterator(){
- assert(!pSection.hasRelocData() && "Given section is not a relocation section");
+ : m_Module(pModule),
+ m_pRelocData(NULL),
+ m_isVisit(false),
+ m_ValidEntryIterator() {
+ assert(!pSection.hasRelocData() &&
+ "Given section is not a relocation section");
m_pRelocData = IRBuilder::CreateRelocData(pSection);
}
-OutputRelocSection::~OutputRelocSection()
-{
+OutputRelocSection::~OutputRelocSection() {
}
-Relocation* OutputRelocSection::create()
-{
+Relocation* OutputRelocSection::create() {
Relocation* reloc = Relocation::Create();
m_pRelocData->append(*reloc);
return reloc;
}
-void OutputRelocSection::reserveEntry(size_t pNum)
-{
- for(size_t i=0; i<pNum; i++)
+void OutputRelocSection::reserveEntry(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
m_pRelocData->append(*Relocation::Create());
}
-Relocation* OutputRelocSection::consumeEntry()
-{
+Relocation* OutputRelocSection::consumeEntry() {
// first time visit this function, set m_ValidEntryIterator to
// Fragments.begin()
- if(!m_isVisit) {
+ if (!m_isVisit) {
assert(!m_pRelocData->getRelocationList().empty() &&
- "DynRelSection contains no entries.");
+ "DynRelSection contains no entries.");
m_ValidEntryIterator = m_pRelocData->begin();
m_isVisit = true;
- }
- else {
+ } else {
// Add m_ValidEntryIterator here instead of at the end of this function.
// We may reserve an entry and then consume it immediately, e.g. for COPY
// relocation, so we need to avoid setting this iterator to
@@ -71,14 +67,13 @@
return &(*m_ValidEntryIterator);
}
-size_t OutputRelocSection::numOfRelocs()
-{
+size_t OutputRelocSection::numOfRelocs() {
return m_pRelocData->size();
}
-bool OutputRelocSection::addSymbolToDynSym(LDSymbol& pSymbol)
-{
+bool OutputRelocSection::addSymbolToDynSym(LDSymbol& pSymbol) {
m_Module.getSymbolTable().changeToDynamic(pSymbol);
return true;
}
+} // namespace mcld
diff --git a/lib/Target/PLT.cpp b/lib/Target/PLT.cpp
index 6f9524e..4548c5d 100644
--- a/lib/Target/PLT.cpp
+++ b/lib/Target/PLT.cpp
@@ -6,24 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Target/PLT.h"
-#include <mcld/Target/PLT.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/IRBuilder.h"
-using namespace mcld;
+namespace mcld {
class GOT;
//===----------------------------------------------------------------------===//
// PLT
//===----------------------------------------------------------------------===//
-PLT::PLT(LDSection& pSection)
- :m_Section(pSection)
-{
+PLT::PLT(LDSection& pSection) : m_Section(pSection) {
m_pSectionData = IRBuilder::CreateSectionData(pSection);
}
-PLT::~PLT()
-{
+PLT::~PLT() {
}
+} // namespace mcld
diff --git a/lib/Target/TargetLDBackend.cpp b/lib/Target/TargetLDBackend.cpp
index e955916..f5e2865 100644
--- a/lib/Target/TargetLDBackend.cpp
+++ b/lib/Target/TargetLDBackend.cpp
@@ -6,16 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/Target/TargetLDBackend.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+
+namespace mcld {
TargetLDBackend::TargetLDBackend(const LinkerConfig& pConfig)
- : m_Config(pConfig) {
+ : m_Config(pConfig) {
}
-TargetLDBackend::~TargetLDBackend()
-{
+TargetLDBackend::~TargetLDBackend() {
}
+} // namespace mcld
diff --git a/lib/Target/X86/Android.mk b/lib/Target/X86/Android.mk
index 77b7258..ee136ff 100644
--- a/lib/Target/X86/Android.mk
+++ b/lib/Target/X86/Android.mk
@@ -3,15 +3,12 @@
mcld_x86_target_SRC_FILES := \
X86Diagnostic.cpp \
X86ELFDynamic.cpp \
- X86ELFMCLinker.cpp \
X86Emulation.cpp \
X86GOT.cpp \
X86GOTPLT.cpp \
X86LDBackend.cpp \
- X86MCLinker.cpp \
X86PLT.cpp \
- X86Relocator.cpp \
- X86TargetMachine.cpp
+ X86Relocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/X86/TargetInfo/X86TargetInfo.cpp b/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
index 8e3a7c0..f87e531 100644
--- a/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
+++ b/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -16,11 +16,8 @@
extern "C" void MCLDInitializeX86LDTargetInfo() {
// register into mcld::TargetRegistry
- mcld::RegisterTarget<llvm::Triple::x86>
- X(TheX86_32Target, "x86");
- mcld::RegisterTarget<llvm::Triple::x86_64>
- Y(TheX86_64Target, "x86-64");
+ mcld::RegisterTarget<llvm::Triple::x86> X(TheX86_32Target, "x86");
+ mcld::RegisterTarget<llvm::Triple::x86_64> Y(TheX86_64Target, "x86-64");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/X86/X86.h b/lib/Target/X86/X86.h
index 5090a67..8153478 100644
--- a/lib/Target/X86/X86.h
+++ b/lib/Target/X86/X86.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86_H
-#define TARGET_X86_X86_H
+#ifndef TARGET_X86_X86_H_
+#define TARGET_X86_X86_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -22,9 +22,8 @@
extern mcld::Target TheX86_32Target;
extern mcld::Target TheX86_64Target;
-TargetLDBackend *createX86LDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createX86LDBackend(const llvm::Target&, const std::string&);
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86_H_
diff --git a/lib/Target/X86/X86Diagnostic.cpp b/lib/Target/X86/X86Diagnostic.cpp
index 9dab719..3d225ae 100644
--- a/lib/Target/X86/X86Diagnostic.cpp
+++ b/lib/Target/X86/X86Diagnostic.cpp
@@ -6,30 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "X86.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createX86Diagnostic - the help function to create corresponding X86Diagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createX86DiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeX86Diagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86DiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheX86_32Target, createX86DiagLineInfo);
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheX86_64Target, createX86DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheX86_32Target,
+ mcld::createX86DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheX86_64Target,
+ mcld::createX86DiagLineInfo);
}
-
diff --git a/lib/Target/X86/X86ELFDynamic.cpp b/lib/Target/X86/X86ELFDynamic.cpp
index 74611c5..4db9189 100644
--- a/lib/Target/X86/X86ELFDynamic.cpp
+++ b/lib/Target/X86/X86ELFDynamic.cpp
@@ -8,30 +8,28 @@
//===----------------------------------------------------------------------===//
#include "X86ELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
X86ELFDynamic::X86ELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-X86ELFDynamic::~X86ELFDynamic()
-{
+X86ELFDynamic::~X86ELFDynamic() {
}
-void X86ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void X86ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void X86ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void X86ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
+
+} // namespace mcld
diff --git a/lib/Target/X86/X86ELFDynamic.h b/lib/Target/X86/X86ELFDynamic.h
index 931d1f6..df83e14 100644
--- a/lib/Target/X86/X86ELFDynamic.h
+++ b/lib/Target/X86/X86ELFDynamic.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86ELFDYNAMIC_H
-#define TARGET_X86_X86ELFDYNAMIC_H
+#ifndef TARGET_X86_X86ELFDYNAMIC_H_
+#define TARGET_X86_X86ELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
-class X86ELFDynamic : public ELFDynamic
-{
-public:
+class X86ELFDynamic : public ELFDynamic {
+ public:
X86ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~X86ELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_X86_X86ELFDYNAMIC_H_
diff --git a/lib/Target/X86/X86ELFMCLinker.cpp b/lib/Target/X86/X86ELFMCLinker.cpp
deleted file mode 100644
index a57fe37..0000000
--- a/lib/Target/X86/X86ELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- X86ELFMCLinker.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86ELFMCLinker.h"
-
-using namespace mcld;
-
-X86ELFMCLinker::X86ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-X86ELFMCLinker::~X86ELFMCLinker()
-{
-}
-
diff --git a/lib/Target/X86/X86ELFMCLinker.h b/lib/Target/X86/X86ELFMCLinker.h
deleted file mode 100644
index 6a184aa..0000000
--- a/lib/Target/X86/X86ELFMCLinker.h
+++ /dev/null
@@ -1,36 +0,0 @@
-//===- X86ELFMCLinker.h ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86ELFMCLINKER_H
-#define TARGET_X86_X86ELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class X86ELFMCLinker
- * \brief X86ELFMCLinker sets up the environment for linking.
- *
- * \see
- */
-class X86ELFMCLinker : public ELFMCLinker
-{
-public:
- X86ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~X86ELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/X86/X86Emulation.cpp b/lib/Target/X86/X86Emulation.cpp
index d91d46d..58c797d 100644
--- a/lib/Target/X86/X86Emulation.cpp
+++ b/lib/Target/X86/X86Emulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "X86.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -23,12 +22,11 @@
pConfig.targets().setEndian(TargetOptions::Little);
unsigned int bitclass;
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
- assert (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
+ assert(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
if (arch == llvm::Triple::x86 ||
pConfig.targets().triple().getEnvironment() == llvm::Triple::GNUX32) {
bitclass = 32;
- }
- else {
+ } else {
bitclass = 64;
}
pConfig.targets().setBitClass(bitclass);
@@ -48,8 +46,7 @@
//===----------------------------------------------------------------------===//
// emulateX86LD - the help function to emulate X86 ld
//===----------------------------------------------------------------------===//
-bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -62,14 +59,15 @@
return MCLDEmulateX86ELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// X86Emulation
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86Emulation() {
// Register the emulation
- mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_32Target, mcld::emulateX86LD);
- mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_64Target, mcld::emulateX86LD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_32Target,
+ mcld::emulateX86LD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_64Target,
+ mcld::emulateX86LD);
}
-
diff --git a/lib/Target/X86/X86GNUInfo.h b/lib/Target/X86/X86GNUInfo.h
index da4cb24..62bd32f 100644
--- a/lib/Target/X86/X86GNUInfo.h
+++ b/lib/Target/X86/X86GNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GNUINFO_H
-#define TARGET_X86_X86GNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_X86_X86GNUINFO_H_
+#define TARGET_X86_X86GNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class X86_32GNUInfo : public GNUInfo
-{
-public:
- X86_32GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class X86_32GNUInfo : public GNUInfo {
+ public:
+ explicit X86_32GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_386; }
@@ -26,13 +25,11 @@
/// flags - the value of ElfXX_Ehdr::e_flags
/// FIXME
uint64_t flags() const { return 0x0; }
-
};
-class X86_64GNUInfo : public GNUInfo
-{
-public:
- X86_64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class X86_64GNUInfo : public GNUInfo {
+ public:
+ explicit X86_64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_X86_64; }
@@ -41,10 +38,8 @@
/// flags - the value of ElfXX_Ehdr::e_flags
/// FIXME
uint64_t flags() const { return 0x0; }
-
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86GNUINFO_H_
diff --git a/lib/Target/X86/X86GOT.cpp b/lib/Target/X86/X86GOT.cpp
index 79421f1..9518aa7 100644
--- a/lib/Target/X86/X86GOT.cpp
+++ b/lib/Target/X86/X86GOT.cpp
@@ -8,44 +8,37 @@
//===----------------------------------------------------------------------===//
#include "X86GOT.h"
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// X86_32GOT
//===----------------------------------------------------------------------===//
-X86_32GOT::X86_32GOT(LDSection& pSection)
- : GOT(pSection)
-{
+X86_32GOT::X86_32GOT(LDSection& pSection) : GOT(pSection) {
}
-X86_32GOT::~X86_32GOT()
-{
+X86_32GOT::~X86_32GOT() {
}
-X86_32GOTEntry* X86_32GOT::create()
-{
+X86_32GOTEntry* X86_32GOT::create() {
return new X86_32GOTEntry(0, m_SectionData);
}
//===----------------------------------------------------------------------===//
// X86_64GOT
//===----------------------------------------------------------------------===//
-X86_64GOT::X86_64GOT(LDSection& pSection)
- : GOT(pSection)
-{
+X86_64GOT::X86_64GOT(LDSection& pSection) : GOT(pSection) {
}
-X86_64GOT::~X86_64GOT()
-{
+X86_64GOT::~X86_64GOT() {
}
-X86_64GOTEntry* X86_64GOT::create()
-{
+X86_64GOTEntry* X86_64GOT::create() {
return new X86_64GOTEntry(0, m_SectionData);
}
+} // namespace mcld
diff --git a/lib/Target/X86/X86GOT.h b/lib/Target/X86/X86GOT.h
index f977362..c2cc145 100644
--- a/lib/Target/X86/X86GOT.h
+++ b/lib/Target/X86/X86GOT.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GOT_H
-#define TARGET_X86_X86GOT_H
+#ifndef TARGET_X86_X86GOT_H_
+#define TARGET_X86_X86GOT_H_
-#include <mcld/Target/GOT.h>
+#include "mcld/Target/GOT.h"
namespace mcld {
@@ -19,22 +19,19 @@
/** \class X86_32GOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class X86_32GOTEntry : public GOT::Entry<4>
-{
-public:
+class X86_32GOTEntry : public GOT::Entry<4> {
+ public:
X86_32GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class X86_32GOT
* \brief X86_32 Global Offset Table.
*/
-class X86_32GOT : public GOT
-{
-public:
- X86_32GOT(LDSection& pSection);
+class X86_32GOT : public GOT {
+ public:
+ explicit X86_32GOT(LDSection& pSection);
~X86_32GOT();
@@ -44,29 +41,25 @@
/** \class X86_64GOTEntry
* \brief GOT Entry with size of 8 bytes
*/
-class X86_64GOTEntry : public GOT::Entry<8>
-{
-public:
+class X86_64GOTEntry : public GOT::Entry<8> {
+ public:
X86_64GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<8>(pContent, pParent)
- {}
+ : GOT::Entry<8>(pContent, pParent) {}
};
/** \class X86_64GOT
* \brief X86_64 Global Offset Table.
*/
-class X86_64GOT : public GOT
-{
-public:
- X86_64GOT(LDSection& pSection);
+class X86_64GOT : public GOT {
+ public:
+ explicit X86_64GOT(LDSection& pSection);
~X86_64GOT();
X86_64GOTEntry* create();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86GOT_H_
diff --git a/lib/Target/X86/X86GOTPLT.cpp b/lib/Target/X86/X86GOTPLT.cpp
index 7baa5cb..5b97d8d 100644
--- a/lib/Target/X86/X86GOTPLT.cpp
+++ b/lib/Target/X86/X86GOTPLT.cpp
@@ -9,49 +9,43 @@
#include "X86GOTPLT.h"
#include "X86PLT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace mcld {
//===----------------------------------------------------------------------===//
// X86_32GOTPLT
//===----------------------------------------------------------------------===//
-X86_32GOTPLT::X86_32GOTPLT(LDSection& pSection)
- : X86_32GOT(pSection)
-{
+X86_32GOTPLT::X86_32GOTPLT(LDSection& pSection) : X86_32GOT(pSection) {
// create GOT0 entries
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
create();
}
-X86_32GOTPLT::~X86_32GOTPLT()
-{
+X86_32GOTPLT::~X86_32GOTPLT() {
}
-bool X86_32GOTPLT::hasGOT1() const
-{
+bool X86_32GOTPLT::hasGOT1() const {
return (m_SectionData->size() > X86GOTPLT0Num);
}
-void X86_32GOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<X86_32GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void X86_32GOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<X86_32GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
-{
+void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
++it;
// address of corresponding plt entry
uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<X86_32GOTEntry>(*it).setValue(plt_addr + 6);
plt_addr += pPLT.getPLT1Size();
}
@@ -60,40 +54,34 @@
//===----------------------------------------------------------------------===//
// X86_64GOTPLT
//===----------------------------------------------------------------------===//
-X86_64GOTPLT::X86_64GOTPLT(LDSection& pSection)
- : X86_64GOT(pSection)
-{
+X86_64GOTPLT::X86_64GOTPLT(LDSection& pSection) : X86_64GOT(pSection) {
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
create();
}
-X86_64GOTPLT::~X86_64GOTPLT()
-{
+X86_64GOTPLT::~X86_64GOTPLT() {
}
-bool X86_64GOTPLT::hasGOT1() const
-{
+bool X86_64GOTPLT::hasGOT1() const {
return (m_SectionData->size() > X86GOTPLT0Num);
}
-void X86_64GOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<X86_64GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void X86_64GOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<X86_64GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void X86_64GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
-{
+void X86_64GOTPLT::applyAllGOTPLT(const X86PLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
++it;
// address of corresponding plt entry
uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<X86_64GOTEntry>(*it).setValue(plt_addr + 6);
plt_addr += pPLT.getPLT1Size();
}
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/X86/X86GOTPLT.h b/lib/Target/X86/X86GOTPLT.h
index 4f9fcbd..f9060e1 100644
--- a/lib/Target/X86/X86GOTPLT.h
+++ b/lib/Target/X86/X86GOTPLT.h
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GOTPLT_H
-#define TARGET_X86_X86GOTPLT_H
-
-#include <llvm/ADT/DenseMap.h>
+#ifndef TARGET_X86_X86GOTPLT_H_
+#define TARGET_X86_X86GOTPLT_H_
#include "X86GOT.h"
+#include <llvm/ADT/DenseMap.h>
+
namespace mcld {
-class X86PLT;
class LDSection;
+class X86PLT;
const unsigned int X86GOTPLT0Num = 3;
/** \class X86_32GOTPLT
* \brief X86_32 .got.plt section.
*/
-class X86_32GOTPLT : public X86_32GOT
-{
-public:
- X86_32GOTPLT(LDSection &pSection);
+class X86_32GOTPLT : public X86_32GOT {
+ public:
+ explicit X86_32GOTPLT(LDSection& pSection);
~X86_32GOTPLT();
@@ -41,10 +40,9 @@
/** \class X86_64GOTPLT
* \brief X86_64 .got.plt section.
*/
-class X86_64GOTPLT : public X86_64GOT
-{
-public:
- X86_64GOTPLT(LDSection &pSection);
+class X86_64GOTPLT : public X86_64GOT {
+ public:
+ explicit X86_64GOTPLT(LDSection& pSection);
~X86_64GOTPLT();
@@ -56,7 +54,6 @@
void applyAllGOTPLT(const X86PLT& pPLT);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86GOTPLT_H_
diff --git a/lib/Target/X86/X86LDBackend.cpp b/lib/Target/X86/X86LDBackend.cpp
index eb4c6c6..3a6928a 100644
--- a/lib/Target/X86/X86LDBackend.cpp
+++ b/lib/Target/X86/X86LDBackend.cpp
@@ -12,23 +12,23 @@
#include "X86Relocator.h"
#include "X86GNUInfo.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
-
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Object/ObjectBuilder.h>
#include <llvm/Support/Dwarf.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// X86GNULDBackend
@@ -36,17 +36,16 @@
X86GNULDBackend::X86GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo,
Relocation::Type pCopyRel)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pPLT(NULL),
- m_pRelDyn(NULL),
- m_pRelPLT(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_CopyRel(pCopyRel)
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pPLT(NULL),
+ m_pRelDyn(NULL),
+ m_pRelPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_CopyRel(pCopyRel) {
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
- assert (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
+ assert(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
if (arch == llvm::Triple::x86 ||
pConfig.targets().triple().getEnvironment() == llvm::Triple::GNUX32) {
m_RelEntrySize = 8;
@@ -55,16 +54,14 @@
m_PointerRel = llvm::ELF::R_386_32;
else
m_PointerRel = llvm::ELF::R_X86_64_32;
- }
- else {
+ } else {
m_RelEntrySize = 16;
m_RelaEntrySize = 24;
m_PointerRel = llvm::ELF::R_X86_64_64;
}
}
-X86GNULDBackend::~X86GNULDBackend()
-{
+X86GNULDBackend::~X86GNULDBackend() {
delete m_pRelocator;
delete m_pPLT;
delete m_pRelDyn;
@@ -72,22 +69,19 @@
delete m_pDynamic;
}
-const Relocator* X86GNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* X86GNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* X86GNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* X86GNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new X86ELFDynamic(*this, config());
// set .got.plt and .got sizes
@@ -101,14 +95,16 @@
// set .rel.dyn/.rela.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelDynSize();
}
// set .rel.plt/.rela.plt size
if (!m_pRelPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelPLTSize();
}
}
@@ -117,57 +113,50 @@
addEhFrameForPLT(pBuilder.getModule());
}
-void X86GNULDBackend::doPostLayout(Module& pModule,
- IRBuilder& pBuilder)
-{
+void X86GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-X86ELFDynamic& X86GNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+X86ELFDynamic& X86GNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const X86ELFDynamic& X86GNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const X86ELFDynamic& X86GNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-void X86GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag)
-{
+void X86GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag) {
// define symbol _GLOBAL_OFFSET_TABLE_
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
}
}
uint64_t X86GNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* FileFormat = getOutputFormat();
@@ -198,61 +187,50 @@
RegionSize += EntrySize;
++it;
}
- }
- else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
+ } else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
RegionSize += emitGOTSectionData(pRegion);
- }
- else if (FileFormat->hasGOTPLT() &&
- (&pSection == &(FileFormat->getGOTPLT()))) {
+ } else if (FileFormat->hasGOTPLT() &&
+ (&pSection == &(FileFormat->getGOTPLT()))) {
RegionSize += emitGOTPLTSectionData(pRegion, FileFormat);
- }
- else {
- fatal(diag::unrecognized_output_sectoin)
- << pSection.name()
- << "mclinker@googlegroups.com";
+ } else {
+ fatal(diag::unrecognized_output_sectoin) << pSection.name()
+ << "mclinker@googlegroups.com";
}
return RegionSize;
}
-X86PLT& X86GNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+X86PLT& X86GNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const X86PLT& X86GNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const X86PLT& X86GNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& X86GNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn && ".rel.dyn/.rela.dyn section not exist");
+OutputRelocSection& X86GNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL && ".rel.dyn/.rela.dyn section not exist");
return *m_pRelDyn;
}
-const OutputRelocSection& X86GNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn && ".rel.dyn/.rela.dyn section not exist");
+const OutputRelocSection& X86GNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL && ".rel.dyn/.rela.dyn section not exist");
return *m_pRelDyn;
}
-OutputRelocSection& X86GNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPLT && ".rel.plt/.rela.plt section not exist");
+OutputRelocSection& X86GNULDBackend::getRelPLT() {
+ assert(m_pRelPLT != NULL && ".rel.plt/.rela.plt section not exist");
return *m_pRelPLT;
}
-const OutputRelocSection& X86GNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPLT && ".rel.plt/.rela.plt section not exist");
+const OutputRelocSection& X86GNULDBackend::getRelPLT() const {
+ assert(m_pRelPLT != NULL && ".rel.plt/.rela.plt section not exist");
return *m_pRelPLT;
}
-unsigned int
-X86GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int X86GNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -273,26 +251,24 @@
return SHO_UNDEFINED;
}
-void X86GNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void X86GNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
if (LinkerConfig::Object != config().codeGenType()) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
}
}
-void X86GNULDBackend::addEhFrameForPLT(Module& pModule)
-{
+void X86GNULDBackend::addEhFrameForPLT(Module& pModule) {
LDSection* plt_sect = pModule.getSection(".plt");
if (!plt_sect || plt_sect->size() == 0u)
return;
@@ -309,8 +285,8 @@
EhFrame::CIE* cie = new EhFrame::GeneratedCIE(cie_region);
EhFrame::FDE* fde = new EhFrame::GeneratedFDE(fde_region, *cie);
// Augmentation data only contains FDE encoding.
- uint8_t aug_data = (uint8_t)(llvm::dwarf::DW_EH_PE_pcrel |
- llvm::dwarf::DW_EH_PE_sdata4);
+ uint8_t aug_data =
+ (uint8_t)(llvm::dwarf::DW_EH_PE_pcrel | llvm::dwarf::DW_EH_PE_sdata4);
cie->setFDEEncode(aug_data);
cie->setAugmentationData(std::string(1, aug_data));
@@ -337,42 +313,37 @@
}
/// finalizeSymbol - finalize the symbol value
-bool X86GNULDBackend::finalizeTargetSymbols()
-{
+bool X86GNULDBackend::finalizeTargetSymbols() {
return true;
}
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void X86GNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void X86GNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
X86_32GNULDBackend::X86_32GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_386_COPY),
- m_pGOT (NULL),
- m_pGOTPLT (NULL) {
+ : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_386_COPY),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL) {
}
-X86_32GNULDBackend::~X86_32GNULDBackend()
-{
+X86_32GNULDBackend::~X86_32GNULDBackend() {
delete m_pGOT;
delete m_pGOTPLT;
}
-bool X86_32GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool X86_32GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new X86_32Relocator(*this, config());
}
return true;
}
void X86_32GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
// initialize .got
@@ -396,107 +367,95 @@
// initialize .rel.dyn
LDSection& reldyn = file_format->getRelDyn();
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
-
}
}
-X86_32GOT& X86_32GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+X86_32GOT& X86_32GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const X86_32GOT& X86_32GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const X86_32GOT& X86_32GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-llvm::StringRef X86_32GNULDBackend::createCIERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+16] = {
- 0x14, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 1, // version
- 'z', 'R', '\0', // augmentation string
- 1, // code alignment factor
- 0x7c, // data alignment factor
- 8, // return address column
- 1, // augmentation data size
- DW_EH_PE_pcrel | DW_EH_PE_sdata4, // FDE encoding
- DW_CFA_def_cfa, 4, 4,
- DW_CFA_offset + 8, 1,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_32GNULDBackend::createCIERegionForPLT() {
+ static const uint8_t data[4 + 4 + 16] = {
+ 0x14, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 1, // version
+ 'z', 'R', '\0', // augmentation string
+ 1, // code alignment factor
+ 0x7c, // data alignment factor
+ 8, // return address column
+ 1, // augmentation data size
+ llvm::dwarf::DW_EH_PE_pcrel
+ | llvm::dwarf::DW_EH_PE_sdata4, // FDE encoding
+ llvm::dwarf::DW_CFA_def_cfa, 4, 4,
+ llvm::dwarf::DW_CFA_offset + 8, 1,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+16);
+ return llvm::StringRef((const char*)data, 4 + 4 + 16);
}
-llvm::StringRef X86_32GNULDBackend::createFDERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+32] = {
- 0x24, 0, 0, 0, // length
- 0, 0, 0, 0, // offset to CIE
- 0, 0, 0, 0, // offset to PLT
- 0, 0, 0, 0, // size of PLT
- 0, // augmentation data size
- DW_CFA_def_cfa_offset, 8,
- DW_CFA_advance_loc + 6,
- DW_CFA_def_cfa_offset, 12,
- DW_CFA_advance_loc + 10,
- DW_CFA_def_cfa_expression,
- 11,
- DW_OP_breg4, 4,
- DW_OP_breg8, 0,
- DW_OP_lit15,
- DW_OP_and,
- DW_OP_lit11,
- DW_OP_ge,
- DW_OP_lit2,
- DW_OP_shl,
- DW_OP_plus,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_32GNULDBackend::createFDERegionForPLT() {
+ static const uint8_t data[4 + 4 + 32] = {
+ 0x24, 0, 0, 0, // length
+ 0, 0, 0, 0, // offset to CIE
+ 0, 0, 0, 0, // offset to PLT
+ 0, 0, 0, 0, // size of PLT
+ 0, // augmentation data size
+ llvm::dwarf::DW_CFA_def_cfa_offset, 8,
+ llvm::dwarf::DW_CFA_advance_loc + 6,
+ llvm::dwarf::DW_CFA_def_cfa_offset, 12,
+ llvm::dwarf::DW_CFA_advance_loc + 10,
+ llvm::dwarf::DW_CFA_def_cfa_expression,
+ 11,
+ llvm::dwarf::DW_OP_breg4, 4,
+ llvm::dwarf::DW_OP_breg8, 0,
+ llvm::dwarf::DW_OP_lit15,
+ llvm::dwarf::DW_OP_and,
+ llvm::dwarf::DW_OP_lit11,
+ llvm::dwarf::DW_OP_ge,
+ llvm::dwarf::DW_OP_lit2,
+ llvm::dwarf::DW_OP_shl,
+ llvm::dwarf::DW_OP_plus,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+32);
+ return llvm::StringRef((const char*)data, 4 + 4 + 32);
}
-void X86_32GNULDBackend::setRelDynSize()
-{
+void X86_32GNULDBackend::setRelDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelDyn().setSize
- (m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
-void X86_32GNULDBackend::setRelPLTSize()
-{
+void X86_32GNULDBackend::setRelPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelPlt().setSize
- (m_pRelPLT->numOfRelocs() * getRelEntrySize());
+ file_format->getRelPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelEntrySize());
}
-void X86_32GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void X86_32GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -506,8 +465,7 @@
m_pGOT->finalizeSectionSize();
}
-uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
@@ -516,8 +474,8 @@
unsigned int EntrySize = X86_32GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_32GOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (X86_32GOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_32GOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -526,9 +484,9 @@
return RegionSize;
}
-uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
+uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -539,8 +497,9 @@
unsigned int EntrySize = X86_32GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_32GOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (X86_32GOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_32GOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -551,119 +510,107 @@
X86_64GNULDBackend::X86_64GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_X86_64_COPY),
- m_pGOT (NULL),
- m_pGOTPLT (NULL) {
+ : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_X86_64_COPY),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL) {
}
-X86_64GNULDBackend::~X86_64GNULDBackend()
-{
+X86_64GNULDBackend::~X86_64GNULDBackend() {
delete m_pGOT;
delete m_pGOTPLT;
}
-bool X86_64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool X86_64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new X86_64Relocator(*this, config());
}
return true;
}
-X86_64GOT& X86_64GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+X86_64GOT& X86_64GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const X86_64GOT& X86_64GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const X86_64GOT& X86_64GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-llvm::StringRef X86_64GNULDBackend::createCIERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+16] = {
- 0x14, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 1, // CIE version
- 'z', 'R', '\0', // augmentation string
- 1, // code alignment factor
- 0x78, // data alignment factor
- 16, // return address column
- 1, // augmentation data size
- DW_EH_PE_pcrel | DW_EH_PE_sdata4, // FDE encoding
- DW_CFA_def_cfa, 7, 8,
- DW_CFA_offset + 16, 1,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_64GNULDBackend::createCIERegionForPLT() {
+ static const uint8_t data[4 + 4 + 16] = {
+ 0x14, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 1, // CIE version
+ 'z', 'R', '\0', // augmentation string
+ 1, // code alignment factor
+ 0x78, // data alignment factor
+ 16, // return address column
+ 1, // augmentation data size
+ llvm::dwarf::DW_EH_PE_pcrel
+ | llvm::dwarf::DW_EH_PE_sdata4, // FDE encoding
+ llvm::dwarf::DW_CFA_def_cfa, 7, 8,
+ llvm::dwarf::DW_CFA_offset + 16, 1,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+16);
+ return llvm::StringRef((const char*)data, 4 + 4 + 16);
}
-llvm::StringRef X86_64GNULDBackend::createFDERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+32] = {
- 0x24, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 0, 0, 0, 0, // offset to PLT
- 0, 0, 0, 0, // size of PLT
- 0, // augmentation data size
- DW_CFA_def_cfa_offset, 16,
- DW_CFA_advance_loc + 6,
- DW_CFA_def_cfa_offset, 24,
- DW_CFA_advance_loc + 10,
- DW_CFA_def_cfa_expression,
- 11,
- DW_OP_breg7, 8,
- DW_OP_breg16, 0,
- DW_OP_lit15,
- DW_OP_and,
- DW_OP_lit11,
- DW_OP_ge,
- DW_OP_lit3,
- DW_OP_shl,
- DW_OP_plus,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_64GNULDBackend::createFDERegionForPLT() {
+ static const uint8_t data[4 + 4 + 32] = {
+ 0x24, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 0, 0, 0, 0, // offset to PLT
+ 0, 0, 0, 0, // size of PLT
+ 0, // augmentation data size
+ llvm::dwarf::DW_CFA_def_cfa_offset, 16,
+ llvm::dwarf::DW_CFA_advance_loc + 6,
+ llvm::dwarf::DW_CFA_def_cfa_offset, 24,
+ llvm::dwarf::DW_CFA_advance_loc + 10,
+ llvm::dwarf::DW_CFA_def_cfa_expression,
+ 11,
+ llvm::dwarf::DW_OP_breg7, 8,
+ llvm::dwarf::DW_OP_breg16, 0,
+ llvm::dwarf::DW_OP_lit15,
+ llvm::dwarf::DW_OP_and,
+ llvm::dwarf::DW_OP_lit11,
+ llvm::dwarf::DW_OP_ge,
+ llvm::dwarf::DW_OP_lit3,
+ llvm::dwarf::DW_OP_shl,
+ llvm::dwarf::DW_OP_plus,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+32);
+ return llvm::StringRef((const char*)data, 4 + 4 + 32);
}
-void X86_64GNULDBackend::setRelDynSize()
-{
+void X86_64GNULDBackend::setRelDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaDyn().setSize
- (m_pRelDyn->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelaEntrySize());
}
-void X86_64GNULDBackend::setRelPLTSize()
-{
+void X86_64GNULDBackend::setRelPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaPlt().setSize
- (m_pRelPLT->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelaEntrySize());
}
void X86_64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
// initialize .got
@@ -687,16 +634,13 @@
// initialize .rela.dyn
LDSection& reldyn = file_format->getRelaDyn();
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
-
}
}
-void X86_64GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void X86_64GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -706,8 +650,7 @@
m_pGOT->finalizeSectionSize();
}
-uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
@@ -716,8 +659,8 @@
unsigned int EntrySize = X86_64GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_64GOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (X86_64GOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_64GOTEntry>((*it)));
*buffer = static_cast<uint64_t>(got->getValue());
RegionSize += EntrySize;
@@ -726,10 +669,9 @@
return RegionSize;
}
-uint64_t
-X86_64GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
+uint64_t X86_64GNULDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -740,8 +682,9 @@
unsigned int EntrySize = X86_64GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_64GOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (X86_64GOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_64GOTEntry>((*it)));
*buffer = static_cast<uint64_t>(got->getValue());
RegionSize += EntrySize;
@@ -750,13 +693,10 @@
return RegionSize;
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createX86LDBackend - the help funtion to create corresponding X86LDBackend
///
-TargetLDBackend* createX86LDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createX86LDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -775,20 +715,22 @@
}
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
if (arch == llvm::Triple::x86)
- return new X86_32GNULDBackend(pConfig,
- new X86_32GNUInfo(pConfig.targets().triple()));
- assert (arch == llvm::Triple::x86_64);
+ return new X86_32GNULDBackend(
+ pConfig, new X86_32GNUInfo(pConfig.targets().triple()));
+ assert(arch == llvm::Triple::x86_64);
return new X86_64GNULDBackend(pConfig,
new X86_64GNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86LDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheX86_32Target, createX86LDBackend);
- mcld::TargetRegistry::RegisterTargetLDBackend(TheX86_64Target, createX86LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheX86_32Target,
+ mcld::createX86LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheX86_64Target,
+ mcld::createX86LDBackend);
}
diff --git a/lib/Target/X86/X86LDBackend.h b/lib/Target/X86/X86LDBackend.h
index 503fca9..411ff51 100644
--- a/lib/Target/X86/X86LDBackend.h
+++ b/lib/Target/X86/X86LDBackend.h
@@ -6,16 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86LDBACKEND_H
-#define TARGET_X86_X86LDBACKEND_H
+#ifndef TARGET_X86_X86LDBACKEND_H_
+#define TARGET_X86_X86LDBACKEND_H_
#include "X86ELFDynamic.h"
#include "X86GOT.h"
#include "X86GOTPLT.h"
#include "X86PLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
@@ -25,9 +26,8 @@
//===----------------------------------------------------------------------===//
/// X86GNULDBackend - linker backend of X86 target of GNU ELF format
///
-class X86GNULDBackend : public GNULDBackend
-{
-public:
+class X86GNULDBackend : public GNULDBackend {
+ public:
X86GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo,
Relocation::Type pCopyRel);
@@ -99,24 +99,21 @@
bool finalizeTargetSymbols();
/// getPointerRel - get pointer relocation type.
- Relocation::Type getPointerRel()
- { return m_PointerRel; }
+ Relocation::Type getPointerRel() { return m_PointerRel; }
- Relocation::Type getCopyRelType() const { return m_CopyRel; }
+ Relocation::Type getCopyRelType() const { return m_CopyRel; }
Relocation::Type getPointerRelType() const { return m_PointerRel; }
-protected:
+ protected:
void defineGOTSymbol(IRBuilder& pBuilder, Fragment&);
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return m_RelEntrySize; }
+ size_t getRelEntrySize() { return m_RelEntrySize; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return m_RelaEntrySize; }
+ size_t getRelaEntrySize() { return m_RelaEntrySize; }
-private:
+ private:
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
void doCreateProgramHdrs(Module& pModule);
@@ -125,9 +122,9 @@
virtual uint64_t emitGOTSectionData(MemoryRegion& pRegion) const = 0;
- virtual uint64_t
- emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const = 0;
+ virtual uint64_t emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const = 0;
virtual void setRelDynSize() = 0;
virtual void setRelPLTSize() = 0;
@@ -136,7 +133,7 @@
virtual llvm::StringRef createCIERegionForPLT() = 0;
virtual llvm::StringRef createFDERegionForPLT() = 0;
-protected:
+ protected:
Relocator* m_pRelocator;
X86PLT* m_pPLT;
/// m_RelDyn - dynamic relocation table of .rel.dyn
@@ -158,9 +155,8 @@
//===----------------------------------------------------------------------===//
/// X86_32GNULDBackend - linker backend of X86-32 target of GNU ELF format
///
-class X86_32GNULDBackend : public X86GNULDBackend
-{
-public:
+class X86_32GNULDBackend : public X86GNULDBackend {
+ public:
X86_32GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~X86_32GNULDBackend();
@@ -175,7 +171,7 @@
const X86_32GOTPLT& getGOTPLT() const;
-private:
+ private:
/// initRelocator - create and initialize Relocator.
bool initRelocator();
@@ -192,7 +188,7 @@
llvm::StringRef createCIERegionForPLT();
llvm::StringRef createFDERegionForPLT();
-private:
+ private:
X86_32GOT* m_pGOT;
X86_32GOTPLT* m_pGOTPLT;
};
@@ -201,9 +197,8 @@
//===----------------------------------------------------------------------===//
/// X86_64GNULDBackend - linker backend of X86-64 target of GNU ELF format
///
-class X86_64GNULDBackend : public X86GNULDBackend
-{
-public:
+class X86_64GNULDBackend : public X86GNULDBackend {
+ public:
X86_64GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~X86_64GNULDBackend();
@@ -218,7 +213,7 @@
const X86_64GOTPLT& getGOTPLT() const;
-private:
+ private:
/// initRelocator - create and initialize Relocator.
bool initRelocator();
@@ -235,11 +230,11 @@
llvm::StringRef createCIERegionForPLT();
llvm::StringRef createFDERegionForPLT();
-private:
+ private:
X86_64GOT* m_pGOT;
X86_64GOTPLT* m_pGOTPLT;
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86LDBACKEND_H_
diff --git a/lib/Target/X86/X86MCLinker.cpp b/lib/Target/X86/X86MCLinker.cpp
deleted file mode 100644
index 46d7bb5..0000000
--- a/lib/Target/X86/X86MCLinker.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- X86MCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86.h"
-#include "X86ELFMCLinker.h"
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <llvm/ADT/Triple.h>
-
-using namespace mcld;
-
-namespace mcld {
-
-//===----------------------------------------------------------------------===//
-/// createX86MCLinker - the help funtion to create corresponding X86MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createX86MCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new X86ELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// X86MCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeX86MCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheX86_32Target, createX86MCLinker);
- mcld::TargetRegistry::RegisterMCLinker(TheX86_64Target, createX86MCLinker);
-}
-
diff --git a/lib/Target/X86/X86PLT.cpp b/lib/Target/X86/X86PLT.cpp
index 09b25c4..38d64e7 100644
--- a/lib/Target/X86/X86PLT.cpp
+++ b/lib/Target/X86/X86PLT.cpp
@@ -9,94 +9,82 @@
#include "X86GOTPLT.h"
#include "X86PLT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// PLT entry data
//===----------------------------------------------------------------------===//
X86_32DynPLT0::X86_32DynPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_dyn_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_dyn_plt0)>(pParent) {
}
X86_32DynPLT1::X86_32DynPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_dyn_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_dyn_plt1)>(pParent) {
}
X86_32ExecPLT0::X86_32ExecPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_exec_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_exec_plt0)>(pParent) {
}
X86_32ExecPLT1::X86_32ExecPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_exec_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_exec_plt1)>(pParent) {
}
X86_64PLT0::X86_64PLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_64_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_64_plt0)>(pParent) {
}
X86_64PLT1::X86_64PLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_64_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_64_plt1)>(pParent) {
}
//===----------------------------------------------------------------------===//
// X86PLT
//===----------------------------------------------------------------------===//
X86PLT::X86PLT(LDSection& pSection, const LinkerConfig& pConfig, int got_size)
- : PLT(pSection),
- m_Config(pConfig)
-{
+ : PLT(pSection), m_Config(pConfig) {
assert(LinkerConfig::DynObj == m_Config.codeGenType() ||
- LinkerConfig::Exec == m_Config.codeGenType() ||
+ LinkerConfig::Exec == m_Config.codeGenType() ||
LinkerConfig::Binary == m_Config.codeGenType());
if (got_size == 32) {
if (LinkerConfig::DynObj == m_Config.codeGenType()) {
m_PLT0 = x86_32_dyn_plt0;
m_PLT1 = x86_32_dyn_plt1;
- m_PLT0Size = sizeof (x86_32_dyn_plt0);
- m_PLT1Size = sizeof (x86_32_dyn_plt1);
+ m_PLT0Size = sizeof(x86_32_dyn_plt0);
+ m_PLT1Size = sizeof(x86_32_dyn_plt1);
// create PLT0
new X86_32DynPLT0(*m_pSectionData);
- }
- else {
+ } else {
m_PLT0 = x86_32_exec_plt0;
m_PLT1 = x86_32_exec_plt1;
- m_PLT0Size = sizeof (x86_32_exec_plt0);
- m_PLT1Size = sizeof (x86_32_exec_plt1);
+ m_PLT0Size = sizeof(x86_32_exec_plt0);
+ m_PLT1Size = sizeof(x86_32_exec_plt1);
// create PLT0
new X86_32ExecPLT0(*m_pSectionData);
}
- }
- else {
+ } else {
assert(got_size == 64);
m_PLT0 = x86_64_plt0;
m_PLT1 = x86_64_plt1;
- m_PLT0Size = sizeof (x86_64_plt0);
- m_PLT1Size = sizeof (x86_64_plt1);
+ m_PLT0Size = sizeof(x86_64_plt0);
+ m_PLT1Size = sizeof(x86_64_plt1);
// create PLT0
new X86_64PLT0(*m_pSectionData);
}
}
-X86PLT::~X86PLT()
-{
+X86PLT::~X86PLT() {
}
-void X86PLT::finalizeSectionSize()
-{
+void X86PLT::finalizeSectionSize() {
uint64_t size = 0;
// plt0 size
size = getPLT0()->size();
@@ -119,21 +107,18 @@
}
}
-bool X86PLT::hasPLT1() const
-{
+bool X86PLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-PLTEntryBase* X86PLT::create()
-{
+PLTEntryBase* X86PLT::create() {
if (LinkerConfig::DynObj == m_Config.codeGenType())
return new X86_32DynPLT1(*m_pSectionData);
else
return new X86_32ExecPLT1(*m_pSectionData);
}
-PLTEntryBase* X86PLT::getPLT0() const
-{
+PLTEntryBase* X86PLT::getPLT0() const {
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -150,13 +135,11 @@
X86_32PLT::X86_32PLT(LDSection& pSection,
X86_32GOTPLT& pGOTPLT,
const LinkerConfig& pConfig)
- : X86PLT(pSection, pConfig, 32),
- m_GOTPLT(pGOTPLT) {
+ : X86PLT(pSection, pConfig, 32), m_GOTPLT(pGOTPLT) {
}
// FIXME: It only works on little endian machine.
-void X86_32PLT::applyPLT0()
-{
+void X86_32PLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
unsigned char* data = 0;
@@ -168,7 +151,7 @@
memcpy(data, m_PLT0, plt0->size());
if (m_PLT0 == x86_32_exec_plt0) {
- uint32_t *offset = reinterpret_cast<uint32_t*>(data + 2);
+ uint32_t* offset = reinterpret_cast<uint32_t*>(data + 2);
*offset = m_GOTPLT.addr() + 4;
offset = reinterpret_cast<uint32_t*>(data + 8);
*offset = m_GOTPLT.addr() + 8;
@@ -178,8 +161,7 @@
}
// FIXME: It only works on little endian machine.
-void X86_32PLT::applyPLT1()
-{
+void X86_32PLT::applyPLT1() {
assert(m_Section.addr() && ".plt base address is NULL!");
X86PLT::iterator it = m_pSectionData->begin();
@@ -193,7 +175,7 @@
if (LinkerConfig::Exec == m_Config.codeGenType())
GOTEntryOffset += m_GOTPLT.addr();
- //skip PLT0
+ // skip PLT0
uint64_t PLTEntryOffset = m_PLT0Size;
++it;
@@ -203,7 +185,7 @@
while (it != ie) {
plt1 = &(llvm::cast<PLTEntryBase>(*it));
- unsigned char *data;
+ unsigned char* data;
data = static_cast<unsigned char*>(malloc(plt1->size()));
if (!data)
@@ -219,7 +201,7 @@
offset = reinterpret_cast<uint32_t*>(data + 7);
*offset = PLTRelOffset;
- PLTRelOffset += sizeof (llvm::ELF::Elf32_Rel);
+ PLTRelOffset += sizeof(llvm::ELF::Elf32_Rel);
offset = reinterpret_cast<uint32_t*>(data + 12);
*offset = -(PLTEntryOffset + 12 + 4);
@@ -236,13 +218,11 @@
X86_64PLT::X86_64PLT(LDSection& pSection,
X86_64GOTPLT& pGOTPLT,
const LinkerConfig& pConfig)
- : X86PLT(pSection, pConfig, 64),
- m_GOTPLT(pGOTPLT) {
+ : X86PLT(pSection, pConfig, 64), m_GOTPLT(pGOTPLT) {
}
// FIXME: It only works on little endian machine.
-void X86_64PLT::applyPLT0()
-{
+void X86_64PLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
unsigned char* data = 0;
@@ -254,7 +234,7 @@
memcpy(data, m_PLT0, plt0->size());
// pushq GOT + 8(%rip)
- uint32_t *offset = reinterpret_cast<uint32_t*>(data + 2);
+ uint32_t* offset = reinterpret_cast<uint32_t*>(data + 2);
*offset = m_GOTPLT.addr() - addr() + 8 - 6;
// jmq *GOT + 16(%rip)
offset = reinterpret_cast<uint32_t*>(data + 8);
@@ -264,8 +244,7 @@
}
// FIXME: It only works on little endian machine.
-void X86_64PLT::applyPLT1()
-{
+void X86_64PLT::applyPLT1() {
assert(m_Section.addr() && ".plt base address is NULL!");
X86PLT::iterator it = m_pSectionData->begin();
@@ -293,7 +272,7 @@
while (it != ie) {
plt1 = &(llvm::cast<PLTEntryBase>(*it));
- unsigned char *data;
+ unsigned char* data;
data = static_cast<unsigned char*>(malloc(plt1->size()));
if (!data)
@@ -323,3 +302,4 @@
}
}
+} // namespace mcld
diff --git a/lib/Target/X86/X86PLT.h b/lib/Target/X86/X86PLT.h
index a220efc..b4aa8cb 100644
--- a/lib/Target/X86/X86PLT.h
+++ b/lib/Target/X86/X86PLT.h
@@ -6,51 +6,47 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86PLT_H
-#define TARGET_X86_X86PLT_H
+#ifndef TARGET_X86_X86PLT_H_
+#define TARGET_X86_X86PLT_H_
-#include <mcld/Target/PLT.h>
-
-namespace {
+#include "mcld/Target/PLT.h"
const uint8_t x86_32_dyn_plt0[] = {
- 0xff, 0xb3, 0x04, 0, 0, 0, // pushl 0x4(%ebx)
- 0xff, 0xa3, 0x08, 0, 0, 0, // jmp *0x8(%ebx)
- 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
+ 0xff, 0xb3, 0x04, 0, 0, 0, // pushl 0x4(%ebx)
+ 0xff, 0xa3, 0x08, 0, 0, 0, // jmp *0x8(%ebx)
+ 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
};
const uint8_t x86_32_dyn_plt1[] = {
- 0xff, 0xa3, 0, 0, 0, 0, // jmp *sym@GOT(%ebx)
- 0x68, 0, 0, 0, 0, // pushl $offset
- 0xe9, 0, 0, 0, 0 // jmp plt0
+ 0xff, 0xa3, 0, 0, 0, 0, // jmp *sym@GOT(%ebx)
+ 0x68, 0, 0, 0, 0, // pushl $offset
+ 0xe9, 0, 0, 0, 0 // jmp plt0
};
const uint8_t x86_32_exec_plt0[] = {
- 0xff, 0x35, 0, 0, 0, 0, // pushl .got + 4
- 0xff, 0x25, 0, 0, 0, 0, // jmp *(.got + 8)
- 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
+ 0xff, 0x35, 0, 0, 0, 0, // pushl .got + 4
+ 0xff, 0x25, 0, 0, 0, 0, // jmp *(.got + 8)
+ 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
};
const uint8_t x86_32_exec_plt1[] = {
- 0xff, 0x25, 0, 0, 0, 0, // jmp *(sym in .got)
- 0x68, 0, 0, 0, 0, // pushl $offset
- 0xe9, 0, 0, 0, 0 // jmp plt0
+ 0xff, 0x25, 0, 0, 0, 0, // jmp *(sym in .got)
+ 0x68, 0, 0, 0, 0, // pushl $offset
+ 0xe9, 0, 0, 0, 0 // jmp plt0
};
const uint8_t x86_64_plt0[] = {
- 0xff, 0x35, 0x8, 0, 0, 0, // pushq GOT + 8(%rip)
- 0xff, 0x25, 0x16, 0, 0, 0, // jmq *GOT + 16(%rip)
- 0x0f, 0x1f, 0x40, 0 // nopl 0(%rax)
+ 0xff, 0x35, 0x8, 0, 0, 0, // pushq GOT + 8(%rip)
+ 0xff, 0x25, 0x16, 0, 0, 0, // jmq *GOT + 16(%rip)
+ 0x0f, 0x1f, 0x40, 0 // nopl 0(%rax)
};
const uint8_t x86_64_plt1[] = {
- 0xff, 0x25, 0, 0, 0, 0, // jmpq *sym@GOTPCREL(%rip)
- 0x68, 0, 0, 0, 0, // pushq $index
- 0xe9, 0, 0, 0, 0 // jmpq plt0
+ 0xff, 0x25, 0, 0, 0, 0, // jmpq *sym@GOTPCREL(%rip)
+ 0x68, 0, 0, 0, 0, // pushq $index
+ 0xe9, 0, 0, 0, 0 // jmpq plt0
};
-} // anonymous namespace
-
namespace mcld {
class X86_32GOTPLT;
@@ -60,42 +56,36 @@
//===----------------------------------------------------------------------===//
// X86_32PLT Entry
//===----------------------------------------------------------------------===//
-class X86_32DynPLT0 : public PLT::Entry<sizeof(x86_32_dyn_plt0)>
-{
-public:
+class X86_32DynPLT0 : public PLT::Entry<sizeof(x86_32_dyn_plt0)> {
+ public:
X86_32DynPLT0(SectionData& pParent);
};
-class X86_32DynPLT1 : public PLT::Entry<sizeof(x86_32_dyn_plt1)>
-{
-public:
+class X86_32DynPLT1 : public PLT::Entry<sizeof(x86_32_dyn_plt1)> {
+ public:
X86_32DynPLT1(SectionData& pParent);
};
-class X86_32ExecPLT0 : public PLT::Entry<sizeof(x86_32_exec_plt0)>
-{
-public:
+class X86_32ExecPLT0 : public PLT::Entry<sizeof(x86_32_exec_plt0)> {
+ public:
X86_32ExecPLT0(SectionData& pParent);
};
-class X86_32ExecPLT1 : public PLT::Entry<sizeof(x86_32_exec_plt1)>
-{
-public:
+class X86_32ExecPLT1 : public PLT::Entry<sizeof(x86_32_exec_plt1)> {
+ public:
X86_32ExecPLT1(SectionData& pParent);
};
//===----------------------------------------------------------------------===//
// X86_64PLT Entry
//===----------------------------------------------------------------------===//
-class X86_64PLT0 : public PLT::Entry<sizeof(x86_64_plt0)>
-{
-public:
+class X86_64PLT0 : public PLT::Entry<sizeof(x86_64_plt0)> {
+ public:
X86_64PLT0(SectionData& pParent);
};
-class X86_64PLT1 : public PLT::Entry<sizeof(x86_64_plt1)>
-{
-public:
+class X86_64PLT1 : public PLT::Entry<sizeof(x86_64_plt1)> {
+ public:
X86_64PLT1(SectionData& pParent);
};
@@ -105,12 +95,9 @@
/** \class X86PLT
* \brief X86 Procedure Linkage Table
*/
-class X86PLT : public PLT
-{
-public:
- X86PLT(LDSection& pSection,
- const LinkerConfig& pConfig,
- int got_size);
+class X86PLT : public PLT {
+ public:
+ X86PLT(LDSection& pSection, const LinkerConfig& pConfig, int got_size);
~X86PLT();
// finalizeSectionSize - set LDSection size
@@ -128,12 +115,12 @@
unsigned int getPLT0Size() const { return m_PLT0Size; }
unsigned int getPLT1Size() const { return m_PLT1Size; }
-protected:
+ protected:
PLTEntryBase* getPLT0() const;
-protected:
- const uint8_t *m_PLT0;
- const uint8_t *m_PLT1;
+ protected:
+ const uint8_t* m_PLT0;
+ const uint8_t* m_PLT1;
unsigned int m_PLT0Size;
unsigned int m_PLT1Size;
@@ -146,9 +133,8 @@
/** \class X86_32PLT
* \brief X86_32 Procedure Linkage Table
*/
-class X86_32PLT : public X86PLT
-{
-public:
+class X86_32PLT : public X86PLT {
+ public:
X86_32PLT(LDSection& pSection,
X86_32GOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -157,7 +143,7 @@
void applyPLT1();
-private:
+ private:
X86_32GOTPLT& m_GOTPLT;
};
@@ -167,9 +153,8 @@
/** \class X86_64PLT
* \brief X86_64 Procedure Linkage Table
*/
-class X86_64PLT : public X86PLT
-{
-public:
+class X86_64PLT : public X86PLT {
+ public:
X86_64PLT(LDSection& pSection,
X86_64GOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -178,11 +163,10 @@
void applyPLT1();
-private:
+ private:
X86_64GOTPLT& m_GOTPLT;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86PLT_H_
diff --git a/lib/Target/X86/X86RelocationFunctions.h b/lib/Target/X86/X86RelocationFunctions.h
index a4568bb..69c877b 100644
--- a/lib/Target/X86/X86RelocationFunctions.h
+++ b/lib/Target/X86/X86RelocationFunctions.h
@@ -6,123 +6,128 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_X86_X86RELOCATIONFUNCTIONS_H_
+#define TARGET_X86_X86RELOCATIONFUNCTIONS_H_
-#define DECL_X86_32_APPLY_RELOC_FUNC(Name) \
-static X86Relocator::Result Name(Relocation& pEntry, X86_32Relocator& pParent);
+#define DECL_X86_32_APPLY_RELOC_FUNC(Name) \
+ static X86Relocator::Result Name(Relocation& pEntry, \
+ X86_32Relocator& pParent);
-#define DECL_X86_32_APPLY_RELOC_FUNCS \
-DECL_X86_32_APPLY_RELOC_FUNC(none) \
-DECL_X86_32_APPLY_RELOC_FUNC(abs) \
-DECL_X86_32_APPLY_RELOC_FUNC(rel) \
-DECL_X86_32_APPLY_RELOC_FUNC(plt32) \
-DECL_X86_32_APPLY_RELOC_FUNC(got32) \
-DECL_X86_32_APPLY_RELOC_FUNC(gotoff32) \
-DECL_X86_32_APPLY_RELOC_FUNC(gotpc32) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_gd) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ie) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_gotie) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_le) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ldm) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ldo_32) \
-DECL_X86_32_APPLY_RELOC_FUNC(unsupport)
+#define DECL_X86_32_APPLY_RELOC_FUNCS \
+ DECL_X86_32_APPLY_RELOC_FUNC(none) \
+ DECL_X86_32_APPLY_RELOC_FUNC(abs) \
+ DECL_X86_32_APPLY_RELOC_FUNC(rel) \
+ DECL_X86_32_APPLY_RELOC_FUNC(plt32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(got32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(gotoff32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(gotpc32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_gd) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ie) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_gotie) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_le) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ldm) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ldo_32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(unsupported)
+#define DECL_X86_32_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_386_NONE", 0 }, \
+ { &abs, 1, "R_386_32", 32 }, \
+ { &rel, 2, "R_386_PC32", 32 }, \
+ { &got32, 3, "R_386_GOT32", 32 }, \
+ { &plt32, 4, "R_386_PLT32", 32 }, \
+ { &none, 5, "R_386_COPY", 0 }, \
+ { &none, 6, "R_386_GLOB_DAT", 0 }, \
+ { &none, 7, "R_386_JMP_SLOT", 0 }, \
+ { &none, 8, "R_386_RELATIVE", 0 }, \
+ { &gotoff32, 9, "R_386_GOTOFF", 32 }, \
+ { &gotpc32, 10, "R_386_GOTPC", 32 }, \
+ { &unsupported, 11, "R_386_32PLT", 0 }, \
+ { &unsupported, 12, "", 0 }, \
+ { &unsupported, 13, "", 0 }, \
+ { &unsupported, 14, "R_386_TLS_TPOFF", 0 }, \
+ { &tls_ie, 15, "R_386_TLS_IE", 32 }, \
+ { &tls_gotie, 16, "R_386_TLS_GOTIE", 32 }, \
+ { &tls_le, 17, "R_386_TLS_LE", 32 }, \
+ { &tls_gd, 18, "R_386_TLS_GD", 32 }, \
+ { &tls_ldm, 19, "R_386_TLS_LDM", 32 }, \
+ { &abs, 20, "R_386_16", 16 }, \
+ { &rel, 21, "R_386_PC16", 16 }, \
+ { &abs, 22, "R_386_8", 8 }, \
+ { &rel, 23, "R_386_PC8", 8 }, \
+ { &unsupported, 24, "R_386_TLS_GD_32", 0 }, \
+ { &unsupported, 25, "R_386_TLS_GD_PUSH", 0 }, \
+ { &unsupported, 26, "R_386_TLS_GD_CALL", 0 }, \
+ { &unsupported, 27, "R_386_TLS_GD_POP", 0 }, \
+ { &unsupported, 28, "R_386_TLS_LDM_32", 0 }, \
+ { &unsupported, 29, "R_386_TLS_LDM_PUSH", 0 }, \
+ { &unsupported, 30, "R_386_TLS_LDM_CALL", 0 }, \
+ { &unsupported, 31, "R_386_TLS_LDM_POP", 0 }, \
+ { &tls_ldo_32, 32, "R_386_TLS_LDO_32", 32 }, \
+ { &unsupported, 33, "R_386_TLS_IE_32", 0 }, \
+ { &unsupported, 34, "R_386_TLS_LE_32", 0 }, \
+ { &unsupported, 35, "R_386_TLS_DTPMOD32", 0 }, \
+ { &unsupported, 36, "R_386_TLS_DTPOFF32", 0 }, \
+ { &unsupported, 37, "R_386_TLS_TPOFF32", 0 }, \
+ { &unsupported, 38, "", 0 }, \
+ { &unsupported, 39, "R_386_TLS_GOTDESC", 0 }, \
+ { &unsupported, 40, "R_386_TLS_DESC_CALL", 0 }, \
+ { &unsupported, 41, "R_386_TLS_DESC", 0 }, \
+ { &unsupported, 42, "R_386_IRELATIVE", 0 }, \
+ { &unsupported, 43, "R_386_NUM", 0 }, \
+ { &none, 44, "R_386_TLS_OPT", 32 }
-#define DECL_X86_32_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_386_NONE", 0 }, \
- { &abs, 1, "R_386_32", 32 }, \
- { &rel, 2, "R_386_PC32", 32 }, \
- { &got32, 3, "R_386_GOT32", 32 }, \
- { &plt32, 4, "R_386_PLT32", 32 }, \
- { &none, 5, "R_386_COPY", 0 }, \
- { &none, 6, "R_386_GLOB_DAT", 0 }, \
- { &none, 7, "R_386_JMP_SLOT", 0 }, \
- { &none, 8, "R_386_RELATIVE", 0 }, \
- { &gotoff32, 9, "R_386_GOTOFF", 32 }, \
- { &gotpc32, 10, "R_386_GOTPC", 32 }, \
- { &unsupport, 11, "R_386_32PLT", 0 }, \
- { &unsupport, 12, "", 0 }, \
- { &unsupport, 13, "", 0 }, \
- { &unsupport, 14, "R_386_TLS_TPOFF", 0 }, \
- { &tls_ie, 15, "R_386_TLS_IE", 32 }, \
- { &tls_gotie, 16, "R_386_TLS_GOTIE", 32 }, \
- { &tls_le, 17, "R_386_TLS_LE", 32 }, \
- { &tls_gd, 18, "R_386_TLS_GD", 32 }, \
- { &tls_ldm, 19, "R_386_TLS_LDM", 32 }, \
- { &abs, 20, "R_386_16", 16 }, \
- { &rel, 21, "R_386_PC16", 16 }, \
- { &abs, 22, "R_386_8", 8 }, \
- { &rel, 23, "R_386_PC8", 8 }, \
- { &unsupport, 24, "R_386_TLS_GD_32", 0 }, \
- { &unsupport, 25, "R_386_TLS_GD_PUSH", 0 }, \
- { &unsupport, 26, "R_386_TLS_GD_CALL", 0 }, \
- { &unsupport, 27, "R_386_TLS_GD_POP", 0 }, \
- { &unsupport, 28, "R_386_TLS_LDM_32", 0 }, \
- { &unsupport, 29, "R_386_TLS_LDM_PUSH", 0 }, \
- { &unsupport, 30, "R_386_TLS_LDM_CALL", 0 }, \
- { &unsupport, 31, "R_386_TLS_LDM_POP", 0 }, \
- { &tls_ldo_32, 32, "R_386_TLS_LDO_32", 32 }, \
- { &unsupport, 33, "R_386_TLS_IE_32", 0 }, \
- { &unsupport, 34, "R_386_TLS_LE_32", 0 }, \
- { &unsupport, 35, "R_386_TLS_DTPMOD32", 0 }, \
- { &unsupport, 36, "R_386_TLS_DTPOFF32", 0 }, \
- { &unsupport, 37, "R_386_TLS_TPOFF32", 0 }, \
- { &unsupport, 38, "", 0 }, \
- { &unsupport, 39, "R_386_TLS_GOTDESC", 0 }, \
- { &unsupport, 40, "R_386_TLS_DESC_CALL", 0 }, \
- { &unsupport, 41, "R_386_TLS_DESC", 0 }, \
- { &unsupport, 42, "R_386_IRELATIVE", 0 }, \
- { &unsupport, 43, "R_386_NUM", 0 }, \
- { &none, 44, "R_386_TLS_OPT", 32 }
+#define DECL_X86_64_APPLY_RELOC_FUNC(Name) \
+ static X86Relocator::Result Name(Relocation& pEntry, \
+ X86_64Relocator& pParent);
-#define DECL_X86_64_APPLY_RELOC_FUNC(Name) \
-static X86Relocator::Result Name(Relocation& pEntry, X86_64Relocator& pParent);
+#define DECL_X86_64_APPLY_RELOC_FUNCS \
+ DECL_X86_64_APPLY_RELOC_FUNC(none) \
+ DECL_X86_64_APPLY_RELOC_FUNC(abs) \
+ DECL_X86_64_APPLY_RELOC_FUNC(signed32) \
+ DECL_X86_64_APPLY_RELOC_FUNC(gotpcrel) \
+ DECL_X86_64_APPLY_RELOC_FUNC(plt32) \
+ DECL_X86_64_APPLY_RELOC_FUNC(rel) \
+ DECL_X86_64_APPLY_RELOC_FUNC(unsupported)
-#define DECL_X86_64_APPLY_RELOC_FUNCS \
-DECL_X86_64_APPLY_RELOC_FUNC(none) \
-DECL_X86_64_APPLY_RELOC_FUNC(abs) \
-DECL_X86_64_APPLY_RELOC_FUNC(signed32) \
-DECL_X86_64_APPLY_RELOC_FUNC(gotpcrel) \
-DECL_X86_64_APPLY_RELOC_FUNC(plt32) \
-DECL_X86_64_APPLY_RELOC_FUNC(rel) \
-DECL_X86_64_APPLY_RELOC_FUNC(unsupport)
+#define DECL_X86_64_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_X86_64_NONE", 0 }, \
+ { &abs, 1, "R_X86_64_64", 64 }, \
+ { &rel, 2, "R_X86_64_PC32", 32 }, \
+ { &unsupported, 3, "R_X86_64_GOT32", 32 }, \
+ { &plt32, 4, "R_X86_64_PLT32", 32 }, \
+ { &none, 5, "R_X86_64_COPY", 0 }, \
+ { &none, 6, "R_X86_64_GLOB_DAT", 0 }, \
+ { &none, 7, "R_X86_64_JMP_SLOT", 0 }, \
+ { &none, 8, "R_X86_64_RELATIVE", 0 }, \
+ { &gotpcrel, 9, "R_X86_64_GOTPCREL", 32 }, \
+ { &abs, 10, "R_X86_64_32", 32 }, \
+ { &signed32, 11, "R_X86_64_32S", 32 }, \
+ { &abs, 12, "R_X86_64_16", 16 }, \
+ { &rel, 13, "R_X86_64_PC16", 16 }, \
+ { &abs, 14, "R_X86_64_8", 8 }, \
+ { &rel, 15, "R_X86_64_PC8", 8 }, \
+ { &none, 16, "R_X86_64_DTPMOD64", 0 }, \
+ { &unsupported, 17, "R_X86_64_DTPOFF64", 0 }, \
+ { &none, 18, "R_X86_64_TPOFF64", 0 }, \
+ { &unsupported, 19, "R_X86_64_TLSGD", 0 }, \
+ { &unsupported, 20, "R_X86_64_TLSLD", 0 }, \
+ { &unsupported, 21, "R_X86_64_DTPOFF32", 0 }, \
+ { &unsupported, 22, "R_X86_64_GOTTPOFF", 0 }, \
+ { &unsupported, 23, "R_X86_64_TPOFF32", 0 }, \
+ { &unsupported, 24, "R_X86_64_PC64", 64 }, \
+ { &unsupported, 25, "R_X86_64_GOTOFF64", 64 }, \
+ { &unsupported, 26, "R_X86_64_GOTPC32", 32 }, \
+ { &unsupported, 27, "R_X86_64_GOT64", 64 }, \
+ { &unsupported, 28, "R_X86_64_GOTPCREL64", 64 }, \
+ { &unsupported, 29, "R_X86_64_GOTPC64", 64 }, \
+ { &unsupported, 30, "R_X86_64_GOTPLT64", 64 }, \
+ { &unsupported, 31, "R_X86_64_PLTOFF64", 64 }, \
+ { &unsupported, 32, "R_X86_64_SIZE32", 32 }, \
+ { &unsupported, 33, "R_X86_64_SIZE64", 64 }, \
+ { &unsupported, 34, "R_X86_64_GOTPC32_TLSDESC", 0 }, \
+ { &unsupported, 35, "R_X86_64_TLSDESC_CALL", 0 }, \
+ { &none, 36, "R_X86_64_TLSDESC", 0 }, \
+ { &none, 37, "R_X86_64_IRELATIVE", 0 }, \
+ { &none, 38, "R_X86_64_RELATIVE64", 0 }
-#define DECL_X86_64_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_X86_64_NONE", 0 }, \
- { &abs, 1, "R_X86_64_64", 64 }, \
- { &rel, 2, "R_X86_64_PC32", 32 }, \
- { &unsupport, 3, "R_X86_64_GOT32", 32 }, \
- { &plt32, 4, "R_X86_64_PLT32", 32 }, \
- { &none, 5, "R_X86_64_COPY", 0 }, \
- { &none, 6, "R_X86_64_GLOB_DAT", 0 }, \
- { &none, 7, "R_X86_64_JMP_SLOT", 0 }, \
- { &none, 8, "R_X86_64_RELATIVE", 0 }, \
- { &gotpcrel, 9, "R_X86_64_GOTPCREL", 32 }, \
- { &abs, 10, "R_X86_64_32", 32 }, \
- { &signed32, 11, "R_X86_64_32S", 32 }, \
- { &abs, 12, "R_X86_64_16", 16 }, \
- { &rel, 13, "R_X86_64_PC16", 16 }, \
- { &abs, 14, "R_X86_64_8", 8 }, \
- { &rel, 15, "R_X86_64_PC8", 8 }, \
- { &none, 16, "R_X86_64_DTPMOD64", 0 }, \
- { &unsupport, 17, "R_X86_64_DTPOFF64", 0 }, \
- { &none, 18, "R_X86_64_TPOFF64", 0 }, \
- { &unsupport, 19, "R_X86_64_TLSGD", 0 }, \
- { &unsupport, 20, "R_X86_64_TLSLD", 0 }, \
- { &unsupport, 21, "R_X86_64_DTPOFF32", 0 }, \
- { &unsupport, 22, "R_X86_64_GOTTPOFF", 0 }, \
- { &unsupport, 23, "R_X86_64_TPOFF32", 0 }, \
- { &unsupport, 24, "R_X86_64_PC64", 64 }, \
- { &unsupport, 25, "R_X86_64_GOTOFF64", 64 }, \
- { &unsupport, 26, "R_X86_64_GOTPC32", 32 }, \
- { &unsupport, 27, "R_X86_64_GOT64", 64 }, \
- { &unsupport, 28, "R_X86_64_GOTPCREL64", 64 }, \
- { &unsupport, 29, "R_X86_64_GOTPC64", 64 }, \
- { &unsupport, 30, "R_X86_64_GOTPLT64", 64 }, \
- { &unsupport, 31, "R_X86_64_PLTOFF64", 64 }, \
- { &unsupport, 32, "R_X86_64_SIZE32", 32 }, \
- { &unsupport, 33, "R_X86_64_SIZE64", 64 }, \
- { &unsupport, 34, "R_X86_64_GOTPC32_TLSDESC", 0 }, \
- { &unsupport, 35, "R_X86_64_TLSDESC_CALL", 0 }, \
- { &none, 36, "R_X86_64_TLSDESC", 0 }, \
- { &none, 37, "R_X86_64_IRELATIVE", 0 }, \
- { &none, 38, "R_X86_64_RELATIVE64", 0 }
+#endif // TARGET_X86_X86RELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/X86/X86Relocator.cpp b/lib/Target/X86/X86Relocator.cpp
index 794296b..b685d51 100644
--- a/lib/Target/X86/X86Relocator.cpp
+++ b/lib/Target/X86/X86Relocator.cpp
@@ -9,37 +9,35 @@
#include "X86Relocator.h"
#include "X86RelocationFunctions.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// X86_32 Relocation helper function
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rel.dyn
-static
-Relocation& helper_DynRel_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- X86_32Relocator& pParent)
-{
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ X86_32Relocator& pParent) {
X86_32GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_386_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_386_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -49,28 +47,22 @@
/// helper_use_relative_reloc - Check if symbol ceuse relocation
/// R_386_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const X86_32Relocator& pFactory)
-
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const X86_32Relocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static
-X86_32GOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- X86_32Relocator& pParent)
-{
+static X86_32GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ X86_32Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_32GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
X86_32GOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -78,51 +70,44 @@
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_RELATIVE,
- pParent);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_RELATIVE, pParent);
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_GLOB_DAT,
- pParent);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_GLOB_DAT, pParent);
got_entry->setValue(0x0);
}
}
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(X86_32Relocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(X86_32Relocator& pParent) {
return pParent.getTarget().getGOTPLT().addr();
}
-static
-Relocator::Address helper_get_GOT_address(Relocation& pReloc,
- X86_32Relocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(Relocation& pReloc,
+ X86_32Relocator& pParent) {
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static
-PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_32Relocator& pParent)
-{
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ X86_32Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_32GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but GOTPLT entry exist!");
X86_32GOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -135,11 +120,10 @@
return *plt_entry;
}
-static Relocator::Address
-helper_get_PLT_address(ResolveInfo& pSym, X86_32Relocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ X86_32Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
@@ -153,8 +137,7 @@
X86_32Relocator& pParent);
// the table entry of applying functions
-struct X86_32ApplyFunctionTriple
-{
+struct X86_32ApplyFunctionTriple {
X86_32ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -163,42 +146,38 @@
// declare the table of applying functions
static const X86_32ApplyFunctionTriple X86_32ApplyFunctions[] = {
- DECL_X86_32_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_X86_32_APPLY_RELOC_FUNC_PTRS};
//===--------------------------------------------------------------------===//
// X86Relocator
//===--------------------------------------------------------------------===//
-X86Relocator::X86Relocator(const LinkerConfig& pConfig)
- : Relocator(pConfig) {
+X86Relocator::X86Relocator(const LinkerConfig& pConfig) : Relocator(pConfig) {
}
-X86Relocator::~X86Relocator()
-{
+X86Relocator::~X86Relocator() {
}
void X86Relocator::scanRelocation(Relocation& pReloc,
IRBuilder& pLinker,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
if (LinkerConfig::Object == config().codeGenType())
return;
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if the GOT/PLT/Dynamic Relocation
// entries should be created.
- if (rsym->isLocal()) // rsym is local
+ if (rsym->isLocal()) // rsym is local
scanLocalReloc(pReloc, pLinker, pModule, pSection);
- else // rsym is external
+ else // rsym is external
scanGlobalReloc(pReloc, pLinker, pModule, pSection);
// check if we should issue undefined reference for the relocation target
@@ -207,8 +186,7 @@
issueUndefRef(pReloc, pSection, pInput);
}
-void X86Relocator::addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget)
-{
+void X86Relocator::addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget) {
Relocation& rel_entry = *pTarget.getRelDyn().create();
rel_entry.setType(pTarget.getCopyRelType());
assert(pSym.outSymbol()->hasFragRef());
@@ -223,8 +201,7 @@
/// @note This is executed at `scan relocation' stage.
LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
const ResolveInfo& pSym,
- X86GNULDBackend& pTarget)
-{
+ X86GNULDBackend& pTarget) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = pTarget.getOutputFormat();
@@ -234,7 +211,7 @@
bss_sect_hdr = &file_format->getBSS();
// get or create corresponding BSS SectionData
- assert(NULL != bss_sect_hdr);
+ assert(bss_sect_hdr != NULL);
SectionData* bss_section = NULL;
if (bss_sect_hdr->hasSectionData())
bss_section = bss_sect_hdr->getSectionData();
@@ -247,9 +224,7 @@
// allocate space in BSS for the copy symbol
Fragment* frag = new FillFragment(0x0, 1, pSym.size());
- uint64_t size = ObjectBuilder::AppendFragment(*frag,
- *bss_section,
- addralign);
+ uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_section, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
@@ -259,32 +234,32 @@
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// output all other alias symbols if any
- Module &pModule = pBuilder.getModule();
+ Module& pModule = pBuilder.getModule();
Module::AliasList* alias_list = pModule.getAliasList(pSym);
- if (NULL!=alias_list) {
- Module::alias_iterator it, it_e=alias_list->end();
- for (it=alias_list->begin(); it!=it_e; ++it) {
+ if (alias_list != NULL) {
+ Module::alias_iterator it, it_e = alias_list->end();
+ for (it = alias_list->begin(); it != it_e; ++it) {
const ResolveInfo* alias = *it;
- if (alias!=&pSym && alias->isDyn()) {
+ if (alias != &pSym && alias->isDyn()) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- alias->name(),
- (ResolveInfo::Type)alias->type(),
- ResolveInfo::Define,
- binding,
- alias->size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)alias->other());
+ alias->name(),
+ (ResolveInfo::Type)alias->type(),
+ ResolveInfo::Define,
+ binding,
+ alias->size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)alias->other());
}
}
}
@@ -292,20 +267,18 @@
return *cpy_sym;
}
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// X86_32Relocator
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
X86_32Relocator::X86_32Relocator(X86_32GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : X86Relocator(pConfig), m_Target(pParent) {
+ : X86Relocator(pConfig), m_Target(pParent) {
}
-Relocator::Result
-X86_32Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result X86_32Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type >= sizeof (X86_32ApplyFunctions) / sizeof (X86_32ApplyFunctions[0]) ) {
+ if (type >= sizeof(X86_32ApplyFunctions) / sizeof(X86_32ApplyFunctions[0])) {
return Unknown;
}
@@ -313,19 +286,16 @@
return X86_32ApplyFunctions[type].func(pRelocation, *this);
}
-const char* X86_32Relocator::getName(Relocation::Type pType) const
-{
+const char* X86_32Relocator::getName(Relocation::Type pType) const {
return X86_32ApplyFunctions[pType].name;
}
-Relocator::Size X86_32Relocator::getSize(Relocation::Type pType) const
-{
- return X86_32ApplyFunctions[pType].size;;
+Relocator::Size X86_32Relocator::getSize(Relocation::Type pType) const {
+ return X86_32ApplyFunctions[pType].size;
}
-bool
-X86_32Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool X86_32Relocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
switch (pReloc.type()) {
case llvm::ELF::R_386_32:
case llvm::ELF::R_386_16:
@@ -334,22 +304,18 @@
case llvm::ELF::R_386_GOT32: {
return true;
}
- default: {
- return false;
- }
+ default: { return false; }
}
}
void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
-
+ switch (pReloc.type()) {
case llvm::ELF::R_386_32:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -374,8 +340,11 @@
// Reserve an entry in .rel.dyn
if (config().isCodeIndep()) {
// set up the dyn rel directly
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(), pReloc.type(), *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ pReloc.type(),
+ *this);
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -398,20 +367,14 @@
// FIXME: check STT_GNU_IFUNC symbol
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rel.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn()) {
+ // If building PIC object, a dynamic relocation with
+ // type RELATIVE is needed to relocate this GOT entry.
+ if (config().isCodeIndep())
helper_GOT_init(pReloc, true, *this);
- // set GOT bit
- rsym->setReserved(rsym->reserved() | ReserveGOT);
- return;
- }
+ else
+ helper_GOT_init(pReloc, false, *this);
- // elsewhere if the GOT is used in statically linked binaries,
- // the GOT entry is enough and no relocation is needed.
- helper_GOT_init(pReloc, false, *this);
+ // set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -431,22 +394,21 @@
// need to define that section symbol here
ELFFileFormat* file_format = getTarget().getOutputFormat();
const LDSection* sym_sect =
- &rsym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &rsym->outSymbol()->fragRef()->frag()->getParent()->getSection();
LDSymbol* sect_sym = NULL;
if (&file_format->getTData() == sym_sect) {
if (!getTarget().hasTDATASymbol()) {
sect_sym = pModule.getSectionSymbolSet().get(*sym_sect);
getTarget().setTDATASymbol(*sect_sym);
}
- }
- else if (&file_format->getTBSS() == sym_sect || rsym->isCommon()) {
+ } else if (&file_format->getTBSS() == sym_sect || rsym->isCommon()) {
if (!getTarget().hasTBSSSymbol()) {
sect_sym = pModule.getSectionSymbolSet().get(*sym_sect);
getTarget().setTBSSSymbol(*sect_sym);
}
- }
- else
+ } else {
error(diag::invalid_tls) << rsym->name() << sym_sect->name();
+ }
// set up a pair of got entries and a dyn rel
// set GOT bit
@@ -459,8 +421,8 @@
got_entry1->setValue(0x0);
// setup dyn rel for got_entry1
- Relocation& rel_entry1 = helper_DynRel_init(rsym, *got_entry1, 0x0,
- llvm::ELF::R_386_TLS_DTPMOD32, *this);
+ Relocation& rel_entry1 = helper_DynRel_init(
+ rsym, *got_entry1, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
// for local tls symbol, add rel entry against the section symbol this
// symbol belong to (.tdata or .tbss)
rel_entry1.setSymInfo(sect_sym->resolveInfo());
@@ -478,13 +440,14 @@
// if building shared object, a RELATIVE dynamic relocation is needed
if (LinkerConfig::DynObj == config().codeGenType()) {
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_386_RELATIVE, *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_386_RELATIVE,
+ *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
- }
- else {
+ } else {
// for local sym, we can convert ie to le if not building shared object
convertTLSIEtoLE(pReloc, pSection);
return;
@@ -497,8 +460,8 @@
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
// add symbol to dyn sym table
@@ -514,8 +477,8 @@
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
@@ -536,27 +499,26 @@
getTarget().checkAndSetHasTextRel(*pSection.getLink());
// the target symbol of the dynamic relocation is rsym, so we need to
// emit it into .dynsym
- assert(NULL != rsym->outSymbol());
+ assert(rsym->outSymbol() != NULL);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
}
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_386_32:
case llvm::ELF::R_386_16:
case llvm::ELF::R_386_8:
@@ -564,7 +526,7 @@
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -574,30 +536,32 @@
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
if (llvm::ELF::R_386_32 == pReloc.type() &&
- helper_use_relative_reloc(*rsym, *this))
+ helper_use_relative_reloc(*rsym, *this)) {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
llvm::ELF::R_386_RELATIVE,
*this);
- else
+ } else {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
pReloc.type(),
*this);
+ }
}
}
return;
@@ -638,11 +602,9 @@
// return if we already create GOT for this symbol
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rel.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // if the symbol cannot be fully resolved at link time, then we need a
+ // dynamic relocation
+ if (!getTarget().symbolFinalValueIsKnown(*rsym))
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -657,7 +619,7 @@
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -667,31 +629,32 @@
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
// symbol needs dynamic relocation entry, setup an entry in .rel.dyn
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym,
- getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
if (llvm::ELF::R_386_32 == pReloc.type() &&
- helper_use_relative_reloc(*rsym, *this))
+ helper_use_relative_reloc(*rsym, *this)) {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
llvm::ELF::R_386_RELATIVE,
*this);
- else
+ } else {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
pReloc.type(),
*this);
+ }
}
}
return;
@@ -708,10 +671,10 @@
got_entry1->setValue(0x0);
got_entry2->setValue(0x0);
// setup dyn rel for got entries against rsym
- helper_DynRel_init(rsym, *got_entry1, 0x0,
- llvm::ELF::R_386_TLS_DTPMOD32, *this);
- helper_DynRel_init(rsym, *got_entry2, 0x0,
- llvm::ELF::R_386_TLS_DTPOFF32, *this);
+ helper_DynRel_init(
+ rsym, *got_entry1, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
+ helper_DynRel_init(
+ rsym, *got_entry2, 0x0, llvm::ELF::R_386_TLS_DTPOFF32, *this);
// add the rsym to dynamic symbol table
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
@@ -731,9 +694,11 @@
getTarget().setHasStaticTLS();
// if buildint shared object, a RELATIVE dynamic relocation is needed
if (LinkerConfig::DynObj == config().codeGenType()) {
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_386_RELATIVE, *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_386_RELATIVE,
+ *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
} else {
@@ -749,8 +714,8 @@
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -764,8 +729,8 @@
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
@@ -789,55 +754,54 @@
return;
default: {
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
}
- } // end switch
+ } // end switch
}
// Create a GOT entry for the TLS module index
-X86_32GOTEntry& X86_32Relocator::getTLSModuleID()
-{
+X86_32GOTEntry& X86_32Relocator::getTLSModuleID() {
static X86_32GOTEntry* got_entry = NULL;
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
got_entry = getTarget().getGOT().create();
getTarget().getGOT().create()->setValue(0x0);
- helper_DynRel_init(NULL, *got_entry, 0x0, llvm::ELF::R_386_TLS_DTPMOD32,
- *this);
+ helper_DynRel_init(
+ NULL, *got_entry, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
return *got_entry;
}
/// convert R_386_TLS_IE to R_386_TLS_LE
void X86_32Relocator::convertTLSIEtoLE(Relocation& pReloc,
- LDSection& pSection)
-{
+ LDSection& pSection) {
assert(pReloc.type() == llvm::ELF::R_386_TLS_IE);
- assert(NULL != pReloc.targetRef().frag());
+ assert(pReloc.targetRef().frag() != NULL);
// 1. create the new relocs
Relocation* reloc =
- Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
- *FragmentRef::Create(*pReloc.targetRef().frag(),
- pReloc.targetRef().offset() - 1),
- 0x0);
+ Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
+ *FragmentRef::Create(*pReloc.targetRef().frag(),
+ pReloc.targetRef().offset() - 1),
+ 0x0);
// FIXME: should we create a special symbol for the tls opt instead?
reloc->setSymInfo(pReloc.symInfo());
// 2. modify the opcodes to the appropriate ones
- uint8_t* op = (reinterpret_cast<uint8_t*>(&reloc->target()));
+ uint8_t* op = (reinterpret_cast<uint8_t*>(&reloc->target()));
if (op[0] == 0xa1) {
op[0] = 0xb8;
} else {
// create the new reloc (move 1 byte forward).
- reloc = Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
- *FragmentRef::Create(*pReloc.targetRef().frag(),
- pReloc.targetRef().offset() - 2),
- 0x0);
+ reloc = Relocation::Create(
+ X86_32Relocator::R_386_TLS_OPT,
+ *FragmentRef::Create(*pReloc.targetRef().frag(),
+ pReloc.targetRef().offset() - 2),
+ 0x0);
reloc->setSymInfo(pReloc.symInfo());
op = (reinterpret_cast<uint8_t*>(&reloc->target()));
switch (op[0]) {
@@ -860,40 +824,52 @@
// 3. insert the new relocs "BEFORE" the original reloc.
assert(reloc != NULL);
pSection.getRelocData()->getRelocationList().insert(
- RelocData::iterator(pReloc), reloc);
+ RelocData::iterator(pReloc), reloc);
// 4. change the type of the original reloc
pReloc.setType(llvm::ELF::R_386_TLS_LE);
}
+uint32_t X86_32Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_386_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void X86_32Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//================================================//
// X86_32 Each relocation function implementation //
//================================================//
// R_386_NONE
-Relocator::Result none(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, X86_32Relocator& pParent) {
return Relocator::OK;
}
// R_386_32: S + A
// R_386_16
// R_386_8
-Relocator::Result abs(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
bool has_dyn_rel = pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- true);
-
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), true);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A;
return Relocator::OK;
}
@@ -920,21 +896,19 @@
// R_386_PC32: S + A - P
// R_386_PC16
// R_386_PC8
-Relocator::Result rel(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
bool has_dyn_rel = pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- true);
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), true);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A - P;
return Relocator::OK;
}
@@ -950,15 +924,14 @@
return Relocator::OK;
}
- // perform static relocation
+ // perform static relocation
pReloc.target() = S + A - P;
return Relocator::OK;
}
// R_386_GOTOFF: S + A - GOT_ORG
-Relocator::Result gotoff32(Relocation& pReloc, X86_32Relocator& pParent)
-{
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+Relocator::Result gotoff32(Relocation& pReloc, X86_32Relocator& pParent) {
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
Relocator::Address S = pReloc.symValue();
@@ -967,9 +940,8 @@
}
// R_386_GOTPC: GOT_ORG + A - P
-Relocator::Result gotpc32(Relocation& pReloc, X86_32Relocator& pParent)
-{
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+Relocator::Result gotpc32(Relocation& pReloc, X86_32Relocator& pParent) {
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_ORG + A - pReloc.place();
@@ -977,8 +949,7 @@
}
// R_386_GOT32: GOT(S) + A - GOT_ORG
-Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & (X86Relocator::ReserveGOT)))
return Relocator::BadReloc;
@@ -986,12 +957,12 @@
// set up got entry value if the got has no dyn rel or
// the dyn rel is RELATIVE
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
if (got_entry->getValue() == X86Relocator::SymVal)
got_entry->setValue(pReloc.symValue());
- Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + A - GOT_ORG;
@@ -999,23 +970,21 @@
}
// R_386_PLT32: PLT(S) + A - P
-Relocator::Result plt32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result plt32(Relocation& pReloc, X86_32Relocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & X86Relocator::ReservePLT))
PLT_S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
else
PLT_S = pReloc.symValue();
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address P = pReloc.place();
pReloc.target() = PLT_S + A - P;
return Relocator::OK;
}
// R_386_TLS_GD:
-Relocator::Result tls_gd(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_gd(Relocation& pReloc, X86_32Relocator& pParent) {
// global-dynamic
ResolveInfo* rsym = pReloc.symInfo();
// must reserve two pairs of got and dynamic relocation
@@ -1031,30 +1000,29 @@
// set the got_entry2 value to symbol value
if (rsym->isLocal())
- pParent.getSymGOTMap().lookUpSecondEntry(*rsym)->setValue(pReloc.symValue());
+ pParent.getSymGOTMap().lookUpSecondEntry(*rsym)->setValue(
+ pReloc.symValue());
// perform relocation to the first got entry
Relocator::DWord A = pReloc.target() + pReloc.addend();
// GOT_OFF - the offset between the got_entry1 and _GLOBAL_OFFSET_TABLE (the
// .got.plt section)
- Relocator::Address GOT_OFF =
- file_format->getGOT().addr() +
- got_entry1->getOffset() -
- file_format->getGOTPLT().addr();
+ Relocator::Address GOT_OFF = file_format->getGOT().addr() +
+ got_entry1->getOffset() -
+ file_format->getGOTPLT().addr();
pReloc.target() = GOT_OFF + A;
return Relocator::OK;
}
// R_386_TLS_LDM
-Relocator::Result tls_ldm(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ldm(Relocation& pReloc, X86_32Relocator& pParent) {
// FIXME: no linker optimization for TLS relocation
const X86_32GOTEntry& got_entry = pParent.getTLSModuleID();
// All GOT offsets are relative to the end of the GOT.
- X86Relocator::SWord GOT_S = got_entry.getOffset() -
- (pParent.getTarget().getGOTPLT().addr() -
- pParent.getTarget().getGOT().addr());
+ X86Relocator::SWord GOT_S =
+ got_entry.getOffset() - (pParent.getTarget().getGOTPLT().addr() -
+ pParent.getTarget().getGOT().addr());
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1062,8 +1030,7 @@
}
// R_386_TLS_LDO_32
-Relocator::Result tls_ldo_32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ldo_32(Relocation& pReloc, X86_32Relocator& pParent) {
// FIXME: no linker optimization for TLS relocation
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address S = pReloc.symValue();
@@ -1072,19 +1039,18 @@
}
// R_X86_TLS_IE
-Relocator::Result tls_ie(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ie(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & X86Relocator::ReserveGOT)) {
- return Relocator::BadReloc;
+ return Relocator::BadReloc;
}
// set up the got and dynamic relocation entries if not exist
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*rsym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
// perform relocation to the absolute address of got_entry
Relocator::Address GOT_S =
- pParent.getTarget().getGOT().addr() + got_entry->getOffset();
+ pParent.getTarget().getGOT().addr() + got_entry->getOffset();
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1093,20 +1059,20 @@
}
// R_386_TLS_GOTIE
-Relocator::Result tls_gotie(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_gotie(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & X86Relocator::ReserveGOT)) {
- return Relocator::BadReloc;
+ return Relocator::BadReloc;
}
// set up the got and dynamic relocation entries if not exist
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*rsym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
// All GOT offsets are relative to the end of the GOT.
- X86Relocator::SWord GOT_S = got_entry->getOffset() -
- (pParent.getTarget().getGOTPLT().addr() - pParent.getTarget().getGOT().addr());
+ X86Relocator::SWord GOT_S =
+ got_entry->getOffset() - (pParent.getTarget().getGOTPLT().addr() -
+ pParent.getTarget().getGOT().addr());
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1114,17 +1080,15 @@
}
// R_X86_TLS_LE
-Relocator::Result tls_le(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_le(Relocation& pReloc, X86_32Relocator& pParent) {
if (pReloc.symInfo()->reserved() & X86Relocator::ReserveRel)
return Relocator::OK;
// perform static relocation
// get TLS segment
ELFSegmentFactory::const_iterator tls_seg =
- pParent.getTarget().elfSegmentTable().find(llvm::ELF::PT_TLS,
- llvm::ELF::PF_R,
- 0x0);
+ pParent.getTarget().elfSegmentTable().find(
+ llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
assert(tls_seg != pParent.getTarget().elfSegmentTable().end());
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address S = pReloc.symValue();
@@ -1132,27 +1096,24 @@
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, X86_32Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, X86_32Relocator& pParent) {
+ return Relocator::Unsupported;
}
//===--------------------------------------------------------------------===//
// X86_64 Relocation helper function
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static
-Relocation& helper_DynRel_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- X86_64Relocator& pParent)
-{
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ X86_64Relocator& pParent) {
X86_64GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_X86_64_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_X86_64_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -1160,31 +1121,24 @@
return rel_entry;
}
-
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_X86_64_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const X86_64Relocator& pFactory)
-
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const X86_64Relocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static
-X86_64GOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- X86_64Relocator& pParent)
-{
+static X86_64GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ X86_64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
X86_64GOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -1193,61 +1147,52 @@
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- Relocation& rel_entry = helper_DynRel_init(rsym, *got_entry, 0x0,
- llvm::ELF::R_X86_64_RELATIVE, pParent);
- rel_entry.setAddend(X86Relocator::SymVal);
- pParent.getRelRelMap().record(pReloc, rel_entry);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_GLOB_DAT,
- pParent);
+ Relocation& rel_entry = helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_RELATIVE, pParent);
+ rel_entry.setAddend(X86Relocator::SymVal);
+ pParent.getRelRelMap().record(pReloc, rel_entry);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_GLOB_DAT, pParent);
}
got_entry->setValue(0);
}
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(X86_64Relocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(X86_64Relocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static
-Relocator::Address helper_get_GOT_address(Relocation& pReloc,
- X86_64Relocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(Relocation& pReloc,
+ X86_64Relocator& pParent) {
X86_64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return got_entry->getOffset();
}
-static
-Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- X86_64Relocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ X86_64Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static
-PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_64Relocator& pParent)
-{
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ X86_64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
X86_64GOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -1260,9 +1205,9 @@
return *plt_entry;
}
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// X86_64 Relocation Functions and Tables
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
DECL_X86_64_APPLY_RELOC_FUNCS
/// the prototype of applying function
@@ -1270,8 +1215,7 @@
X86_64Relocator& pParent);
// the table entry of applying functions
-struct X86_64ApplyFunctionTriple
-{
+struct X86_64ApplyFunctionTriple {
X86_64ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -1280,23 +1224,20 @@
// declare the table of applying functions
static const X86_64ApplyFunctionTriple X86_64ApplyFunctions[] = {
- DECL_X86_64_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_X86_64_APPLY_RELOC_FUNC_PTRS};
//===--------------------------------------------------------------------===//
// X86_64Relocator
//===--------------------------------------------------------------------===//
X86_64Relocator::X86_64Relocator(X86_64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : X86Relocator(pConfig), m_Target(pParent) {
+ : X86Relocator(pConfig), m_Target(pParent) {
}
-Relocator::Result
-X86_64Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result X86_64Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type >= sizeof (X86_64ApplyFunctions) / sizeof (X86_64ApplyFunctions[0]) ) {
+ if (type >= sizeof(X86_64ApplyFunctions) / sizeof(X86_64ApplyFunctions[0])) {
return Unknown;
}
@@ -1304,19 +1245,16 @@
return X86_64ApplyFunctions[type].func(pRelocation, *this);
}
-const char* X86_64Relocator::getName(Relocation::Type pType) const
-{
+const char* X86_64Relocator::getName(Relocation::Type pType) const {
return X86_64ApplyFunctions[pType].name;
}
-Relocator::Size X86_64Relocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size X86_64Relocator::getSize(Relocation::Type pType) const {
return X86_64ApplyFunctions[pType].size;
}
-bool
-X86_64Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool X86_64Relocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
bool possible_funcptr_reloc = false;
switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
@@ -1338,25 +1276,24 @@
}
}
- if (pReloc.symInfo()->isGlobal()) {
+ if (pReloc.symInfo()->isGlobal()) {
return (config().codeGenType() == LinkerConfig::DynObj) &&
((pReloc.symInfo()->visibility() != ResolveInfo::Default) ||
possible_funcptr_reloc);
- } else {
+ } else {
return (config().codeGenType() == LinkerConfig::DynObj) ||
possible_funcptr_reloc;
- }
+ }
}
void X86_64Relocator::scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -1405,11 +1342,9 @@
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rela.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // If building PIC object, a dynamic relocation with
+ // type RELATIVE is needed to relocate this GOT entry.
+ if (config().isCodeIndep())
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -1417,21 +1352,20 @@
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
case llvm::ELF::R_X86_64_32:
case llvm::ELF::R_X86_64_16:
@@ -1441,7 +1375,7 @@
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need to reserve a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rela.plt.
@@ -1451,14 +1385,15 @@
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -1470,8 +1405,7 @@
llvm::ELF::R_X86_64_RELATIVE,
*this);
getRelRelMap().record(pReloc, reloc);
- }
- else {
+ } else {
Relocation& reloc = helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
@@ -1490,11 +1424,9 @@
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rela.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // if the symbol cannot be fully resolved at link time, then we need a
+ // dynamic relocation
+ if (!getTarget().symbolFinalValueIsKnown(*rsym))
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -1516,7 +1448,7 @@
// if symbol is defined in the ouput file and it's not
// preemptible, no need plt
if (rsym->isDefine() && !rsym->isDyn() &&
- !getTarget().isSymbolPreemptible(*rsym)) {
+ !getTarget().isSymbolPreemptible(*rsym)) {
return;
}
@@ -1534,7 +1466,7 @@
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -1550,28 +1482,45 @@
// All other dynamic relocations may lead to run-time relocation
// overflow.
if (getTarget().isDynamicSymbol(*rsym) &&
- getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false) &&
- getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false) &&
+ getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
}
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
-// ===
-//
-// ===
+uint32_t X86_64Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_X86_64_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void X86_64Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
+//------------------------------------------------//
+// X86_64 Each relocation function implementation //
+//------------------------------------------------//
// R_X86_64_NONE
-Relocator::Result none(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, X86_64Relocator& pParent) {
return Relocator::OK;
}
@@ -1579,18 +1528,17 @@
// R_X86_64_32:
// R_X86_64_16:
// R_X86_64_8
-Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != dyn_rel);
+ bool has_dyn_rel = (dyn_rel != NULL);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A;
return Relocator::OK;
}
@@ -1613,8 +1561,7 @@
if (llvm::ELF::R_X86_64_64 == pReloc.type() &&
helper_use_relative_reloc(*rsym, pParent)) {
dyn_rel->setAddend(S + A);
- }
- else {
+ } else {
dyn_rel->setAddend(A);
return Relocator::OK;
}
@@ -1627,22 +1574,21 @@
}
// R_X86_64_32S: S + A
-Relocator::Result signed32(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result signed32(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
// There should be no dynamic relocations for R_X86_64_32S.
- if (NULL != pParent.getRelRelMap().lookUp(pReloc))
+ if (pParent.getRelRelMap().lookUp(pReloc) != NULL)
return Relocator::BadReloc;
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
// An external symbol may need PLT and dynamic relocation
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag()) &&
- !rsym->isLocal() && rsym->reserved() & X86Relocator::ReservePLT)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0 && !rsym->isLocal() &&
+ rsym->reserved() & X86Relocator::ReservePLT)
S = helper_get_PLT_address(*rsym, pParent);
#if notyet
@@ -1658,8 +1604,7 @@
}
// R_X86_64_GOTPCREL: GOT(S) + GOT_ORG + A - P
-Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & X86Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -1671,12 +1616,12 @@
// setup relocation addend if needed
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rel) && (X86Relocator::SymVal == dyn_rel->addend())) {
+ if ((dyn_rel != NULL) && (X86Relocator::SymVal == dyn_rel->addend())) {
dyn_rel->setAddend(pReloc.symValue());
}
- Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + GOT_ORG + A - pReloc.place();
@@ -1684,15 +1629,14 @@
}
// R_X86_64_PLT32: PLT(S) + A - P
-Relocator::Result plt32(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result plt32(Relocation& pReloc, X86_64Relocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & X86Relocator::ReservePLT))
PLT_S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
else
PLT_S = pReloc.symValue();
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address P = pReloc.place();
pReloc.target() = PLT_S + A - P;
return Relocator::OK;
@@ -1701,46 +1645,45 @@
// R_X86_64_PC32: S + A - P
// R_X86_64_PC16
// R_X86_64_PC8
-Relocator::Result rel(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A - P;
return Relocator::OK;
}
// setup relocation addend if needed
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rel) && (X86Relocator::SymVal == dyn_rel->addend())) {
+ if ((dyn_rel != NULL) && (X86Relocator::SymVal == dyn_rel->addend())) {
dyn_rel->setAddend(S);
}
// An external symbol may need PLT and dynamic relocation
if (!rsym->isLocal()) {
if (rsym->reserved() & X86Relocator::ReservePLT) {
- S = helper_get_PLT_address(*rsym, pParent);
+ S = helper_get_PLT_address(*rsym, pParent);
}
- if (pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- false)) {
+ if (pParent.getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), false)) {
return Relocator::Overflow;
}
}
- // perform static relocation
+ // perform static relocation
pReloc.target() = S + A - P;
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, X86_64Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, X86_64Relocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/X86/X86Relocator.h b/lib/Target/X86/X86Relocator.h
index 84170fe..77ce188 100644
--- a/lib/Target/X86/X86Relocator.h
+++ b/lib/Target/X86/X86Relocator.h
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86RELOCATOR_H
-#define TARGET_X86_X86RELOCATOR_H
+#ifndef TARGET_X86_X86RELOCATOR_H_
+#define TARGET_X86_X86RELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "X86LDBackend.h"
namespace mcld {
-class ResolveInfo;
class LinkerConfig;
+class ResolveInfo;
/** \class X86Relocator
* \brief X86Relocator creates and destroys the X86 relocations.
*
*/
-class X86Relocator : public Relocator
-{
-public:
+class X86Relocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, PLTEntryBase> SymPLTMap;
/** \enum ReservedEntryType
@@ -48,10 +47,10 @@
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -59,13 +58,10 @@
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
- X86Relocator(const LinkerConfig& pConfig);
+ public:
+ explicit X86Relocator(const LinkerConfig& pConfig);
~X86Relocator();
virtual Result applyRelocation(Relocation& pRelocation) = 0;
@@ -73,7 +69,7 @@
virtual const char* getName(Relocation::Type pType) const = 0;
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -87,7 +83,7 @@
LDSection& pSection,
Input& pInput);
-protected:
+ protected:
/// addCopyReloc - add a copy relocation into .rel.dyn for pSym
/// @param pSym - A resolved copy symbol that defined in BSS section
void addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget);
@@ -99,7 +95,7 @@
const ResolveInfo& pSym,
X86GNULDBackend& pTarget);
-private:
+ private:
virtual void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -110,7 +106,7 @@
Module& pModule,
LDSection& pSection) = 0;
-private:
+ private:
SymPLTMap m_SymPLTMap;
};
@@ -118,36 +114,33 @@
* \brief X86_32Relocator creates and destroys the X86-32 relocations.
*
*/
-class X86_32Relocator : public X86Relocator
-{
-public:
+class X86_32Relocator : public X86Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, X86_32GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, X86_32GOTEntry> SymGOTPLTMap;
enum {
- R_386_TLS_OPT = 44 // mcld internal relocation type
+ R_386_TLS_OPT = 44 // mcld internal relocation type
};
-public:
+ public:
X86_32Relocator(X86_32GNULDBackend& pParent, const LinkerConfig& pConfig);
Result applyRelocation(Relocation& pRelocation);
- X86_32GNULDBackend& getTarget()
- { return m_Target; }
+ X86_32GNULDBackend& getTarget() { return m_Target; }
- const X86_32GNULDBackend& getTarget() const
- { return m_Target; }
+ const X86_32GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
X86_32GOTEntry& getTLSModuleID();
@@ -155,7 +148,15 @@
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -170,7 +171,7 @@
/// convert R_386_TLS_IE to R_386_TLS_LE
void convertTLSIEtoLE(Relocation& pReloc, LDSection& pSection);
-private:
+ private:
X86_32GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymGOTPLTMap m_SymGOTPLTMap;
@@ -180,42 +181,47 @@
* \brief X86_64Relocator creates and destroys the X86-64 relocations.
*
*/
-class X86_64Relocator : public X86Relocator
-{
-public:
+class X86_64Relocator : public X86Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, X86_64GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, X86_64GOTEntry> SymGOTPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
-public:
+ public:
X86_64Relocator(X86_64GNULDBackend& pParent, const LinkerConfig& pConfig);
Result applyRelocation(Relocation& pRelocation);
- X86_64GNULDBackend& getTarget()
- { return m_Target; }
+ X86_64GNULDBackend& getTarget() { return m_Target; }
- const X86_64GNULDBackend& getTarget() const
- { return m_Target; }
+ const X86_64GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
/// mayHaveFunctionPointerAccess - check if the given reloc would possibly
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -226,14 +232,13 @@
Module& pModule,
LDSection& pSection);
-private:
+ private:
X86_64GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymGOTPLTMap m_SymGOTPLTMap;
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
-
+#endif // TARGET_X86_X86RELOCATOR_H_
diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp
deleted file mode 100644
index 82fea93..0000000
--- a/lib/Target/X86/X86TargetMachine.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- X86TargetMachine.cpp -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86TargetMachine.h"
-
-#include "X86.h"
-#include <mcld/Support/TargetRegistry.h>
-
-extern "C" void MCLDInitializeX86LDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::X86TargetMachine> X(mcld::TheX86_32Target);
- mcld::RegisterTargetMachine<mcld::X86TargetMachine> Y(mcld::TheX86_64Target);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// X86TargetMachine
-//===----------------------------------------------------------------------===//
-X86TargetMachine::X86TargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
diff --git a/lib/Target/X86/X86TargetMachine.h b/lib/Target/X86/X86TargetMachine.h
deleted file mode 100644
index c3893da..0000000
--- a/lib/Target/X86/X86TargetMachine.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===- X86TargetMachine.h -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86TARGETMACHINE_H
-#define TARGET_X86_X86TARGETMACHINE_H
-#include "X86.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class X86TargetMachine : public MCLDTargetMachine
-{
-public:
- X86TargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-