-/*** copy.c -- copy object file from input to output, optionally
- massaging it */
+/* copy.c -- copy object file from input to output, optionally massaging it.
+ Copyright (C) 1991 Free Software Foundation, Inc.
-#include "bfd.h"
+This file is part of GNU Binutils.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
asymbol **sympp;
char *input_target = NULL;
static boolean strip;
static boolean verbose;
+/* This flag distinguishes between strip and copy:
+ 1 means this is 'strip'; 0 means this is 'copy'.
+ -1 means if we should use argv[0] to decide. */
+extern int is_strip;
+
/* IMPORTS */
extern char *program_name;
extern char *xmalloc();
}
/* Copy architecture of input file to output file */
- if (!bfd_set_arch_mach(obfd, bfd_get_architecture(ibfd),
- bfd_get_machine(ibfd))) {
+ if (!bfd_set_arch_mach(obfd, bfd_get_arch(ibfd),
+ bfd_get_mach(ibfd))) {
fprintf(stderr, "Output file cannot represent architecture %s\n",
- bfd_printable_arch_mach(bfd_get_architecture(ibfd),
- bfd_get_machine(ibfd)));
+ bfd_printable_arch_mach(bfd_get_arch(ibfd),
+ bfd_get_mach(ibfd)));
}
if (!bfd_set_format(obfd, bfd_get_format(ibfd)))
{
sympp = (asymbol **) xmalloc(get_symtab_upper_bound(ibfd));
symcount = bfd_canonicalize_symtab(ibfd, sympp);
- bfd_set_symtab(obfd, sympp, strip == true ? 0 : symcount);
+ bfd_set_symtab(obfd, sympp, is_strip ? 0 : symcount);
/*
bfd mandates that all output sections be created and sizes set before
copy_object(ibfd, obfd);
+ if (ibfd->flags & EXEC_P)
+ obfd->flags |= EXEC_P;
if (!bfd_close(obfd))
bfd_fatal(output_filename);
{
sec_ptr osection;
char *err;
- osection = bfd_make_section(obfd, bfd_section_name(ibfd, isection));
+
+ osection = bfd_get_section_by_name(obfd, bfd_section_name(ibfd, isection));
if (osection == NULL) {
- err = "making";
- goto loser;
+ osection = bfd_make_section(obfd, bfd_section_name(ibfd, isection));
+ if (osection == NULL) {
+ err = "making";
+ goto loser;
+ }
}
if (!bfd_set_section_size(obfd,
if (size == 0)
return;
- if (strip == true || get_reloc_upper_bound(ibfd, isection) == 0)
+ if (is_strip || get_reloc_upper_bound(ibfd, isection) == 0)
{
bfd_set_reloc(obfd, osection, (arelent **)NULL, 0);
}
program_name = argv[0];
- if (strcmp(program_name,"strip") == 0) {
- strip = true;
+ bfd_init();
+
+ if (is_strip < 0) {
+ i = strlen (program_name);
+ is_strip = (i >= 5 && strcmp(program_name+i-5,"strip"));
}
for (i = 1; i < argc; i++)
input_target = output_target = argv[i];
break;
case 'S':
- strip = true;
+ is_strip = 1;
break;
case 's':
i++;
else {
copy_file(input_filename, output_filename);
}
- return 1;
+ return 0;
}