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]

Re: [PATCH/PE-COFF] Encode required alignment into IMAGE_SCN_ALIGN bits of object s_flags - Take 3


Sorry.  This time with correct attachment

On 11/5/07, Danny Smith <dansmister@gmail.com> wrote:
> 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.
>
>
Index: bfd/pe-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/pe-i386.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 pe-i386.c
*** bfd/pe-i386.c	3 Jul 2007 14:26:42 -0000	1.13
--- bfd/pe-i386.c	4 Nov 2007 21:47:40 -0000
***************
*** 32,51 ****
  #define COFF_LONG_FILENAMES
  
  #define COFF_SECTION_ALIGNMENT_ENTRIES \
- { COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".data"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".data$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".rdata"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".rdata$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".text"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".text$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  { COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
    COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
  { COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
--- 32,37 ----
Index: bfd/pei-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-i386.c,v
retrieving revision 1.12
diff -c -3 -p -r1.12 pei-i386.c
*** bfd/pei-i386.c	3 Jul 2007 14:26:42 -0000	1.12
--- bfd/pei-i386.c	4 Nov 2007 21:47:40 -0000
***************
*** 33,52 ****
  #define COFF_LONG_FILENAMES
  
  #define COFF_SECTION_ALIGNMENT_ENTRIES \
- { COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".data"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".data$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".rdata"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".rdata$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_EXACT_MATCH (".text"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
- { COFF_SECTION_NAME_PARTIAL_MATCH (".text$"), \
-   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  { COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
    COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
  { COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
--- 33,38 ----
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	4 Nov 2007 21:48:06 -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.93
diff -c -3 -p -r1.93 tc-i386.h
*** gas/config/tc-i386.h	1 Nov 2007 18:40:53 -0000	1.93
--- gas/config/tc-i386.h	4 Nov 2007 21:48:09 -0000
*************** extern int x86_64_section_letter (int, c
*** 344,349 ****
--- 344,350 ----
  
  #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	4 Nov 2007 21:48:17 -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: ld/testsuite/ld-scripts/align.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/align.exp,v
retrieving revision 1.11
diff -c -3 -p -r1.11 align.exp
*** ld/testsuite/ld-scripts/align.exp	6 Jul 2007 14:09:45 -0000	1.11
--- ld/testsuite/ld-scripts/align.exp	4 Nov 2007 21:48:27 -0000
*************** global LDFLAGS
*** 38,48 ****
  set saved_LDFLAGS "$LDFLAGS"
  if [istarget "x86_64-*-mingw*"] then {
    set LDFLAGS "$LDFLAGS --image-base 0"
- } else {
-   if [is_pecoff_format] {
-   global target_triplet
-   setup_xfail $target_triplet
-   }
  }
  
  if ![ld_simple_link $ld tmpdir/align "$LDFLAGS -T $srcdir/$subdir/align.t tmpdir/align.o"] {
--- 38,43 ----
Index: ld/testsuite/ld-scripts/alignof.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/alignof.exp,v
retrieving revision 1.3
diff -c -3 -p -r1.3 alignof.exp
*** ld/testsuite/ld-scripts/alignof.exp	6 Jul 2007 14:09:45 -0000	1.3
--- ld/testsuite/ld-scripts/alignof.exp	4 Nov 2007 21:48:27 -0000
***************
*** 19,27 ****
  # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  # MA 02110-1301, USA.
  
! # Only ELF targets record section alignment.
  
! if ![is_elf_format] {
      return
  }
  
--- 19,27 ----
  # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  # MA 02110-1301, USA.
  
! # Only ELF and PE-COFF targets record section alignment.
  
! if {![is_elf_format] && ![is_pecoff_format]} {
      return
  }

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