emul_aix.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Binutils emulation layer.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Written by Tom Rix, Red Hat Inc.
  4. This file is part of GNU Binutils.
  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 "binemul.h"
  18. #include "bfdlink.h"
  19. #include "coff/internal.h"
  20. #include "coff/xcoff.h"
  21. #include "libcoff.h"
  22. #include "libxcoff.h"
  23. /* Default to <bigaf>. */
  24. /* FIXME: write only variable. */
  25. static bool big_archive = true;
  26. /* Whether to include 32 bit objects. */
  27. static bool X32 = true;
  28. /* Whether to include 64 bit objects. */
  29. static bool X64 = false;
  30. static void
  31. ar_emul_aix_usage (FILE *fp)
  32. {
  33. AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
  34. /* xgettext:c-format */
  35. fprintf (fp, _(" [-g] - 32 bit small archive\n"));
  36. fprintf (fp, _(" [-X32] - ignores 64 bit objects\n"));
  37. fprintf (fp, _(" [-X64] - ignores 32 bit objects\n"));
  38. fprintf (fp, _(" [-X32_64] - accepts 32 and 64 bit objects\n"));
  39. }
  40. static bool
  41. check_aix (bfd *try_bfd)
  42. {
  43. extern const bfd_target rs6000_xcoff_vec;
  44. extern const bfd_target rs6000_xcoff64_vec;
  45. extern const bfd_target rs6000_xcoff64_aix_vec;
  46. if (bfd_check_format (try_bfd, bfd_object))
  47. {
  48. if (!X32 && try_bfd->xvec == &rs6000_xcoff_vec)
  49. return false;
  50. if (!X64 && (try_bfd->xvec == &rs6000_xcoff64_vec
  51. || try_bfd->xvec == &rs6000_xcoff64_aix_vec))
  52. return false;
  53. }
  54. return true;
  55. }
  56. static bool
  57. ar_emul_aix_append (bfd **after_bfd, bfd *new_bfd,
  58. bool verbose, bool flatten)
  59. {
  60. return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, check_aix);
  61. }
  62. static bool
  63. ar_emul_aix_replace (bfd **after_bfd, bfd *new_bfd,
  64. bool verbose)
  65. {
  66. if (!check_aix (new_bfd))
  67. return false;
  68. AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, bfd_get_filename (new_bfd));
  69. new_bfd->archive_next = *after_bfd;
  70. *after_bfd = new_bfd;
  71. return true;
  72. }
  73. static bool
  74. ar_emul_aix_parse_arg (char *arg)
  75. {
  76. if (startswith (arg, "-X32_64"))
  77. {
  78. big_archive = true;
  79. X32 = true;
  80. X64 = true;
  81. }
  82. else if (startswith (arg, "-X32"))
  83. {
  84. big_archive = true;
  85. X32 = true;
  86. X64 = false;
  87. }
  88. else if (startswith (arg, "-X64"))
  89. {
  90. big_archive = true;
  91. X32 = false;
  92. X64 = true;
  93. }
  94. else if (startswith (arg, "-g"))
  95. {
  96. big_archive = false;
  97. X32 = true;
  98. X64 = false;
  99. }
  100. else
  101. return false;
  102. return true;
  103. }
  104. struct bin_emulation_xfer_struct bin_aix_emulation =
  105. {
  106. ar_emul_aix_usage,
  107. ar_emul_aix_append,
  108. ar_emul_aix_replace,
  109. ar_emul_aix_parse_arg,
  110. };