From 200b2bb9e8930d9d47fa5f378cf595328ee9c9bc Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 28 Jun 2011 22:25:14 +0000 Subject: * target.h (class Target): Add osabi_ field. (Target::osabi): New function. (Target::set_osabi): New function. (Target::Target): Initialize osabi_. (Target::do_adjust_elf_header): Make pure virtual. (Sized_target::do_adjust_elf_header): Declare. * target.cc (Sized_target::do_adjust_elf_header): New function. (class Sized_target): Instantiate all versions. * freebsd.h (class Target_freebsd): Remove. (Target_selector_freebsd::do_recognize): Call set_osabi on Target. (Target_selector_freebsd::do_recognize_by_name): Likewise. (Target_selector_freebsd::set_osabi): Remove. * i386.cc (class Target_i386): Inherit from Sized_target rather than Target_freebsd. * x86_64.cc (class Target_x86_64): Likewise. --- gold/freebsd.h | 87 ++++------------------------------------------------------ 1 file changed, 5 insertions(+), 82 deletions(-) (limited to 'gold/freebsd.h') diff --git a/gold/freebsd.h b/gold/freebsd.h index de69735..bb86432 100644 --- a/gold/freebsd.h +++ b/gold/freebsd.h @@ -1,6 +1,6 @@ // freebsd.h -- FreeBSD support for gold -*- C++ -*- -// Copyright 2009 Free Software Foundation, Inc. +// Copyright 2009, 2011 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -30,59 +30,8 @@ namespace gold { // FreeBSD 4.1 and later wants the EI_OSABI field in the ELF header to -// be set to ELFOSABI_FREEBSD. This is a subclass of Sized_target -// which supports that. The real target would be a subclass of this -// one. We permit combining FreeBSD and non-FreeBSD object files. -// The effect of this target is to set the code in the output file. - -template -class Target_freebsd : public Sized_target -{ - public: - // Set the value to use for the EI_OSABI field in the ELF header. - void - set_osabi(elfcpp::ELFOSABI osabi) - { this->osabi_ = osabi; } - - protected: - Target_freebsd(const Target::Target_info* pti) - : Sized_target(pti), - osabi_(elfcpp::ELFOSABI_NONE) - { } - - virtual void - do_adjust_elf_header(unsigned char* view, int len) const; - - private: - // Value to store in the EI_OSABI field of the ELF file header. - elfcpp::ELFOSABI osabi_; -}; - -// Adjust the ELF file header by storing the requested value in the -// OSABI field. This is for FreeBSD support. - -template -inline void -Target_freebsd::do_adjust_elf_header(unsigned char* view, - int len) const -{ - if (this->osabi_ != elfcpp::ELFOSABI_NONE) - { - gold_assert(len == elfcpp::Elf_sizes::ehdr_size); - - elfcpp::Ehdr ehdr(view); - unsigned char e_ident[elfcpp::EI_NIDENT]; - memcpy(e_ident, ehdr.get_e_ident(), elfcpp::EI_NIDENT); - - e_ident[elfcpp::EI_OSABI] = this->osabi_; - - elfcpp::Ehdr_write oehdr(view); - oehdr.put_e_ident(e_ident); - } -} - -// A target selector for targets which permit combining both FreeBSD -// and non-FreeBSD object files. +// be set to ELFOSABI_FREEBSD. This is a target selector for targets +// which permit combining both FreeBSD and non-FreeBSD object files. class Target_selector_freebsd : public Target_selector { @@ -102,7 +51,7 @@ class Target_selector_freebsd : public Target_selector { Target* ret = this->instantiate_target(); if (osabi == elfcpp::ELFOSABI_FREEBSD) - this->set_osabi(ret); + ret->set_osabi(static_cast(osabi)); return ret; } @@ -115,7 +64,7 @@ class Target_selector_freebsd : public Target_selector else if (strcmp(name, this->freebsd_bfd_name_) == 0) { Target* ret = this->instantiate_target(); - this->set_osabi(ret); + ret->set_osabi(elfcpp::ELFOSABI_FREEBSD); return ret; } else @@ -131,32 +80,6 @@ class Target_selector_freebsd : public Target_selector } private: - // Set the OSABI field. This is quite ugly. - void - set_osabi(Target* target) - { - if (this->get_size() == 32) - { - if (this->is_big_endian()) - static_cast*>(target)-> - set_osabi(elfcpp::ELFOSABI_FREEBSD); - else - static_cast*>(target)-> - set_osabi(elfcpp::ELFOSABI_FREEBSD); - } - else if (this->get_size() == 64) - { - if (this->is_big_endian()) - static_cast*>(target)-> - set_osabi(elfcpp::ELFOSABI_FREEBSD); - else - static_cast*>(target)-> - set_osabi(elfcpp::ELFOSABI_FREEBSD); - } - else - gold_unreachable(); - } - // The BFD name for the non-Freebsd target. const char* bfd_name_; // The BFD name for the Freebsd target. -- cgit v1.1