diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-06-17 13:18:13 +0100 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-24 10:57:51 -0400 |
commit | 0da1540aaa8d36145329572938aeec6c86fb1ee7 (patch) | |
tree | f3831b276a19a1c870af6420065f155df0d8cc22 /Source | |
parent | e21188df8bd08a5f306afc09bcb829d148b982d5 (diff) | |
download | cmake-0da1540aaa8d36145329572938aeec6c86fb1ee7.tar.gz |
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.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmELF.cxx | 15 | ||||
-rw-r--r-- | Source/cmELF.h | 3 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 3 |
3 files changed, 19 insertions, 2 deletions
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 01dc0b1d6e..d96644b5b1 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -145,6 +145,7 @@ public: virtual std::vector<char> 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 c479e2b951..5700a3817c 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 488e69c532..d6b82086d6 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -3102,8 +3102,7 @@ static cm::optional<bool> 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 |