From 2b2d74f4a135e69fa2e0b68dd273212a4db88f81 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Tue, 15 Dec 2020 14:37:22 -0800 Subject: Cosmetic improvements for OSABI access. Add accessor methods to elfcpp::Ehdr class for EI_OSABI and EI_ABIVERSION; use those to simplify initialization of Osabi class and eliminate the need to template the class. elfcpp/ * elfcpp.h (class Ehdr): Add get_ei_osabi and get_ei_abiversion methods. gold/ * dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and get_ei_abiversion methods. * incremental.cc (make_sized_incremental_binary): Likewise. * object.cc (Sized_relobj_file::Sized_relobj_file): Likewise. (make_elf_sized_object): Likewise. * object.h (class Osabi): Make the class untemplated. --- gold/ChangeLog | 9 +++++++++ gold/dwp.cc | 4 ++-- gold/incremental.cc | 4 ++-- gold/object.cc | 8 ++++---- gold/object.h | 10 ++++------ 5 files changed, 21 insertions(+), 14 deletions(-) (limited to 'gold') diff --git a/gold/ChangeLog b/gold/ChangeLog index 32decc6..77b1f88 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,12 @@ +2020-12-15 Cary Coutant + + * dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and + get_ei_abiversion methods. + * incremental.cc (make_sized_incremental_binary): Likewise. + * object.cc (Sized_relobj_file::Sized_relobj_file): Likewise. + (make_elf_sized_object): Likewise. + * object.h (class Osabi): Make the class untemplated. + 2020-12-15 Vivek Das Mohapatra Implement -z unique / -z nounique options. diff --git a/gold/dwp.cc b/gold/dwp.cc index 7c4eef0..aae1fe2 100644 --- a/gold/dwp.cc +++ b/gold/dwp.cc @@ -1107,8 +1107,8 @@ Dwo_file::sized_make_object(const unsigned char* p, Input_file* input_file, if (output_file != NULL) output_file->record_target_info( this->name_, ehdr.get_e_machine(), size, big_endian, - ehdr.get_e_ident()[elfcpp::EI_OSABI], - ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]); + ehdr.get_ei_osabi(), + ehdr.get_ei_abiversion()); return obj; } diff --git a/gold/incremental.cc b/gold/incremental.cc index 8d0df2d..1f2ae5b 100644 --- a/gold/incremental.cc +++ b/gold/incremental.cc @@ -856,8 +856,8 @@ make_sized_incremental_binary(Output_file* file, { Target* target = select_target(NULL, 0, // XXX ehdr.get_e_machine(), size, big_endian, - ehdr.get_e_ident()[elfcpp::EI_OSABI], - ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]); + ehdr.get_ei_osabi(), + ehdr.get_ei_abiversion()); if (target == NULL) { explain_no_incremental(_("unsupported ELF machine number %d"), diff --git a/gold/object.cc b/gold/object.cc index 072563b..0edaf47 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -464,7 +464,8 @@ Sized_relobj_file::Sized_relobj_file( const elfcpp::Ehdr& ehdr) : Sized_relobj(name, input_file, offset), elf_file_(this, ehdr), - osabi_(ehdr), + osabi_(ehdr.get_ei_osabi()), + e_type_(ehdr.get_e_type()), symtab_shndx_(-1U), local_symbol_count_(0), output_local_symbol_count_(0), @@ -482,7 +483,6 @@ Sized_relobj_file::Sized_relobj_file( deferred_layout_relocs_(), output_views_(NULL) { - this->e_type_ = ehdr.get_e_type(); } template @@ -3387,8 +3387,8 @@ make_elf_sized_object(const std::string& name, Input_file* input_file, { Target* target = select_target(input_file, offset, ehdr.get_e_machine(), size, big_endian, - ehdr.get_e_ident()[elfcpp::EI_OSABI], - ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]); + ehdr.get_ei_osabi(), + ehdr.get_ei_abiversion()); if (target == NULL) gold_fatal(_("%s: unsupported ELF machine number %d"), name.c_str(), ehdr.get_e_machine()); diff --git a/gold/object.h b/gold/object.h index 4afee99..1ab98ce 100644 --- a/gold/object.h +++ b/gold/object.h @@ -386,13 +386,11 @@ build_compressed_section_map(const unsigned char* pshdrs, unsigned int shnum, // Osabi represents the EI_OSABI field from the ELF header. -template class Osabi { public: - Osabi(const elfcpp::Ehdr& ehdr) - : ei_osabi_(static_cast( - ehdr.get_e_ident()[elfcpp::EI_OSABI])) + Osabi(unsigned char ei_osabi) + : ei_osabi_(static_cast(ei_osabi)) { } bool @@ -2249,7 +2247,7 @@ class Sized_relobj_file : public Sized_relobj { return this->e_type_; } // Return the EI_OSABI. - const Osabi& + const Osabi& osabi() const { return this->osabi_; } @@ -2894,7 +2892,7 @@ class Sized_relobj_file : public Sized_relobj // General access to the ELF file. elfcpp::Elf_file elf_file_; // The EI_OSABI. - const Osabi osabi_; + const Osabi 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_; -- cgit v1.1