blob: df61c24fa2088d8c31487c5c434336a1d8fe93d9 [file] [log] [blame]
Zonr Changaffc1502012-07-16 14:28:23 +08001//===- EhFrame.cpp --------------------------------------------------------===//
2//
3// The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include <mcld/LD/EhFrame.h>
Shih-wei Liao22add6f2012-12-15 17:21:00 -080010#include <mcld/LD/LDSection.h>
11#include <mcld/LD/SectionData.h>
12#include <mcld/Support/MemoryRegion.h>
13#include <mcld/Object/ObjectBuilder.h>
Shih-wei Liaocedee4b2012-08-02 23:13:03 -070014
Zonr Changaffc1502012-07-16 14:28:23 +080015using namespace mcld;
16
Shih-wei Liao22add6f2012-12-15 17:21:00 -080017//===----------------------------------------------------------------------===//
18// EhFrame::CIE
19//===----------------------------------------------------------------------===//
20EhFrame::CIE::CIE(MemoryRegion& pRegion)
21 : RegionFragment(pRegion) {
22}
23
24//===----------------------------------------------------------------------===//
25// EhFrame::FDE
26//===----------------------------------------------------------------------===//
27EhFrame::FDE::FDE(MemoryRegion& pRegion,
28 const EhFrame::CIE& pCIE,
29 uint32_t pDataStart)
30 : RegionFragment(pRegion),
31 m_CIE(pCIE),
32 m_DataStart(pDataStart) {
33}
34
35//===----------------------------------------------------------------------===//
Zonr Changaffc1502012-07-16 14:28:23 +080036// EhFrame
Shih-wei Liao22add6f2012-12-15 17:21:00 -080037//===----------------------------------------------------------------------===//
38EhFrame::EhFrame(LDSection& pSection)
39 : m_Section(pSection),
40 m_pSectionData(NULL) {
41 m_pSectionData = SectionData::Create(pSection);
Zonr Changaffc1502012-07-16 14:28:23 +080042}
43
44EhFrame::~EhFrame()
45{
Shih-wei Liao22add6f2012-12-15 17:21:00 -080046 // Since all CIEs, FDEs and regular fragments are stored in iplist, iplist
47 // will delete the fragments and we do not need to handle with it.
Zonr Changaffc1502012-07-16 14:28:23 +080048}
49
Shih-wei Liao22add6f2012-12-15 17:21:00 -080050void EhFrame::addFragment(RegionFragment& pFrag)
Zonr Changaffc1502012-07-16 14:28:23 +080051{
Shih-wei Liao22add6f2012-12-15 17:21:00 -080052 uint32_t offset = 0;
53 if (!m_pSectionData->empty())
54 offset = m_pSectionData->back().getOffset() + m_pSectionData->back().size();
Zonr Changaffc1502012-07-16 14:28:23 +080055
Shih-wei Liao22add6f2012-12-15 17:21:00 -080056 m_pSectionData->getFragmentList().push_back(&pFrag);
57 pFrag.setOffset(offset);
Zonr Changaffc1502012-07-16 14:28:23 +080058}
59
Shih-wei Liao22add6f2012-12-15 17:21:00 -080060void EhFrame::addCIE(EhFrame::CIE& pCIE)
Zonr Changaffc1502012-07-16 14:28:23 +080061{
Shih-wei Liao22add6f2012-12-15 17:21:00 -080062 m_CIEs.push_back(&pCIE);
63 addFragment(pCIE);
Zonr Changaffc1502012-07-16 14:28:23 +080064}
65
Shih-wei Liao22add6f2012-12-15 17:21:00 -080066void EhFrame::addFDE(EhFrame::FDE& pFDE)
Zonr Changaffc1502012-07-16 14:28:23 +080067{
Shih-wei Liao22add6f2012-12-15 17:21:00 -080068 m_FDEs.push_back(&pFDE);
69 addFragment(pFDE);
Zonr Changaffc1502012-07-16 14:28:23 +080070}
71
Shih-wei Liao22add6f2012-12-15 17:21:00 -080072EhFrame& EhFrame::merge(EhFrame& pOther)
Zonr Changaffc1502012-07-16 14:28:23 +080073{
Shih-wei Liao22add6f2012-12-15 17:21:00 -080074 ObjectBuilder::MoveSectionData(pOther.getSectionData(), *m_pSectionData);
Zonr Changaffc1502012-07-16 14:28:23 +080075
Shih-wei Liao22add6f2012-12-15 17:21:00 -080076 m_CIEs.reserve(pOther.numOfCIEs() + m_CIEs.size());
77 for (cie_iterator cie = pOther.cie_begin(); cie != pOther.cie_end(); ++cie)
78 m_CIEs.push_back(*cie);
Zonr Changaffc1502012-07-16 14:28:23 +080079
Shih-wei Liao22add6f2012-12-15 17:21:00 -080080 m_FDEs.reserve(pOther.numOfFDEs() + m_FDEs.size());
81 for (fde_iterator fde = pOther.fde_begin(); fde != pOther.fde_end(); ++fde)
82 m_FDEs.push_back(*fde);
Zonr Changaffc1502012-07-16 14:28:23 +080083
Shih-wei Liao22add6f2012-12-15 17:21:00 -080084 pOther.m_CIEs.clear();
85 pOther.m_FDEs.clear();
86 return *this;
Zonr Changaffc1502012-07-16 14:28:23 +080087}
88