[cmake-commits] king committed cmComputeLinkInformation.cxx 1.22 1.23 cmComputeLinkInformation.h 1.14 1.15 cmFileCommand.cxx 1.100 1.101 cmFileCommand.h 1.34 1.35 cmInstallTargetGenerator.cxx 1.59 1.60 cmSystemTools.cxx 1.363 1.364 cmSystemTools.h 1.148 1.149 cmTarget.cxx 1.200 1.201 cmTarget.h 1.107 1.108

cmake-commits at cmake.org cmake-commits at cmake.org
Sat Mar 1 12:51:09 EST 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv22604/Source

Modified Files:
	cmComputeLinkInformation.cxx cmComputeLinkInformation.h 
	cmFileCommand.cxx cmFileCommand.h cmInstallTargetGenerator.cxx 
	cmSystemTools.cxx cmSystemTools.h cmTarget.cxx cmTarget.h 
Log Message:
ENH: Use builtin chrpath instead of relinking ELF targets

  - Add cmSystemTools::ChangeRPath method
  - Add undocumented file(CHRPATH) command
  - When installing use file(CHRPATH) to change the rpath
    instead of relinking
  - Remove CMAKE_CHRPATH lookup from CMakeFindBinUtils
  - Remove CMAKE_USE_CHRPATH option since this should
    always work


Index: cmSystemTools.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.h,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- cmSystemTools.h	21 Feb 2008 18:58:41 -0000	1.148
+++ cmSystemTools.h	1 Mar 2008 17:51:07 -0000	1.149
@@ -381,6 +381,11 @@
   static bool GuessLibrarySOName(std::string const& fullPath,
                                  std::string& soname);
 
+  /** Try to set the RPATH in an ELF binary.  */
+  static bool ChangeRPath(std::string const& file,
+                          std::string const& newRPath,
+                          std::string* emsg = 0);
+
 private:
   static bool s_ForceUnixPaths;
   static bool s_RunCommandHideConsole;

Index: cmComputeLinkInformation.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkInformation.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmComputeLinkInformation.h	21 Feb 2008 16:41:11 -0000	1.14
+++ cmComputeLinkInformation.h	1 Mar 2008 17:51:07 -0000	1.15
@@ -58,7 +58,6 @@
   void GetRPath(std::vector<std::string>& runtimeDirs, bool for_install);
   std::string GetRPathString(bool for_install);
   std::string GetChrpathString();
-  std::string GetChrpathTool();
   std::set<cmTarget*> const& GetSharedLibrariesLinked();
 
   std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; }

Index: cmComputeLinkInformation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkInformation.cxx,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cmComputeLinkInformation.cxx	29 Feb 2008 14:15:32 -0000	1.22
+++ cmComputeLinkInformation.cxx	1 Mar 2008 17:51:07 -0000	1.23
@@ -1476,9 +1476,3 @@
 
   return this->GetRPathString(true);
 }
-
-//----------------------------------------------------------------------------
-std::string cmComputeLinkInformation::GetChrpathTool()
-{
-  return this->Makefile->GetSafeDefinition("CMAKE_CHRPATH");
-}

Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.363
retrieving revision 1.364
diff -u -d -r1.363 -r1.364
--- cmSystemTools.cxx	27 Feb 2008 21:26:35 -0000	1.363
+++ cmSystemTools.cxx	1 Mar 2008 17:51:07 -0000	1.364
@@ -2195,3 +2195,86 @@
     }
   return false;
 }
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::ChangeRPath(std::string const& file,
+                                std::string const& newRPath,
+                                std::string* emsg)
+{
+#if defined(CMAKE_USE_ELF_PARSER)
+  unsigned long rpathPosition = 0;
+  unsigned long rpathSize = 0;
+  {
+  cmELF elf(file.c_str());
+  if(cmELF::StringEntry const* se = elf.GetRPath())
+    {
+    rpathPosition = se->Position;
+    rpathSize = se->Size;
+    }
+  else
+    {
+    if(emsg)
+      {
+      *emsg = "No valid ELF RPATH entry exists in the file.";
+      }
+    return false;
+    }
+  }
+  // Make sure there is enough room to store the new rpath and at
+  // least one null terminator.
+  if(rpathSize < newRPath.length()+1)
+    {
+    if(emsg)
+      {
+      *emsg = "The replacement RPATH is too long.";
+      }
+    return false;
+    }
+
+  // Open the file for update and seek to the RPATH position.
+  std::ofstream f(file.c_str(),
+                  std::ios::in | std::ios::out | std::ios::binary);
+  if(!f)
+    {
+    if(emsg)
+      {
+      *emsg = "Error opening file for update.";
+      }
+    return false;
+    }
+  if(!f.seekp(rpathPosition))
+    {
+    if(emsg)
+      {
+      *emsg = "Error seeking to RPATH position.";
+      }
+    return false;
+    }
+
+  // Write the new rpath.  Follow it with enough null terminators to
+  // fill the string table entry.
+  f << newRPath;
+  for(unsigned long i=newRPath.length(); i < rpathSize; ++i)
+    {
+    f << '\0';
+    }
+
+  // Make sure everything was okay.
+  if(f)
+    {
+    return true;
+    }
+  else
+    {
+    if(emsg)
+      {
+      *emsg = "Error writing the new rpath to the file.";
+      }
+    return false;
+    }
+#else
+  (void)file;
+  (void)newRPath;
+  return false;
+#endif
+}

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- cmFileCommand.cxx	18 Feb 2008 20:42:55 -0000	1.100
+++ cmFileCommand.cxx	1 Mar 2008 17:51:07 -0000	1.101
@@ -112,6 +112,10 @@
     {
     return this->HandleInstallCommand(args);
     }
