mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-03 05:08:47 -06:00
Merge topic 'file-rpath-elf-static'
02f3e5be6afile(RPATH_CHANGE ...): no-op for static binaryccbbf64552Tests/RunCMake/file-RPATH: Prepare to cover statically linked binaries Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !9623
This commit is contained in:
@@ -112,6 +112,9 @@ public:
|
||||
virtual bool IsMips() const = 0;
|
||||
virtual void PrintInfo(std::ostream& os) const = 0;
|
||||
|
||||
/** Returns true if the ELF file has a dynamic section **/
|
||||
bool HasDynamicSection() const { return this->DynamicSectionIndex >= 0; }
|
||||
|
||||
// Lookup the SONAME in the DYNAMIC section.
|
||||
StringEntry const* GetSOName()
|
||||
{
|
||||
@@ -461,7 +464,7 @@ template <class Types>
|
||||
bool cmELFInternalImpl<Types>::LoadDynamicSection()
|
||||
{
|
||||
// If there is no dynamic section we are done.
|
||||
if (this->DynamicSectionIndex < 0) {
|
||||
if (!this->HasDynamicSection()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -772,6 +775,11 @@ std::vector<char> cmELF::EncodeDynamicEntries(
|
||||
return std::vector<char>();
|
||||
}
|
||||
|
||||
bool cmELF::HasDynamicSection() const
|
||||
{
|
||||
return this->Valid() && this->Internal->HasDynamicSection();
|
||||
}
|
||||
|
||||
bool cmELF::GetSOName(std::string& soname)
|
||||
{
|
||||
if (StringEntry const* se = this->GetSOName()) {
|
||||
|
||||
@@ -88,6 +88,9 @@ public:
|
||||
std::vector<char> EncodeDynamicEntries(
|
||||
const DynamicEntryList& entries) const;
|
||||
|
||||
/** Returns true if the ELF file has a dynamic section **/
|
||||
bool HasDynamicSection() const;
|
||||
|
||||
/** Get the SONAME field if any. */
|
||||
bool GetSOName(std::string& soname);
|
||||
StringEntry const* GetSOName();
|
||||
|
||||
@@ -2817,6 +2817,10 @@ cm::optional<bool> AdjustRPathELF(std::string const& file,
|
||||
return cm::nullopt; // Not a valid ELF file.
|
||||
}
|
||||
|
||||
if (!elf.HasDynamicSection()) {
|
||||
return true; // No dynamic section to update.
|
||||
}
|
||||
|
||||
// Get the RPATH and RUNPATH entries from it.
|
||||
int se_count = 0;
|
||||
cmELF::StringEntry const* se[2] = { nullptr, nullptr };
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
# Prepare binaries on which to operate.
|
||||
set(in "${CMAKE_CURRENT_LIST_DIR}/${format}")
|
||||
set(out "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
foreach(f ${names})
|
||||
foreach(f ${dynamic})
|
||||
file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
|
||||
list(APPEND files "${out}/${f}")
|
||||
list(APPEND dynamic_files "${out}/${f}")
|
||||
endforeach()
|
||||
foreach(f ${static})
|
||||
file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
|
||||
list(APPEND static_files "${out}/${f}")
|
||||
endforeach()
|
||||
|
||||
foreach(f ${files})
|
||||
foreach(f ${dynamic_files})
|
||||
# Check for the initial RPATH.
|
||||
file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath")
|
||||
if(NOT EXISTS "${f}")
|
||||
@@ -65,11 +69,11 @@ endforeach()
|
||||
|
||||
# TODO Implement RPATH_SET in XCOFF.
|
||||
if(format STREQUAL "ELF")
|
||||
foreach(f ${names})
|
||||
foreach(f ${dynamic})
|
||||
file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
|
||||
endforeach()
|
||||
|
||||
foreach(f ${files})
|
||||
foreach(f ${dynamic_files})
|
||||
# Set the RPATH.
|
||||
file(RPATH_SET FILE "${f}"
|
||||
NEW_RPATH "/new/rpath")
|
||||
@@ -99,3 +103,8 @@ if(format STREQUAL "ELF")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Verify that modifying rpaths on a static library is a no-op
|
||||
foreach(f ${static_files})
|
||||
file(RPATH_CHANGE FILE "${f}" OLD_RPATH "/rpath/foo" NEW_RPATH "/rpath/bar")
|
||||
endforeach()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
set(names
|
||||
set(dynamic
|
||||
elf32lsb.bin
|
||||
elf32msb.bin
|
||||
elf64lsb.bin
|
||||
elf64msb.bin
|
||||
)
|
||||
set(static
|
||||
elf64lsb-static.bin
|
||||
)
|
||||
set(format ELF)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake)
|
||||
|
||||
BIN
Tests/RunCMake/file-RPATH/ELF/elf64lsb-static.bin
Executable file
BIN
Tests/RunCMake/file-RPATH/ELF/elf64lsb-static.bin
Executable file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
set(names
|
||||
set(dynamic
|
||||
xcoff32.bin
|
||||
xcoff64.bin
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user