summaryrefslogtreecommitdiff
path: root/lib/Target
diff options
context:
space:
mode:
authorShih-wei Liao <sliao@google.com>2012-08-02 23:13:03 -0700
committerShih-wei Liao <sliao@google.com>2012-08-02 23:13:03 -0700
commitcedee4b38f4786845183be7f5916dd520a170ae0 (patch)
tree33f34be2b8018b8ba6f4e70f32f7bd0d9bdc3b6c /lib/Target
parent67e37f1be98c926645219cfb47fab9e90d8c725c (diff)
downloadmclinker-cedee4b38f4786845183be7f5916dd520a170ae0.tar.gz
Change-Id: I6d12c63bdae94299558dc1cf42b489bb98748851
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/ARM/ARMGOT.cpp14
-rw-r--r--lib/Target/ARM/ARMGOT.h9
-rw-r--r--lib/Target/ARM/ARMLDBackend.cpp61
-rw-r--r--lib/Target/ARM/ARMLDBackend.h2
-rw-r--r--lib/Target/ARM/ARMPLT.cpp19
-rw-r--r--lib/Target/ARM/ARMPLT.h13
-rw-r--r--lib/Target/ARM/ARMRelocationFactory.cpp4
-rw-r--r--lib/Target/GNULDBackend.cpp96
-rw-r--r--lib/Target/GOT.cpp11
-rw-r--r--lib/Target/Mips/MipsGOT.cpp11
-rw-r--r--lib/Target/Mips/MipsGOT.h9
-rw-r--r--lib/Target/Mips/MipsLDBackend.cpp55
-rw-r--r--lib/Target/Mips/MipsLDBackend.h5
-rw-r--r--lib/Target/Mips/MipsRelocationFactory.cpp2
-rw-r--r--lib/Target/OutputRelocSection.cpp13
-rw-r--r--lib/Target/PLT.cpp13
-rw-r--r--lib/Target/X86/X86GOT.cpp12
-rw-r--r--lib/Target/X86/X86GOT.h12
-rw-r--r--lib/Target/X86/X86GOTPLT.cpp14
-rw-r--r--lib/Target/X86/X86GOTPLT.h14
-rw-r--r--lib/Target/X86/X86LDBackend.cpp23
-rw-r--r--lib/Target/X86/X86PLT.cpp26
-rw-r--r--lib/Target/X86/X86PLT.h25
-rw-r--r--lib/Target/X86/X86RelocationFactory.cpp4
-rw-r--r--lib/Target/X86/X86SectLinker.cpp1
25 files changed, 272 insertions, 196 deletions
diff --git a/lib/Target/ARM/ARMGOT.cpp b/lib/Target/ARM/ARMGOT.cpp
index af37768..200bcb5 100644
--- a/lib/Target/ARM/ARMGOT.cpp
+++ b/lib/Target/ARM/ARMGOT.cpp
@@ -7,10 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "ARMGOT.h"
+
+#include <new>
+
+#include <llvm/Support/Casting.h>
+
#include <mcld/LD/LDFileFormat.h>
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
-#include <new>
namespace {
const size_t ARMGOTEntrySize = 4;
@@ -20,7 +24,7 @@ using namespace mcld;
//===----------------------------------------------------------------------===//
// ARMGOT
-ARMGOT::ARMGOT(LDSection& pSection, llvm::MCSectionData& pSectionData)
+ARMGOT::ARMGOT(LDSection& pSection, SectionData& pSectionData)
: GOT(pSection, pSectionData, ARMGOTEntrySize),
m_NormalGOTIterator(), m_GOTPLTIterator(),
m_GOTPLTBegin(), m_GOTPLTEnd()
@@ -33,7 +37,7 @@ ARMGOT::ARMGOT(LDSection& pSection, llvm::MCSectionData& pSectionData)
&m_SectionData);
if (!Entry)
- fatal(diag::fail_allocate_memory) << "GOT0";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + ARMGOTEntrySize);
}
@@ -66,7 +70,7 @@ void ARMGOT::reserveEntry(size_t pNum)
&m_SectionData);
if (!Entry)
- fatal(diag::fail_allocate_memory) << "GOTEntry";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + ARMGOTEntrySize);
}
@@ -79,7 +83,7 @@ void ARMGOT::reserveGOTPLTEntry()
got_entry= new GOTEntry(0, getEntrySize(),&(getSectionData()));
if (!got_entry)
- fatal(diag::fail_allocate_memory) << "GOTEntry";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + getEntrySize());
diff --git a/lib/Target/ARM/ARMGOT.h b/lib/Target/ARM/ARMGOT.h
index 90f0f53..13d3424 100644
--- a/lib/Target/ARM/ARMGOT.h
+++ b/lib/Target/ARM/ARMGOT.h
@@ -12,7 +12,10 @@
#include <gtest.h>
#endif
+#include <llvm/ADT/DenseMap.h>
+
#include <mcld/Target/GOT.h>
+#include <mcld/LD/SectionData.h>
namespace mcld
{
@@ -27,15 +30,15 @@ class ARMGOT : public GOT
typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
enum {
ARMGOT0Num = 3
};
public:
- ARMGOT(LDSection &pSection, llvm::MCSectionData& pSectionData);
+ ARMGOT(LDSection &pSection, SectionData& pSectionData);
~ARMGOT();
diff --git a/lib/Target/ARM/ARMLDBackend.cpp b/lib/Target/ARM/ARMLDBackend.cpp
index 81915c9..a44f1da 100644
--- a/lib/Target/ARM/ARMLDBackend.cpp
+++ b/lib/Target/ARM/ARMLDBackend.cpp
@@ -6,28 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "ARM.h"
+#include "ARMELFDynamic.h"
+#include "ARMLDBackend.h"
+#include "ARMRelocationFactory.h"
+
+#include <cstring>
+
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Support/ELF.h>
+#include <llvm/Support/Casting.h>
#include <mcld/LD/SectionMap.h>
+#include <mcld/LD/FillFragment.h>
+#include <mcld/LD/AlignFragment.h>
+#include <mcld/LD/RegionFragment.h>
#include <mcld/MC/MCLDInfo.h>
#include <mcld/MC/MCLDOutput.h>
#include <mcld/MC/MCLinker.h>
-#include <mcld/MC/MCRegionFragment.h>
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
#include <mcld/Support/TargetRegistry.h>
-#include <cstring>
-
-#include "ARM.h"
-#include "ARMELFDynamic.h"
-#include "ARMLDBackend.h"
-#include "ARMRelocationFactory.h"
-
using namespace mcld;
+//===----------------------------------------------------------------------===//
+// ARMGNULDBackend
+//===----------------------------------------------------------------------===//
ARMGNULDBackend::ARMGNULDBackend()
: m_pRelocFactory(NULL),
m_pGOT(NULL),
@@ -176,7 +182,7 @@ const ARMELFDynamic& ARMGNULDBackend::dynamic() const
void ARMGNULDBackend::createARMGOT(MCLinker& pLinker, const Output& pOutput)
{
- // get .got LDSection and create MCSectionData
+ // get .got LDSection and create SectionData
ELFFileFormat* file_format = getOutputFormat(pOutput);
LDSection& got = file_format->getGOT();
@@ -218,11 +224,11 @@ void ARMGNULDBackend::createARMPLTandRelPLT(MCLinker& pLinker,
// get .plt and .rel.plt LDSection
LDSection& plt = file_format->getPLT();
LDSection& relplt = file_format->getRelPlt();
- // create MCSectionData and ARMPLT
+ // create SectionData and ARMPLT
m_pPLT = new ARMPLT(plt, pLinker.getOrCreateSectData(plt), *m_pGOT);
// set info of .rel.plt to .plt
relplt.setLink(&plt);
- // create MCSectionData and ARMRelDynSection
+ // create SectionData and ARMRelDynSection
m_pRelPLT = new OutputRelocSection(relplt,
pLinker.getOrCreateSectData(relplt),
8);
@@ -233,9 +239,9 @@ void ARMGNULDBackend::createARMRelDyn(MCLinker& pLinker,
{
ELFFileFormat* file_format = getOutputFormat(pOutput);
- // get .rel.dyn LDSection and create MCSectionData
+ // get .rel.dyn LDSection and create SectionData
LDSection& reldyn = file_format->getRelDyn();
- // create MCSectionData and ARMRelDynSection
+ // create SectionData and ARMRelDynSection
m_pRelDyn = new OutputRelocSection(reldyn,
pLinker.getOrCreateSectData(reldyn),
8);
@@ -274,9 +280,9 @@ LDSymbol& ARMGNULDBackend::defineSymbolforCopyReloc(MCLinker& pLinker,
llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC);
}
- // get or create corresponding BSS MCSectionData
+ // get or create corresponding BSS SectionData
assert(NULL != bss_sect_hdr);
- llvm::MCSectionData& bss_section = pLinker.getOrCreateSectData(
+ SectionData& bss_section = pLinker.getOrCreateSectData(
*bss_sect_hdr);
// Determine the alignment by the symbol value
@@ -284,7 +290,7 @@ LDSymbol& ARMGNULDBackend::defineSymbolforCopyReloc(MCLinker& pLinker,
uint32_t addralign = bitclass() / 8;
// allocate space in BSS for the copy symbol
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, pSym.size());
+ Fragment* frag = new FillFragment(0x0, 1, pSym.size());
uint64_t size = pLinker.getLayout().appendFragment(*frag,
bss_section,
addralign);
@@ -763,22 +769,21 @@ uint64_t ARMGNULDBackend::emitSectionData(const Output& pOutput,
&pSection == m_pEXTAB) {
// FIXME: Currently Emitting .ARM.attributes, .ARM.exidx, and .ARM.extab
// directly from the input file.
- const llvm::MCSectionData* sect_data = pSection.getSectionData();
- llvm::MCSectionData::const_iterator frag_iter, frag_end = sect_data->end();
+ const SectionData* sect_data = pSection.getSectionData();
+ SectionData::const_iterator frag_iter, frag_end = sect_data->end();
uint8_t* out_offset = pRegion.start();
for (frag_iter = sect_data->begin(); frag_iter != frag_end; ++frag_iter) {
size_t size = computeFragmentSize(pLayout, *frag_iter);
switch(frag_iter->getKind()) {
- case llvm::MCFragment::FT_Region: {
- const MCRegionFragment& region_frag =
- llvm::cast<MCRegionFragment>(*frag_iter);
+ case Fragment::Region: {
+ const RegionFragment& region_frag =
+ llvm::cast<RegionFragment>(*frag_iter);
const uint8_t* start = region_frag.getRegion().start();
memcpy(out_offset, start, size);
break;
}
- case llvm::MCFragment::FT_Align: {
- llvm::MCAlignFragment& align_frag =
- llvm::cast<llvm::MCAlignFragment>(*frag_iter);
+ case Fragment::Alignment: {
+ AlignFragment& align_frag = llvm::cast<AlignFragment>(*frag_iter);
uint64_t count = size / align_frag.getValueSize();
switch (align_frag.getValueSize()) {
case 1u:
@@ -844,16 +849,16 @@ bool ARMGNULDBackend::readSection(Input& pInput,
MemoryRegion* region = pInput.memArea()->request(
pInput.fileOffset() + pInputSectHdr.offset(), pInputSectHdr.size());
- llvm::MCSectionData& sect_data = pLinker.getOrCreateSectData(pInputSectHdr);
+ SectionData& sect_data = pLinker.getOrCreateSectData(pInputSectHdr);
- llvm::MCFragment* frag = NULL;
+ Fragment* frag = NULL;
if (NULL == region) {
// If the input section's size is zero, we got a NULL region.
// use a virtual fill fragment
- frag = new llvm::MCFillFragment(0x0, 0, 0);
+ frag = new FillFragment(0x0, 0, 0);
}
else
- frag = new MCRegionFragment(*region);
+ frag = new RegionFragment(*region);
uint64_t size = pLinker.getLayout().appendFragment(*frag,
sect_data,
diff --git a/lib/Target/ARM/ARMLDBackend.h b/lib/Target/ARM/ARMLDBackend.h
index 3e46cd7..981228e 100644
--- a/lib/Target/ARM/ARMLDBackend.h
+++ b/lib/Target/ARM/ARMLDBackend.h
@@ -155,7 +155,7 @@ public:
/// call back target backend to emit the data.
///
/// Backends handle the target-special tables (plt, gp,...) by themselves.
- /// Backend can put the data of the tables in MCSectionData directly
+ /// Backend can put the data of the tables in SectionData directly
/// - LDSection.getSectionData can get the section data.
/// Or, backend can put the data into special data structure
/// - backend can maintain its own map<LDSection, table> to get the table
diff --git a/lib/Target/ARM/ARMPLT.cpp b/lib/Target/ARM/ARMPLT.cpp
index 015d767..c9bc333 100644
--- a/lib/Target/ARM/ARMPLT.cpp
+++ b/lib/Target/ARM/ARMPLT.cpp
@@ -8,10 +8,13 @@
//===----------------------------------------------------------------------===//
#include "ARMGOT.h"
#include "ARMPLT.h"
-#include <llvm/Support/raw_ostream.h>
+
+#include <new>
+
+#include <llvm/Support/Casting.h>
+
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
-#include <new>
namespace {
@@ -33,17 +36,17 @@ const uint32_t arm_plt1[] = {
using namespace mcld;
-ARMPLT0::ARMPLT0(llvm::MCSectionData* pParent)
+ARMPLT0::ARMPLT0(SectionData* pParent)
: PLTEntry(sizeof(arm_plt0), pParent) {}
-ARMPLT1::ARMPLT1(llvm::MCSectionData* pParent)
+ARMPLT1::ARMPLT1(SectionData* pParent)
: PLTEntry(sizeof(arm_plt1), pParent) {}
//===----------------------------------------------------------------------===//
// ARMPLT
ARMPLT::ARMPLT(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
+ SectionData& pSectionData,
ARMGOT &pGOTPLT)
: PLT(pSection, pSectionData), m_GOT(pGOTPLT), m_PLTEntryIterator() {
ARMPLT0* plt0_entry = new ARMPLT0(&m_SectionData);
@@ -65,7 +68,7 @@ void ARMPLT::reserveEntry(size_t pNum)
plt1_entry = new (std::nothrow) ARMPLT1(&m_SectionData);
if (!plt1_entry)
- fatal(diag::fail_allocate_memory) << "ARMPLT1";
+ fatal(diag::fail_allocate_memory_plt);
m_Section.setSize(m_Section.size() + plt1_entry->getEntrySize());
@@ -166,7 +169,7 @@ void ARMPLT::applyPLT0() {
data = static_cast<uint32_t*>(malloc(plt0->getEntrySize()));
if (!data)
- fatal(diag::fail_allocate_memory) << "plt0";
+ fatal(diag::fail_allocate_memory_plt);
memcpy(data, arm_plt0, plt0->getEntrySize());
data[4] = offset;
@@ -203,7 +206,7 @@ void ARMPLT::applyPLT1() {
Out = static_cast<uint32_t*>(malloc(plt1->getEntrySize()));
if (!Out)
- fatal(diag::fail_allocate_memory) << "plt1";
+ fatal(diag::fail_allocate_memory_plt);
// Offset is the distance between the last PLT entry and the associated
// GOT entry.
diff --git a/lib/Target/ARM/ARMPLT.h b/lib/Target/ARM/ARMPLT.h
index f55aaa3..db36563 100644
--- a/lib/Target/ARM/ARMPLT.h
+++ b/lib/Target/ARM/ARMPLT.h
@@ -9,6 +9,7 @@
#ifndef MCLD_ARM_PLT_H
#define MCLD_ARM_PLT_H
+#include <mcld/LD/SectionData.h>
#include <mcld/Target/PLT.h>
namespace mcld {
@@ -19,12 +20,12 @@ class MemoryRegion;
class ARMPLT0 : public PLTEntry {
public:
- ARMPLT0(llvm::MCSectionData* pParent);
+ ARMPLT0(SectionData* pParent);
};
class ARMPLT1 : public PLTEntry {
public:
- ARMPLT1(llvm::MCSectionData* pParent);
+ ARMPLT1(SectionData* pParent);
};
/** \class ARMPLT
@@ -35,13 +36,11 @@ class ARMPLT : public PLT
typedef llvm::DenseMap<const ResolveInfo*, ARMPLT1*> SymbolIndexType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
public:
- ARMPLT(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
- ARMGOT& pGOTPLT);
+ ARMPLT(LDSection& pSection, SectionData& pSectionData, ARMGOT& pGOTPLT);
~ARMPLT();
// Override virtual function.
diff --git a/lib/Target/ARM/ARMRelocationFactory.cpp b/lib/Target/ARM/ARMRelocationFactory.cpp
index 3d4b0dc..cc561db 100644
--- a/lib/Target/ARM/ARMRelocationFactory.cpp
+++ b/lib/Target/ARM/ARMRelocationFactory.cpp
@@ -169,7 +169,7 @@ GOTEntry& helper_get_GOT_and_init(Relocation& pReloc,
rel_entry.targetRef().assign(got_entry);
}
else {
- fatal(diag::reserve_entry_number_mismatch) << "GOT";
+ fatal(diag::reserve_entry_number_mismatch_got);
}
}
return got_entry;
@@ -216,7 +216,7 @@ PLTEntry& helper_get_PLT_and_init(Relocation& pReloc,
rel_entry.setSymInfo(rsym);
}
else {
- fatal(diag::reserve_entry_number_mismatch) << "PLT";
+ fatal(diag::reserve_entry_number_mismatch_plt);
}
}
return plt_entry;
diff --git a/lib/Target/GNULDBackend.cpp b/lib/Target/GNULDBackend.cpp
index 69d0927..f81133f 100644
--- a/lib/Target/GNULDBackend.cpp
+++ b/lib/Target/GNULDBackend.cpp
@@ -6,27 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
+#include <mcld/Target/GNULDBackend.h>
+
+#include <string>
+#include <cstring>
+#include <cassert>
+
#include <llvm/Support/ELF.h>
+
#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Target/GNULDBackend.h>
+#include <mcld/LD/LDSymbol.h>
+#include <mcld/LD/Layout.h>
+#include <mcld/LD/FillFragment.h>
#include <mcld/MC/MCLDInfo.h>
#include <mcld/MC/MCLDOutput.h>
#include <mcld/MC/InputTree.h>
#include <mcld/MC/SymbolCategory.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/Layout.h>
+#include <mcld/MC/MCLinker.h>
#include <mcld/Support/MemoryArea.h>
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
-#include <mcld/MC/MCLinker.h>
-#include <string>
-#include <cstring>
-#include <cassert>
+#include <mcld/Support/MemoryAreaFactory.h>
using namespace mcld;
//===----------------------------------------------------------------------===//
// GNULDBackend
+//===----------------------------------------------------------------------===//
GNULDBackend::GNULDBackend()
: m_pArchiveReader(NULL),
m_pObjectReader(NULL),
@@ -97,10 +104,16 @@ uint64_t GNULDBackend::segmentStartAddr(const Output& pOutput,
return defaultTextSegmentAddr();
}
-bool GNULDBackend::initArchiveReader(MCLinker&, MCLDInfo &pInfo)
+bool GNULDBackend::initArchiveReader(MCLinker& pLinker,
+ MCLDInfo& pInfo,
+ MemoryAreaFactory& pMemAreaFactory)
{
- if (NULL == m_pArchiveReader)
- m_pArchiveReader = new GNUArchiveReader(pInfo);
+ if (NULL == m_pArchiveReader) {
+ assert(NULL != m_pObjectReader);
+ m_pArchiveReader = new GNUArchiveReader(pInfo,
+ pMemAreaFactory,
+ *m_pObjectReader);
+ }
return true;
}
@@ -164,7 +177,7 @@ bool GNULDBackend::initStandardSymbols(MCLinker& pLinker, const Output& pOutput)
// ----- section symbols ----- //
// .preinit_array
- MCFragmentRef* preinit_array = NULL;
+ FragmentRef* preinit_array = NULL;
if (file_format->hasPreInitArray()) {
preinit_array = pLinker.getLayout().getFragmentRef(
*(file_format->getPreInitArray().getSectionData()->begin()),
@@ -194,7 +207,7 @@ bool GNULDBackend::initStandardSymbols(MCLinker& pLinker, const Output& pOutput)
ResolveInfo::Hidden);
// .init_array
- MCFragmentRef* init_array = NULL;
+ FragmentRef* init_array = NULL;
if (file_format->hasInitArray()) {
init_array = pLinker.getLayout().getFragmentRef(
*(file_format->getInitArray().getSectionData()->begin()),
@@ -225,7 +238,7 @@ bool GNULDBackend::initStandardSymbols(MCLinker& pLinker, const Output& pOutput)
ResolveInfo::Hidden);
// .fini_array
- MCFragmentRef* fini_array = NULL;
+ FragmentRef* fini_array = NULL;
if (file_format->hasFiniArray()) {
fini_array = pLinker.getLayout().getFragmentRef(
*(file_format->getFiniArray().getSectionData()->begin()),
@@ -256,7 +269,7 @@ bool GNULDBackend::initStandardSymbols(MCLinker& pLinker, const Output& pOutput)
ResolveInfo::Hidden);
// .stack
- MCFragmentRef* stack = NULL;
+ FragmentRef* stack = NULL;
if (file_format->hasStack()) {
stack = pLinker.getLayout().getFragmentRef(
*(file_format->getStack().getSectionData()->begin()),
@@ -1283,9 +1296,9 @@ GNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker) co
assert(NULL != bss_sect && NULL !=tbss_sect);
- // get or create corresponding BSS MCSectionData
- llvm::MCSectionData& bss_sect_data = pLinker.getOrCreateSectData(*bss_sect);
- llvm::MCSectionData& tbss_sect_data = pLinker.getOrCreateSectData(*tbss_sect);
+ // get or create corresponding BSS SectionData
+ SectionData& bss_sect_data = pLinker.getOrCreateSectData(*bss_sect);
+ SectionData& tbss_sect_data = pLinker.getOrCreateSectData(*tbss_sect);
// remember original BSS size
uint64_t bss_offset = bss_sect->size();
@@ -1302,8 +1315,8 @@ GNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker) co
// when emitting the regular name pools. We must change the symbols'
// description here.
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, (*com_sym)->size());
- (*com_sym)->setFragmentRef(new MCFragmentRef(*frag, 0));
+ Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
+ (*com_sym)->setFragmentRef(new FragmentRef(*frag, 0));
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
@@ -1328,8 +1341,8 @@ GNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker) co
// when emitting the regular name pools. We must change the symbols'
// description here.
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, (*com_sym)->size());
- (*com_sym)->setFragmentRef(new MCFragmentRef(*frag, 0));
+ Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
+ (*com_sym)->setFragmentRef(new FragmentRef(*frag, 0));
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
@@ -1366,33 +1379,38 @@ void GNULDBackend::createProgramHdrs(Output& pOutput, const MCLDInfo& pInfo)
interp_seg->addSection(&file_format->getInterp());
}
+ // FIXME: Should we consider -z relro here?
if (pInfo.options().hasRelro()) {
// if -z relro is given, we need to adjust sections' offset again, and let
// PT_GNU_RELRO end on a common page boundary
LDContext::SectionTable& sect_table = pOutput.context()->getSectionTable();
- size_t idx = 0;
- while (idx < pOutput.context()->numOfSections()) {
- // find the first non-relro section, and align its offset to a page
- // boundary
+
+ size_t idx;
+ for (idx = 0; idx < pOutput.context()->numOfSections(); ++idx) {
+ // find the first non-relro section
if (getSectionOrder(pOutput, *sect_table[idx], pInfo) > SHO_RELRO_LAST) {
- uint64_t offset = sect_table[idx]->offset();
- alignAddress(offset, commonPageSize(pInfo));
- sect_table[idx]->setOffset(offset);
- ++idx;
break;
}
- ++idx;
}
- while (idx < pOutput.context()->numOfSections()) {
- // adjust the remaining sections' offset
- uint64_t offset = sect_table[idx - 1]->offset();
- if (LDFileFormat::BSS != sect_table[idx - 1]->kind())
- offset += sect_table[idx - 1]->size();
+
+ // align the first non-relro section to page boundary
+ uint64_t offset = sect_table[idx]->offset();
+ alignAddress(offset, commonPageSize(pInfo));
+ sect_table[idx]->setOffset(offset);
+
+ // set up remaining section's offset
+ for (++idx; idx < pOutput.context()->numOfSections(); ++idx) {
+ uint64_t offset;
+ size_t prev_idx = idx - 1;
+ if (LDFileFormat::BSS == sect_table[prev_idx]->kind())
+ offset = sect_table[prev_idx]->offset();
+ else
+ offset = sect_table[prev_idx]->offset() + sect_table[prev_idx]->size();
+
alignAddress(offset, sect_table[idx]->align());
sect_table[idx]->setOffset(offset);
- ++idx;
}
- }
+ } // relro
uint32_t cur_seg_flag, prev_seg_flag = getSegmentFlag(0);
uint64_t padding = 0;
@@ -1411,7 +1429,7 @@ void GNULDBackend::createProgramHdrs(Output& pOutput, const MCLDInfo& pInfo)
LDFileFormat::Null == (*sect)->kind()) {
// create new PT_LOAD segment
load_seg = m_ELFSegmentTable.produce(llvm::ELF::PT_LOAD);
- load_seg->setAlign(commonPageSize(pInfo));
+ load_seg->setAlign(abiPageSize(pInfo));
// check if this segment needs padding
padding = 0;
@@ -1585,7 +1603,7 @@ void GNULDBackend::preLayout(const Output& pOutput,
}
}
-/// postLayout -Backend can do any needed modification after layout
+/// postLayout - Backend can do any needed modification after layout
void GNULDBackend::postLayout(const Output& pOutput,
const MCLDInfo& pInfo,
MCLinker& pLinker)
diff --git a/lib/Target/GOT.cpp b/lib/Target/GOT.cpp
index a05b574..f9e7b91 100644
--- a/lib/Target/GOT.cpp
+++ b/lib/Target/GOT.cpp
@@ -6,7 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include <mcld/Target/GOT.h>
+
#include <cstring>
#include <cstdlib>
@@ -14,9 +16,9 @@ using namespace mcld;
//===----------------------------------------------------------------------===//
// GOTEntry
-GOTEntry::GOTEntry(uint64_t pContent, size_t pEntrySize,
- llvm::MCSectionData* pParent)
- : MCTargetFragment(llvm::MCFragment::FT_Target, pParent),
+//===----------------------------------------------------------------------===//
+GOTEntry::GOTEntry(uint64_t pContent, size_t pEntrySize, SectionData* pParent)
+ : TargetFragment(Fragment::Target, pParent),
f_Content(pContent), m_EntrySize(pEntrySize) {
}
@@ -26,8 +28,9 @@ GOTEntry::~GOTEntry()
//===----------------------------------------------------------------------===//
// GOT
+//===----------------------------------------------------------------------===//
GOT::GOT(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
+ SectionData& pSectionData,
size_t pEntrySize)
: m_Section(pSection),
m_SectionData(pSectionData),
diff --git a/lib/Target/Mips/MipsGOT.cpp b/lib/Target/Mips/MipsGOT.cpp
index 57e5c70..42ef972 100644
--- a/lib/Target/Mips/MipsGOT.cpp
+++ b/lib/Target/Mips/MipsGOT.cpp
@@ -7,10 +7,13 @@
//
//===----------------------------------------------------------------------===//
+#include "MipsGOT.h"
+
+#include <llvm/Support/Casting.h>
+
#include <mcld/LD/ResolveInfo.h>
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
-#include "MipsGOT.h"
namespace {
const size_t MipsGOTEntrySize = 4;
@@ -21,7 +24,7 @@ using namespace mcld;
//===----------------------------------------------------------------------===//
// MipsGOT
-MipsGOT::MipsGOT(LDSection& pSection, llvm::MCSectionData& pSectionData)
+MipsGOT::MipsGOT(LDSection& pSection, SectionData& pSectionData)
: GOT(pSection, pSectionData, MipsGOTEntrySize),
m_pLocalNum(0)
{
@@ -31,7 +34,7 @@ MipsGOT::MipsGOT(LDSection& pSection, llvm::MCSectionData& pSectionData)
new (std::nothrow) GOTEntry(0, MipsGOTEntrySize, &m_SectionData);
if (NULL == entry)
- fatal(diag::fail_allocate_memory) << "GOT0";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + MipsGOTEntrySize);
}
@@ -94,7 +97,7 @@ void MipsGOT::reserveEntry(size_t pNum)
new (std::nothrow) GOTEntry(0, MipsGOTEntrySize, &m_SectionData);
if (NULL == entry)
- fatal(diag::fail_allocate_memory) << "GOTEntry";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + MipsGOTEntrySize);
}
diff --git a/lib/Target/Mips/MipsGOT.h b/lib/Target/Mips/MipsGOT.h
index 2f04ef4..23a3ded 100644
--- a/lib/Target/Mips/MipsGOT.h
+++ b/lib/Target/Mips/MipsGOT.h
@@ -12,7 +12,10 @@
#include <gtest.h>
#endif
+#include <llvm/ADT/DenseMap.h>
+
#include <mcld/Target/GOT.h>
+#include <mcld/LD/SectionData.h>
namespace mcld
{
@@ -29,11 +32,11 @@ private:
typedef llvm::DenseMap<const ResolveInfo*, bool> SymbolTypeMapType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
public:
- MipsGOT(LDSection& pSection, llvm::MCSectionData& pSectionData);
+ MipsGOT(LDSection& pSection, SectionData& pSectionData);
iterator begin();
iterator end();
diff --git a/lib/Target/Mips/MipsLDBackend.cpp b/lib/Target/Mips/MipsLDBackend.cpp
index 87e43b8..e8b68ea 100644
--- a/lib/Target/Mips/MipsLDBackend.cpp
+++ b/lib/Target/Mips/MipsLDBackend.cpp
@@ -7,9 +7,15 @@
//
//===----------------------------------------------------------------------===//
+#include "Mips.h"
+#include "MipsELFDynamic.h"
+#include "MipsLDBackend.h"
+#include "MipsRelocationFactory.h"
+
#include <llvm/ADT/Triple.h>
#include <llvm/Support/ELF.h>
+#include <mcld/LD/FillFragment.h>
#include <mcld/LD/SectionMap.h>
#include <mcld/MC/MCLDInfo.h>
#include <mcld/MC/MCLinker.h>
@@ -18,11 +24,6 @@
#include <mcld/Support/TargetRegistry.h>
#include <mcld/Target/OutputRelocSection.h>
-#include "Mips.h"
-#include "MipsELFDynamic.h"
-#include "MipsLDBackend.h"
-#include "MipsRelocationFactory.h"
-
enum {
// The original o32 abi.
E_MIPS_ABI_O32 = 0x00001000,
@@ -67,21 +68,6 @@ bool MipsGNULDBackend::initTargetSectionMap(SectionMap& pSectionMap)
void MipsGNULDBackend::initTargetSections(MCLinker& pLinker)
{
- // Set up .dynamic
- ELFFileFormat* file_format = NULL;
- switch(pLinker.getLDInfo().output().type()) {
- case Output::DynObj:
- file_format = getDynObjFileFormat();
- break;
- case Output::Exec:
- file_format = getExecFileFormat();
- break;
- case Output::Object:
- default:
- // TODO: not support yet
- return;
- }
- file_format->getDynamic().setFlag(llvm::ELF::SHF_ALLOC);
}
void MipsGNULDBackend::initTargetSymbols(MCLinker& pLinker, const Output& pOutput)
@@ -213,6 +199,14 @@ uint64_t MipsGNULDBackend::defaultTextSegmentAddr() const
return 0x80000;
}
+uint64_t MipsGNULDBackend::abiPageSize(const MCLDInfo& pInfo) const
+{
+ if (pInfo.options().maxPageSize() > 0)
+ return pInfo.options().maxPageSize();
+ else
+ return static_cast<uint64_t>(0x10000);
+}
+
void MipsGNULDBackend::doPreLayout(const Output& pOutput,
const MCLDInfo& pInfo,
MCLinker& pLinker)
@@ -498,7 +492,8 @@ MipsGNULDBackend::getTargetSectionOrder(const Output& pOutput,
/// finalizeSymbol - finalize the symbol value
bool MipsGNULDBackend::finalizeTargetSymbols(MCLinker& pLinker, const Output& pOutput)
{
- m_pGpDispSymbol->setValue(m_pGOT->getSection().addr() + 0x7FF0);
+ if (NULL != m_pGpDispSymbol)
+ m_pGpDispSymbol->setValue(m_pGOT->getSection().addr() + 0x7FF0);
return true;
}
@@ -550,9 +545,9 @@ MipsGNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker
assert(NULL != bss_sect && NULL != tbss_sect);
- // get or create corresponding BSS MCSectionData
- llvm::MCSectionData& bss_sect_data = pLinker.getOrCreateSectData(*bss_sect);
- llvm::MCSectionData& tbss_sect_data = pLinker.getOrCreateSectData(*tbss_sect);
+ // get or create corresponding BSS SectionData
+ SectionData& bss_sect_data = pLinker.getOrCreateSectData(*bss_sect);
+ SectionData& tbss_sect_data = pLinker.getOrCreateSectData(*tbss_sect);
// remember original BSS size
uint64_t bss_offset = bss_sect->size();
@@ -569,8 +564,8 @@ MipsGNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker
// when emitting the regular name pools. We must change the symbols'
// description here.
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, (*com_sym)->size());
- (*com_sym)->setFragmentRef(new MCFragmentRef(*frag, 0));
+ Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
+ (*com_sym)->setFragmentRef(new FragmentRef(*frag, 0));
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
@@ -596,8 +591,8 @@ MipsGNULDBackend::allocateCommonSymbols(const MCLDInfo& pInfo, MCLinker& pLinker
// when emitting the regular name pools. We must change the symbols'
// description here.
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, (*com_sym)->size());
- (*com_sym)->setFragmentRef(new MCFragmentRef(*frag, 0));
+ Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
+ (*com_sym)->setFragmentRef(new FragmentRef(*frag, 0));
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
@@ -879,9 +874,9 @@ void MipsGNULDBackend::createRelDyn(MCLinker& pLinker, const Output& pOutput)
{
ELFFileFormat* file_format = getOutputFormat(pOutput);
- // get .rel.dyn LDSection and create MCSectionData
+ // get .rel.dyn LDSection and create SectionData
LDSection& reldyn = file_format->getRelDyn();
- // create MCSectionData and ARMRelDynSection
+ // create SectionData and ARMRelDynSection
m_pRelDyn = new OutputRelocSection(reldyn,
pLinker.getOrCreateSectData(reldyn),
8);
diff --git a/lib/Target/Mips/MipsLDBackend.h b/lib/Target/Mips/MipsLDBackend.h
index f9742ed..84f2277 100644
--- a/lib/Target/Mips/MipsLDBackend.h
+++ b/lib/Target/Mips/MipsLDBackend.h
@@ -78,6 +78,9 @@ public:
uint64_t defaultTextSegmentAddr() const;
+ /// abiPageSize - the abi page size of the target machine
+ uint64_t abiPageSize(const MCLDInfo& pInfo) const;
+
/// preLayout - Backend can do any needed modification before layout
void doPreLayout(const Output& pOutput,
const MCLDInfo& pInfo,
@@ -101,7 +104,7 @@ public:
/// call back target backend to emit the data.
///
/// Backends handle the target-special tables (plt, gp,...) by themselves.
- /// Backend can put the data of the tables in MCSectionData directly
+ /// Backend can put the data of the tables in SectionData directly
/// - LDSection.getSectionData can get the section data.
/// Or, backend can put the data into special data structure
/// - backend can maintain its own map<LDSection, table> to get the table
diff --git a/lib/Target/Mips/MipsRelocationFactory.cpp b/lib/Target/Mips/MipsRelocationFactory.cpp
index e9d26f8..a9a34b2 100644
--- a/lib/Target/Mips/MipsRelocationFactory.cpp
+++ b/lib/Target/Mips/MipsRelocationFactory.cpp
@@ -131,7 +131,7 @@ GOTEntry& helper_GetGOTEntry(Relocation& pReloc,
got_entry.setContent(pReloc.symValue());
}
else {
- fatal(diag::reserve_entry_number_mismatch) << "GOT";
+ fatal(diag::reserve_entry_number_mismatch_got);
}
}
diff --git a/lib/Target/OutputRelocSection.cpp b/lib/Target/OutputRelocSection.cpp
index dbb8194..c5bb9a8 100644
--- a/lib/Target/OutputRelocSection.cpp
+++ b/lib/Target/OutputRelocSection.cpp
@@ -6,18 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSection.h>
+
#include <mcld/Target/OutputRelocSection.h>
+
+#include <llvm/Support/Casting.h>
+
+#include <mcld/LD/LDSection.h>
#include <mcld/Support/MsgHandling.h>
using namespace mcld;
-//==========================
+//===----------------------------------------------------------------------===//
// OutputRelocSection
-
-
+//===----------------------------------------------------------------------===//
OutputRelocSection::OutputRelocSection(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
+ SectionData& pSectionData,
unsigned int pEntrySize)
: m_pSection(&pSection),
m_pSectionData(&pSectionData),
diff --git a/lib/Target/PLT.cpp b/lib/Target/PLT.cpp
index a29dfd8..782d974 100644
--- a/lib/Target/PLT.cpp
+++ b/lib/Target/PLT.cpp
@@ -6,16 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include <mcld/Target/PLT.h>
using namespace mcld;
class GOT;
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// PLTEntry
-PLTEntry::PLTEntry(size_t pSize, llvm::MCSectionData* pParent)
- : MCTargetFragment(llvm::MCFragment::FT_Target, pParent),
+//===----------------------------------------------------------------------===//
+PLTEntry::PLTEntry(size_t pSize, SectionData* pParent)
+ : TargetFragment(Fragment::Target, pParent),
m_EntrySize(pSize), m_pContent(NULL)
{
}
@@ -28,9 +30,10 @@ PLTEntry::~PLTEntry()
}
}
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// PLT
-PLT::PLT(LDSection& pSection, llvm::MCSectionData& pSectionData)
+//===----------------------------------------------------------------------===//
+PLT::PLT(LDSection& pSection, SectionData& pSectionData)
:m_Section(pSection),
m_SectionData(pSectionData)
{
diff --git a/lib/Target/X86/X86GOT.cpp b/lib/Target/X86/X86GOT.cpp
index 91c7d65..518cc36 100644
--- a/lib/Target/X86/X86GOT.cpp
+++ b/lib/Target/X86/X86GOT.cpp
@@ -7,9 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "X86GOT.h"
+
+#include <new>
+
+#include <llvm/Support/Casting.h>
+
#include <mcld/LD/LDFileFormat.h>
+#include <mcld/LD/SectionData.h>
#include <mcld/Support/MsgHandling.h>
-#include <new>
namespace {
const size_t X86GOTEntrySize = 4;
@@ -19,7 +24,8 @@ using namespace mcld;
//===----------------------------------------------------------------------===//
// X86GOT
-X86GOT::X86GOT(LDSection& pSection, llvm::MCSectionData& pSectionData)
+//===----------------------------------------------------------------------===//
+X86GOT::X86GOT(LDSection& pSection, SectionData& pSectionData)
: GOT(pSection, pSectionData, X86GOTEntrySize),
m_GOTIterator(), m_fIsVisit(false)
{
@@ -38,7 +44,7 @@ void X86GOT::reserveEntry(size_t pNum)
&m_SectionData);
if (!Entry)
- fatal(diag::fail_allocate_memory) << "GOTEntry";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + X86GOTEntrySize);
}
diff --git a/lib/Target/X86/X86GOT.h b/lib/Target/X86/X86GOT.h
index d758de0..91cc3e8 100644
--- a/lib/Target/X86/X86GOT.h
+++ b/lib/Target/X86/X86GOT.h
@@ -6,14 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_X86_GOT_H
-#define MCLD_X86_GOT_H
+#ifndef MCLD_TARGET_X86_GOT_H
+#define MCLD_TARGET_X86_GOT_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif
#include "X86PLT.h"
+
#include <mcld/Target/GOT.h>
+#include <mcld/LD/SectionData.h>
namespace mcld
{
@@ -28,11 +30,11 @@ class X86GOT : public GOT
typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
public:
- X86GOT(LDSection& pSection, llvm::MCSectionData& pSectionData);
+ X86GOT(LDSection& pSection, SectionData& pSectionData);
~X86GOT();
diff --git a/lib/Target/X86/X86GOTPLT.cpp b/lib/Target/X86/X86GOTPLT.cpp
index 2ba5669..49f3449 100644
--- a/lib/Target/X86/X86GOTPLT.cpp
+++ b/lib/Target/X86/X86GOTPLT.cpp
@@ -6,10 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include "X86GOTPLT.h"
+
+#include <new>
+
+#include <llvm/Support/Casting.h>
+
#include <mcld/LD/LDFileFormat.h>
#include <mcld/Support/MsgHandling.h>
-#include <new>
namespace {
const uint64_t X86GOTPLTEntrySize = 4;
@@ -19,7 +24,8 @@ namespace mcld {
//===----------------------------------------------------------------------===//
// X86GOTPLT
-X86GOTPLT::X86GOTPLT(LDSection& pSection, llvm::MCSectionData& pSectionData)
+//===----------------------------------------------------------------------===//
+X86GOTPLT::X86GOTPLT(LDSection& pSection, SectionData& pSectionData)
: GOT(pSection, pSectionData, X86GOTPLTEntrySize), m_GOTPLTIterator()
{
GOTEntry* Entry = 0;
@@ -30,7 +36,7 @@ X86GOTPLT::X86GOTPLT(LDSection& pSection, llvm::MCSectionData& pSectionData)
&m_SectionData);
if (!Entry)
- fatal(diag::fail_allocate_memory) << "GOT0";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + X86GOTPLTEntrySize);
}
@@ -84,7 +90,7 @@ void X86GOTPLT::reserveEntry(size_t pNum)
for (size_t i = 0; i < pNum; ++i) {
got_entry = new GOTEntry(0, getEntrySize(),&(getSectionData()));
if (!got_entry)
- fatal(diag::fail_allocate_memory) << "GOT";
+ fatal(diag::fail_allocate_memory_got);
m_Section.setSize(m_Section.size() + getEntrySize());
}
diff --git a/lib/Target/X86/X86GOTPLT.h b/lib/Target/X86/X86GOTPLT.h
index ae9f0f7..7ca695b 100644
--- a/lib/Target/X86/X86GOTPLT.h
+++ b/lib/Target/X86/X86GOTPLT.h
@@ -12,28 +12,30 @@
#include <gtest.h>
#endif
+#include <llvm/ADT/DenseMap.h>
+
#include <mcld/Target/GOT.h>
+#include <mcld/LD/SectionData.h>
namespace mcld
{
class LDSection;
+const unsigned int X86GOTPLT0Num = 3;
+
/** \class X86GOTPLT
* \brief X86 .got.plt section.
*/
-
-const unsigned int X86GOTPLT0Num = 3;
-
class X86GOTPLT : public GOT
{
typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
public:
- X86GOTPLT(LDSection &pSection, llvm::MCSectionData& pSectionData);
+ X86GOTPLT(LDSection &pSection, SectionData& pSectionData);
~X86GOTPLT();
diff --git a/lib/Target/X86/X86LDBackend.cpp b/lib/Target/X86/X86LDBackend.cpp
index 2355afc..d02e621 100644
--- a/lib/Target/X86/X86LDBackend.cpp
+++ b/lib/Target/X86/X86LDBackend.cpp
@@ -13,11 +13,14 @@
#include "X86RelocationFactory.h"
#include <llvm/ADT/Triple.h>
+#include <llvm/Support/Casting.h>
+
#include <mcld/LD/SectionMap.h>
+#include <mcld/LD/FillFragment.h>
+#include <mcld/LD/RegionFragment.h>
#include <mcld/MC/MCLDInfo.h>
#include <mcld/MC/MCLDOutput.h>
#include <mcld/MC/MCLinker.h>
-#include <mcld/MC/MCRegionFragment.h>
#include <mcld/Support/MemoryRegion.h>
#include <mcld/Support/MsgHandling.h>
#include <mcld/Support/TargetRegistry.h>
@@ -106,7 +109,7 @@ const X86ELFDynamic& X86GNULDBackend::dynamic() const
void X86GNULDBackend::createX86GOT(MCLinker& pLinker, const Output& pOutput)
{
- // get .got LDSection and create MCSectionData
+ // get .got LDSection and create SectionData
ELFFileFormat* file_format = getOutputFormat(pOutput);
LDSection& got = file_format->getGOT();
@@ -115,7 +118,7 @@ void X86GNULDBackend::createX86GOT(MCLinker& pLinker, const Output& pOutput)
void X86GNULDBackend::createX86GOTPLT(MCLinker& pLinker, const Output& pOutput)
{
- // get .got.plt LDSection and create MCSectionData
+ // get .got.plt LDSection and create SectionData
ELFFileFormat* file_format = getOutputFormat(pOutput);
LDSection& gotplt = file_format->getGOTPLT();
@@ -158,12 +161,12 @@ void X86GNULDBackend::createX86PLTandRelPLT(MCLinker& pLinker,
LDSection& plt = file_format->getPLT();
LDSection& relplt = file_format->getRelPlt();
assert(m_pGOTPLT != NULL);
- // create MCSectionData and X86PLT
+ // create SectionData and X86PLT
m_pPLT = new X86PLT(plt, pLinker.getOrCreateSectData(plt), *m_pGOTPLT, pOutput);
// set info of .rel.plt to .plt
relplt.setLink(&plt);
- // create MCSectionData and X86RelDynSection
+ // create SectionData and X86RelDynSection
m_pRelPLT = new OutputRelocSection(relplt,
pLinker.getOrCreateSectData(relplt),
8);
@@ -172,11 +175,11 @@ void X86GNULDBackend::createX86PLTandRelPLT(MCLinker& pLinker,
void X86GNULDBackend::createX86RelDyn(MCLinker& pLinker,
const Output& pOutput)
{
- // get .rel.dyn LDSection and create MCSectionData
+ // get .rel.dyn LDSection and create SectionData
ELFFileFormat* file_format = getOutputFormat(pOutput);
LDSection& reldyn = file_format->getRelDyn();
- // create MCSectionData and X86RelDynSection
+ // create SectionData and X86RelDynSection
m_pRelDyn = new OutputRelocSection(reldyn,
pLinker.getOrCreateSectData(reldyn),
8);
@@ -215,9 +218,9 @@ LDSymbol& X86GNULDBackend::defineSymbolforCopyReloc(MCLinker& pLinker,
llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC);
}
- // get or create corresponding BSS MCSectionData
+ // get or create corresponding BSS SectionData
assert(NULL != bss_sect_hdr);
- llvm::MCSectionData& bss_section = pLinker.getOrCreateSectData(
+ SectionData& bss_section = pLinker.getOrCreateSectData(
*bss_sect_hdr);
// Determine the alignment by the symbol value
@@ -225,7 +228,7 @@ LDSymbol& X86GNULDBackend::defineSymbolforCopyReloc(MCLinker& pLinker,
uint32_t addralign = bitclass() / 8;
// allocate space in BSS for the copy symbol
- llvm::MCFragment* frag = new llvm::MCFillFragment(0x0, 1, pSym.size());
+ Fragment* frag = new FillFragment(0x0, 1, pSym.size());
uint64_t size = pLinker.getLayout().appendFragment(*frag,
bss_section,
addralign);
diff --git a/lib/Target/X86/X86PLT.cpp b/lib/Target/X86/X86PLT.cpp
index 2396a21..cbdb568 100644
--- a/lib/Target/X86/X86PLT.cpp
+++ b/lib/Target/X86/X86PLT.cpp
@@ -1,4 +1,4 @@
-//===- X86PLT.cpp -----------------------------------------------------------===//
+//===- X86PLT.cpp ---------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -8,12 +8,18 @@
//===----------------------------------------------------------------------===//
#include "X86GOTPLT.h"
#include "X86PLT.h"
-#include <llvm/Support/raw_ostream.h>
+
+#include <new>
+
#include <llvm/Support/ELF.h>
+#include <llvm/Support/Casting.h>
+
#include <mcld/MC/MCLDOutput.h>
#include <mcld/Support/MsgHandling.h>
-#include <new>
+//===----------------------------------------------------------------------===//
+// PLT entry data
+//===----------------------------------------------------------------------===//
namespace {
const uint8_t x86_dyn_plt0[] = {
@@ -44,17 +50,17 @@ const uint8_t x86_exec_plt1[] = {
namespace mcld {
-X86PLT0::X86PLT0(llvm::MCSectionData* pParent, unsigned int pSize)
+X86PLT0::X86PLT0(SectionData* pParent, unsigned int pSize)
: PLTEntry(pSize, pParent) { }
-X86PLT1::X86PLT1(llvm::MCSectionData* pParent, unsigned int pSize)
+X86PLT1::X86PLT1(SectionData* pParent, unsigned int pSize)
: PLTEntry(pSize, pParent) { }
//===----------------------------------------------------------------------===//
// X86PLT
-
+//===----------------------------------------------------------------------===//
X86PLT::X86PLT(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
+ SectionData& pSectionData,
X86GOTPLT &pGOTPLT,
const Output& pOutput)
: PLT(pSection, pSectionData),
@@ -94,7 +100,7 @@ void X86PLT::reserveEntry(size_t pNum)
plt1_entry = new (std::nothrow) X86PLT1(&m_SectionData, m_PLT1Size);
if (!plt1_entry)
- fatal(diag::fail_allocate_memory) << "X86PLT1";
+ fatal(diag::fail_allocate_memory_plt);
m_Section.setSize(m_Section.size() + plt1_entry->getEntrySize());
@@ -152,7 +158,7 @@ void X86PLT::applyPLT0() {
data = static_cast<unsigned char*>(malloc(plt0->getEntrySize()));
if (!data)
- fatal(diag::fail_allocate_memory) << "plt0";
+ fatal(diag::fail_allocate_memory_plt);
memcpy(data, m_PLT0, plt0->getEntrySize());
@@ -200,7 +206,7 @@ void X86PLT::applyPLT1() {
data = static_cast<unsigned char*>(malloc(plt1->getEntrySize()));
if (!data)
- fatal(diag::fail_allocate_memory) << "plt1";
+ fatal(diag::fail_allocate_memory_plt);
memcpy(data, m_PLT1, plt1->getEntrySize());
diff --git a/lib/Target/X86/X86PLT.h b/lib/Target/X86/X86PLT.h
index 6c7002a..1669a49 100644
--- a/lib/Target/X86/X86PLT.h
+++ b/lib/Target/X86/X86PLT.h
@@ -1,4 +1,4 @@
-//===- X86PLT.h -----------------------------------------------------===//
+//===- X86PLT.h -----------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,10 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef X86_PLT_H
-#define X86_PLT_H
+#ifndef MCLD_TARGET_X86_PLT_H
+#define MCLD_TARGET_X86_PLT_H
+
+#include <llvm/ADT/DenseMap.h>
#include <mcld/Target/PLT.h>
+#include <mcld/LD/SectionData.h>
namespace mcld {
@@ -17,14 +20,16 @@ class X86GOTPLT;
class GOTEntry;
class Output;
-class X86PLT0 : public PLTEntry {
+class X86PLT0 : public PLTEntry
+{
public:
- X86PLT0(llvm::MCSectionData* pParent, unsigned int pSize);
+ X86PLT0(SectionData* pParent, unsigned int pSize);
};
-class X86PLT1 : public PLTEntry {
+class X86PLT1 : public PLTEntry
+{
public:
- X86PLT1(llvm::MCSectionData* pParent, unsigned int pSize);
+ X86PLT1(SectionData* pParent, unsigned int pSize);
};
/** \class X86PLT
@@ -35,12 +40,12 @@ class X86PLT : public PLT
typedef llvm::DenseMap<const ResolveInfo*, X86PLT1*> SymbolIndexType;
public:
- typedef llvm::MCSectionData::iterator iterator;
- typedef llvm::MCSectionData::const_iterator const_iterator;
+ typedef SectionData::iterator iterator;
+ typedef SectionData::const_iterator const_iterator;
public:
X86PLT(LDSection& pSection,
- llvm::MCSectionData& pSectionData,
+ SectionData& pSectionData,
X86GOTPLT& pGOTPLT,
const Output& pOutput);
~X86PLT();
diff --git a/lib/Target/X86/X86RelocationFactory.cpp b/lib/Target/X86/X86RelocationFactory.cpp
index 71fa344..f603b6e 100644
--- a/lib/Target/X86/X86RelocationFactory.cpp
+++ b/lib/Target/X86/X86RelocationFactory.cpp
@@ -132,7 +132,7 @@ GOTEntry& helper_get_GOT_and_init(Relocation& pReloc,
rel_entry.targetRef().assign(got_entry);
}
else {
- fatal(diag::reserve_entry_number_mismatch) << "GOT";
+ fatal(diag::reserve_entry_number_mismatch_got);
}
}
return got_entry;
@@ -182,7 +182,7 @@ PLTEntry& helper_get_PLT_and_init(Relocation& pReloc,
rel_entry.setSymInfo(rsym);
}
else {
- fatal(diag::reserve_entry_number_mismatch) << "PLT";
+ fatal(diag::reserve_entry_number_mismatch_plt);
}
}
return plt_entry;
diff --git a/lib/Target/X86/X86SectLinker.cpp b/lib/Target/X86/X86SectLinker.cpp
index a888f47..2954d1f 100644
--- a/lib/Target/X86/X86SectLinker.cpp
+++ b/lib/Target/X86/X86SectLinker.cpp
@@ -47,3 +47,4 @@ extern "C" void LLVMInitializeX86SectLinker() {
// Register the linker frontend
mcld::TargetRegistry::RegisterSectLinker(TheX86Target, createX86SectLinker);
}
+