From 0da1540aaa8d36145329572938aeec6c86fb1ee7 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 17 Jun 2021 13:18:13 +0100 Subject: cmELF: Fix check for TagMipsRldMapRel DT_MIPS_RLD_MAP_REL is a machine-speicific dynamic tag, so other architectures could re-use the value of 0x70000035 to mean something else. Before using DT_MIPS_RLD_MAP_REL, we have to check that the ELF file is actually has a e_machine of EM_MIPS. --- Source/cmELF.cxx | 15 +++++++++++++++ Source/cmELF.h | 3 +++ Source/cmSystemTools.cxx | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 01dc0b1..d96644b 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -145,6 +145,7 @@ public: virtual std::vector EncodeDynamicEntries( const cmELF::DynamicEntryList&) = 0; virtual StringEntry const* GetDynamicSectionString(unsigned int tag) = 0; + virtual bool IsMips() const = 0; virtual void PrintInfo(std::ostream& os) const = 0; // Lookup the SONAME in the DYNAMIC section. @@ -256,6 +257,12 @@ public: // Lookup a string from the dynamic section with the given tag. StringEntry const* GetDynamicSectionString(unsigned int tag) override; +#ifdef EM_MIPS + bool IsMips() const override { return this->ELFHeader.e_machine == EM_MIPS; } +#else + bool IsMips() const override { false; } +#endif + // Print information about the ELF file. void PrintInfo(std::ostream& os) const override { @@ -830,6 +837,14 @@ cmELF::StringEntry const* cmELF::GetRunPath() return nullptr; } +bool cmELF::IsMIPS() const +{ + if (this->Valid()) { + return this->Internal->IsMips(); + } + return false; +} + void cmELF::PrintInfo(std::ostream& os) const { if (this->Valid()) { diff --git a/Source/cmELF.h b/Source/cmELF.h index c479e2b..5700a38 100644 --- a/Source/cmELF.h +++ b/Source/cmELF.h @@ -98,6 +98,9 @@ public: /** Get the RUNPATH field if any. */ StringEntry const* GetRunPath(); + /** Returns true if the ELF file targets a MIPS CPU. */ + bool IsMIPS() const; + /** Print human-readable information about the ELF file. */ void PrintInfo(std::ostream& os) const; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 488e69c..d6b8208 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -3102,8 +3102,7 @@ static cm::optional RemoveRPathELF(std::string const& file, entriesErased++; continue; } - if (cmELF::TagMipsRldMapRel != 0 && - it->first == cmELF::TagMipsRldMapRel) { + if (it->first == cmELF::TagMipsRldMapRel && elf.IsMIPS()) { // 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 -- cgit v0.12