summaryrefslogtreecommitdiff
path: root/Source/cmELF.cxx
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2016-10-05 16:43:16 +0100
committerJames Cowgill <james410@cowgill.org.uk>2016-10-06 16:52:36 +0100
commit72eb6a374ed12cfa0dee0ce1930a4dcd8473c700 (patch)
treec1b2e6f9b611a50de3217a0591d4a3e833f2f561 /Source/cmELF.cxx
parent66c4d0820ca86b0b119303859f3dae0f7c560969 (diff)
downloadcmake-72eb6a374ed12cfa0dee0ce1930a4dcd8473c700.tar.gz
elf: add DynamicEntryList methods and rpath tag constants
Diffstat (limited to 'Source/cmELF.cxx')
-rw-r--r--Source/cmELF.cxx77
1 files changed, 77 insertions, 0 deletions
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index f78eed510a..bf0130acbc 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -134,6 +134,9 @@ public:
virtual unsigned int GetNumberOfSections() const = 0;
virtual unsigned int GetDynamicEntryCount() = 0;
virtual unsigned long GetDynamicEntryPosition(int j) = 0;
+ virtual cmELF::DynamicEntryList GetDynamicEntries() = 0;
+ virtual std::vector<char> EncodeDynamicEntries(
+ const cmELF::DynamicEntryList&) = 0;
virtual StringEntry const* GetDynamicSectionString(unsigned int tag) = 0;
virtual void PrintInfo(std::ostream& os) const = 0;
@@ -250,6 +253,10 @@ public:
unsigned int GetDynamicEntryCount() CM_OVERRIDE;
unsigned long GetDynamicEntryPosition(int j) CM_OVERRIDE;
+ cmELF::DynamicEntryList GetDynamicEntries() CM_OVERRIDE;
+ std::vector<char> EncodeDynamicEntries(const cmELF::DynamicEntryList&)
+ CM_OVERRIDE;
+
// Lookup a string from the dynamic section with the given tag.
StringEntry const* GetDynamicSectionString(unsigned int tag) CM_OVERRIDE;
@@ -553,6 +560,54 @@ unsigned long cmELFInternalImpl<Types>::GetDynamicEntryPosition(int j)
}
template <class Types>
+cmELF::DynamicEntryList cmELFInternalImpl<Types>::GetDynamicEntries()
+{
+ cmELF::DynamicEntryList result;
+
+ // Ensure entries have been read from file
+ if (!this->LoadDynamicSection()) {
+ return result;
+ }
+
+ // Copy into public array
+ result.reserve(this->DynamicSectionEntries.size());
+ for (typename std::vector<ELF_Dyn>::iterator di =
+ this->DynamicSectionEntries.begin();
+ di != this->DynamicSectionEntries.end(); ++di) {
+ ELF_Dyn& dyn = *di;
+ result.push_back(
+ std::pair<unsigned long, unsigned long>(dyn.d_tag, dyn.d_un.d_val));
+ }
+
+ return result;
+}
+
+template <class Types>
+std::vector<char> cmELFInternalImpl<Types>::EncodeDynamicEntries(
+ const cmELF::DynamicEntryList& entries)
+{
+ std::vector<char> result;
+ result.reserve(sizeof(ELF_Dyn) * entries.size());
+
+ for (cmELF::DynamicEntryList::const_iterator it = entries.begin();
+ it != entries.end(); it++) {
+ // Store the entry in an ELF_Dyn, byteswap it, then serialize to chars
+ ELF_Dyn dyn;
+ dyn.d_tag = static_cast<tagtype>(it->first);
+ dyn.d_un.d_val = static_cast<tagtype>(it->second);
+
+ if (this->NeedSwap) {
+ ByteSwap(dyn);
+ }
+
+ char* pdyn = reinterpret_cast<char*>(&dyn);
+ result.insert(result.end(), pdyn, pdyn + sizeof(ELF_Dyn));
+ }
+
+ return result;
+}
+
+template <class Types>
cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
unsigned int tag)
{
@@ -642,6 +697,9 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
//============================================================================
// External class implementation.
+const long cmELF::TagRPath = DT_RPATH;
+const long cmELF::TagRunPath = DT_RUNPATH;
+
cmELF::cmELF(const char* fname)
: Internal(CM_NULLPTR)
{
@@ -745,6 +803,25 @@ unsigned long cmELF::GetDynamicEntryPosition(int index) const
return 0;
}
+cmELF::DynamicEntryList cmELF::GetDynamicEntries() const
+{
+ if (this->Valid()) {
+ return this->Internal->GetDynamicEntries();
+ }
+
+ return cmELF::DynamicEntryList();
+}
+
+std::vector<char> cmELF::EncodeDynamicEntries(
+ const cmELF::DynamicEntryList& dentries) const
+{
+ if (this->Valid()) {
+ return this->Internal->EncodeDynamicEntries(dentries);
+ }
+
+ return std::vector<char>();
+}
+
bool cmELF::ReadBytes(unsigned long pos, unsigned long size, char* buf) const
{
if (this->Valid()) {