summaryrefslogtreecommitdiffstats
path: root/Source/cmELF.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-04-14 19:02:24 (GMT)
committerBrad King <brad.king@kitware.com>2008-04-14 19:02:24 (GMT)
commit3ff5404ccaeefbf4d53efcf86cd3a7d45d8e87e9 (patch)
treefbc64ce256bd09954a864ead572a1594fd14bf94 /Source/cmELF.cxx
parent9b8404a30516b629ad9ebc7322d58b18ce034858 (diff)
downloadCMake-3ff5404ccaeefbf4d53efcf86cd3a7d45d8e87e9.zip
CMake-3ff5404ccaeefbf4d53efcf86cd3a7d45d8e87e9.tar.gz
CMake-3ff5404ccaeefbf4d53efcf86cd3a7d45d8e87e9.tar.bz2
ENH: Added cmELF methods to get information about DYNAMIC section entries.
Diffstat (limited to 'Source/cmELF.cxx')
-rw-r--r--Source/cmELF.cxx88
1 files changed, 88 insertions, 0 deletions
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index a6440ed..5abc62a 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -98,9 +98,18 @@ public:
// Forward to the per-class implementation.
virtual unsigned int GetNumberOfSections() const = 0;
+ virtual unsigned int GetDynamicEntryCount() = 0;
+ virtual unsigned long GetDynamicEntryPosition(int j) = 0;
virtual StringEntry const* GetDynamicSectionString(int tag) = 0;
virtual void PrintInfo(std::ostream& os) const = 0;
+ bool ReadBytes(unsigned long pos, unsigned long size, char* buf)
+ {
+ this->Stream.seekg(pos);
+ this->Stream.read(buf, size);
+ return this->Stream?true:false;
+ }
+
// Lookup the SONAME in the DYNAMIC section.
StringEntry const* GetSOName()
{
@@ -201,6 +210,10 @@ public:
return static_cast<unsigned int>(this->ELFHeader.e_shnum);
}
+ // Get the file position and size of a dynamic section entry.
+ virtual unsigned int GetDynamicEntryCount();
+ virtual unsigned long GetDynamicEntryPosition(int j);
+
// Lookup a string from the dynamic section with the given tag.
virtual StringEntry const* GetDynamicSectionString(int tag);
@@ -552,6 +565,40 @@ bool cmELFInternalImpl<Types>::LoadDynamicSection()
//----------------------------------------------------------------------------
template <class Types>
+unsigned int cmELFInternalImpl<Types>::GetDynamicEntryCount()
+{
+ if(!this->LoadDynamicSection())
+ {
+ return 0;
+ }
+ for(unsigned int i = 0; i < this->DynamicSectionEntries.size(); ++i)
+ {
+ if(this->DynamicSectionEntries[i].d_tag == DT_NULL)
+ {
+ return i;
+ }
+ }
+ return this->DynamicSectionEntries.size();
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
+unsigned long cmELFInternalImpl<Types>::GetDynamicEntryPosition(int j)
+{
+ if(!this->LoadDynamicSection())
+ {
+ return 0;
+ }
+ if(j < 0 || j >= this->DynamicSectionEntries.size())
+ {
+ return 0;
+ }
+ ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+ return sec.sh_offset + sec.sh_entsize*j;
+}
+
+//----------------------------------------------------------------------------
+template <class Types>
cmELF::StringEntry const*
cmELFInternalImpl<Types>::GetDynamicSectionString(int tag)
{
@@ -571,6 +618,7 @@ cmELFInternalImpl<Types>::GetDynamicSectionString(int tag)
StringEntry& se = this->DynamicSectionStrings[tag];
se.Position = 0;
se.Size = 0;
+ se.IndexInSection = -1;
// Try reading the dynamic section.
if(!this->LoadDynamicSection())
@@ -641,6 +689,7 @@ cmELFInternalImpl<Types>::GetDynamicSectionString(int tag)
// The value has been read successfully. Report it.
se.Position = static_cast<unsigned long>(strtab.sh_offset + first);
se.Size = last - first;
+ se.IndexInSection = di - this->DynamicSectionEntries.begin();
return &se;
}
}
@@ -762,6 +811,45 @@ unsigned int cmELF::GetNumberOfSections() const
}
//----------------------------------------------------------------------------
+unsigned int cmELF::GetDynamicEntryCount() const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetDynamicEntryCount();
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+unsigned long cmELF::GetDynamicEntryPosition(int index) const
+{
+ if(this->Valid())
+ {
+ return this->Internal->GetDynamicEntryPosition(index);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmELF::ReadBytes(unsigned long pos, unsigned long size, char* buf) const
+{
+ if(this->Valid())
+ {
+ return this->Internal->ReadBytes(pos, size, buf);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+//----------------------------------------------------------------------------
bool cmELF::GetSOName(std::string& soname)
{
if(StringEntry const* se = this->GetSOName())