[PATCH] Revise long section names coff extension handling for PE targets, take 2.

Dave Korn dave.korn.cygwin@googlemail.com
Mon Feb 16 23:21:00 GMT 2009


    Hi again,

  Here's the revised version of the PE/COFF long section names patch that I
posted previously at

http://sourceware.org/ml/binutils/2009-02/msg00136.html

  Rationale and full details are there and in the earlier threads it
references[*]; this respin just accounts for the altered behaviour introduced
by the relocs-in-image-files fix.

  I have tested it on i686-pc-linux x {a29k-unknown-coff alpha-freebsd
alpha-linuxecoff alpha-unknown-linux alpha-unknown-linuxecoff arc-unknown-elf
arm-elf arm-epoc-pe arm-unknown-aout arm-unknown-coff arm-unknown-linux
arm-vxworks arm-wince-pe avr-unknown-elf cris-unknown-elf d10v-unknown-elf
d30v-unknown-elf dlx-unknown-elf fr30-unknown-elf frv-unknown-elf
h8300-unknown-elf h8300-unknown-rtems h8500-unknown-rtems hppa-unknown-linux
hppa64-unknown-linux i370-unknown-linux i386-coff i386-msdos i386-pc-netbsdpe
i386-pc-pe i586-linux i586-pc-interix i586-pc-msdosdjgpp i586-unknown-aout
i586-unknown-beospe i586-unknown-coff i686-pc-cygwin i686-pc-linux-gnu
i686-pc-mingw32 i860-stardent-elf i960-intel-nindy i960-unknown-coff
i960-unknown-elf ia64-unknown-linux ip2k-unknown-elf m32r-unknown-elf
m68hc11-unknown-elf m68hc12-unknown-elf m68k-coff m68k-unknown-aout
m68k-unknown-coff m68k-unknown-linux m68k-unknown-netbsd m88k-unknown-coff
mcore-unknown-elf mcore-unknown-pe mips-dec-bsd mips-unknown-ecoff
mips-unknown-linux mips-unknown-pe mmix-unknown-elf mn10200-unknown-elf
mn10300-unknown-elf ns32k-unknown-netbsd openrisc-unknown-elf
or32-unknown-coff or32-unknown-elf pj-unknown-elf powerpc-unknown-aix5
powerpc-unknown-linux powerpc64-unknown-linux powerpcle-unknown-pe ppc-eabi
s390-unknown-linux s390x-unknown-linux sh-coff sh-elf sh-unknown-linux
sh-unknown-pe sh-unknown-rtems sh64-unknown-elf sparc-unknown-aout
sparc-unknown-coff sparc-unknown-linux sparc64-unknown-linux thumb-epoc-pe
tic30-unknown-aout tic30-unknown-coff tic54x-unknown-coff tic80-unknown-coff
v850-unknown-elf vax-unknown-netbsd vax-unknown-netbsdelf vax-unknown-vms
vms-vax w65-unknown-coff x86_64-pc-freebsd x86_64-pc-linux-gnu
x86_64-pc-mingw32 x86_64-unknown-linux xstormy16-unknown-elf z8k-coff
z8k-unknown-coff} and on i686-pc-cygwin x {arm-epoc-pe arm-wince-pe
i386-pc-netbsdpe i386-pc-pe i586-pc-interix i586-unknown-beospe i686-pc-cygwin
i686-pc-mingw32 mcore-unknown-pe powerpcle-unknown-pe sh-unknown-pe
thumb-epoc-pe x86_64-pc-freebsd x86_64-pc-linux-gnu x86_64-pc-mingw32}.

  There are no regressions anywhere, but a few of the new tests fail on a few
embedded platforms:

chk-arm-epoc-pe.log:FAIL: PE-COFF Long section names in objects (default)
chk-mcore-unknown-pe.log:FAIL: PE-COFF Long section names in objects (default)
chk-sh-unknown-pe.log:FAIL: PE-COFF Long section names in objects (default)
chk-sh-unknown-pe.log:FAIL: PE-COFF Long section names in objects (disabled)
chk-sh-unknown-pe.log:FAIL: PE-COFF Long section names in objects (enabled)

  The first three failures all arise because on these targets, invoking "ld
