freebsd.h 3.0 KB

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