]>
Commit | Line | Data |
---|---|---|
eb1e0e80 | 1 | /* Binutils emulation layer. |
c3de112b | 2 | Copyright 2002, 2003, 2006, 2007 Free Software Foundation, Inc. |
ad94be02 | 3 | Written by Tom Rix, Red Hat Inc. |
eb1e0e80 NC |
4 | |
5 | This file is part of GNU Binutils. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
32866df7 | 9 | the Free Software Foundation; either version 3 of the License, or |
eb1e0e80 NC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
32866df7 NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
eb1e0e80 NC |
21 | |
22 | #include "binemul.h" | |
23 | #include "bfdlink.h" | |
24 | #include "coff/internal.h" | |
25 | #include "coff/xcoff.h" | |
26 | #include "libcoff.h" | |
27 | #include "libxcoff.h" | |
28 | ||
29 | /* Default to <bigaf>. */ | |
b34976b6 | 30 | static bfd_boolean big_archive = TRUE; |
eb1e0e80 NC |
31 | |
32 | /* Whether to include 32 bit objects. */ | |
b34976b6 | 33 | static bfd_boolean X32 = TRUE; |
eb1e0e80 NC |
34 | |
35 | /* Whether to include 64 bit objects. */ | |
b34976b6 AM |
36 | static bfd_boolean X64 = FALSE; |
37 | ||
2da42df6 AJ |
38 | static void ar_emul_aix_usage (FILE *); |
39 | static bfd_boolean ar_emul_aix_append (bfd **, char *, bfd_boolean); | |
40 | static bfd_boolean ar_emul_aix5_append (bfd **, char *, bfd_boolean); | |
41 | static bfd_boolean ar_emul_aix_replace (bfd **, char *, bfd_boolean); | |
42 | static bfd_boolean ar_emul_aix5_replace (bfd **, char *, bfd_boolean); | |
43 | static bfd_boolean ar_emul_aix_parse_arg (char *); | |
b34976b6 | 44 | static bfd_boolean ar_emul_aix_internal |
2da42df6 | 45 | (bfd **, char *, bfd_boolean, const char *, bfd_boolean); |
eb1e0e80 NC |
46 | |
47 | static void | |
2da42df6 | 48 | ar_emul_aix_usage (FILE *fp) |
eb1e0e80 NC |
49 | { |
50 | AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp); | |
51 | /* xgettext:c-format */ | |
52 | fprintf (fp, _(" [-g] - 32 bit small archive\n")); | |
53 | fprintf (fp, _(" [-X32] - ignores 64 bit objects\n")); | |
54 | fprintf (fp, _(" [-X64] - ignores 32 bit objects\n")); | |
55 | fprintf (fp, _(" [-X32_64] - accepts 32 and 64 bit objects\n")); | |
56 | } | |
57 | ||
b34976b6 | 58 | static bfd_boolean |
2da42df6 AJ |
59 | ar_emul_aix_internal (bfd **after_bfd, char *file_name, bfd_boolean verbose, |
60 | const char * target_name, bfd_boolean is_append) | |
eb1e0e80 NC |
61 | { |
62 | bfd *temp; | |
63 | bfd *try_bfd; | |
64 | ||
65 | temp = *after_bfd; | |
66 | ||
67 | /* Try 64 bit. */ | |
68 | try_bfd = bfd_openr (file_name, target_name); | |
69 | ||
70 | /* Failed or the object is possibly 32 bit. */ | |
71 | if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object)) | |
72 | try_bfd = bfd_openr (file_name, "aixcoff-rs6000"); | |
73 | ||
74 | AR_EMUL_ELEMENT_CHECK (try_bfd, file_name); | |
75 | ||
76 | if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64)) | |
b34976b6 | 77 | return FALSE; |
eb1e0e80 | 78 | |
26044998 | 79 | if (bfd_xcoff_is_xcoff32 (try_bfd) |
eb1e0e80 | 80 | && bfd_check_format (try_bfd, bfd_object) && (! X32)) |
b34976b6 | 81 | return FALSE; |
eb1e0e80 NC |
82 | |
83 | if (is_append) | |
84 | { | |
85 | AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name); | |
86 | } | |
87 | else | |
88 | { | |
89 | AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); | |
90 | } | |
91 | ||
92 | *after_bfd = try_bfd; | |
c3de112b | 93 | (*after_bfd)->archive_next = temp; |
eb1e0e80 | 94 | |
b34976b6 | 95 | return TRUE; |
eb1e0e80 NC |
96 | } |
97 | ||
98 | ||
b34976b6 | 99 | static bfd_boolean |
2da42df6 | 100 | ar_emul_aix_append (bfd **after_bfd, char *file_name, bfd_boolean verbose) |
eb1e0e80 NC |
101 | { |
102 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 103 | "aixcoff64-rs6000", TRUE); |
eb1e0e80 NC |
104 | } |
105 | ||
b34976b6 | 106 | static bfd_boolean |
2da42df6 | 107 | ar_emul_aix5_append (bfd **after_bfd, char *file_name, bfd_boolean verbose) |
eb1e0e80 NC |
108 | { |
109 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 110 | "aix5coff64-rs6000", TRUE); |
eb1e0e80 NC |
111 | } |
112 | ||
b34976b6 | 113 | static bfd_boolean |
2da42df6 | 114 | ar_emul_aix_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose) |
eb1e0e80 NC |
115 | { |
116 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 117 | "aixcoff64-rs6000", FALSE); |
eb1e0e80 NC |
118 | } |
119 | ||
b34976b6 | 120 | static bfd_boolean |
2da42df6 | 121 | ar_emul_aix5_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose) |
eb1e0e80 NC |
122 | { |
123 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 124 | "aix5coff64-rs6000", FALSE); |
eb1e0e80 NC |
125 | } |
126 | ||
b34976b6 | 127 | static bfd_boolean |
2da42df6 | 128 | ar_emul_aix_parse_arg (char *arg) |
eb1e0e80 | 129 | { |
0112cd26 | 130 | if (CONST_STRNEQ (arg, "-X32_64")) |
eb1e0e80 | 131 | { |
b34976b6 AM |
132 | big_archive = TRUE; |
133 | X32 = TRUE; | |
134 | X64 = TRUE; | |
eb1e0e80 | 135 | } |
0112cd26 | 136 | else if (CONST_STRNEQ (arg, "-X32")) |
eb1e0e80 | 137 | { |
b34976b6 AM |
138 | big_archive = TRUE; |
139 | X32 = TRUE; | |
140 | X64 = FALSE; | |
eb1e0e80 | 141 | } |
0112cd26 | 142 | else if (CONST_STRNEQ (arg, "-X64")) |
eb1e0e80 | 143 | { |
b34976b6 AM |
144 | big_archive = TRUE; |
145 | X32 = FALSE; | |
146 | X64 = TRUE; | |
eb1e0e80 | 147 | } |
0112cd26 | 148 | else if (CONST_STRNEQ (arg, "-g")) |
eb1e0e80 | 149 | { |
b34976b6 AM |
150 | big_archive = FALSE; |
151 | X32 = TRUE; | |
152 | X64 = FALSE; | |
eb1e0e80 NC |
153 | } |
154 | else | |
b34976b6 | 155 | return FALSE; |
eb1e0e80 | 156 | |
b34976b6 | 157 | return TRUE; |
eb1e0e80 NC |
158 | } |
159 | ||
26044998 | 160 | struct bin_emulation_xfer_struct bin_aix_emulation = |
eb1e0e80 NC |
161 | { |
162 | ar_emul_aix_usage, | |
163 | ar_emul_aix_append, | |
164 | ar_emul_aix_replace, | |
eb1e0e80 NC |
165 | ar_emul_aix_parse_arg, |
166 | }; | |
167 | ||
26044998 | 168 | struct bin_emulation_xfer_struct bin_aix5_emulation = |
eb1e0e80 NC |
169 | { |
170 | ar_emul_aix_usage, | |
171 | ar_emul_aix5_append, | |
172 | ar_emul_aix5_replace, | |
eb1e0e80 NC |
173 | ar_emul_aix_parse_arg, |
174 | }; |