Back to index

cell-binutils  2.17cvs20070401
emul_aix.c
Go to the documentation of this file.
00001 /* Binutils emulation layer.
00002    Copyright 2002, 2003, 2006 Free Software Foundation, Inc.
00003    Written by Tom Rix, Red Hat Inc.
00004 
00005    This file is part of GNU Binutils.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #include "binemul.h"
00022 #include "bfdlink.h"
00023 #include "coff/internal.h"
00024 #include "coff/xcoff.h"
00025 #include "libcoff.h"
00026 #include "libxcoff.h"
00027 
00028 /* Default to <bigaf>.  */
00029 static bfd_boolean big_archive = TRUE;
00030 
00031 /* Whether to include 32 bit objects.  */
00032 static bfd_boolean X32 = TRUE;
00033 
00034 /* Whether to include 64 bit objects.  */
00035 static bfd_boolean X64 = FALSE;
00036 
00037 static void ar_emul_aix_usage (FILE *);
00038 static bfd_boolean ar_emul_aix_append (bfd **, char *, bfd_boolean);
00039 static bfd_boolean ar_emul_aix5_append (bfd **, char *, bfd_boolean);
00040 static bfd_boolean ar_emul_aix_replace (bfd **, char *, bfd_boolean);
00041 static bfd_boolean ar_emul_aix5_replace (bfd **, char *, bfd_boolean);
00042 static bfd_boolean ar_emul_aix_parse_arg (char *);
00043 static bfd_boolean ar_emul_aix_internal
00044   (bfd **, char *, bfd_boolean, const char *, bfd_boolean);
00045 
00046 static void
00047 ar_emul_aix_usage (FILE *fp)
00048 {
00049   AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
00050   /* xgettext:c-format */
00051   fprintf (fp, _("  [-g]         - 32 bit small archive\n"));
00052   fprintf (fp, _("  [-X32]       - ignores 64 bit objects\n"));
00053   fprintf (fp, _("  [-X64]       - ignores 32 bit objects\n"));
00054   fprintf (fp, _("  [-X32_64]    - accepts 32 and 64 bit objects\n"));
00055 }
00056 
00057 static bfd_boolean
00058 ar_emul_aix_internal (bfd **after_bfd, char *file_name, bfd_boolean verbose,
00059                     const char * target_name, bfd_boolean is_append)
00060 {
00061   bfd *temp;
00062   bfd *try_bfd;
00063 
00064   temp = *after_bfd;
00065 
00066   /* Try 64 bit.  */
00067   try_bfd = bfd_openr (file_name, target_name);
00068 
00069   /* Failed or the object is possibly 32 bit.  */
00070   if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object))
00071     try_bfd = bfd_openr (file_name, "aixcoff-rs6000");
00072 
00073   AR_EMUL_ELEMENT_CHECK (try_bfd, file_name);
00074 
00075   if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64))
00076     return FALSE;
00077 
00078   if (bfd_xcoff_is_xcoff32 (try_bfd)
00079       && bfd_check_format (try_bfd, bfd_object) && (! X32))
00080     return FALSE;
00081 
00082   if (is_append)
00083     {
00084       AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name);
00085     }
00086   else
00087     {
00088       AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
00089     }
00090 
00091   *after_bfd = try_bfd;
00092   (*after_bfd)->next = temp;
00093 
00094   return TRUE;
00095 }
00096 
00097 
00098 static bfd_boolean
00099 ar_emul_aix_append (bfd **after_bfd, char *file_name, bfd_boolean verbose)
00100 {
00101   return ar_emul_aix_internal (after_bfd, file_name, verbose,
00102                             "aixcoff64-rs6000", TRUE);
00103 }
00104 
00105 static bfd_boolean
00106 ar_emul_aix5_append (bfd **after_bfd, char *file_name, bfd_boolean verbose)
00107 {
00108   return ar_emul_aix_internal (after_bfd, file_name, verbose,
00109                             "aix5coff64-rs6000", TRUE);
00110 }
00111 
00112 static bfd_boolean
00113 ar_emul_aix_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose)
00114 {
00115   return ar_emul_aix_internal (after_bfd, file_name, verbose,
00116                             "aixcoff64-rs6000", FALSE);
00117 }
00118 
00119 static bfd_boolean
00120 ar_emul_aix5_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose)
00121 {
00122   return ar_emul_aix_internal (after_bfd, file_name, verbose,
00123                             "aix5coff64-rs6000", FALSE);
00124 }
00125 
00126 static bfd_boolean
00127 ar_emul_aix_parse_arg (char *arg)
00128 {
00129   if (CONST_STRNEQ (arg, "-X32_64"))
00130     {
00131       big_archive = TRUE;
00132       X32 = TRUE;
00133       X64 = TRUE;
00134     }
00135   else if (CONST_STRNEQ (arg, "-X32"))
00136     {
00137       big_archive = TRUE;
00138       X32 = TRUE;
00139       X64 = FALSE;
00140     }
00141   else if (CONST_STRNEQ (arg, "-X64"))
00142     {
00143       big_archive = TRUE;
00144       X32 = FALSE;
00145       X64 = TRUE;
00146     }
00147   else if (CONST_STRNEQ (arg, "-g"))
00148     {
00149       big_archive = FALSE;
00150       X32 = TRUE;
00151       X64 = FALSE;
00152     }
00153   else
00154     return FALSE;
00155 
00156   return TRUE;
00157 }
00158 
00159 struct bin_emulation_xfer_struct bin_aix_emulation =
00160 {
00161   ar_emul_aix_usage,
00162   ar_emul_aix_append,
00163   ar_emul_aix_replace,
00164   ar_emul_aix_parse_arg,
00165 };
00166 
00167 struct bin_emulation_xfer_struct bin_aix5_emulation =
00168 {
00169   ar_emul_aix_usage,
00170   ar_emul_aix5_append,
00171   ar_emul_aix5_replace,
00172   ar_emul_aix_parse_arg,
00173 };