Add support for the ELF .interp section. Review: https://reviews.apache.org/r/56465/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/96f49919 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/96f49919 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/96f49919 Branch: refs/heads/master Commit: 96f49919325f383e4f7f557fe61a267ee808aefb Parents: c2388a5 Author: James Peach <jpe...@apache.org> Authored: Thu Feb 9 13:39:10 2017 -0800 Committer: Jiang Yan Xu <xuj...@apple.com> Committed: Thu Feb 9 13:40:51 2017 -0800 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/elf.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/96f49919/3rdparty/stout/include/stout/elf.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/elf.hpp b/3rdparty/stout/include/stout/elf.hpp index 2bf91a0..da2ce0c 100644 --- a/3rdparty/stout/include/stout/elf.hpp +++ b/3rdparty/stout/include/stout/elf.hpp @@ -46,6 +46,7 @@ enum class SectionType { DYNAMIC = SHT_DYNAMIC, NOTE = SHT_NOTE, + PROGBITS = SHT_PROGBITS, }; enum class DynamicTag @@ -150,7 +151,7 @@ public: } if (SectionType(section->get_type()) != SectionType::NOTE) { - return Error("Section '.note.ABI-tag' is not a NOTE"); + return Error("Section '.note.ABI-tag' is not a NOTE section"); } auto accessor = ELFIO::note_section_accessor(elf, section); @@ -197,6 +198,26 @@ public: return Version(version[1], version[2], version[3]); } + // Return the contents of the .interp section, if such a + // section exits. For Linux ELF executables, the .interp + // section contains the path to the program loader. + // + // https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/specialsections.html + Result<std::string> get_interpreter() const + { + ELFIO::section* section = elf.sections[".interp"]; + + if (section == nullptr) { + return None(); + } + + if (SectionType(section->get_type()) != SectionType::PROGBITS) { + return Error("Section '.interp' is not a PROGBITS section"); + } + + return std::string(section->get_data(), section->get_size()); + } + private: explicit File() {}