1*a9fa9459Szrj // freebsd.h -- FreeBSD support for gold    -*- C++ -*-
2*a9fa9459Szrj 
3*a9fa9459Szrj // Copyright (C) 2009-2016 Free Software Foundation, Inc.
4*a9fa9459Szrj // Written by Ian Lance Taylor <iant@google.com>.
5*a9fa9459Szrj 
6*a9fa9459Szrj // This file is part of gold.
7*a9fa9459Szrj 
8*a9fa9459Szrj // This program is free software; you can redistribute it and/or modify
9*a9fa9459Szrj // it under the terms of the GNU General Public License as published by
10*a9fa9459Szrj // the Free Software Foundation; either version 3 of the License, or
11*a9fa9459Szrj // (at your option) any later version.
12*a9fa9459Szrj 
13*a9fa9459Szrj // This program is distributed in the hope that it will be useful,
14*a9fa9459Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a9fa9459Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*a9fa9459Szrj // GNU General Public License for more details.
17*a9fa9459Szrj 
18*a9fa9459Szrj // You should have received a copy of the GNU General Public License
19*a9fa9459Szrj // along with this program; if not, write to the Free Software
20*a9fa9459Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21*a9fa9459Szrj // MA 02110-1301, USA.
22*a9fa9459Szrj 
23*a9fa9459Szrj #include "target.h"
24*a9fa9459Szrj #include "target-select.h"
25*a9fa9459Szrj 
26*a9fa9459Szrj #ifndef GOLD_FREEBSD_H
27*a9fa9459Szrj #define GOLD_FREEBSD_H
28*a9fa9459Szrj 
29*a9fa9459Szrj namespace gold
30*a9fa9459Szrj {
31*a9fa9459Szrj 
32*a9fa9459Szrj // FreeBSD 4.1 and later wants the EI_OSABI field in the ELF header to
33*a9fa9459Szrj // be set to ELFOSABI_FREEBSD.  This is a target selector for targets
34*a9fa9459Szrj // which permit combining both FreeBSD and non-FreeBSD object files.
35*a9fa9459Szrj 
36*a9fa9459Szrj class Target_selector_freebsd : public Target_selector
37*a9fa9459Szrj {
38*a9fa9459Szrj  public:
Target_selector_freebsd(int machine,int size,bool is_big_endian,const char * bfd_name,const char * freebsd_bfd_name,const char * emulation)39*a9fa9459Szrj   Target_selector_freebsd(int machine, int size, bool is_big_endian,
40*a9fa9459Szrj 			  const char* bfd_name,
41*a9fa9459Szrj 			  const char* freebsd_bfd_name,
42*a9fa9459Szrj 			  const char* emulation)
43*a9fa9459Szrj     : Target_selector(machine, size, is_big_endian, NULL, emulation),
44*a9fa9459Szrj       bfd_name_(bfd_name), freebsd_bfd_name_(freebsd_bfd_name)
45*a9fa9459Szrj   { }
46*a9fa9459Szrj 
47*a9fa9459Szrj  protected:
48*a9fa9459Szrj   // If we see a FreeBSD input file, mark the output file as using
49*a9fa9459Szrj   // FreeBSD.
50*a9fa9459Szrj   virtual Target*
do_recognize(Input_file *,off_t,int,int osabi,int)51*a9fa9459Szrj   do_recognize(Input_file*, off_t, int, int osabi, int)
52*a9fa9459Szrj   {
53*a9fa9459Szrj     Target* ret = this->instantiate_target();
54*a9fa9459Szrj     if (osabi == elfcpp::ELFOSABI_FREEBSD)
55*a9fa9459Szrj       ret->set_osabi(static_cast<elfcpp::ELFOSABI>(osabi));
56*a9fa9459Szrj     return ret;
57*a9fa9459Szrj   }
58*a9fa9459Szrj 
59*a9fa9459Szrj   // Recognize two names.
60*a9fa9459Szrj   virtual Target*
do_recognize_by_bfd_name(const char * name)61*a9fa9459Szrj   do_recognize_by_bfd_name(const char* name)
62*a9fa9459Szrj   {
63*a9fa9459Szrj     if (strcmp(name, this->bfd_name_) == 0)
64*a9fa9459Szrj       return this->instantiate_target();
65*a9fa9459Szrj     else if (strcmp(name, this->freebsd_bfd_name_) == 0)
66*a9fa9459Szrj       {
67*a9fa9459Szrj 	Target* ret = this->instantiate_target();
68*a9fa9459Szrj 	ret->set_osabi(elfcpp::ELFOSABI_FREEBSD);
69*a9fa9459Szrj 	return ret;
70*a9fa9459Szrj       }
71*a9fa9459Szrj     else
72*a9fa9459Szrj       return NULL;
73*a9fa9459Szrj   }
74*a9fa9459Szrj 
75*a9fa9459Szrj   // Print both names in --help output.
76*a9fa9459Szrj   virtual void
do_supported_bfd_names(std::vector<const char * > * names)77*a9fa9459Szrj   do_supported_bfd_names(std::vector<const char*>* names)
78*a9fa9459Szrj   {
79*a9fa9459Szrj     names->push_back(this->bfd_name_);
80*a9fa9459Szrj     names->push_back(this->freebsd_bfd_name_);
81*a9fa9459Szrj   }
82*a9fa9459Szrj 
83*a9fa9459Szrj   // Return appropriate BFD name.
84*a9fa9459Szrj   virtual const char*
do_target_bfd_name(const Target * target)85*a9fa9459Szrj   do_target_bfd_name(const Target* target)
86*a9fa9459Szrj   {
87*a9fa9459Szrj     if (!this->is_our_target(target))
88*a9fa9459Szrj       return NULL;
89*a9fa9459Szrj     return (target->osabi() == elfcpp::ELFOSABI_FREEBSD
90*a9fa9459Szrj 	    ? this->freebsd_bfd_name_
91*a9fa9459Szrj 	    : this->bfd_name_);
92*a9fa9459Szrj   }
93*a9fa9459Szrj 
94*a9fa9459Szrj  private:
95*a9fa9459Szrj   // The BFD name for the non-Freebsd target.
96*a9fa9459Szrj   const char* bfd_name_;
97*a9fa9459Szrj   // The BFD name for the Freebsd target.
98*a9fa9459Szrj   const char* freebsd_bfd_name_;
99*a9fa9459Szrj };
100*a9fa9459Szrj 
101*a9fa9459Szrj } // end namespace gold
102*a9fa9459Szrj 
103*a9fa9459Szrj #endif // !defined(GOLD_FREEBSD_H)
104