This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH/PE-COFF] Translate required alignment into IMAGE_SCN_ALIGN bits of object s_flags
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: Binutils <binutils at sourceware dot org>
- Date: Sun, 21 Oct 2007 22:21:26 +1300
- Subject: [PATCH/PE-COFF] Translate required alignment into IMAGE_SCN_ALIGN bits of object s_flags
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 the hard-coded defaults in
COFF_SECTION_ALIGNMENT_ENTRIES in
bfd/pe-i386. 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
The attached patch fixes by translating the section align_power into the
appropriate bits of the IMAGE_SCN s_flags.
After this patch we get
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000000 00000000 00000000 00000000 2**4
ALLOC, LOAD, READONLY, CODE
1 .data 00000020 00000000 00000000 0000008c 2**5
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000000 2**4
ALLOC
With this patch, we could also reduce some of the default alignment
powers in COFF_SECTION_ALIGNMENT_ENTRIES to their pre-SSE-era values,
since now they will get adjusted upward as necessary.
No regressions after in-tree combined build of mingw-targeted
binutils/gcc. The gcc build incorporated the patch to remove
restrictions on BIGGEST_FIELD_ALIGNMENT
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33774)
bfd/ChangeLog
2007-10-21 Danny Smith <dannysmith@users.sourceforge.net>
* coffcode.h (coff_write_object_contents)[COFF_WITH_PE]:
Translate alignment power into IMAGE_SCN_ALIGN bits of s_flags.
Index: coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.142
diff -c -3 -p -r1.142 coffcode.h
*** coffcode.h 2 Aug 2007 16:02:01 -0000 1.142
--- coffcode.h 21 Oct 2007 09:04:08 -0000
*************** coff_write_object_contents (bfd * abfd)
*** 3589,3594 ****
--- 3589,3600 ----
#ifdef COFF_ENCODE_ALIGNMENT
COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
#endif
+ #ifdef COFF_WITH_PE
+ /* Translate alignment power into IMAGE_SCN_ALIGN bits
+ of s_flags */
+ section.s_flags |=
+ IMAGE_SCN_ALIGN_POWER_CONST (current->alignment_power & 0xF);
+ #endif
#ifdef COFF_IMAGE_WITH_PE
/* Suppress output of the sections if they are null. ld