1 /* Wrapper for ar/ranlib/nm to pass the LTO plugin.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
3 Contributed by Andi Kleen.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "libiberty.h"
26 #error "Please set personality"
29 static const char standard_libexec_prefix
[] = STANDARD_LIBEXEC_PREFIX
;
30 static const char standard_bin_prefix
[] = STANDARD_BINDIR_PREFIX
;
31 static const char *const target_machine
= TARGET_MACHINE
;
33 static const char dir_separator
[] = { DIR_SEPARATOR
, 0 };
36 main(int ac
, char **av
)
44 bool is_ar
= !strcmp (PERSONALITY
, "ar");
45 int exit_code
= FATAL_EXIT_CODE
;
47 exe_name
= PERSONALITY
;
48 #ifdef CROSS_DIRECTORY_STRUCTURE
49 exe_name
= concat (target_machine
, "-", exe_name
, NULL
);
53 /* XXX implement more magic from gcc.c? */
54 nprefix
= getenv ("GCC_EXEC_PREFIX");
58 nprefix
= concat (nprefix
, "gcc-" PERSONALITY
, NULL
);
60 nprefix
= make_relative_prefix (nprefix
,
62 standard_libexec_prefix
);
64 nprefix
= standard_libexec_prefix
;
66 plugin
= concat (nprefix
,
68 DEFAULT_TARGET_MACHINE
,
70 DEFAULT_TARGET_VERSION
,
74 if (access (plugin
, R_OK
))
76 fprintf (stderr
, "%s: Cannot find plugin %s\n", av
[0], plugin
);
80 /* Create new command line with plugin */
81 nargv
= XCNEWVEC (const char *, ac
+ 4);
83 nargv
[1] = "--plugin";
85 if (is_ar
&& av
[1] && av
[1][0] != '-')
86 av
[1] = concat("-", av
[1], NULL
);
87 for (k
= 1; k
< ac
; k
++)
92 /* ??? the const is misplaced in pex_one's argv? */
93 err_msg
= pex_one (PEX_LAST
|PEX_SEARCH
,
95 CONST_CAST2 (char * const *, const char **, nargv
),
96 concat("gcc-", exe_name
, NULL
),
97 NULL
,NULL
, &status
, &err
);
99 fprintf(stderr
, "Error running %s: %s\n", exe_name
, err_msg
);
102 if (WIFSIGNALED (status
))
104 int sig
= WTERMSIG (status
);
105 fprintf (stderr
, "%s terminated with signal %d [%s]%s\n",
106 exe_name
, sig
, strsignal(sig
),
107 WCOREDUMP(status
) ? ", core dumped" : "");
109 else if (WIFEXITED (status
))
110 exit_code
= WEXITSTATUS (status
);
113 exit_code
= SUCCESS_EXIT_CODE
;