This is the mail archive of the binutils@sourceware.cygnus.com 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]

custom section alignment patch


Hello Ian, This patch changes coffcode.h to use a more managable 
way (well, at least I think so) to allow custom section alignments than 
the current if...else way currently used. It allows target-specific section 
alignments by adding them to the target- specific defined .c file rather 
than adding more code to coffcode.h. It can also be easily adapted for 
use by coff_set_alignment_hook. 

I put the new structure in libcoff-in.h and regenerated libcoff.h to test. If 
this is incorrect, I'll move it if need be. 

BTW, I changed my settings so the patch should go through without 
line wrapping. 

1999-07-27 Mark Elbrecht <snowball3@bigfoot.com> 

* libcoff-in.h (coff_section_alignment_entry): New structure.   
(COFF_SECTION_NAME_PARTIAL_MATCH): New macro.   
(COFF_SECTION_NAME_EXACT_MATCH): New macro.   
(COFF_ALIGNMENT_FIELD_EMPTY): New macro. 

* coffcode.h  (coff_new_section_alignment_table): New array. 
  (coff_new_section_alignment_table_size): New constant. 
  (coff_set_custom_section_alignment): New function. 
  (coff_new_section_hook): Use new function. Remove now redundant code. 


* coff-go32.c (TARGET_NEW_SECTION_ALIGNMENT_TABLE): Define macro. 
  coff-stgo32.c (TARGET_NEW_SECTION_ALIGNMENT_TABLE): Define macro. 


*** bfd/libcoff-in.h.orig	Sun Jul 25 17:40:42 1999 
--- bfd/libcoff-in.h	Tue Jul 27 17:34:58 1999 
*************** 
*** 1,7 **** 
  /* BFD COFF object file private structure. 
!    Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998 
     Free Software Foundation, Inc. 
     Written by Cygnus Support. 
  
  ** NOTE: libcoff.h is a GENERATED file.  Don't change it; instead, 
  ** change libcoff-in.h or coffcode.h. 
--- 1,7 ---- 
  /* BFD COFF object file private structure. 
!    Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999 
     Free Software Foundation, Inc. 
     Written by Cygnus Support. 
  
  ** NOTE: libcoff.h is a GENERATED file.  Don't change it; instead, 
  ** change libcoff-in.h or coffcode.h. 
*************** extern boolean _bfd_ppc_xcoff_relocate_s 
*** 527,534 **** 
--- 527,563 ---- 
     linker, and so should start with bfd and be declared in bfd.h.  */ 
  
  extern boolean ppc_allocate_toc_section PARAMS ((struct bfd_link_info *)); 
  extern boolean ppc_process_before_allocation 
    PARAMS ((bfd *, struct bfd_link_info *)); 
+ 
+ /* Helpers for handling sections with non-default alignment.  */ 
+ 
+ #define COFF_SECTION_NAME_EXACT_MATCH(name) name, ((unsigned int)-1) 
+ #define COFF_SECTION_NAME_PARTIAL_MATCH(name) name, (sizeof(name)-1) 
+ #define COFF_ALIGNMENT_FIELD_EMPTY ((unsigned int)-1) 
+ 
+ typedef struct 
+ { 
+   /* The name of the section.  */ 
+   const char *section_name; 
+ 
+   /* Set to COFF_SECTION_NAME_PARTIAL_MATCH (section_name) for a 
+      substring match. Otherwise set to COFF_SECTION_NAME_EXACT_MATCH.  */ 
+   const unsigned int comparison_length; 
+ 
+   /* The default section alignment must be at least this amount 
+      for a match.  You do not need to set this field if you use 
+      the macros mentioned above.  */ 
+   const unsigned int default_alignment_min; 
+ 
+   /* The default section alignment can be no greater than this amount 
+      for a match.  */ 
+   const unsigned int default_alignment_max; 
+ 
+   /* The non-default alignment if a match is found.  */ 
+   const unsigned int alignment_power; 
+ 
+ } coff_section_alignment_entry; 
  
  /* And more taken from the source .. */ 
  
*** bfd/coffcode.h.orig	Wed Jul 21 21:39:22 1999 
--- bfd/coffcode.h	Tue Jul 27 17:48:34 1999 
*************** coff_bad_format_hook (abfd, filehdr) 
*** 1051,1064 **** 
  #endif 
  
    return true; 
  } 
  
! /* 
!    initialize a section structure with information peculiar to this 
!    particular implementation of coff 
! */ 
  
  static boolean 
  coff_new_section_hook (abfd, section) 
       bfd * abfd; 
       asection * section; 
--- 1051,1143 ---- 
  #endif 
  
    return true; 
  } 
  
