Просмотр исходного кода

cmELF: Include the ELF parsing code unconditionally

Now that the ELF definitions are provided on all platforms there is no
need to keep the CMake_USE_ELF_PARSER option.
Alex Richardson 4 лет назад
Родитель
Сommit
115ff6a347

+ 2 - 8
Source/CMakeLists.txt

@@ -11,8 +11,6 @@ endif()
 
 
 include(CheckIncludeFile)
 include(CheckIncludeFile)
 
 
-set(CMake_USE_ELF_PARSER 1)
-
 if(NOT CMake_DEFAULT_RECURSION_LIMIT)
 if(NOT CMake_DEFAULT_RECURSION_LIMIT)
   if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
   if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
     set(CMake_DEFAULT_RECURSION_LIMIT 100)
     set(CMake_DEFAULT_RECURSION_LIMIT 100)
@@ -83,11 +81,6 @@ include_directories(
   ${CMake_HAIKU_INCLUDE_DIRS}
   ${CMake_HAIKU_INCLUDE_DIRS}
   )
   )
 
 
-# The ELF parser can be built on all platforms.
-if(CMake_USE_ELF_PARSER)
-  set(ELF_SRCS cmELF.h cmELF.cxx)
-endif()
-
 # Check if we can build the Mach-O parser.
 # Check if we can build the Mach-O parser.
 if(CMake_USE_MACH_PARSER)
 if(CMake_USE_MACH_PARSER)
   set(MACH_SRCS cmMachO.h cmMachO.cxx)
   set(MACH_SRCS cmMachO.h cmMachO.cxx)
