This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/PE-COFF] Translate required alignment into IMAGE_SCN_ALIGN bits of object s_flags - Take 2


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


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.

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


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.

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.

Index: gas/read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.133
diff -c -3 -p -r1.133 read.c
*** gas/read.c	17 Oct 2007 16:45:54 -0000	1.133
--- gas/read.c	23 Oct 2007 02:41:34 -0000
*************** do_align (int n, char *fill, int len, in
*** 1276,1288 ****
     (in bytes).  A negative ARG is the negative of the length of the
     fill pattern.  BYTES_P is non-zero if the alignment value should be
     interpreted as the byte boundary, rather than the power of 2.  */
! 
! #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
  
  static void
  s_align (int arg, int bytes_p)
  {
!   unsigned int align_limit = ALIGN_LIMIT;
    unsigned int align;
    char *stop = NULL;
    char stopc = 0;
--- 1276,1289 ----
     (in bytes).  A negative ARG is the negative of the length of the
     fill pattern.  BYTES_P is non-zero if the alignment value should be
     interpreted as the byte boundary, rather than the power of 2.  */
! #ifndef TC_ALIGN_LIMIT
! #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
! #endif
  
  static void
  s_align (int arg, int bytes_p)
  {
!   unsigned int align_limit = TC_ALIGN_LIMIT;
    unsigned int align;
    char *stop = NULL;
    char stopc = 0;
Index: gas/config/tc-i386.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.h,v
retrieving revision 1.92
diff -c -3 -p -r1.92 tc-i386.h
*** gas/config/tc-i386.h	26 Sep 2007 08:34:24 -0000	1.92
--- gas/config/tc-i386.h	23 Oct 2007 02:41:35 -0000
*************** extern int x86_64_section_letter (int, c
*** 343,348 ****
--- 343,349 ----
  
  #define TC_DWARF2_EMIT_OFFSET  tc_pe_dwarf2_emit_offset
  void tc_pe_dwarf2_emit_offset (symbolS *, unsigned int);
+ #define TC_ALIGN_LIMIT 13 /* corresponding to
IMAGE_SCN_ALIGN_8192BYTES  */
  
  #endif /* TE_PE */
  
Index: include/coff/pe.h
===================================================================
RCS file: /cvs/src/src/include/coff/pe.h,v
retrieving revision 1.17
diff -c -3 -p -r1.17 pe.h
*** include/coff/pe.h	2 Aug 2007 16:02:01 -0000	1.17
--- include/coff/pe.h	23 Oct 2007 02:41:45 -0000
***************
*** 90,95 ****
--- 90,99 ----
  #define IMAGE_SCN_ALIGN_4096BYTES	     IMAGE_SCN_ALIGN_POWER_CONST
(12)
  #define IMAGE_SCN_ALIGN_8192BYTES	     IMAGE_SCN_ALIGN_POWER_CONST
(13)
  
+ /* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags */
+ #define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
+   ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST
((ALIGNMENT_POWER)))
+ 
  #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section
contains extended relocations. */
  #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is
not cachable.               */
  #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  /* Section is
not pageable.               *


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]