From: Nick Clifton Date: Wed, 18 Jan 2006 11:01:09 +0000 (+0000) Subject: PR binutils/1391 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e2c86ac4d7527225b37dba354e534ed03af747a;p=binutils-gdb.git 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. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index b73144f8abb..999ebd82469 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2006-01-18 Nick Clifton + + 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 PR binutils/1486 diff --git a/binutils/Makefile.am b/binutils/Makefile.am index cda12e1abad..45b04e36014 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 e5417990ef3..64efd089f76 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 2ab3d06bff3..1d19fa8cebf 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 +#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)