summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2006-01-18 11:01:09 +0000
committerNick Clifton <nickc@redhat.com>2006-01-18 11:01:09 +0000
commitf79a4c564c3618382ac25cf16a98a437f1b8d73d (patch)
tree269c1889a8e07a8811b42c8fd0cfdd4e59708b3b
parenta2a5dad410f05039a2d1f64e19e5b52efb0b1bc6 (diff)
downloadbinutils-redhat-f79a4c564c3618382ac25cf16a98a437f1b8d73d.tar.gz
PR binutils/1391
* objcopy.c (copy_object): For PE format targets set the VMA of a newly created gnu_debuglink section to a non-zero, aligned, contiguous value. * Makefile.am (objcopy.c): Add a dependency upon libbfd.h. * Makefile.in: Regenerate.
-rw-r--r--binutils/ChangeLog9
-rw-r--r--binutils/Makefile.am2
-rw-r--r--binutils/Makefile.in2
-rw-r--r--binutils/objcopy.c46
4 files changed, 56 insertions, 3 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b73144f8ab..999ebd8246 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,12 @@
+2006-01-18 Nick Clifton <nickc@redhat.com>
+
+ PR binutils/1391
+ * objcopy.c (copy_object): For PE format targets set the VMA of a
+ newly created gnu_debuglink section to a non-zero, aligned,
+ contiguous value.
+ * Makefile.am (objcopy.c): Add a dependency upon libbfd.h.
+ * Makefile.in: Regenerate.
+
2006-01-17 Andreas Schwab <schwab@suse.de>
PR binutils/1486
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index cda12e1aba..45b04e3601 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -458,7 +458,7 @@ objcopy.o: objcopy.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \
budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h $(BFDDIR)/elf-bfd.h \
$(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
- $(INCDIR)/bfdlink.h
+ $(INCDIR)/bfdlink.h $(BFDDIR)/libbfd.h
objdump.o: objdump.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/symcat.h ../bfd/bfdver.h $(INCDIR)/progress.h \
bucomm.h config.h $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h \
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index e5417990ef..64efd089f7 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -1210,7 +1210,7 @@ objcopy.o: objcopy.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \
budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h $(BFDDIR)/elf-bfd.h \
$(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
- $(INCDIR)/bfdlink.h
+ $(INCDIR)/bfdlink.h $(BFDDIR)/libbfd.h
objdump.o: objdump.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/symcat.h ../bfd/bfdver.h $(INCDIR)/progress.h \
bucomm.h config.h $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h \
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 2ab3d06bff..1d19fa8ceb 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1,6 +1,6 @@
/* objcopy.c -- copy object file from input to output, optionally massaging it.
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005
+ 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Binutils.
@@ -30,6 +30,7 @@
#include "fnmatch.h"
#include "elf-bfd.h"
#include <sys/stat.h>
+#include "libbfd.h"
/* A list of symbols to explicitly strip out, or to keep. A linked
list is good enough for a small number from the command line, but
@@ -1362,6 +1363,49 @@ copy_object (bfd *ibfd, bfd *obfd)
bfd_nonfatal (gnu_debuglink_filename);
return FALSE;
}
+
+ /* Special processing for PE format files. We
+ have no way to distinguish PE from COFF here. */
+ if (bfd_get_flavour (obfd) == bfd_target_coff_flavour)
+ {
+ bfd_vma debuglink_vma;
+ asection * highest_section;
+ asection * sec;
+
+ /* The PE spec requires that all sections be adjacent and sorted
+ in ascending order of VMA. It also specifies that debug
+ sections should be last. This is despite the fact that debug
+ sections are not loaded into memory and so in theory have no
+ use for a VMA.
+
+ This means that the debuglink section must be given a non-zero
+ VMA which makes it contiguous with other debug sections. So
+ walk the current section list, find the section with the
+ highest VMA and start the debuglink section after that one. */
+ for (sec = obfd->sections, highest_section = NULL;
+ sec != NULL;
+ sec = sec->next)
+ if (sec->vma > 0
+ && (highest_section == NULL
+ || sec->vma > highest_section->vma))
+ highest_section = sec;
+
+ if (highest_section)
+ debuglink_vma = BFD_ALIGN (highest_section->vma
+ + highest_section->size,
+ /* FIXME: We ought to be using
+ COFF_PAGE_SIZE here or maybe
+ bfd_get_section_alignment() (if it
+ was set) but since this is for PE
+ and we know the required alignment
+ it is easier just to hard code it. */
+ 0x1000);
+ else
+ /* Umm, not sure what to do in this case. */
+ debuglink_vma = 0x1000;
+
+ bfd_set_section_vma (obfd, gnu_debuglink_section, debuglink_vma);
+ }
}
if (bfd_count_sections (obfd) == 0)