Commit | Line | Data |
---|---|---|
eb1e0e80 NC |
1 | /* Binutils emulation layer. |
2 | Copyright (C) 2002 Free Software Foundation, Inc. | |
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>. */ | |
29 | static boolean big_archive = true; | |
30 | ||
31 | /* Whether to include 32 bit objects. */ | |
32 | static boolean X32 = true; | |
33 | ||
34 | /* Whether to include 64 bit objects. */ | |
35 | static boolean X64 = false; | |
36 | ||
37 | static void ar_emul_aix_usage PARAMS ((FILE *)); | |
38 | static boolean ar_emul_aix_append PARAMS ((bfd **, char *, boolean)); | |
39 | static boolean ar_emul_aix5_append PARAMS ((bfd **, char *, boolean)); | |
40 | static boolean ar_emul_aix_replace PARAMS ((bfd **, char *, boolean)); | |
41 | static boolean ar_emul_aix5_replace PARAMS ((bfd **, char *, boolean)); | |
42 | static boolean ar_emul_aix_parse_arg PARAMS ((char *)); | |
43 | static boolean ar_emul_aix_internal PARAMS ((bfd **, char *, boolean, | |
44 | const char *, boolean)); | |
45 | ||
46 | static void | |
47 | ar_emul_aix_usage (fp) | |
48 | FILE *fp; | |
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 | ||
58 | static boolean | |
59 | ar_emul_aix_internal (after_bfd, file_name, verbose, target_name, is_append) | |
60 | bfd **after_bfd; | |
61 | char *file_name; | |
62 | boolean verbose; | |
63 | const char * target_name; | |
64 | boolean is_append; | |
65 | { | |
66 | bfd *temp; | |
67 | bfd *try_bfd; | |
68 | ||
69 | temp = *after_bfd; | |
70 | ||
71 | /* Try 64 bit. */ | |
72 | try_bfd = bfd_openr (file_name, target_name); | |
73 | ||
74 | /* Failed or the object is possibly 32 bit. */ | |
75 | if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object)) | |
76 | try_bfd = bfd_openr (file_name, "aixcoff-rs6000"); | |
77 | ||
78 | AR_EMUL_ELEMENT_CHECK (try_bfd, file_name); | |
79 | ||
80 | if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64)) | |
81 | return false; | |
82 | ||
26044998 | 83 | if (bfd_xcoff_is_xcoff32 (try_bfd) |
eb1e0e80 NC |
84 | && bfd_check_format (try_bfd, bfd_object) && (! X32)) |
85 | return false; | |
86 | ||
87 | if (is_append) | |
88 | { | |
89 | AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name); | |
90 | } | |
91 | else | |
92 | { | |
93 | AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); | |
94 | } | |
95 | ||
96 | *after_bfd = try_bfd; | |
97 | (*after_bfd)->next = temp; | |
98 | ||
99 | return true; | |
100 | } | |
101 | ||
102 | ||
103 | static boolean | |
104 | ar_emul_aix_append (after_bfd, file_name, verbose) | |
105 | bfd **after_bfd; | |
106 | char *file_name; | |
107 | boolean verbose; | |
108 | { | |
109 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
110 | "aixcoff64-rs6000", true); | |
111 | } | |
112 | ||
113 | static boolean | |
114 | ar_emul_aix5_append (after_bfd, file_name, verbose) | |
115 | bfd **after_bfd; | |
116 | char *file_name; | |
117 | boolean verbose; | |
118 | { | |
119 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
120 | "aix5coff64-rs6000", true); | |
121 | } | |
122 | ||
123 | static boolean | |
124 | ar_emul_aix_replace (after_bfd, file_name, verbose) | |
125 | bfd **after_bfd; | |
126 | char *file_name; | |
127 | boolean verbose; | |
128 | { | |
129 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
130 | "aixcoff64-rs6000", false); | |
131 | } | |
132 | ||
133 | static boolean | |
134 | ar_emul_aix5_replace (after_bfd, file_name, verbose) | |
135 | bfd **after_bfd; | |
136 | char *file_name; | |
137 | boolean verbose; | |
138 | { | |
139 | return ar_emul_aix_internal (after_bfd, file_name, verbose, | |
140 | "aix5coff64-rs6000", false); | |
141 | } | |
142 | ||
26044998 | 143 | boolean |
eb1e0e80 NC |
144 | ar_emul_aix_create (abfd_out, archive_file_name, file_name) |
145 | bfd **abfd_out; | |
146 | char *archive_file_name; | |
147 | char *file_name ATTRIBUTE_UNUSED; | |
148 | { | |
149 | char *target = "aixcoff-rs6000"; | |
150 | ||
151 | /* Create an empty archive. */ | |
152 | *abfd_out = bfd_openw (archive_file_name, target); | |
153 | ||
154 | if (*abfd_out == NULL) | |
155 | bfd_fatal (archive_file_name); | |
156 | ||
157 | /* set to small or big format. */ | |
158 | /* not done. */ | |
159 | return true; | |
160 | } | |
161 | ||
162 | static boolean | |
163 | ar_emul_aix_parse_arg (arg) | |
164 | char *arg; | |
165 | { | |
166 | if (strncmp (arg, "-X32_64", 6) == 0) | |
167 | { | |
168 | big_archive = true; | |
169 | X32 = true; | |
170 | X64 = true; | |
171 | } | |
172 | else if (strncmp (arg, "-X32", 3) == 0) | |
173 | { | |
174 | big_archive = true; | |
175 | X32 = true; | |
176 | X64 = false; | |
177 | } | |
178 | else if (strncmp (arg, "-X64", 3) == 0) | |
179 | { | |
180 | big_archive = true; | |
181 | X32 = false; | |
182 | X64 = true; | |
183 | } | |
184 | else if (strncmp (arg, "-g", 2) == 0) | |
185 | { | |
186 | big_archive = false; | |
187 | X32 = true; | |
188 | X64 = false; | |
189 | } | |
190 | else | |
191 | return false; | |
192 | ||
193 | return true; | |
194 | } | |
195 | ||
26044998 | 196 | struct bin_emulation_xfer_struct bin_aix_emulation = |
eb1e0e80 NC |
197 | { |
198 | ar_emul_aix_usage, | |
199 | ar_emul_aix_append, | |
200 | ar_emul_aix_replace, | |
201 | ar_emul_default_create, | |
202 | ar_emul_aix_parse_arg, | |
203 | }; | |
204 | ||
26044998 | 205 | struct bin_emulation_xfer_struct bin_aix5_emulation = |
eb1e0e80 NC |
206 | { |
207 | ar_emul_aix_usage, | |
208 | ar_emul_aix5_append, | |
209 | ar_emul_aix5_replace, | |
210 | ar_emul_default_create, | |
211 | ar_emul_aix_parse_arg, | |
212 | }; |