emul_aix.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Binutils emulation layer.
  2. Copyright (C) 2002-2015 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 bfd_boolean big_archive = TRUE;
  26. /* Whether to include 32 bit objects. */
  27. static bfd_boolean X32 = TRUE;
  28. /* Whether to include 64 bit objects. */
  29. static bfd_boolean 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 bfd_boolean
  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 bfd_boolean
  57. ar_emul_aix_append (bfd **after_bfd, char *file_name, const char *target,
  58. bfd_boolean verbose, bfd_boolean flatten)
  59. {
  60. bfd *new_bfd;
  61. new_bfd = bfd_openr (file_name, target);
  62. AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
  63. return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, check_aix);
  64. }
  65. static bfd_boolean
  66. ar_emul_aix_replace (bfd **after_bfd, char *file_name, const char *target,
  67. bfd_boolean verbose)
  68. {
  69. bfd *new_bfd;
  70. new_bfd = bfd_openr (file_name, target);
  71. AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
  72. if (!check_aix (new_bfd))
  73. return FALSE;
  74. AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
  75. new_bfd->archive_next = *after_bfd;
  76. *after_bfd = new_bfd;
  77. return TRUE;
  78. }
  79. static bfd_boolean
  80. ar_emul_aix_parse_arg (char *arg)
  81. {
  82. if (CONST_STRNEQ (arg, "-X32_64"))
  83. {
  84. big_archive = TRUE;
  85. X32 = TRUE;
  86. X64 = TRUE;
  87. }
  88. else if (CONST_STRNEQ (arg, "-X32"))
  89. {
  90. big_archive = TRUE;
  91. X32 = TRUE;
  92. X64 = FALSE;
  93. }
  94. else if (CONST_STRNEQ (arg, "-X64"))
  95. {
  96. big_archive = TRUE;
  97. X32 = FALSE;
  98. X64 = TRUE;
  99. }
  100. else if (CONST_STRNEQ (arg, "-g"))
  101. {
  102. big_archive = FALSE;
  103. X32 = TRUE;
  104. X64 = FALSE;
  105. }
  106. else
  107. return FALSE;
  108. return TRUE;
  109. }
  110. struct bin_emulation_xfer_struct bin_aix_emulation =
  111. {
  112. ar_emul_aix_usage,
  113. ar_emul_aix_append,
  114. ar_emul_aix_replace,
  115. ar_emul_aix_parse_arg,
  116. };