! /* Handle sections requiring custom alignment.  */ 
! 
! static boolean 
! coff_set_custom_section_alignment (section, alignment_table, table_size) 
!      asection * section; 
!      CONST coff_section_alignment_entry alignment_table[]; 
!      CONST unsigned int table_size; 
! { 
!   int i; 
!   CONST unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER; 
! 
!   /* Find a partial or exact match, depending on the macro used to 
!      initialize a particular record. The comparison_length field will 
!      contain the minimum length required for a partial match, or an 
!      impossibly high number for an exact match.  */ 
!   for (i = 0; i < table_size; i++) 
!   { 
!     if (strncmp (section->name, alignment_table[i].section_name, 
!                  alignment_table[i].comparison_length) == 0) 
!       break; 
!   } 
! 
!   if (i == table_size) 
!     return false; 
! 
!   /* The default alignment must be greater than or equal to 
!      default_alignment_min (if set).  */ 
!   if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY) 
!     if (!(default_alignment >= alignment_table[i].default_alignment_min)) 
!       return false; 
! 
!   /* The default alignment must be less than or equal to 
!      default_alignment_max (if set).  */ 
!   if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY) 
!     if (!(default_alignment <= alignment_table[i].default_alignment_max)) 
!       return false; 
! 
!   section->alignment_power = alignment_table[i].alignment_power; 
!   return true; 
! } 
! 
! /* Initialize the table containing the alignment records. 
!    The .stab section must be aligned to 2**2 at most, because 
!    otherwise there may be gaps in the section which gdb will not 
!    know how to interpret.  Examining the section name is a hack, but 
!    that is also how gdb locates the section. 
!    We need to handle the .ctors and .dtors sections similarly, to 
!    avoid introducing null words in the tables. 
!    Similarly, the .stabstr section must be aligned to 2**0 at most. 
! 
!    A target can define TARGET_NEW_SECTION_ALIGNMENT_TABLE to enable 
!    target-specific section alignments when creating a new section. 
!    See coff-go32.c for an example of how to define the macro. 
! 
!    Each entry is a structure of type coff_section_alignment_entry 
!    defined in libcoff-in.h.  */ 
! 
! static CONST 
! coff_section_alignment_entry 
! coff_new_section_alignment_table[] = 
! { 
! #ifdef TARGET_NEW_SECTION_ALIGNMENT_TABLE 
!   TARGET_NEW_SECTION_ALIGNMENT_TABLE 
! #endif 
!   { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"), 
!     1, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, 
!   { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"), 
!     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, 
!   { COFF_SECTION_NAME_EXACT_MATCH (".ctors"), 
!     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, 
!   { COFF_SECTION_NAME_EXACT_MATCH (".dtors"), 
!     3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, 
! }; 
! 
! /* Set the table size.  */ 
! 
! static CONST unsigned int 
! coff_new_section_alignment_table_size = 
!   sizeof(coff_new_section_alignment_table) 
!   / sizeof(coff_new_section_alignment_table[0]); 
! 
! /* Initialize a section structure with information peculiar to this 
!    particular implementation of COFF.  */ 
  
  static boolean 
  coff_new_section_hook (abfd, section) 
       bfd * abfd; 
       asection * section; 
*************** coff_new_section_hook (abfd, section) 
*** 1095,1120 **** 
    native->u.syment.n_type = T_NULL; 
    native->u.syment.n_sclass = C_STAT; 
  
    coffsymbol (section->symbol)->native = native; 
  
!   /* The .stab section must be aligned to 2**2 at most, because 
!      otherwise there may be gaps in the section which gdb will not 
!      know how to interpret.  Examining the section name is a hack, but 
!      that is also how gdb locates the section. 
!      We need to handle the .ctors and .dtors sections similarly, to 
!      avoid introducing null words in the tables.  */ 
!   if (COFF_DEFAULT_SECTION_ALIGNMENT_POWER > 2 
!       && (strncmp (section->name, ".stab", 5) == 0 
! 	  || strcmp (section->name, ".ctors") == 0 
! 	  || strcmp (section->name, ".dtors") == 0)) 
!     section->alignment_power = 2; 
! 
!   /* Similarly, the .stabstr section must be aligned to 2**0 at most.  */ 
!   if (COFF_DEFAULT_SECTION_ALIGNMENT_POWER > 0 
!       && strncmp (section->name, ".stabstr", 8) == 0) 
!     section->alignment_power = 0; 
  
    return true; 
  } 
  
  #ifdef COFF_ALIGN_IN_SECTION_HEADER 
--- 1174,1186 ---- 
    native->u.syment.n_type = T_NULL; 
    native->u.syment.n_sclass = C_STAT; 
  
    coffsymbol (section->symbol)->native = native; 
  
!   coff_set_custom_section_alignment (section, 
!                                      coff_new_section_alignment_table, 
!                                      coff_new_section_alignment_table_size); 
  
    return true; 
  } 
  
  #ifdef COFF_ALIGN_IN_SECTION_HEADER 
*** bfd/coff-go32.c.orig	Thu Jul 22 09:10:38 1999 
--- bfd/coff-go32.c	Tue Jul 27 11:40:26 1999 
*************** Foundation, Inc., 59 Temple Place - Suit 
*** 22,27 **** 
--- 22,39 ---- 
  #define TARGET_NAME		"coff-go32" 
  #define TARGET_UNDERSCORE	'_' 
  #define COFF_LONG_SECTION_NAMES 
  #define COFF_SUPPORT_GNU_LINKONCE 
  
+ #define TARGET_NEW_SECTION_ALIGNMENT_TABLE \ 
+ { COFF_SECTION_NAME_EXACT_MATCH (".data"), \ 
+   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 (".gnu.linkonce.d"), \ 
+   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \ 
+ { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.t"), \ 
+   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \ 
+ { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.r"), \ 
+   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, 
+ 
  #include "coff-i386.c" 
*** bfd/coff-stgo32.c.orig	Thu Jul 22 00:11:10 1999 
--- bfd/coff-stgo32.c	Tue Jul 27 11:40:32 1999 
*************** 
*** 40,49 **** 
--- 40,55 ---- 
  #define TARGET_UNDERSCORE	'_' 
  #define COFF_GO32_EXE 
  #define COFF_LONG_SECTION_NAMES 
  #define COFF_SUPPORT_GNU_LINKONCE 
  
+ #define TARGET_NEW_SECTION_ALIGNMENT_TABLE \ 
+ { COFF_SECTION_NAME_EXACT_MATCH (".data"), \ 
+   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \ 
+ { COFF_SECTION_NAME_EXACT_MATCH (".text"), \ 
+   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, 
+ 
  #include "bfd.h" 
  
  /* At first the prototypes */ 
  
  static void 


--- 
Mark Elbrecht, snowball3@bigfoot.com
http://snowball.frogspace.net/

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