arm-wince-pe support resurrection

Nick Clifton nickc@redhat.com
Thu Dec 11 17:54:00 GMT 2003
Hi Dmitry,

  [Sorry about the delay in replying - I have been caught up in all
  kinds of work here].

> With my patch applied the warnings are gone away.

I see - that makes things a lot clearer.  I think that your approach
is OK, but it does not go far enough.  The PE spec mandates the
section flags for quite a few sections, not just the ones you
covered.  So how about this alternative patch (attached) ?  Would you
mind trying it out and letting me know if it works ?

> Although there could be still a source of possible problem --
> alignment is not set inside the section flags by bfd.

Hmm - since at the moment we do not appear to be setting the alignment
for any sections adding the necessary flags in would probably not
hurt.  I wonder if we can deduce the alignment based on the target ?
I suspect that 4byte alignment is going to be the default for the
.text section of most targets, so we may be able to just set that
along with the other flags and then only modify if necessary for
individual targets.

Cheers
        Nick

Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.19
diff -c -3 -p -r1.19 peXXigen.c
*** bfd/peXXigen.c	30 Nov 2003 18:40:41 -0000	1.19
--- bfd/peXXigen.c	11 Dec 2003 17:47:54 -0000
*************** _bfd_XXi_swap_scnhdr_out (abfd, in, out)
*** 953,964 ****
       (0x02000000).  Also, the resource data should also be read and
       writable.  */
  
!   /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
!   /* FIXME: even worse, I don't see how to get the original alignment field*/
!   /*        back...                                                        */
! 
    {
      int flags = scnhdr_int->s_flags;
  
      H_PUT_32 (abfd, flags, scnhdr_ext->s_flags);
    }
--- 953,1001 ----
       (0x02000000).  Also, the resource data should also be read and
       writable.  */
  
!   /* FIXME: alignment is also encoded in this field, at least on PPC and
!      ARM-WINCE.  */
!   /* FIXME: even worse, I don't see how to get the original alignment
!      field back ...  */
    {
+     /* The PE File Format specification mandates certain flags
+        for certain sections.  This is encoded in this array.  */
+     typedef struct
+     {
+       const char * 	name;
+       unsigned long	must_have;
+     }
+     pe_section_flags;
+     
+     pe_section_flags known_sections [] =
+       {
+ 	{ ".arch",  IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE | IMAGE_SCN_ALIGN_8BYTES },
+ 	{ ".bss",   IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE },
+ 	{ ".data",  IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE },
+ 	{ ".edata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ },
+ 	{ ".idata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE },
+ 	{ ".pdata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ },
+ 	{ ".rdata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ },
+ 	{ ".reloc", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE },
+ 	{ ".rsrc",  IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE },
+ 	{ ".text" , IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ },
+ 	{ ".tls",   IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE },
+ 	{ ".xdata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ },
+ 	{ NULL, 0}
+       };
+ 
+     pe_section_flags * p;
      int flags = scnhdr_int->s_flags;
+ 
+     for (p = known_sections; p->name; p++)
+       if (strcmp (scnhdr_int->s_name, p->name) == 0)
+ 	{
+ 	  /* We have defaulted to adding the IMAGE_SCN_MEM_WRITE flag, but now
+ 	     we know that this specific section may or may not want this flag.  */
+ 	  flags &= ~IMAGE_SCN_MEM_WRITE;
+ 	  flags |= p->must_have;
+ 	  break;
+ 	}
  
      H_PUT_32 (abfd, flags, scnhdr_ext->s_flags);
    }
        



More information about the Binutils mailing list