Commit | Line | Data |
---|---|---|
eb1e0e80 | 1 | /* Binutils emulation layer. |
b34976b6 | 2 | Copyright 2002 Free Software Foundation, Inc. |
eb1e0e80 NC |
3 | Written by Tom Rix, Redhat. |
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 | |
9 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "binemul.h" | |
22 | #include "bfdlink.h" | |
23 | #include "coff/internal.h" | |
24 | #include "coff/xcoff.h" | |
25 | #include "libcoff.h" | |
26 | #include "libxcoff.h" | |
27 | ||
28 | /* Default to <bigaf>. */ | |
b34976b6 | 29 | static bfd_boolean big_archive = TRUE; |
eb1e0e80 NC |
30 | |
31 | /* Whether to include 32 bit objects. */ | |
b34976b6 | 32 | static bfd_boolean X32 = TRUE; |
eb1e0e80 NC |
33 | |
34 | /* Whether to include 64 bit objects. */ | |
b34976b6 AM |
35 | static bfd_boolean X64 = FALSE; |
36 | ||
37 | static void ar_emul_aix_usage | |
38 | PARAMS ((FILE *)); | |
39 | static bfd_boolean ar_emul_aix_append | |
40 | PARAMS ((bfd **, char *, bfd_boolean)); | |
41 | static bfd_boolean ar_emul_aix5_append | |
42 | PARAMS ((bfd **, char *, bfd_boolean)); | |
43 | static bfd_boolean ar_emul_aix_replace | |
44 | PARAMS ((bfd **, char *, bfd_boolean)); | |
45 | static bfd_boolean ar_emul_aix5_replace | |
46 | PARAMS ((bfd **, char *, bfd_boolean)); | |
47 | static bfd_boolean ar_emul_aix_parse_arg | |
48 | PARAMS ((char *)); | |
49 | static bfd_boolean ar_emul_aix_internal | |
50 | PARAMS ((bfd **, char *, bfd_boolean, const char *, bfd_boolean)); | |
eb1e0e80 NC |
51 | |
52 | static void | |
53 | ar_emul_aix_usage (fp) | |
54 | FILE *fp; | |
55 | { | |
56 | AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp); | |
57 | /* xgettext:c-format */ | |
58 | fprintf (fp, _(" [-g] - 32 bit small archive\n")); | |
59 | fprintf (fp, _(" [-X32] - ignores 64 bit objects\n")); | |
60 | fprintf (fp, _(" [-X64] - ignores 32 bit objects\n")); | |
61 | fprintf (fp, _(" [-X32_64] - accepts 32 and 64 bit objects\n")); | |
62 | } | |
63 | ||
b34976b6 | 64 | static bfd_boolean |
eb1e0e80 NC |
65 | ar_emul_aix_internal (after_bfd, file_name, verbose, target_name, is_append) |
66 | bfd **after_bfd; | |
67 | char *file_name; | |
b34976b6 | 68 | bfd_boolean verbose; |
eb1e0e80 | 69 | const char * target_name; |
b34976b6 | 70 | bfd_boolean is_append; |
eb1e0e80 NC |
71 | { |
72 | bfd *temp; | |
73 | bfd *try_bfd; | |
74 | ||
75 | temp = *after_bfd; | |
76 | ||
77 | /* Try 64 bit. */ | |
78 | try_bfd = bfd_openr (file_name, target_name); | |
79 | ||
80 | /* Failed or the object is possibly 32 bit. */ | |
81 | if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object)) | |
82 | try_bfd = bfd_openr (file_name, "aixcoff-rs6000"); | |
83 | ||
84 | AR_EMUL_ELEMENT_CHECK (try_bfd, file_name); | |
85 | ||
86 | if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64)) | |
b34976b6 | 87 | return FALSE; |
eb1e0e80 | 88 | |
26044998 | 89 | if (bfd_xcoff_is_xcoff32 (try_bfd) |
eb1e0e80 | 90 | && bfd_check_format (try_bfd, bfd_object) && (! X32)) |
b34976b6 | 91 | return FALSE; |
eb1e0e80 NC |
92 | |
93 | if (is_append) | |
94 | { | |
95 | AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name); | |
96 | } | |
97 | else | |
98 | { | |
99 | AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); | |
100 | } | |
101 | ||
102 | *after_bfd = try_bfd; | |
103 | (*after_bfd)->next = temp; | |
104 | ||
b34976b6 | 105 | return TRUE; |
eb1e0e80 NC |
106 | } |
107 | ||
108 | ||
b34976b6 | 109 | static bfd_boolean |
eb1e0e80 NC |
110 | ar_emul_aix_append (after_bfd, file_name, verbose) |
111 | bfd **after_bfd; | |
112 | char *file_name; | |
b34976b6 | 113 | bfd_boolean verbose; |
eb1e0e80 NC |
114 | { |
115 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 116 | "aixcoff64-rs6000", TRUE); |
eb1e0e80 NC |
117 | } |
118 | ||
b34976b6 | 119 | static bfd_boolean |
eb1e0e80 NC |
120 | ar_emul_aix5_append (after_bfd, file_name, verbose) |
121 | bfd **after_bfd; | |
122 | char *file_name; | |
b34976b6 | 123 | bfd_boolean verbose; |
eb1e0e80 NC |
124 | { |
125 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 126 | "aix5coff64-rs6000", TRUE); |
eb1e0e80 NC |
127 | } |
128 | ||
b34976b6 | 129 | static bfd_boolean |
eb1e0e80 NC |
130 | ar_emul_aix_replace (after_bfd, file_name, verbose) |
131 | bfd **after_bfd; | |
132 | char *file_name; | |
b34976b6 | 133 | bfd_boolean verbose; |
eb1e0e80 NC |
134 | { |
135 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 136 | "aixcoff64-rs6000", FALSE); |
eb1e0e80 NC |
137 | } |
138 | ||
b34976b6 | 139 | static bfd_boolean |
eb1e0e80 NC |
140 | ar_emul_aix5_replace (after_bfd, file_name, verbose) |
141 | bfd **after_bfd; | |
142 | char *file_name; | |
b34976b6 | 143 | bfd_boolean verbose; |
eb1e0e80 NC |
144 | { |
145 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
b34976b6 | 146 | "aix5coff64-rs6000", FALSE); |
eb1e0e80 NC |
147 | } |
148 | ||
b34976b6 | 149 | static bfd_boolean |
eb1e0e80 NC |
150 | ar_emul_aix_parse_arg (arg) |
151 | char *arg; | |
152 | { | |
153 | if (strncmp (arg, "-X32_64", 6) == 0) | |
154 | { | |
b34976b6 AM |
155 | big_archive = TRUE; |
156 | X32 = TRUE; | |
157 | X64 = TRUE; | |
eb1e0e80 NC |
158 | } |
159 | else if (strncmp (arg, "-X32", 3) == 0) | |
160 | { | |
b34976b6 AM |
161 | big_archive = TRUE; |
162 | X32 = TRUE; | |
163 | X64 = FALSE; | |
eb1e0e80 NC |
164 | } |
165 | else if (strncmp (arg, "-X64", 3) == 0) | |
166 | { | |
b34976b6 AM |
167 | big_archive = TRUE; |
168 | X32 = FALSE; | |
169 | X64 = TRUE; | |
eb1e0e80 NC |
170 | } |
171 | else if (strncmp (arg, "-g", 2) == 0) | |
172 | { | |
b34976b6 AM |
173 | big_archive = FALSE; |
174 | X32 = TRUE; | |
175 | X64 = FALSE; | |
eb1e0e80 NC |
176 | } |
177 | else | |
b34976b6 | 178 | return FALSE; |
eb1e0e80 | 179 | |
b34976b6 | 180 | return TRUE; |
eb1e0e80 NC |
181 | } |
182 | ||
26044998 | 183 | struct bin_emulation_xfer_struct bin_aix_emulation = |
eb1e0e80 NC |
184 | { |
185 | ar_emul_aix_usage, | |
186 | ar_emul_aix_append, | |
187 | ar_emul_aix_replace, | |
188 | ar_emul_default_create, | |
189 | ar_emul_aix_parse_arg, | |
190 | }; | |
191 | ||
26044998 | 192 | struct bin_emulation_xfer_struct bin_aix5_emulation = |
eb1e0e80 NC |
193 | { |
194 | ar_emul_aix_usage, | |
195 | ar_emul_aix5_append, | |
196 | ar_emul_aix5_replace, | |
197 | ar_emul_default_create, | |
198 | ar_emul_aix_parse_arg, | |
199 | }; |