-r" on an object file creates a fully-linked executable, not another
relocatable object.  This means that the default setting of the enable/disable
flag for the output is the wrong way round than the target expects.  It also
causes unexpected relocs to be generated on mcore, which cause warnings from
'ld' that make the testcase fail, which is the sole cause of failure for the
final two testcases - if manually run, the generated output is correct.

  I do not know if this means that "ld -r" is broken on those platforms, or if
it is not supported on those platforms; once I find out, I can either XFAIL or
skip the tests if it is not supposed to work, or leave them FAILing if it
indicates a real bug.

  If "ld -r" is supposed to work on these platforms, and is genuinely supposed
to produce an executable object yet also supposed to use the executable image
backend vec to do so, I will also have to follow up with a patch to set the
default long section names enable flag on those platforms at runtime based on
the relocatable flag, but I suspect this is really a bug, or that "ld -r" is
not supported and a change in the behaviour (that is in fact strictly-speaking
correct, but nonetheless not backwardly compatible) of something unsupported
won't matter too much.  (I suspect that sh-unknown-pe may, in fact, need to be
added to the #if clause in the pe-relocs fix that currently only covers arm
and i386 targets, but haven't pursued it).

  There are also two testcases that fail when run cross from Cygwin, yet pass
when run cross from linux:

obj1252-mcore-unknown-pe/check-mcore-unknown-pe.log:FAIL: PE-COFF Long section
names in objects (disabled)
obj1252-mcore-unknown-pe/check-mcore-unknown-pe.log:FAIL: PE-COFF Long section
names in objects (enabled)

  In both cases, the long name section behaviour is correct.  The problem is
that the linux-x-mcore and cygwin-x-mcore linkers generate different outputs
when faced with the same output.  The input .o files have all the same
sections in the same order on both platforms:

---------------------<on cygwin>---------------------
/gnu/binutils/obj1252-mcore-unknown-pe/ld $ ../binutils/objdump -h
tmpdir/dump0.o | md5sum
26464706190e17016c2d9c79a878c84e *-
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/gnu/binutils/obj1252-mcore-unknown-pe/ld $
---------------------<on linux>---------------------
[root@ubique ld]# ../binutils/objdump -h tmpdir/dump0.o | md5sum
26464706190e17016c2d9c79a878c84e  -
[root@ubique ld]# ../binutils/objdump -h tmpdir/dump0.o | head

tmpdir/dump:     file format pei-mcore-little

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000004  00000000  00000000  00000340  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.very.long.section.name 00000004  00000000  00000000  00000344  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
  2 .data         00000008  00000000  00000000  00000348  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  3 .data$1       00000004  00000000  00000000  00000350  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .rodata$1     00000004  00000000  00000000  00000354  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .data$123     00000004  00000000  00000000  00000358  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .rodata$123   00000004  00000000  00000000  0000035c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  7 .data$123456789 00000004  00000000  00000000  00000360  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  8 .rodata$123456789 00000004  00000000  00000000  00000364  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .data.very.long.section 00000004  00000000  00000000  00000368  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 10 .rodata.very.long.section 00000004  00000000  00000000  0000036c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 11 .data.very.long.section$1 00000004  00000000  00000000  00000370  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .rodata.very.long.section$1 00000004  00000000  00000000  00000374  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 13 .data.very.long.section$1234 00000004  00000000  00000000  00000378  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 14 .rodata.very.long.section$1234 00000004  00000000  00000000  0000037c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 15 .bss          00000004  00000000  00000000  00000000  2**2
                  ALLOC
[root@ubique ld]#
-----------------------------------------------------

  But when linked -r (with no other outputs), the two disagree about where the
text sections go quite seriously:

---------------------<on cygwin>---------------------
/gnu/binutils/obj1252-mcore-unknown-pe/ld $ ../binutils/objdump -h tmpdir/dump

