[PATCH/PE-COFF] Encode required alignment into IMAGE_SCN_ALIGN bits of object s_flags - Take 3
Danny Smith
dansmister@gmail.com
Sun Nov 4 21:55:00 GMT 2007
This is a revised version of the patch I submitted earlier.
http://sourceware.org/ml/binutils/2007-10/msg00294.html
The prior patch failed to check if the alignment power fell within valid
range for PE-COFF target,
To recap the earlier message:
Given an alignment >16-bytes, eg
.file "foo.c"
.data
.globl _x
.align 32
_x:
.long 1065353216
.space 28
gas for PE-COFF targets fails to set section alignment flags correctly,
but always uses default. So
as foo.s | objdump -x gives
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000000 00000000 00000000 00000000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000020 00000000 00000000 0000008c 2**4
ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000000 2**4
ALLOC
See also the thread
Re: Fwd: ALIGNOF fails on cygwin at:
http://sourceware.org/ml/binutils/2007-07/msg00014.html
The attached fixs by encoding the section alignment_power into the
appropriate bits of the IMAGE_SCN_ALIGN s_flags using the macro
COFF_ENCODE_ALIGNMENT, defined in coff/pe.h.
Since, now we can pad only as needed, the hardcoded
COFF_SECTION_ALIGNMENT_ENTRIES bfd/pe[i]-i386.c can revert back to the
default.
After this patch we get
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000000 00000000 00000000 00000000 2**2
ALLOC, LOAD, READONLY, CODE
1 .data 00000020 00000000 00000000 0000008c 2**5
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000000 2**2
ALLOC
In addition, it modifies gas/read.c to enable non-default alignment
limits to be checked. The appropriate p2align limit for i386-pe is
defined for TE_PE in config/tc-i386.h as 13, corresponding to the
largest documented PE section alignment flag,IMAGE_SCN_ALIGN_8192BYTE.
No regressions after in-tree combined build of mingw-targeted
binutils/gcc.
The two testcases in ld-scripts/align.exp and alignof.exp now pass
include/ChangeLog
2007-10-24 Danny Smith <dannysmith@users.sourceforge.net>
* coff/pe.h (COFF_ENCODE_ALIGNMENT) Define.
gas/ChangeLog
* read.c (ALIGN_LIMIT): Rename to ...
(TC_ALIGN_LIMIT): Guard against prior definition.
* config/tc-i386.h (TC_ALIGN_LIMIT)[TE_PE]: Define.
bfd/ChangeLog
* pe-i386.c (COFF_SECTION_ALIGNMENT_ENTRIES): Let .data, .text
and .bss section use the default.
* pei-i386.c (COFF_SECTION_ALIGNMENT_ENTRIES): Likewise.
ld/testsuite/ChangeLog
* ld-scripts/align.exp: Enable for PECOFF.
* ld-scripts/alignof.exp: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: align.diff
Type: text/x-patch
Size: 3815 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20071104/e141b717/attachment.bin>
More information about the Binutils
mailing list