[Cmake-commits] CMake branch, next, updated. v3.7.0-rc1-177-g1e663d2

Brad King brad.king at kitware.com
Fri Oct 7 08:30:21 EDT 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  1e663d26f306bbfda333aa57e7664865596f1878 (commit)
       via  15762b72b456998ac0f87ceec750a20e9872f325 (commit)
       via  cd4f573ae9f4ded1cb386698f90c7ccf1504f094 (commit)
       via  b8b1d15186b33ec598b1126169856184805b3e6f (commit)
      from  7c8ee666ec64e2429a4e68ae397fa0ec38ba6a1a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1e663d26f306bbfda333aa57e7664865596f1878
commit 1e663d26f306bbfda333aa57e7664865596f1878
Merge: 7c8ee66 15762b7
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Fri Oct 7 08:30:20 2016 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Oct 7 08:30:20 2016 -0400

    Merge topic 'mips-rld-map-rel' into next
    
    15762b72 elf: Remove GetDynamicEntryCount and ReadBytes methods
    cd4f573a cmSystemTools, elf: handle DT_MIPS_RLD_REL_MAP in RemoveRPath
    b8b1d151 cmSystemTools: rewrite RemoveRPath using DyanmicEntryList methods


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=15762b72b456998ac0f87ceec750a20e9872f325
commit 15762b72b456998ac0f87ceec750a20e9872f325
Author:     James Cowgill <james410 at cowgill.org.uk>
AuthorDate: Wed Oct 5 16:57:24 2016 +0100
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri Oct 7 08:30:00 2016 -0400

    elf: Remove GetDynamicEntryCount and ReadBytes methods
    
    These are no longer used after the DynamicEntryList changes.

diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index 6f2885c..0655da9 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -132,7 +132,6 @@ 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 cmELF::DynamicEntryList GetDynamicEntries() = 0;
   virtual std::vector<char> EncodeDynamicEntries(
@@ -140,13 +139,6 @@ public:
   virtual StringEntry const* GetDynamicSectionString(unsigned 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.fail();
-  }
-
   // Lookup the SONAME in the DYNAMIC section.
   StringEntry const* GetSOName()
   {
@@ -249,8 +241,7 @@ public:
     return static_cast<unsigned int>(this->ELFHeader.e_shnum);
   }
 
-  // Get the file position and size of a dynamic section entry.
-  unsigned int GetDynamicEntryCount() CM_OVERRIDE;
+  // Get the file position of a dynamic section entry.
   unsigned long GetDynamicEntryPosition(int j) CM_OVERRIDE;
 
   cmELF::DynamicEntryList GetDynamicEntries() CM_OVERRIDE;
@@ -533,20 +524,6 @@ 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 static_cast<unsigned int>(this->DynamicSectionEntries.size());
-}
-
-template <class Types>
 unsigned long cmELFInternalImpl<Types>::GetDynamicEntryPosition(int j)
 {
   if (!this->LoadDynamicSection()) {
@@ -793,14 +770,6 @@ unsigned int cmELF::GetNumberOfSections() const
   return 0;
 }
 
-unsigned int cmELF::GetDynamicEntryCount() const
-{
-  if (this->Valid()) {
-    return this->Internal->GetDynamicEntryCount();
-  }
-  return 0;
-}
-
 unsigned long cmELF::GetDynamicEntryPosition(int index) const
 {
   if (this->Valid()) {
@@ -828,14 +797,6 @@ std::vector<char> cmELF::EncodeDynamicEntries(
   return std::vector<char>();
 }
 
-bool cmELF::ReadBytes(unsigned long pos, unsigned long size, char* buf) const
-{
-  if (this->Valid()) {
-    return this->Internal->ReadBytes(pos, size, buf);
-  }
-  return false;
-}
-
 bool cmELF::GetSOName(std::string& soname)
 {
   if (StringEntry const* se = this->GetSOName()) {
diff --git a/Source/cmELF.h b/Source/cmELF.h
index 9c56be7..763a240 100644
--- a/Source/cmELF.h
+++ b/Source/cmELF.h
@@ -72,10 +72,6 @@ public:
   /** Get the number of ELF sections present.  */
   unsigned int GetNumberOfSections() const;
 
-  /** Get the number of DYNAMIC section entries before the first
-      DT_NULL.  Returns zero on error.  */
-  unsigned int GetDynamicEntryCount() const;
-
   /** Get the position of a DYNAMIC section header entry.  Returns
       zero on error.  */
   unsigned long GetDynamicEntryPosition(int index) const;
@@ -89,9 +85,6 @@ public:
   std::vector<char> EncodeDynamicEntries(
     const DynamicEntryList& entries) const;
 
-  /** Read bytes from the file.  */
-  bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
-
   /** Get the SONAME field if any.  */
   bool GetSOName(std::string& soname);
   StringEntry const* GetSOName();

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cd4f573ae9f4ded1cb386698f90c7ccf1504f094
commit cd4f573ae9f4ded1cb386698f90c7ccf1504f094
Author:     James Cowgill <james410 at cowgill.org.uk>
AuthorDate: Wed Oct 5 17:20:58 2016 +0100
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri Oct 7 08:30:00 2016 -0400

    cmSystemTools, elf: handle DT_MIPS_RLD_REL_MAP in RemoveRPath

diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index bf0130a..6f2885c 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -700,6 +700,12 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
 const long cmELF::TagRPath = DT_RPATH;
 const long cmELF::TagRunPath = DT_RUNPATH;
 
+#ifdef DT_MIPS_RLD_MAP_REL
+const long cmELF::TagMipsRldMapRel = DT_MIPS_RLD_MAP_REL;
+#else
+const long cmELF::TagMipsRldMapRel = 0;
+#endif
+
 cmELF::cmELF(const char* fname)
   : Internal(CM_NULLPTR)
 {
diff --git a/Source/cmELF.h b/Source/cmELF.h
index 3fc59b4..9c56be7 100644
--- a/Source/cmELF.h
+++ b/Source/cmELF.h
@@ -107,7 +107,7 @@ public:
 
   /** Interesting dynamic tags.
       If the tag is 0, it does not exist in the host ELF implementation */
-  static const long TagRPath, TagRunPath;
+  static const long TagRPath, TagRunPath, TagMipsRldMapRel;
 
 private:
   friend class cmELFInternal;
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 8951788..d800ef8 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2536,6 +2536,10 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
       zeroSize[i] = se[i]->Size;
     }
 
+    // Get size of one DYNAMIC entry
+    unsigned long const sizeof_dentry =
+      elf.GetDynamicEntryPosition(1) - elf.GetDynamicEntryPosition(0);
+
     // Adjust the entry list as necessary to remove the run path
     unsigned long entriesErased = 0;
     for (cmELF::DynamicEntryList::iterator it = dentries.begin();
@@ -2545,6 +2549,26 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
         entriesErased++;
         continue;
       } else {
+        if (cmELF::TagMipsRldMapRel != 0 &&
+            it->first == cmELF::TagMipsRldMapRel) {
+          // Background: debuggers need to know the "linker map" which contains
+          // the addresses each dynamic object is loaded at. Most arches use
+          // the DT_DEBUG tag which the dynamic linker writes to (directly) and
+          // contain the location of the linker map, however on MIPS the
+          // .dynamic section is always read-only so this is not possible. MIPS
+          // objects instead contain a DT_MIPS_RLD_MAP tag which contains the
+          // address where the dyanmic linker will write to (an indirect
+          // version of DT_DEBUG). Since this doesn't work when using PIE, a
+          // relative equivalent was created - DT_MIPS_RLD_MAP_REL. Since this
+          // version contains a relative offset, moving it changes the
+          // calculated address. This may cause the dyanmic linker to write
+          // into memory it should not be changing.
+          //
+          // To fix this, we adjust the value of DT_MIPS_RLD_MAP_REL here. If
+          // we move it up by n bytes, we add n bytes to the value of this tag.
+          it->second += entriesErased * sizeof_dentry;
+        }
+
         it++;
       }
     }

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b8b1d15186b33ec598b1126169856184805b3e6f
commit b8b1d15186b33ec598b1126169856184805b3e6f
Author:     James Cowgill <james410 at cowgill.org.uk>
AuthorDate: Wed Oct 5 17:19:43 2016 +0100
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri Oct 7 08:29:59 2016 -0400

    cmSystemTools: rewrite RemoveRPath using DyanmicEntryList methods

diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 3d8fdf5..8951788 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2518,9 +2518,9 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
       std::swap(se[0], se[1]);
     }
 
-    // Get the size of the dynamic section header.
-    unsigned int count = elf.GetDynamicEntryCount();
-    if (count == 0) {
+    // Obtain a copy of the dynamic entries
+    cmELF::DynamicEntryList dentries = elf.GetDynamicEntries();
+    if (dentries.empty()) {
       // This should happen only for invalid ELF files where a DT_NULL
       // appears before the end of the table.
       if (emsg) {
@@ -2536,40 +2536,22 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
       zeroSize[i] = se[i]->Size;
     }
 
-    // Get the range of file positions corresponding to each entry and
-    // the rest of the table after them.
-    unsigned long entryBegin[3] = { 0, 0, 0 };
-    unsigned long entryEnd[2] = { 0, 0 };
-    for (int i = 0; i < se_count; ++i) {
-      entryBegin[i] = elf.GetDynamicEntryPosition(se[i]->IndexInSection);
-      entryEnd[i] = elf.GetDynamicEntryPosition(se[i]->IndexInSection + 1);
-    }
-    entryBegin[se_count] = elf.GetDynamicEntryPosition(count);
-
-    // The data are to be written over the old table entries starting at
-    // the first one being removed.
-    bytesBegin = entryBegin[0];
-    unsigned long bytesEnd = entryBegin[se_count];
-
-    // Allocate a buffer to hold the part of the file to be written.
-    // Initialize it with zeros.
-    bytes.resize(bytesEnd - bytesBegin, 0);
-
-    // Read the part of the DYNAMIC section header that will move.
-    // The remainder of the buffer will be left with zeros which
-    // represent a DT_NULL entry.
-    char* data = &bytes[0];
-    for (int i = 0; i < se_count; ++i) {
-      // Read data between the entries being removed.
-      unsigned long sz = entryBegin[i + 1] - entryEnd[i];
-      if (sz > 0 && !elf.ReadBytes(entryEnd[i], sz, data)) {
-        if (emsg) {
-          *emsg = "Failed to read DYNAMIC section header.";
-        }
-        return false;
+    // Adjust the entry list as necessary to remove the run path
+    unsigned long entriesErased = 0;
+    for (cmELF::DynamicEntryList::iterator it = dentries.begin();
+         it != dentries.end();) {
+      if (it->first == cmELF::TagRPath || it->first == cmELF::TagRunPath) {
+        it = dentries.erase(it);
+        entriesErased++;
+        continue;
+      } else {
+        it++;
       }
-      data += sz;
     }
+
+    // Encode new entries list
+    bytes = elf.EncodeDynamicEntries(dentries);
+    bytesBegin = elf.GetDynamicEntryPosition(0);
   }
 
   // Open the file for update.

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list