tmpdir/dump:     file format pei-mcore-little

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text.very.long.section.name 00000004  00000000  00000000  00000340  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
  1 .data         00000008  00000000  00000000  00000344  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .data$1       00000004  00000000  00000000  0000034c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  3 .rodata$1     00000004  00000000  00000000  00000350  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .data$123     00000004  00000000  00000000  00000354  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .rodata$123   00000004  00000000  00000000  00000358  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .data$123456789 00000004  00000000  00000000  0000035c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  7 .rodata$123456789 00000004  00000000  00000000  00000360  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  8 .data.very.long.section 00000004  00000000  00000000  00000364  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .rodata.very.long.section 00000004  00000000  00000000  00000368  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 10 .data.very.long.section$1 00000004  00000000  00000000  0000036c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 11 .rodata.very.long.section$1 00000004  00000000  00000000  00000370  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .data.very.long.section$1234 00000004  00000000  00000000  00000374  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 13 .rodata.very.long.section$1234 00000004  00000000  00000000  00000378  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 14 .bss          00000004  00000000  00000000  00000000  2**2
                  ALLOC
 15 .text         00000004  00000000  00000000  0000037c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

---------------------<on linux>---------------------
[root@ubique ld]# ../binutils/objdump -h tmpdir/dump

tmpdir/dump:     file format pei-mcore-little

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000004  00000000  00000000  00000340  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.very.long.section.name 00000004  00000000  00000000  00000344  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
  2 .data         00000008  00000000  00000000  00000348  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  3 .data$1       00000004  00000000  00000000  00000350  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .rodata$1     00000004  00000000  00000000  00000354  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .data$123     00000004  00000000  00000000  00000358  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .rodata$123   00000004  00000000  00000000  0000035c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  7 .data$123456789 00000004  00000000  00000000  00000360  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  8 .rodata$123456789 00000004  00000000  00000000  00000364  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .data.very.long.section 00000004  00000000  00000000  00000368  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 10 .rodata.very.long.section 00000004  00000000  00000000  0000036c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 11 .data.very.long.section$1 00000004  00000000  00000000  00000370  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .rodata.very.long.section$1 00000004  00000000  00000000  00000374  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 13 .data.very.long.section$1234 00000004  00000000  00000000  00000378  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 14 .rodata.very.long.section$1234 00000004  00000000  00000000  0000037c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 15 .bss          00000004  00000000  00000000  00000000  2**2
                  ALLOC
[root@ubique ld]# ../binutils/objdump -h tmpdir/dump0.o | md5sum
-----------------------------------------------------

  That looks to me like Linux has it right and Cygwin has getting it wrong, so
I think the testcase is correct and there's a problem on Cygwin.  However it's
not a regression in as much as unpatched cygwin x mcore ld also gets it wrong.

  Given all that, OK for trunk, or shall we wait to hear from the other
maintainers about what to do with the "ld -r" failure?


    cheers,
      DaveK

bfd/ChangeLog

	* coff-alpha.c (alpha_ecoff_backend_data):  Initialise fields which
	control long section name handling with ECOFF_NO_LONG_SECTION_NAMES.
	* coff-mips.c (mips_ecoff_backend_data):  Likewise.
	* coff-rs6000.c (bfd_xcoff_backend_data):  Initialise fields which
	control long section name handling with XCOFF_NO_LONG_SECTION_NAMES.
	(bfd_pmac_xcoff_backend_data):  Likewise.
	* coff64-rs6000.c (bfd_xcoff_backend_data):  Likewise.
	(bfd_xcoff_aix5_backend_data):  Likewise.
	(xcoff64_write_object_contents):  Delete unused long_section_names
	local variable.
	* coff-sh.c (bfd_coff_small_swap_table):  Initialise long section
	name members using COFF_DEFAULT_LONG_SECTION_NAMES and make entire
	struct non-const.
	* coffcode.h (documentation):  Update to describe long section names.
	(COFFLONGSECTIONCATHELPER):  New helper macro.
	(BLANKOR1TOODD):  Likewise.
	(COFF_ENABLE_LONG_SECTION_NAMES):  Likewise.
	(COFF_LONG_SECTION_NAMES_SETTER):  Likewise.
	(COFF_DEFAULT_LONG_SECTION_NAMES):  Likewise.
	(bfd_coff_set_long_section_names_allowed):  New function.
	(bfd_coff_set_long_section_names_disallowed):  Likewise.
	(struct bfd_coff_backend_data):  Add new backend hook function
	pointer _bfd_coff_set_long_section_names.
	(bfd_coff_set_long_section_names):  New backend hook.
	(coff_write_object_contents):  Only generate long section names if
	bfd_coff_long_section_names() indicates they are currently enabled.
	(bfd_coff_std_swap_table):  Make non-const, and initialise long
	section name fields using COFF_DEFAULT_LONG_SECTION_NAMES.
	(ticoff0_swap_table):  Likewise to both.
	(ticoff1_swap_table):  Again, likewise to both.
	* coffgen.c (make_a_section_from_file):  Allow long section names
	as inputs even if not currently allowed for outputs.
	* ecoff.c (_bfd_ecoff_no_long_sections):  New function.
	* efi-app-ia32.c (COFF_LONG_SECTION_NAMES):  Define to 0, not blank.
	* efi-app-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-app-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-ia32.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-ia32.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-arm.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-i386.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-mcore.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-mips.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-ppc.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-sh.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* libcoff-in.h:  Update copyright year to cause updated copyright
	year in generated libcoff.h, and fix typo.
	* libcoff.h:  Regenerated.
	* libecoff.h (ECOFF_NO_LONG_SECTION_NAMES):  New macro.
	(_bfd_ecoff_no_long_sections):  Add prototype.
	* libxcoff.h (XCOFF_NO_LONG_SECTION_NAMES):  New macro.
	* pe-mips.c (COFF_LONG_SECTION_NAMES):  Define empty if not already
	defined by an including .c file.
	* ticoff.h (ticoff0_swap_table):  Make non-const, and initialise
	long section name fields using COFF_DEFAULT_LONG_SECTION_NAMES.
	(ticoff1_swap_table):  Likewise to both.