@@ -217,7 +210,8 @@ set(SRCS
   cmDocumentationSection.cxx
   cmDocumentationSection.cxx
   cmDynamicLoader.cxx
   cmDynamicLoader.cxx
   cmDynamicLoader.h
   cmDynamicLoader.h
-  ${ELF_SRCS}
+  cmELF.h
+  cmELF.cxx
   cmExprParserHelper.cxx
   cmExprParserHelper.cxx
   cmExportBuildAndroidMKGenerator.h
   cmExportBuildAndroidMKGenerator.h
   cmExportBuildAndroidMKGenerator.cxx
   cmExportBuildAndroidMKGenerator.cxx

+ 0 - 1
Source/cmConfigure.cmake.h.in

@@ -16,7 +16,6 @@
 
 
 #cmakedefine HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE
 #cmakedefine HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE
 #cmakedefine HAVE_UNSETENV
 #cmakedefine HAVE_UNSETENV
-#cmakedefine CMake_USE_ELF_PARSER
 #cmakedefine CMake_USE_MACH_PARSER
 #cmakedefine CMake_USE_MACH_PARSER
 #cmakedefine CMake_USE_XCOFF_PARSER
 #cmakedefine CMake_USE_XCOFF_PARSER
 #define CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@
 #define CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@

+ 0 - 4
Source/cmELF.h

@@ -10,10 +10,6 @@
 #include <utility>
 #include <utility>
 #include <vector>
 #include <vector>
 
 
-#if !defined(CMake_USE_ELF_PARSER)
-#  error "This file may be included only if CMake_USE_ELF_PARSER is enabled."
-#endif
-
 class cmELFInternal;
 class cmELFInternal;
 
 
 /** \class cmELF
 /** \class cmELF

+ 6 - 14
Source/cmFileCommand.cxx

@@ -31,6 +31,7 @@
 #include "cmArgumentParser.h"
 #include "cmArgumentParser.h"
 #include "cmCMakePath.h"
 #include "cmCMakePath.h"
 #include "cmCryptoHash.h"
 #include "cmCryptoHash.h"
+#include "cmELF.h"
 #include "cmExecutionStatus.h"
 #include "cmExecutionStatus.h"
 #include "cmFSPermissions.h"
 #include "cmFSPermissions.h"
 #include "cmFileCopier.h"
 #include "cmFileCopier.h"
@@ -64,10 +65,6 @@
 #  include "cmFileLockResult.h"
 #  include "cmFileLockResult.h"
 #endif
 #endif
 
 
-#if defined(CMake_USE_ELF_PARSER)
-#  include "cmELF.h"
-#endif
-
 #if defined(_WIN32)
 #if defined(_WIN32)
 #  include <windows.h>
 #  include <windows.h>
 #endif
 #endif
@@ -1242,8 +1239,12 @@ bool HandleReadElfCommand(std::vector<std::string> const& args,
     return false;
     return false;
   }
   }
 
 
-#if defined(CMake_USE_ELF_PARSER)
   cmELF elf(fileNameArg.c_str());
   cmELF elf(fileNameArg.c_str());
+  if (!elf) {
+    status.SetError(cmStrCat("READ_ELF given FILE \"", fileNameArg,
+                             "\" that is not a valid ELF file."));
+    return false;
+  }
 
 
   if (!arguments.RPath.empty()) {
   if (!arguments.RPath.empty()) {
     if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
     if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
@@ -1261,15 +1262,6 @@ bool HandleReadElfCommand(std::vector<std::string> const& args,
   }
   }
 
 
   return true;
   return true;
-#else
-  std::string error = "ELF parser not available on this platform.";
-  if (arguments.Error.empty()) {
-    status.SetError(error);
-    return false;
-  }
-  status.GetMakefile().AddDefinition(arguments.Error, error);
-  return true;
-#endif
 }
 }
 
 
 bool HandleInstallCommand(std::vector<std::string> const& args,
 bool HandleInstallCommand(std::vector<std::string> const& args,

+ 2 - 7
Source/cmGeneratorTarget.cxx

@@ -2142,7 +2142,6 @@ bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
     return true;
     return true;
   }
   }
 
 
-#if defined(CMake_USE_ELF_PARSER) || defined(CMake_USE_XCOFF_PARSER)
   // Enable if the rpath flag uses a separator and the target uses
   // Enable if the rpath flag uses a separator and the target uses
   // binaries we know how to edit.
   // binaries we know how to edit.
   std::string ll = this->GetLinkerLanguage(config);
   std::string ll = this->GetLinkerLanguage(config);
@@ -2155,21 +2154,17 @@ bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
       // CMAKE_EXECUTABLE_FORMAT.
       // CMAKE_EXECUTABLE_FORMAT.
       if (cmProp fmt =
       if (cmProp fmt =
             this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
             this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
-#  if defined(CMake_USE_ELF_PARSER)
         if (*fmt == "ELF") {
         if (*fmt == "ELF") {
           return true;
           return true;
         }
         }
-#  endif
-#  if defined(CMake_USE_XCOFF_PARSER)
+#if defined(CMake_USE_XCOFF_PARSER)
         if (*fmt == "XCOFF") {
         if (*fmt == "XCOFF") {
           return true;
           return true;
         }
         }
-#  endif
+#endif
       }
       }
     }
     }
   }
   }
-#endif
-  static_cast<void>(config);
   return false;
   return false;
 }
 }
 
 

+ 3 - 33
Source/cmSystemTools.cxx

@@ -20,6 +20,7 @@
 #include <cm3p/uv.h>
 #include <cm3p/uv.h>
 
 
 #include "cmDuration.h"
 #include "cmDuration.h"
+#include "cmELF.h"
 #include "cmMessageMetadata.h"
 #include "cmMessageMetadata.h"
 #include "cmProcessOutput.h"
 #include "cmProcessOutput.h"
 #include "cmRange.h"
 #include "cmRange.h"
@@ -46,12 +47,6 @@
 #  include "cmCryptoHash.h"
 #  include "cmCryptoHash.h"
 #endif
 #endif
 
 
-#if defined(CMake_USE_ELF_PARSER)
-#  include "cmELF.h"
-#else
-class cmELF;
-#endif
-
 #if defined(CMake_USE_MACH_PARSER)
 #if defined(CMake_USE_MACH_PARSER)
 #  include "cmMachO.h"
 #  include "cmMachO.h"
 #endif
 #endif
@@ -2448,14 +2443,12 @@ void cmSystemTools::MakefileColorEcho(int color, const char* message,
 bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath,
 bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath,
                                        std::string& soname)
                                        std::string& soname)
 {
 {
-// For ELF shared libraries use a real parser to get the correct
-// soname.
-#if defined(CMake_USE_ELF_PARSER)
+  // For ELF shared libraries use a real parser to get the correct
+  // soname.
   cmELF elf(fullPath.c_str());
   cmELF elf(fullPath.c_str());
   if (elf) {
   if (elf) {
     return elf.GetSOName(soname);
     return elf.GetSOName(soname);
   }
   }
-#endif
 
 
   // If the file is not a symlink we have no guess for its soname.
   // If the file is not a symlink we have no guess for its soname.
   if (!cmSystemTools::FileIsSymlink(fullPath)) {
   if (!cmSystemTools::FileIsSymlink(fullPath)) {
@@ -2543,14 +2536,6 @@ cm::optional<bool> AdjustRPathELF(std::string const& file,
                                   const AdjustCallback& adjustCallback,
                                   const AdjustCallback& adjustCallback,
                                   std::string* emsg, bool* changed)
                                   std::string* emsg, bool* changed)
 {
 {
-#if !defined(CMake_USE_ELF_PARSER)
-  (void)file;
-  (void)emptyCallback;
-  (void)adjustCallback;
-  (void)emsg;
-  (void)changed;
-  return cm::nullopt; // Cannot handle ELF files.
-#else
   if (changed) {
   if (changed) {
     *changed = false;
     *changed = false;
   }
   }
@@ -2678,7 +2663,6 @@ cm::optional<bool> AdjustRPathELF(std::string const& file,
     *changed = true;
     *changed = true;
   }
   }
   return true;
   return true;
-#endif
 }
 }
 
 
 std::function<bool(std::string*, const cmELF&)> MakeEmptyCallback(
 std::function<bool(std::string*, const cmELF&)> MakeEmptyCallback(
@@ -2690,16 +2674,11 @@ std::function<bool(std::string*, const cmELF&)> MakeEmptyCallback(
       // okay.
       // okay.
       return true;
       return true;
     }
     }
-#if defined(CMake_USE_ELF_PARSER)
     if (emsg) {
     if (emsg) {
       *emsg =
       *emsg =
         cmStrCat("No valid ELF RPATH or RUNPATH entry exists in the file; ",
         cmStrCat("No valid ELF RPATH or RUNPATH entry exists in the file; ",
                  elf.GetErrorMessage());
                  elf.GetErrorMessage());
     }
     }
-#else
-    static_cast<void>(emsg);
-    static_cast<void>(elf);
-#endif
     return false;
     return false;
   };
   };
 }
 }
@@ -3033,12 +3012,6 @@ int cmSystemTools::strverscmp(std::string const& lhs, std::string const& rhs)
 static cm::optional<bool> RemoveRPathELF(std::string const& file,
 static cm::optional<bool> RemoveRPathELF(std::string const& file,
                                          std::string* emsg, bool* removed)
                                          std::string* emsg, bool* removed)
 {
 {
-#if !defined(CMake_USE_ELF_PARSER)
-  (void)file;
-  (void)emsg;
-  (void)removed;
-  return cm::nullopt; // Cannot handle ELF files.
-#else
   if (removed) {
   if (removed) {
     *removed = false;
     *removed = false;
   }
   }
@@ -3177,7 +3150,6 @@ static cm::optional<bool> RemoveRPathELF(std::string const& file,
     *removed = true;
     *removed = true;
   }
   }
   return true;
   return true;
-#endif
 }
 }
 
 
 static cm::optional<bool> RemoveRPathXCOFF(std::string const& file,
 static cm::optional<bool> RemoveRPathXCOFF(std::string const& file,
@@ -3224,7 +3196,6 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
 bool cmSystemTools::CheckRPath(std::string const& file,
 bool cmSystemTools::CheckRPath(std::string const& file,
                                std::string const& newRPath)
                                std::string const& newRPath)
 {
 {
-#if defined(CMake_USE_ELF_PARSER)
   // Parse the ELF binary.
   // Parse the ELF binary.
   cmELF elf(file.c_str());
   cmELF elf(file.c_str());
   if (elf) {
   if (elf) {
@@ -3247,7 +3218,6 @@ bool cmSystemTools::CheckRPath(std::string const& file,
     }
     }
     return false;
     return false;
   }
   }
-#endif
 #if defined(CMake_USE_XCOFF_PARSER)
 #if defined(CMake_USE_XCOFF_PARSER)
   // Parse the XCOFF binary.
   // Parse the XCOFF binary.
   cmXCOFF xcoff(file.c_str());
   cmXCOFF xcoff(file.c_str());

+ 1 - 3
Tests/RunCMake/CMakeLists.txt

@@ -377,9 +377,7 @@ add_RunCMake_test(ctest_upload)
 add_RunCMake_test(ctest_fixtures)
 add_RunCMake_test(ctest_fixtures)
 add_RunCMake_test(file -DMSYS=${MSYS})
 add_RunCMake_test(file -DMSYS=${MSYS})
 add_RunCMake_test(file-CHMOD -DMSYS=${MSYS})
 add_RunCMake_test(file-CHMOD -DMSYS=${MSYS})
-if(CMake_USE_ELF_PARSER)
-  add_RunCMake_test(file-RPATH -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCMake_USE_ELF_PARSER=${CMake_USE_ELF_PARSER})
-endif()
+add_RunCMake_test(file-RPATH -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
 add_RunCMake_test(find_file)
 add_RunCMake_test(find_file)
 add_RunCMake_test(find_library -DCYGWIN=${CYGWIN} -DMSYS=${MSYS})
 add_RunCMake_test(find_library -DCYGWIN=${CYGWIN} -DMSYS=${MSYS})
 add_RunCMake_test(find_package -DMSYS=${MSYS})
 add_RunCMake_test(find_package -DMSYS=${MSYS})

+ 1 - 3
Tests/RunCMake/file-RPATH/RunCMakeTest.cmake

@@ -1,8 +1,6 @@
 include(RunCMake)
 include(RunCMake)
 
 
-if(CMake_USE_ELF_PARSER)
-  run_cmake_command(ELF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ELF.cmake)
-endif()
+run_cmake_command(ELF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ELF.cmake)
 
 
 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
   run_cmake_command(XCOFF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/XCOFF.cmake)
   run_cmake_command(XCOFF ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/XCOFF.cmake)

+ 1 - 0
bootstrap

@@ -324,6 +324,7 @@ CMAKE_CXX_SOURCES="\
   cmDefinePropertyCommand \
   cmDefinePropertyCommand \
   cmDefinitions \
   cmDefinitions \
   cmDocumentationFormatter \
   cmDocumentationFormatter \
+  cmELF \
   cmEnableLanguageCommand \
   cmEnableLanguageCommand \
   cmEnableTestingCommand \
   cmEnableTestingCommand \
   cmExecProgramCommand \
   cmExecProgramCommand \