This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA:] collect2.c: Support not running strip when the ld "-s" option is seen
- To: gcc-patches at gcc dot gnu dot org
- Subject: [RFA:] collect2.c: Support not running strip when the ld "-s" option is seen
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- Date: Wed, 15 Nov 2000 18:20:33 +0100
The case I use this for is where some executables aren't
strippable after linking, so re-linking with "-s" is how it must
be done. It's kind of impure magic that collect2 maps "-s" to
"strip" anyway, since "ld -s" *might* mean other things on some
systems.
Bootstrapped on i686-pc-linux-gnu with no regressions with
--disable-libstdcxx-v3, (because that seems the only way to
bootstrap there at the time I started the bootstrap).
Ok to commit?
* tm.texi (collect2-specific options): Document
SET_STRIPPABLE_EXECUTABLE.
* collect2.c (SET_STRIPPABLE_EXECUTABLE): New macro to support not
mapping "-s" to mean run "strip".
Index: tm.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tm.texi,v
retrieving revision 1.151
diff -c -p -r1.151 tm.texi
*** tm.texi 2000/11/10 05:56:47 1.151
--- tm.texi 2000/11/15 00:38:48
*************** from @code{LDD_SUFFIX}. If the line lis
*** 6330,6335 ****
--- 6330,6350 ----
code must advance @var{PTR} to the beginning of the filename on that
line. Otherwise, it must set @var{PTR} to @code{NULL}.
+ @findex SET_STRIPPABLE_EXECUTABLE
+ @item SET_STRIPPABLE_EXECUTABLE (@var{do_strip}, @var{argc}, @var{argv})
+ This statement macro takes as arguments an @code{int} variable
+ @var{do_strip} and the @var{argc} and @var{argv} seen by the linker. You
+ should define this macro if @code{strip} is unusable on executables linked
+ with certain linker options on the target system.
+
+ When gcc is given the option @code{-s}, the program @code{collect2} will
+ by default only pass it on the to the linker if it needs to re-link files
+ after processing symbol names. If @code{collect2} finds that it does not
+ need to re-link and this macro is either not defined or sets
+ @var{do_strip} to a non-zero value, it will instead invoke @code{strip}.
+ When @var{do_strip} is set to zero, @code{collect2} will instead re-link
+ with @code{-s}.
+
@end table
@node Instruction Output
Index: collect2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/collect2.c,v
retrieving revision 1.102
diff -c -p -r1.102 collect2.c
*** collect2.c 2000/11/13 21:22:10 1.102
--- collect2.c 2000/11/15 00:38:49
*************** Boston, MA 02111-1307, USA. */
*** 139,144 ****
--- 139,150 ----
#endif /* OBJECT_FORMAT_NONE */
+ /* Some systems can't use strip on executables when certain options are
+ used; we must then relink instead. */
+ #ifndef SET_STRIPPABLE_EXECUTABLE
+ #define SET_STRIPPABLE_EXECUTABLE(X, Y, Z)
+ #endif
+
/* Some systems use __main in a way incompatible with its use in gcc, in these
cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
give the same symbol without quotes for an alternative entry point. You
*************** main (argc, argv)
*** 830,835 ****
--- 836,843 ----
int argc;
char *argv[];
{
+ int orig_argc = argc;
+ char **orig_argv = argv;
const char *ld_suffix = "ld";
const char *full_ld_suffix = ld_suffix;
const char *real_ld_suffix = "real-ld";
*************** main (argc, argv)
*** 1198,1204 ****
{
/* We must strip after the nm run, otherwise C++ linking
will not work. Thus we strip in the second ld run, or
! else with strip if there is no second ld run. */
strip_flag = 1;
ld1--;
}
--- 1206,1213 ----
{
/* We must strip after the nm run, otherwise C++ linking
will not work. Thus we strip in the second ld run, or
! else with strip if there is no second ld run. For
! some systems, we might re-link instead. */
strip_flag = 1;
ld1--;
}
*************** main (argc, argv)
*** 1397,1411 ****
/* Strip now if it was requested on the command line. */
if (strip_flag)
{
! char **real_strip_argv = (char **) xcalloc (sizeof (char *), 3);
! const char ** strip_argv = (const char **) real_strip_argv;
!
! strip_argv[0] = strip_file_name;
! strip_argv[1] = output_file;
! strip_argv[2] = (char *) 0;
! fork_execute ("strip", real_strip_argv);
! }
#ifdef COLLECT_EXPORT_LIST
maybe_unlink (export_file);
#endif
--- 1406,1443 ----
/* Strip now if it was requested on the command line. */
if (strip_flag)
{
! int strippable = 1;
! SET_STRIPPABLE_EXECUTABLE (strippable, orig_argc, orig_argv);
! if (strippable)
! {
! char **real_strip_argv = (char **) xcalloc (sizeof (char *), 3);
! const char ** strip_argv = (const char **) real_strip_argv;
+ strip_argv[0] = strip_file_name;
+ strip_argv[1] = output_file;
+ strip_argv[2] = (char *) 0;
+ fork_execute ("strip", real_strip_argv);
+ }
+ else
+ {
+ /* If we shouldn't strip, re-link instead. Delete the
+ file from the previous ld run, so any link failures
+ will not leave an executable with unwanted contents. */
+ unlink (output_file);
+
+ /* Move arguments and put the "-s" argument first in
+ ld1_argv (after the program name); there is room for
+ it. Note that GNU ld can handle options after files,
+ but we can't rely on it. We can't use orig_argv
+ because it names collect2 as the program to use, and we
+ can't use ld2_argv, since it contains the "extra"
+ objects. */
+ memmove (ld1_argv + 2, ld1_argv + 1,
+ ((char **) ld1 + 1 - (ld1_argv + 1)) * sizeof (*ld1));
+ ld1_argv[1] = "-s";
+ fork_execute ("ld", ld1_argv);
+ }
+ }
#ifdef COLLECT_EXPORT_LIST
maybe_unlink (export_file);
#endif
brgds, H-P