* PATCH: PR binutils/5299: Duplicated sections for COFF/PE
@ 2007-11-10 15:52 H.J. Lu
2007-11-12 1:21 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2007-11-10 15:52 UTC (permalink / raw)
To: binutils
PE target may have duplicated sections due to calling
coff_real_object_p more than once. This patch saves and restores
previous sections if needed. I also fixed a bug where we
failed to update subsystem with
# objcopy -O efi-app-ia32 a.exe e.efi
H.J.
---
2007-11-10 H.J. Lu <hongjiu.lu@intel.com>
* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Update
subsystem if needed.
PR binutils/5299
* peicode.h (pe_bfd_object_p): Save and restore previous
sections if needed.
--- bfd/peXXigen.c.dup 2007-07-03 19:35:09.000000000 -0700
+++ bfd/peXXigen.c 2007-11-10 07:45:25.000000000 -0800
@@ -1987,13 +1987,22 @@ _bfd_XX_print_private_bfd_data_common (b
bfd_boolean
_bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
{
+ pe_data_type *ipe, *ope;
+
/* One day we may try to grok other private data. */
if (ibfd->xvec->flavour != bfd_target_coff_flavour
|| obfd->xvec->flavour != bfd_target_coff_flavour)
return TRUE;
- pe_data (obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr;
- pe_data (obfd)->dll = pe_data (ibfd)->dll;
+ ipe = pe_data (ibfd);
+ ope = pe_data (obfd);
+
+ ope->pe_opthdr = ipe->pe_opthdr;
+ ope->dll = ipe->dll;
+
+ /* We may need to update subsystem. */
+ if (obfd->xvec != ibfd->xvec)
+ ope->pe_opthdr.Subsystem = ope->target_subsystem;
/* For strip: if we removed .reloc, we'll make a real mess of things
if we don't remove this entry as well. */
--- bfd/peicode.h.dup 2007-07-12 11:59:24.000000000 -0700
+++ bfd/peicode.h 2007-11-10 07:48:03.000000000 -0800
@@ -1263,6 +1263,8 @@ pe_bfd_object_p (bfd * abfd)
struct external_PEI_IMAGE_hdr image_hdr;
file_ptr offset;
const bfd_target *target;
+ struct bfd_section *sections, *section_last;
+ unsigned int section_count;
/* Detect if this a Microsoft Import Library Format element. */
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
@@ -1327,6 +1329,23 @@ pe_bfd_object_p (bfd * abfd)
return NULL;
}
+ /* FIXME: coff_object_p will load sections. Do we need to restore
+ the previous sections if the current target doesn't match? */
+ section_count = abfd->section_count;
+ if (section_count != 0)
+ {
+ sections = abfd->sections;
+ section_last = abfd->section_last;
+ abfd->section_count = 0;
+ abfd->sections = NULL;
+ abfd->section_last = NULL;
+ }
+ else
+ {
+ sections = NULL;
+ section_last = NULL;
+ }
+
target = coff_object_p (abfd);
if (target)
{
@@ -1361,8 +1380,17 @@ pe_bfd_object_p (bfd * abfd)
if (efi)
{
+no_match:
/* TARGET_PTR is an EFI backend. Don't match
TARGET with a EFI file. */
+
+ if (section_count != 0)
+ {
+ abfd->section_count = section_count;
+ abfd->sections = sections;
+ abfd->section_last = section_last;
+ }
+
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
@@ -1377,12 +1405,17 @@ pe_bfd_object_p (bfd * abfd)
{
/* TARGET_PTR is a PE backend. Don't match
TARGET with a PE file. */
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto no_match;
}
}
}
}
+ else if (section_count != 0)
+ {
+ abfd->section_count = section_count;
+ abfd->sections = sections;
+ abfd->section_last = section_last;
+ }
return target;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: PR binutils/5299: Duplicated sections for COFF/PE
2007-11-10 15:52 PATCH: PR binutils/5299: Duplicated sections for COFF/PE H.J. Lu
@ 2007-11-12 1:21 ` Alan Modra
2007-11-12 14:36 ` H.J. Lu
0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2007-11-12 1:21 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Sat, Nov 10, 2007 at 07:52:16AM -0800, H.J. Lu wrote:
> PR binutils/5299
> * peicode.h (pe_bfd_object_p): Save and restore previous
> sections if needed.
You should use bfd_preserve_save/restore here, I think.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: PR binutils/5299: Duplicated sections for COFF/PE
2007-11-12 1:21 ` Alan Modra
@ 2007-11-12 14:36 ` H.J. Lu
2007-11-12 21:30 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2007-11-12 14:36 UTC (permalink / raw)
To: binutils
On Mon, Nov 12, 2007 at 11:51:36AM +1030, Alan Modra wrote:
> On Sat, Nov 10, 2007 at 07:52:16AM -0800, H.J. Lu wrote:
> > PR binutils/5299
> > * peicode.h (pe_bfd_object_p): Save and restore previous
> > sections if needed.
>
> You should use bfd_preserve_save/restore here, I think.
>
Here is the updatd patch.
H.J.
----
2007-11-12 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/5299
* peicode.h (pe_bfd_object_p): Save and restore previous bfd
state when calling coff_object_p.
--- bfd/peicode.h.dup 2007-07-12 11:59:24.000000000 -0700
+++ bfd/peicode.h 2007-11-12 06:31:15.000000000 -0800
@@ -1263,6 +1263,7 @@ pe_bfd_object_p (bfd * abfd)
struct external_PEI_IMAGE_hdr image_hdr;
file_ptr offset;
const bfd_target *target;
+ struct bfd_preserve preserve;
/* Detect if this a Microsoft Import Library Format element. */
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
@@ -1327,6 +1328,10 @@ pe_bfd_object_p (bfd * abfd)
return NULL;
}
+ preserve.marker = NULL;
+ if (! bfd_preserve_save (abfd, &preserve))
+ return NULL;
+
target = coff_object_p (abfd);
if (target)
{
@@ -1344,7 +1349,10 @@ pe_bfd_object_p (bfd * abfd)
/* Don't check PE vs. EFI if arch is unknown. */
if (arch == arch_type_unknown)
- return target;
+ {
+ bfd_preserve_finish (abfd, &preserve);
+ return target;
+ }
for (target_ptr = bfd_target_vector; *target_ptr != NULL;
target_ptr++)
@@ -1361,8 +1369,10 @@ pe_bfd_object_p (bfd * abfd)
if (efi)
{
+no_match:
/* TARGET_PTR is an EFI backend. Don't match
TARGET with a EFI file. */
+ bfd_preserve_restore (abfd, &preserve);
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
@@ -1377,12 +1387,15 @@ pe_bfd_object_p (bfd * abfd)
{
/* TARGET_PTR is a PE backend. Don't match
TARGET with a PE file. */
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto no_match;
}
}
}
+
+ bfd_preserve_finish (abfd, &preserve);
}
+ else
+ bfd_preserve_restore (abfd, &preserve);
return target;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: PR binutils/5299: Duplicated sections for COFF/PE
2007-11-12 14:36 ` H.J. Lu
@ 2007-11-12 21:30 ` Alan Modra
0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2007-11-12 21:30 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Mon, Nov 12, 2007 at 06:36:23AM -0800, H.J. Lu wrote:
> PR binutils/5299
> * peicode.h (pe_bfd_object_p): Save and restore previous bfd
> state when calling coff_object_p.
OK.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-12 21:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-10 15:52 PATCH: PR binutils/5299: Duplicated sections for COFF/PE H.J. Lu
2007-11-12 1:21 ` Alan Modra
2007-11-12 14:36 ` H.J. Lu
2007-11-12 21:30 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).