diff options
author | Cary Coutant <ccoutant@gmail.com> | 2020-12-14 15:46:47 -0800 |
---|---|---|
committer | Cary Coutant <ccoutant@gmail.com> | 2020-12-14 15:49:27 -0800 |
commit | ff4bc37d77a0ca7286883a477adcb3aa145fc782 (patch) | |
tree | f90757858598811f287e2100b14fa0299d39cdde /gold/object.h | |
parent | 8cd6d968de17f5dac1601d7cbdda838c9d82c822 (diff) | |
download | gdb-ff4bc37d77a0ca7286883a477adcb3aa145fc782.zip gdb-ff4bc37d77a0ca7286883a477adcb3aa145fc782.tar.gz gdb-ff4bc37d77a0ca7286883a477adcb3aa145fc782.tar.bz2 |
Keep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD ELFOSABIs.
2020-12-14 H.J. Lu <hjl.tools@gmail.com>
Cary Coutant <ccoutant@gmail.com>
elfcpp/
PR gold/27039
* elfcpp.h (SHF): Add SHF_GNU_RETAIN.
gold/
PR gold/27039
* layout.cc (Layout::layout): Strip SHF_GNU_RETAIN.
* object.cc (Sized_relobj_file::Sized_relobj_file): Initialize osabi_.
(Sized_relobj_file::do_layout): Keep SHF_GNU_RETAIN sections for
GNU/FreBSD ELFOSABIs.
* object.h (Osabi) New class.
(Sized_relobj_file): Add osabi() and osabi_.
* testsuite/Makefile.am (check_SCRIPTS): Add retain.sh.
(check_DATA): Add retain_1.out retain_2.out.
(MOSTLYCLEANFILES): Add retain_1 retain_2.
(retain_1.out): New target.
(retain_1): Likewise.
(retain_1.o): Likewise.
(retain_2.out): Likewise.
(retain_2): Likewise.
(retain_2.o): Likewise.
* testsuite/Makefile.in: Regenerate.
* testsuite/retain.sh: New file.
* testsuite/retain_1.s: Likewise.
* testsuite/retain_2.s: Likewise.
Diffstat (limited to 'gold/object.h')
-rw-r--r-- | gold/object.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gold/object.h b/gold/object.h index b7bd38f..4afee99 100644 --- a/gold/object.h +++ b/gold/object.h @@ -384,6 +384,49 @@ build_compressed_section_map(const unsigned char* pshdrs, unsigned int shnum, const char* names, section_size_type names_size, Object* obj, bool decompress_if_needed); +// Osabi represents the EI_OSABI field from the ELF header. + +template <int size, bool big_endian> +class Osabi +{ + public: + Osabi(const elfcpp::Ehdr<size, big_endian>& ehdr) + : ei_osabi_(static_cast<elfcpp::ELFOSABI>( + ehdr.get_e_ident()[elfcpp::EI_OSABI])) + { } + + bool + has_shf_retain(elfcpp::Elf_Xword sh_flags) const + { + switch (this->ei_osabi_) + { + case elfcpp::ELFOSABI_GNU: + case elfcpp::ELFOSABI_FREEBSD: + return (sh_flags & elfcpp::SHF_GNU_RETAIN) != 0; + default: + break; + } + return false; + } + + elfcpp::Elf_Xword + ignored_sh_flags() const + { + switch (this->ei_osabi_) + { + case elfcpp::ELFOSABI_GNU: + case elfcpp::ELFOSABI_FREEBSD: + return elfcpp::SHF_GNU_RETAIN; + default: + break; + } + return 0; + } + + private: + elfcpp::ELFOSABI ei_osabi_; +}; + // Object is an abstract base class which represents either a 32-bit // or a 64-bit input object. This can be a regular object file // (ET_REL) or a shared object (ET_DYN). @@ -2205,6 +2248,11 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian> e_type() const { return this->e_type_; } + // Return the EI_OSABI. + const Osabi<size, big_endian>& + osabi() const + { return this->osabi_; } + // Return the number of symbols. This is only valid after // Object::add_symbols has been called. unsigned int @@ -2845,6 +2893,8 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian> // General access to the ELF file. elfcpp::Elf_file<size, big_endian, Object> elf_file_; + // The EI_OSABI. + const Osabi<size, big_endian> osabi_; // Type of ELF file (ET_REL or ET_EXEC). ET_EXEC files are allowed // as input files only for the --just-symbols option. int e_type_; |