• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ELFSegment.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/ELFSegment.h>
10 
11 using namespace mcld;
12 
13 //==========================
14 // ELFSegment
ELFSegment(uint32_t pType,uint32_t pFlag,uint64_t pOffset,uint64_t pVaddr,uint64_t pPaddr,uint64_t pFilesz,uint64_t pMemsz,uint64_t pAlign,uint64_t pMaxSectAlign)15 ELFSegment::ELFSegment(uint32_t pType,
16                        uint32_t pFlag,
17                        uint64_t pOffset,
18                        uint64_t pVaddr,
19                        uint64_t pPaddr,
20                        uint64_t pFilesz,
21                        uint64_t pMemsz,
22                        uint64_t pAlign,
23                        uint64_t pMaxSectAlign)
24   : m_Type(pType),
25     m_Flag(pFlag),
26     m_Offset(pOffset),
27     m_Vaddr(pVaddr),
28     m_Paddr(pPaddr),
29     m_Filesz(pFilesz),
30     m_Memsz(pMemsz),
31     m_Align(pAlign),
32     m_MaxSectionAlign(pMaxSectAlign) {
33 }
34 
~ELFSegment()35 ELFSegment::~ELFSegment()
36 {
37 }
38 
isDataSegment() const39 bool ELFSegment::isDataSegment() const
40 {
41   bool result = false;
42   if ((type() == llvm::ELF::PT_LOAD) && (flag() & llvm::ELF::PF_W) != 0x0) {
43     for (const_sect_iterator it = begin(), ie = end(); it != ie; ++it) {
44       if ((*it)->kind() != LDFileFormat::BSS) {
45         result = true;
46         break;
47       }
48     }
49   }
50   return result;
51 }
52 
isBssSegment() const53 bool ELFSegment::isBssSegment() const
54 {
55   bool result = false;
56   if ((type() == llvm::ELF::PT_LOAD) && (flag() & llvm::ELF::PF_W) != 0x0) {
57     const_sect_iterator it = begin(), ie = end();
58     for (; it != ie; ++it) {
59       if ((*it)->kind() != LDFileFormat::BSS)
60         break;
61     }
62     if (it == ie)
63       result = true;
64   }
65   return result;
66 }
67 
68