When we build bfd with --enable-targets=all and test objdump on sample PE file:
$ ../src/binutils/objdump -h ./a.exe We've got: #v+ ./a.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0013412a 00401000 00401000 00001000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .rdata 0005775f 00536000 00536000 00136000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 2 .data 00007000 0058e000 0058e000 0018e000 2**2 CONTENTS, ALLOC, LOAD, DATA 3 .tls 00000029 005a9000 005a9000 00195000 2**2 CONTENTS, ALLOC, LOAD, DATA 4 .rsrc 0000c170 005aa000 005aa000 00196000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .text 0013412a 00401000 00401000 00001000 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE 6 .rdata 0005775f 00536000 00536000 00136000 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 .data 00007000 0058e000 0058e000 0018e000 2**4 CONTENTS, ALLOC, LOAD, DATA 8 .tls 00000029 005a9000 005a9000 00195000 2**2 CONTENTS, ALLOC, LOAD, DATA 9 .rsrc 0000c170 005aa000 005aa000 00196000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA #v- Both: pei-i386 and efi-app-ia32 adds sections, however because of check in pe_bfd_object_p(): #v+ target = coff_object_p (abfd); /* !!! here: we add sections to abfd */ if (target) { bfd_boolean efi = i->Subsystem == IMAGE_SUBSYSTEM_EFI_APPLICATION; /* Pseudo language: check if we've got proper target. When efi is set: it must starts with efi- else it must starts with pei- */ #v- Although it doesn't matter if efi is set or no. When we build pei-i386 and efi-app-ia32 (for x86 app) we always would get duplications. efi- or pei- target is discared with: bfd_error_wrong_format (but sections which was added in coff_object_p() isn't discared!) So in bfd_check_format_matches() we have only one proper target. So programmer after successed bfd_check_format_matches() continue his work, and he thinks everything is fine. However after first run of bfd_check_format_matches() we already know proper target, so we can once again execute objdump with -b set #v+ $ ../src/binutils/objdump -h ./a.exe -b pei-i386 ./a.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0013412a 00401000 00401000 00001000 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .rdata 0005775f 00536000 00536000 00136000 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA 2 .data 00007000 0058e000 0058e000 0018e000 2**4 CONTENTS, ALLOC, LOAD, DATA 3 .tls 00000029 005a9000 005a9000 00195000 2**2 CONTENTS, ALLOC, LOAD, DATA 4 .rsrc 0000c170 005aa000 005aa000 00196000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA #v- and it's good. So workaround for now is: When bfd_check_format_matches() success with only one target. Save target name. Close bfd, bfd_set_default_target() to that target. Pass to bfd_openr() that target. And hope it's ok. But I think it's hack, and bfd_check_format_matches() should matter about this cases. For example: when checking target don't use passed bfd. But only copy of it. Or second option: check if target is good before operating on bfd (use only private struct?) (I found this bug in two targets, don't know if it's more this kind bugs) When target is good, and it's only one: run again check only for that target (to read sections) or use saved copy (if we save bfd's among test) -- Summary: [bfd] after bfd_check_format_matches() we can have duplicated sections Product: binutils Version: unspecified Status: NEW Severity: normal Priority: P2 Component: binutils AssignedTo: unassigned at sources dot redhat dot com ReportedBy: darkjames at darkjames dot ath dot cx CC: bug-binutils at gnu dot org GCC build triplet: x86_64-pc-linux-gnu GCC host triplet: x86_64-pc-linux-gnu GCC target triplet: --enable-targets=all (but connected with pei-i386 <==> efi-app-i http://sourceware.org/bugzilla/show_bug.cgi?id=5299 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-binutils