+  else if ( subCommand == "CHRPATH" )
+    {
+    return this->HandleChrpathCommand(args);
+    }
   else if ( subCommand == "RELATIVE_PATH" )
     {
     return this->HandleRelativePathCommand(args);
@@ -1327,6 +1331,34 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmFileCommand::HandleChrpathCommand(std::vector<std::string> const& args)
+{
+  if(args.size() != 3)
+    {
+    this->SetError("CHRPATH must be given a file and a new rpath.");
+    return false;
+    }
+  if(!cmSystemTools::FileExists(args[1].c_str(), true))
+    {
+    this->SetError("CHRPATH given file that does not exist.");
+    return false;
+    }
+  std::string emsg;
+  if(cmSystemTools::ChangeRPath(args[1], args[2], &emsg))
+    {
+    return true;
+    }
+  else
+    {
+    cmOStringStream e;
+    e << "CHRPATH could not write new RPATH to the file: "
+      << emsg;
+    this->SetError(e.str().c_str());
+    return false;
+    }
+}
+
+//----------------------------------------------------------------------------
 bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
 {
   if ( args.size() < 6 )

Index: cmTarget.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.h,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- cmTarget.h	21 Feb 2008 16:41:11 -0000	1.107
+++ cmTarget.h	1 Mar 2008 17:51:07 -0000	1.108
@@ -335,7 +335,7 @@
   bool HaveBuildTreeRPATH();
   bool HaveInstallTreeRPATH();
 
-  /** Return true if chrpath might work for this target */
+  /** Return true if builtin chrpath will work for this target */
   bool IsChrpathUsed();
 
   std::string GetInstallNameDirForBuildTree(const char* config);

Index: cmInstallTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.cxx,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- cmInstallTargetGenerator.cxx	6 Feb 2008 19:20:35 -0000	1.59
+++ cmInstallTargetGenerator.cxx	1 Mar 2008 17:51:07 -0000	1.60
@@ -576,12 +576,9 @@
   // Get the install RPATH from the link information.
   std::string newRpath = cli->GetChrpathString();
 
-  // Fix the RPATH in installed ELF binaries using chrpath.
-  std::string chrpathTool = cli->GetChrpathTool();
-
   // Write a rule to run chrpath to set the install-tree RPATH
-  os << indent << "EXECUTE_PROCESS(COMMAND \"" << chrpathTool;
-  os << "\" -r \"" << newRpath << "\" \"" << toDestDirPath << "\")\n";
+  os << indent
+     << "FILE(CHRPATH \"" << toDestDirPath << "\" \"" << newRpath << "\")\n";
 }
 
 //----------------------------------------------------------------------------

Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- cmFileCommand.h	7 Feb 2008 18:26:16 -0000	1.34
+++ cmFileCommand.h	1 Mar 2008 17:51:07 -0000	1.35
@@ -171,6 +171,7 @@
   bool HandleRelativePathCommand(std::vector<std::string> const& args);
   bool HandleCMakePathCommand(std::vector<std::string> const& args,
                               bool nativePath);
+  bool HandleChrpathCommand(std::vector<std::string> const& args);
 
   // file(INSTALL ...) related functions
   bool HandleInstallCommand(std::vector<std::string> const& args);

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.200
retrieving revision 1.201
diff -u -d -r1.200 -r1.201
--- cmTarget.cxx	24 Feb 2008 19:05:11 -0000	1.200
+++ cmTarget.cxx	1 Mar 2008 17:51:07 -0000	1.201
@@ -3006,8 +3006,9 @@
 //----------------------------------------------------------------------------
 bool cmTarget::IsChrpathUsed()
 {
-  // Enable use of "chrpath" if it is available, the user has turned
-  // on the feature, and the rpath flag uses a separator.
+#if defined(CMAKE_USE_ELF_PARSER)
+  // Enable if the rpath flag uses a separator and the target uses ELF
+  // binaries.
   if(const char* ll = this->GetLinkerLanguage(
        this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
     {
@@ -3017,13 +3018,16 @@
     const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
     if(sep && *sep)
       {
-      if(this->Makefile->IsSet("CMAKE_CHRPATH") &&
-         this->Makefile->IsOn("CMAKE_USE_CHRPATH"))
+      // TODO: Add ELF check to ABI detection and get rid of
+      // CMAKE_EXECUTABLE_FORMAT.
+      if(const char* fmt =
+         this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
         {
-        return true;
+        return strcmp(fmt, "ELF") == 0;
         }
       }
     }
+#endif
   return false;
 }
 



More information about the Cmake-commits mailing list