Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 1 | //===- 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 Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 10 | #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 Liao | cedee4b | 2012-08-02 23:13:03 -0700 | [diff] [blame] | 14 | |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 15 | using namespace mcld; |
| 16 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 17 | //===----------------------------------------------------------------------===// |
| 18 | // EhFrame::CIE |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | EhFrame::CIE::CIE(MemoryRegion& pRegion) |
| 21 | : RegionFragment(pRegion) { |
| 22 | } |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // EhFrame::FDE |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | EhFrame::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 Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 36 | // EhFrame |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 37 | //===----------------------------------------------------------------------===// |
| 38 | EhFrame::EhFrame(LDSection& pSection) |
| 39 | : m_Section(pSection), |
| 40 | m_pSectionData(NULL) { |
| 41 | m_pSectionData = SectionData::Create(pSection); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | EhFrame::~EhFrame() |
| 45 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 46 | // 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 Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 48 | } |
| 49 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 50 | void EhFrame::addFragment(RegionFragment& pFrag) |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 51 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 52 | uint32_t offset = 0; |
| 53 | if (!m_pSectionData->empty()) |
| 54 | offset = m_pSectionData->back().getOffset() + m_pSectionData->back().size(); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 55 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 56 | m_pSectionData->getFragmentList().push_back(&pFrag); |
| 57 | pFrag.setOffset(offset); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 60 | void EhFrame::addCIE(EhFrame::CIE& pCIE) |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 61 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 62 | m_CIEs.push_back(&pCIE); |
| 63 | addFragment(pCIE); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 66 | void EhFrame::addFDE(EhFrame::FDE& pFDE) |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 67 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 68 | m_FDEs.push_back(&pFDE); |
| 69 | addFragment(pFDE); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 70 | } |
| 71 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 72 | EhFrame& EhFrame::merge(EhFrame& pOther) |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 73 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 74 | ObjectBuilder::MoveSectionData(pOther.getSectionData(), *m_pSectionData); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 75 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 76 | 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 Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 79 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 80 | 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 Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 83 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame^] | 84 | pOther.m_CIEs.clear(); |
| 85 | pOther.m_FDEs.clear(); |
| 86 | return *this; |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 87 | } |
| 88 | |