From b473cf198e8952376a2b4a1e1225c1fd0251ee20 Mon Sep 17 00:00:00 2001 From: Steve Chamberlain Date: Tue, 26 Mar 1991 22:05:50 +0000 Subject: [PATCH] If stripping, don't copy reloc info --- binutils/copy.c | 64 +++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/binutils/copy.c b/binutils/copy.c index 87937bd2e8..05d9f2dfed 100644 --- a/binutils/copy.c +++ b/binutils/copy.c @@ -292,48 +292,56 @@ loser: exit(1); } /* setup_sections() */ +/* +Copy all the section related data from an input section +to an output section + +If stripping then don't copy any relocation info +*/ static void copy_sections(ibfd, isection, obfd) bfd *ibfd; sec_ptr isection; bfd *obfd; { - static unsigned char *memhunk = NULL; - arelent **relpp; - int relcount; - sec_ptr osection; - unsigned long size; - osection = bfd_get_section_by_name(obfd, - bfd_section_name(ibfd, isection)); - size = bfd_section_size(ibfd, isection); + arelent **relpp; + int relcount; + sec_ptr osection; + unsigned long size; + osection = bfd_get_section_by_name(obfd, + bfd_section_name(ibfd, isection)); - if (size == 0) - return; + size = bfd_section_size(ibfd, isection); - if (strip == false && get_reloc_upper_bound(ibfd, isection) != 0) { - relpp = (arelent **) xmalloc(get_reloc_upper_bound(ibfd, isection)); - - relcount = bfd_canonicalize_reloc(ibfd, isection, relpp, sympp); + if (size == 0) + return; - bfd_set_reloc(obfd, osection, relpp, relcount); + if (strip == true || get_reloc_upper_bound(ibfd, isection) == 0) + { + bfd_set_reloc(obfd, osection, (arelent **)NULL, 0); + } + else + { + relpp = (arelent **) xmalloc(get_reloc_upper_bound(ibfd, isection)); + relcount = bfd_canonicalize_reloc(ibfd, isection, relpp, sympp); + bfd_set_reloc(obfd, osection, relpp, relcount); } - else { - bfd_set_reloc(obfd, osection, (arelent **)NULL, 0); - } - - if (bfd_get_section_flags(ibfd, isection) & SEC_HAS_CONTENTS) { - memhunk = (unsigned char *) xmalloc(size); - /* now we have enough memory, just do it: */ - if (!bfd_get_section_contents(ibfd, isection, memhunk, 0, size)) - bfd_fatal(bfd_get_filename(ibfd)); - if (!bfd_set_section_contents(obfd, osection, memhunk, 0, size)) - bfd_fatal(bfd_get_filename(obfd)); - } /* only if the section has contents. */ + if (bfd_get_section_flags(ibfd, isection) & SEC_HAS_CONTENTS) + { + unsigned char *memhunk = (unsigned char *) xmalloc(size); + + if (!bfd_get_section_contents(ibfd, isection, memhunk, 0, size)) + bfd_fatal(bfd_get_filename(ibfd)); + + if (!bfd_set_section_contents(obfd, osection, memhunk, 0, size)) + bfd_fatal(bfd_get_filename(obfd)); + free(memhunk); + } + - free(memhunk); } int main(argc, argv) -- 2.34.1