* [patch] bfd - PE/COFF updates and clarifications
@ 2006-09-05 16:00 Phil Lello
2006-11-14 19:07 ` Nick Clifton
0 siblings, 1 reply; 4+ messages in thread
From: Phil Lello @ 2006-09-05 16:00 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]
Hi,
Here is a small patch for BFD to allow objdump et al. to recognise XBOX and
EFI ROM subsystems, and to identify the CLR Runtime Directory entry.
I've also changed the references to the DataDirectory array to use #define'd
indexes instead of constants (for clarity).
Phil
Index: ./bfd/ChangeLog
===================================================================
RCS file: /cvs/src/src/bfd/ChangeLog,v
retrieving revision 1.3601
diff -r1.3601 ChangeLog
0a1,11
> 2006-09-01 Phil Lello <phil.lello@homecall.co.uk>
> * peXXigen.c: Updates for PE/COFF V8.0, and clarification
> (dir_names): Added CLR Runtime Header to dir_names[].
> (_bfd_XX_print_private_bfd_data_common): Added EFI_ROM and XBOX
> subsystem names
> (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
> (pe_print_idata, pe_print_edata)
> (_bfd_XX_bfd_copy_private_bfd_data_common)
> (_bfd_XXi_final_link_postscript): Use #DEFINEs for index into
> DataDirectory
>
Index: ./include/coff/ChangeLog
===================================================================
RCS file: /cvs/src/src/include/coff/ChangeLog,v
retrieving revision 1.66
diff -r1.66 ChangeLog
0a1,7
> 2006-09-05 Phil Lello <phil.lello@homecall.co.uk>
> * pe.h: Added defines for IMAGE_SUBSYSTEM_EFI_ROM and
> IMAGE_SUBSYSTEM_XBOX
> * internal.h: Added defines for PE directory entry types.
> NB: in internal.h because IMAGE_NUMBEROF_DIRECTORY_ENTRYIES is in
> pe.h
>
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 12176 bytes --]
Index: bfd/ChangeLog
===================================================================
RCS file: /cvs/src/src/bfd/ChangeLog,v
retrieving revision 1.3601
diff -p -u -r1.3601 ChangeLog
--- bfd/ChangeLog 25 Aug 2006 00:08:53 -0000 1.3601
+++ bfd/ChangeLog 5 Sep 2006 15:56:25 -0000
@@ -1,3 +1,14 @@
+2006-09-01 Phil Lello <phil.lello@homecall.co.uk>
+ * peXXigen.c: Updates for PE/COFF V8.0, and clarification
+ (dir_names): Added CLR Runtime Header to dir_names[].
+ (_bfd_XX_print_private_bfd_data_common): Added EFI_ROM and XBOX
+ subsystem names
+ (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
+ (pe_print_idata, pe_print_edata)
+ (_bfd_XX_bfd_copy_private_bfd_data_common)
+ (_bfd_XXi_final_link_postscript): Use #DEFINEs for index into
+ DataDirectory
+
2006-08-24 Bob Wilson <bob.wilson@acm.org>
* elf32-xtensa.c (xtensa_get_property_section_name): Delete.
Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.36
diff -p -u -r1.36 peXXigen.c
--- bfd/peXXigen.c 24 Jul 2006 16:51:26 -0000 1.36
+++ bfd/peXXigen.c 5 Sep 2006 15:56:27 -0000
@@ -481,9 +481,9 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
/* These three fields are normally set up by ppc_relocate_section.
In the case of reading a file in, we can pick them up from the
DataDirectory. */
- first_thunk_address = a->DataDirectory[12].VirtualAddress;
- thunk_size = a->DataDirectory[12].Size;
- import_table_size = a->DataDirectory[1].Size;
+ first_thunk_address = a->DataDirectory[PE_IMPORT_ADDRESS_TABLE].VirtualAddress;
+ thunk_size = a->DataDirectory[PE_IMPORT_ADDRESS_TABLE].Size;
+ import_table_size = a->DataDirectory[PE_IMPORT_TABLE].Size;
#endif
}
@@ -541,9 +541,9 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
fa = extra->FileAlignment;
ib = extra->ImageBase;
- idata2 = pe->pe_opthdr.DataDirectory[1];
- idata5 = pe->pe_opthdr.DataDirectory[12];
- tls = pe->pe_opthdr.DataDirectory[9];
+ idata2 = pe->pe_opthdr.DataDirectory[PE_IMPORT_TABLE];
+ idata5 = pe->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE];
+ tls = pe->pe_opthdr.DataDirectory[PE_TLS_TABLE];
if (aouthdr_in->tsize)
{
@@ -593,11 +593,11 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
So - we copy the input values into the output values, and then, if
a final link is going to be performed, it can overwrite them. */
- extra->DataDirectory[1] = idata2;
- extra->DataDirectory[12] = idata5;
- extra->DataDirectory[9] = tls;
+ extra->DataDirectory[PE_IMPORT_TABLE] = idata2;
+ extra->DataDirectory[PE_IMPORT_ADDRESS_TABLE] = idata5;
+ extra->DataDirectory[PE_TLS_TABLE] = tls;
- if (extra->DataDirectory[1].VirtualAddress == 0)
+ if (extra->DataDirectory[PE_IMPORT_TABLE].VirtualAddress == 0)
/* Until other .idata fixes are made (pending patch), the entry for
.idata is needed for backwards compatibility. FIXME. */
add_data_entry (abfd, extra, 1, ".idata", ib);
@@ -1018,7 +1018,7 @@ static char * dir_names[IMAGE_NUMBEROF_D
N_("Bound Import Directory"),
N_("Import Address Table Directory"),
N_("Delay Import Directory"),
- N_("Reserved"),
+ N_("CLR Runtime Header"),
N_("Reserved")
};
@@ -1052,9 +1052,9 @@ pe_print_idata (bfd * abfd, void * vfile
bfd_vma addr;
- addr = extra->DataDirectory[1].VirtualAddress;
+ addr = extra->DataDirectory[PE_IMPORT_TABLE].VirtualAddress;
- if (addr == 0 && extra->DataDirectory[1].Size == 0)
+ if (addr == 0 && extra->DataDirectory[PE_IMPORT_TABLE].Size == 0)
{
/* Maybe the extra header isn't there. Look for the section. */
section = bfd_get_section_by_name (abfd, ".idata");
@@ -1172,7 +1172,7 @@ pe_print_idata (bfd * abfd, void * vfile
bfd_size_type j;
char *dll;
- /* Print (i + extra->DataDirectory[1].VirtualAddress). */
+ /* Print (i + extra->DataDirectory[PE_IMPORT_TABLE].VirtualAddress). */
fprintf (file, " %08lx\t", (unsigned long) (i + adj + dataoff));
hint_addr = bfd_get_32 (abfd, data + i + dataoff);
time_stamp = bfd_get_32 (abfd, data + i + 4 + dataoff);
@@ -1214,7 +1214,8 @@ pe_print_idata (bfd * abfd, void * vfile
ft_idx = first_thunk - adj;
ft_allocated = 0;
- if (first_thunk != hint_addr)
+ // PCL HACK
+ if (first_thunk != first_thunk/*first_thunk != hint_addr*/)
{
/* Find the section which contains the first thunk. */
for (ft_section = abfd->sections;
@@ -1337,9 +1338,9 @@ pe_print_edata (bfd * abfd, void * vfile
bfd_vma addr;
- addr = extra->DataDirectory[0].VirtualAddress;
+ addr = extra->DataDirectory[PE_EXPORT_TABLE].VirtualAddress;
- if (addr == 0 && extra->DataDirectory[0].Size == 0)
+ if (addr == 0 && extra->DataDirectory[PE_EXPORT_TABLE].Size == 0)
{
/* Maybe the extra header isn't there. Look for the section. */
section = bfd_get_section_by_name (abfd, ".edata");
@@ -1368,7 +1369,7 @@ pe_print_edata (bfd * abfd, void * vfile
}
dataoff = addr - section->vma;
- datasize = extra->DataDirectory[0].Size;
+ datasize = extra->DataDirectory[PE_EXPORT_TABLE].Size;
if (datasize > section->size - dataoff)
{
fprintf (file,
@@ -1838,6 +1839,16 @@ _bfd_XX_print_private_bfd_data_common (b
case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
subsystem_name = "EFI runtime driver";
break;
+ // These are from revision 8.0 of the MS PE/COFF spec
+ case IMAGE_SUBSYSTEM_EFI_ROM:
+ subsystem_name = "EFI ROM";
+ break;
+ case IMAGE_SUBSYSTEM_XBOX:
+ subsystem_name = "XBOX";
+ break;
+ // Added default case for clarity - subsystem_name is NULL anyway.
+ default:
+ subsystem_name = NULL;
}
fprintf (file, "Subsystem\t\t%08x", i->Subsystem);
@@ -1890,8 +1901,8 @@ _bfd_XX_bfd_copy_private_bfd_data_common
if we don't remove this entry as well. */
if (! pe_data (obfd)->has_reloc_section)
{
- pe_data (obfd)->pe_opthdr.DataDirectory[5].VirtualAddress = 0;
- pe_data (obfd)->pe_opthdr.DataDirectory[5].Size = 0;
+ pe_data (obfd)->pe_opthdr.DataDirectory[PE_BASE_RELOCATION_TABLE].VirtualAddress = 0;
+ pe_data (obfd)->pe_opthdr.DataDirectory[PE_BASE_RELOCATION_TABLE].Size = 0;
}
return TRUE;
}
@@ -1969,7 +1980,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
message for any sections tht could not be found. */
if (h1->root.u.def.section != NULL
&& h1->root.u.def.section->output_section != NULL)
- pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress =
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_TABLE].VirtualAddress =
(h1->root.u.def.value
+ h1->root.u.def.section->output_section->vma
+ h1->root.u.def.section->output_offset);
@@ -1986,11 +1997,11 @@ _bfd_XXi_final_link_postscript (bfd * ab
if (h1 != NULL
&& h1->root.u.def.section != NULL
&& h1->root.u.def.section->output_section != NULL)
- pe_data (abfd)->pe_opthdr.DataDirectory[1].Size =
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_TABLE].Size =
((h1->root.u.def.value
+ h1->root.u.def.section->output_section->vma
+ h1->root.u.def.section->output_offset)
- - pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress);
+ - pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_TABLE].VirtualAddress);
else
{
_bfd_error_handler
@@ -2006,7 +2017,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
if (h1 != NULL
&& h1->root.u.def.section != NULL
&& h1->root.u.def.section->output_section != NULL)
- pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress =
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].VirtualAddress =
(h1->root.u.def.value
+ h1->root.u.def.section->output_section->vma
+ h1->root.u.def.section->output_offset);
@@ -2023,15 +2034,15 @@ _bfd_XXi_final_link_postscript (bfd * ab
if (h1 != NULL
&& h1->root.u.def.section != NULL
&& h1->root.u.def.section->output_section != NULL)
- pe_data (abfd)->pe_opthdr.DataDirectory[12].Size =
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].Size =
((h1->root.u.def.value
+ h1->root.u.def.section->output_section->vma
+ h1->root.u.def.section->output_offset)
- - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);
+ - pe_data (abfd)->pe_opthdr.DataDirectory[PE_IMPORT_ADDRESS_TABLE].VirtualAddress);
else
{
_bfd_error_handler
- (_("%B: unable to fill in DataDictionary[12] because .idata$6 is missing"),
+ (_("%B: unable to fill in DataDictionary[PE_IMPORT_ADDRESS_TABLE (12)] because .idata$6 is missing"),
abfd);
result = FALSE;
}
@@ -2043,7 +2054,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
{
if (h1->root.u.def.section != NULL
&& h1->root.u.def.section->output_section != NULL)
- pe_data (abfd)->pe_opthdr.DataDirectory[9].VirtualAddress =
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].VirtualAddress =
(h1->root.u.def.value
+ h1->root.u.def.section->output_section->vma
+ h1->root.u.def.section->output_offset
@@ -2056,7 +2067,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
result = FALSE;
}
- pe_data (abfd)->pe_opthdr.DataDirectory[9].Size = 0x18;
+ pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x18;
}
/* If we couldn't find idata$2, we either have an excessively
Index: include/coff/ChangeLog
===================================================================
RCS file: /cvs/src/src/include/coff/ChangeLog,v
retrieving revision 1.66
diff -p -u -r1.66 ChangeLog
--- include/coff/ChangeLog 5 Feb 2006 11:57:34 -0000 1.66
+++ include/coff/ChangeLog 5 Sep 2006 15:56:29 -0000
@@ -1,3 +1,10 @@
+2006-09-05 Phil Lello <phil.lello@homecall.co.uk>
+ * pe.h: Added defines for IMAGE_SUBSYSTEM_EFI_ROM and
+ IMAGE_SUBSYSTEM_XBOX
+ * internal.h: Added defines for PE directory entry types.
+ NB: in internal.h because IMAGE_NUMBEROF_DIRECTORY_ENTRYIES is in
+ pe.h
+
2006-02-05 Arnold Metselaar <arnold.metselaar@planet.nl>
* internal.h: Add relocation number R_IMM24 for Z80.
Index: include/coff/internal.h
===================================================================
RCS file: /cvs/src/src/include/coff/internal.h,v
retrieving revision 1.18
diff -p -u -r1.18 internal.h
--- include/coff/internal.h 5 Feb 2006 11:57:34 -0000 1.18
+++ include/coff/internal.h 5 Sep 2006 15:56:30 -0000
@@ -103,6 +103,22 @@ typedef struct _IMAGE_DATA_DIRECTORY
bfd_vma VirtualAddress;
long Size;
} IMAGE_DATA_DIRECTORY;
+#define PE_EXPORT_TABLE 0
+#define PE_IMPORT_TABLE 1
+#define PE_RESOURCE_TABLE 2
+#define PE_EXCEPTION_TABLE 3
+#define PE_CERTIFICATE_TABLE 4
+#define PE_BASE_RELOCATION_TABLE 5
+#define PE_DEBUG_DATA 6
+#define PE_ARCHITECTURE 7
+#define PE_GLOBAL_PTR 8
+#define PE_TLS_TABLE 9
+#define PE_LOAD_CONFIG_TABLE 10
+#define PE_BOUND_IMPORT_TABLE 11
+#define PE_IMPORT_ADDRESS_TABLE 12
+#define PE_DELAY_IMPORT_DESCRIPTOR 13
+#define PE_CLR_RUNTIME_HEADER 14
+/* DataDirectory[15] is currently reserved, so no define. */
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
/* Default image base for NT. */
Index: include/coff/pe.h
===================================================================
RCS file: /cvs/src/src/include/coff/pe.h,v
retrieving revision 1.14
diff -p -u -r1.14 pe.h
--- include/coff/pe.h 10 May 2005 10:21:09 -0000 1.14
+++ include/coff/pe.h 5 Sep 2006 15:56:32 -0000
@@ -129,6 +129,8 @@
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
+#define IMAGE_SUBSYSTEM_EFI_ROM 13
+#define IMAGE_SUBSYSTEM_XBOX 14
/* Magic values that are true for all dos/nt implementations. */
#define DOSMAGIC 0x5a4d
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] bfd - PE/COFF updates and clarifications
2006-09-05 16:00 [patch] bfd - PE/COFF updates and clarifications Phil Lello
@ 2006-11-14 19:07 ` Nick Clifton
2006-11-15 3:14 ` Phil Lello
0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2006-11-14 19:07 UTC (permalink / raw)
To: Phil Lello; +Cc: binutils
Hi Phil,
I am very sorry that it has taken me so long to get around to
reviewing this patch.
>> 2006-09-01 Phil Lello <phil.lello@homecall.co.uk>
>> * peXXigen.c: Updates for PE/COFF V8.0, and clarification
>> (dir_names): Added CLR Runtime Header to dir_names[].
>> (_bfd_XX_print_private_bfd_data_common): Added EFI_ROM and XBOX
>> subsystem names
>> (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
>> (pe_print_idata, pe_print_edata)
>> (_bfd_XX_bfd_copy_private_bfd_data_common)
>> (_bfd_XXi_final_link_postscript): Use #DEFINEs for index into
>> DataDirectory
>> 2006-09-05 Phil Lello <phil.lello@homecall.co.uk>
>> * pe.h: Added defines for IMAGE_SUBSYSTEM_EFI_ROM and
>> IMAGE_SUBSYSTEM_XBOX
>> * internal.h: Added defines for PE directory entry types.
>> NB: in internal.h because IMAGE_NUMBEROF_DIRECTORY_ENTRYIES is in
>> pe.h
I have approved and applied your patch, except for one small part:
>> @@ -1214,7 +1214,8 @@ pe_print_idata (bfd * abfd, void * vfile
>> ft_idx = first_thunk - adj;
>> ft_allocated = 0;
>>
>> - if (first_thunk != hint_addr)
>> + // PCL HACK
>> + if (first_thunk != first_thunk/*first_thunk != hint_addr*/)
>> {
>> /* Find the section which contains the first thunk. */
>> for (ft_section = abfd->sections;
It is not clear to me whether this change was intentional or just some
debugging that was left in. Either way it is unsuitable. If you really
do want to disable the test you should use "if (0)" and add a comment
explaining why the test and the body of the if statement have been
suppressed.
Cheers
Nick
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [patch] bfd - PE/COFF updates and clarifications
2006-11-14 19:07 ` Nick Clifton
@ 2006-11-15 3:14 ` Phil Lello
2006-11-15 15:20 ` Nick Clifton
0 siblings, 1 reply; 4+ messages in thread
From: Phil Lello @ 2006-11-15 3:14 UTC (permalink / raw)
To: 'Nick Clifton'; +Cc: binutils
Hi Nick,
> >> 2006-09-01 Phil Lello <phil.lello@homecall.co.uk>
> >> * peXXigen.c: Updates for PE/COFF V8.0, and clarification
> >> (dir_names): Added CLR Runtime Header to dir_names[].
> >> (_bfd_XX_print_private_bfd_data_common): Added
> EFI_ROM and XBOX
> >> subsystem names
> >> (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
> >> (pe_print_idata, pe_print_edata)
> >> (_bfd_XX_bfd_copy_private_bfd_data_common)
> >> (_bfd_XXi_final_link_postscript): Use #DEFINEs for index into
> >> DataDirectory
>
> >> 2006-09-05 Phil Lello <phil.lello@homecall.co.uk>
> >> * pe.h: Added defines for IMAGE_SUBSYSTEM_EFI_ROM and
> >> IMAGE_SUBSYSTEM_XBOX
> >> * internal.h: Added defines for PE directory entry types.
> >> NB: in internal.h because
> IMAGE_NUMBEROF_DIRECTORY_ENTRYIES is in
> >> pe.h
>
> I have approved and applied your patch, except for one small part:
>
> >> @@ -1214,7 +1214,8 @@ pe_print_idata (bfd * abfd, void * vfile
> >> ft_idx = first_thunk - adj;
> >> ft_allocated = 0;
> >>
> >> - if (first_thunk != hint_addr)
> >> + // PCL HACK
> >> + if (first_thunk != first_thunk/*first_thunk != hint_addr*/)
> >> {
> >> /* Find the section which contains the first thunk. */
> >> for (ft_section = abfd->sections;
>
> It is not clear to me whether this change was intentional or
> just some debugging that was left in. Either way it is
> unsuitable. If you really do want to disable the test you
> should use "if (0)" and add a comment explaining why the test
> and the body of the if statement have been suppressed.
>
Thanks for that. This last change (to pe_print_idata) was indeed
left-over debugging, and shouldn't have been in my patch. I will
make sure I check more carefully in future.
It looks like although bfd/peXXigen.c has been updated with the
other changes, the ChangeLog entry (bfd/ChangeLog) hasn't made it
to CVS yet.
Thanks,
Phil Lello
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] bfd - PE/COFF updates and clarifications
2006-11-15 3:14 ` Phil Lello
@ 2006-11-15 15:20 ` Nick Clifton
0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2006-11-15 15:20 UTC (permalink / raw)
To: Phil Lello; +Cc: binutils
Hi Phil,
> It looks like although bfd/peXXigen.c has been updated with the
> other changes, the ChangeLog entry (bfd/ChangeLog) hasn't made it
> to CVS yet.
Oops - for some reason cvs was not registering my edit to that file.
Anyway I have now checked the entry in, so everything should be up to date.
Cheers
Nick
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-11-15 15:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-05 16:00 [patch] bfd - PE/COFF updates and clarifications Phil Lello
2006-11-14 19:07 ` Nick Clifton
2006-11-15 3:14 ` Phil Lello
2006-11-15 15:20 ` Nick Clifton
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).