ld/ChangeLog

	* ld.texinfo:  Update to mention long section name options.
	* NEWS:  Mention new behaviour and command-line options.
	* pe-dll.c (pe_use_coff_long_section_names):  New global variable.
	(pe_output_file_set_long_section_names):  New function.
	(pe_dll_build_sections):  Call it on output BFDs.
	(pe_exe_build_sections):  Likewise.
	(pe_dll_fill_sections):  Likewise.
	(pe_exe_fill_sections):  Likewise.
	* pe-dll.h (pe_use_coff_long_section_names):  Declare extern.
	(pe_output_file_set_long_section_names):  Add prototype.
	* pep-dll.c (pe_use_coff_long_section_names):  Define pep_ alias.
	(pe_output_file_set_long_section_names):  Likewise.
	* pep-dll.h (pep_use_coff_long_section_names):  Declare extern.
	(pep_output_file_set_long_section_names):  Add prototype.
	* pe.em (OPTION_ENABLE_LONG_SECTION_NAMES):  New getopt value macro.
	(OPTION_DISABLE_LONG_SECTION_NAMES):  Likewise.
	(gld${EMULATION_NAME}_add_options):  Add new options to xtra_long[].
	(gld_${EMULATION_NAME}_list_options):  Describe them.
	(gld${EMULATION_NAME}_handle_option):  Set or clear global
	pe_use_coff_long_section_names flag when options recognised.
	(gld_${EMULATION_NAME}_after_open):  En/disable long section names
	for main output bfd by calling pe_output_file_set_long_section_names.
	* pep.em (enum options):  Extend enum with new getopt option values.
	(gld${EMULATION_NAME}_add_options):  Add new options to xtra_long[].
	(gld_${EMULATION_NAME}_list_options):  Describe them.
	(gld${EMULATION_NAME}_handle_option):  Set or clear global
	pe_use_coff_long_section_names flag when options recognised.
	(gld_${EMULATION_NAME}_after_open):  En/disable long section names
	for main output bfd by calling pep_output_file_set_long_section_names.

ld/testsuite/ChangeLog

	* ld-pe/longsecn-1.d:  New test file.
	* ld-pe/longsecn-2.d:  Likewise.
	* ld-pe/longsecn-3.d:  Likewise.
	* ld-pe/longsecn-4.d:  Likewise.
	* ld-pe/longsecn-5.d:  Likewise.
	* ld-pe/longsecn.d:  Likewise.
	* ld-pe/longsecn.exp:  New test control script.
	* ld-pe/longsecn.s:  New test source file.
-- 
[*] - see also for reference thread at
http://gcc.gnu.org/ml/gcc/2009-02/threads.html#00026, continued at
http://sourceware.org/ml/binutils/2009-02/threads.html#00010

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pe-long-section-names-patch-revised.diff
URL: <https://sourceware.org/pipermail/binutils/attachments/20090216/578726cd/attachment.ksh>


More information about the Binutils mailing list