Commits

a4z committed b4d01d8

make rpath runpath distinguishable and some re naming/factoring

Comments (0)

Files changed (2)

include/sbbdep/elffile.hpp

   
   ~ElfFile();
 
-  const PathName& getName() const { return m_name; }
+  const PathName& getName() const { return _name; }
   
-  Arch getArch() const {return m_arch;}
+  Arch getArch() const {return _arch;}
 
-  Type getType()  const{ return m_type; }  
+  Type getType()  const{ return _type; }  
   
   std::string soName() const {
-    if(getType()== ElfFile::Library && m_soName.empty())
+    if(getType()== ElfFile::Library && _soName.empty())
       return getName().getBase();
 
-    return m_soName ;
+    return _soName ;
   }
   
-  const StringVec& getNeeded() const { return m_needed ; }
+  const StringVec& getNeeded() const { return _needed ; }
   
-  const StringVec& getRRunPaths() const { return m_rrunpaths ; }
+  const StringVec& getRRunPaths() const { return _rrunpaths ; }
   
   bool isBinaryOrLibrary(){ return getType() == ElfFile::Binary || getType() == ElfFile::Library ;}
 
+  bool hasRPath() const {return !_hasRunPath && !_rrunpaths.empty();}
+  bool hasRunPath() const {return _hasRunPath && !_rrunpaths.empty();}
+
 private:
   
 
-  PathName m_name;
-  Arch m_arch ;
-  Type m_type ;
+  PathName _name;
+  Arch _arch ;
+  Type _type ;
   
-  std::string m_soName;
-  StringVec m_needed;
-  StringVec m_rrunpaths;
+  std::string _soName;
+  StringVec _needed;
+  StringVec _rrunpaths;
+
+  bool _hasRunPath;
 
   void load();
  

src/sbbdep/elffile.cpp

 
 
 ElfFile::ElfFile(const PathName& name) noexcept
-  : m_name(name)
-  , m_arch(ArchNA)
-  , m_type(TypeNA)
-  , m_soName()
-  , m_needed()
-  , m_rrunpaths()
+  : _name{name}
+  , _arch{ArchNA}
+  , _type{TypeNA}
+  , _soName{}
+  , _needed{}
+  , _rrunpaths{}
+  , _hasRunPath{false}
 {
   try
   {
 }
 //--------------------------------------------------------------------------------------------------
 
+
 void
 ElfFile::load()
 {
   // firewall against invalid pathnames
-  if(not Path(m_name).isRegularFile())
+  if(not Path(_name).isRegularFile())
     return ;
 
   ELFIO::elfio elfreader;
 
-  if ( not elfreader.load( m_name ) ) {
+  if ( not elfreader.load( _name ) ) {
       return;
   }
 
   if (elfclass == ELFCLASSNONE)
     throw ErrUnexpected("should already have returned false");
   else if (elfclass == ELFCLASS32)
-    m_arch = Arch32;
+    _arch = Arch32;
   else if (elfclass == ELFCLASS64)
-    m_arch = Arch64;
+    _arch = Arch64;
   else
     throw ErrUnexpected("unknown arch should not happen");
 
   ELFIO::Elf_Half type = elfreader.get_type();
 
   if (type == ET_NONE)
-    m_type = TypeNA;
+    _type = TypeNA;
   else if (type == ET_EXEC)
-    m_type = Binary;
+    _type = Binary;
   else if (type == ET_DYN)
-    m_type = Library;
+    _type = Library;
   else
-    m_type=Other;
+    _type=Other;
 
 
-  if( !( m_type == Binary || m_type == Library ) )
+  if( !( _type == Binary || _type == Library ) )
     return ;
 
 
 
               if( tag == DT_NEEDED )
                 {
-                  m_needed.push_back(std::string(val));
+                  _needed.push_back(std::string(val));
                 }
               else if( tag == DT_SONAME )
                 {
-                  m_soName = val;
+                  _soName = val;
                 }
               else if( tag == DT_RPATH )
                 {
                       spos != epos && spos != pathes.size(); epos = pathes.find(":", spos))
                     {
                       std::string rpath = pathes.substr(spos, epos - spos);
-                      m_rrunpaths.push_back(rpath);
+                      _rrunpaths.push_back(rpath);
                       spos = epos == std::string::npos ? std::string::npos : epos + 1;
                     }
 
                 }
               else if( tag == DT_RUNPATH )
                 { // assume that runpath is always after rpath
-                  m_rrunpaths.clear();
+                  // what should be the case, rpath only if runpath does not exist
+                  _rrunpaths.clear();
+                  _hasRunPath = true;
 
                   std::string pathes = val;
 
                       spos != epos && spos != pathes.size(); epos = pathes.find(":", spos))
                     {
                       std::string rpath = pathes.substr(spos, epos - spos);
-                      m_rrunpaths.push_back(rpath);
+                      _rrunpaths.push_back(rpath);
                       spos = epos == std::string::npos ? std::string::npos : epos + 1;
                     }
 
 
   return retval;
 }
-
+//--------------------------------------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------------------------------------