PATCH to gas:Fix handling of 'shared' data sections for PE targets

Danny Smith danny_r_smith_2001@yahoo.co.nz
Sat Oct 26 21:41:00 GMT 2002


The shared variable attribute in gcc for PE targets is broken by the way gas
handles the 's' flag.

With the following example, adapted from gcc's extend.texi,

#include <stdio.h>

int foo __attribute__((section ("bar"), shared)) = 0;

main()
{
  ++foo;
  printf("%d copies of shared.exe have been loaded", foo);
  for (;;) {}
   
}

gcc -S produces:

.globl _foo
	.section	bar,"ws"
	.align 4


So far okay.

However, gas produces the following section header for 'ws' flags


  3 bar           00000004  00000000  00000000  000000e4  2**2
                  CONTENTS, SHARED


Although the code compiles into an executable, the image is not recognized as
valid by the OS.


Changing the 'ws' flag to 'w'  produces valid object

  3 bar           00000004  00000000  00000000  000000e4  2**2
                  CONTENTS, ALLOC, LOAD, DATA

because 'w' alone sets to TC_COFF_SECTION_DEFAULT_ATTRIBUTES, which is
(SEC_LOAD | SEC_DATA)


The following patch fixes, producing

 3 bar           00000004  00000000  00000000  000000e4  2**2
                  CONTENTS, ALLOC, LOAD, DATA, SHARED

and an executable that does the right thing.

Danny

2002-10-27  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/obj-coff.c (obj-coff-section): Set SEC_DATA and
	SEC_LOAD flags for sections marked as 's'.


--- obj-coff.c.orig	Sun Sep 29 04:24:01 2002
+++ obj-coff.c	Sun Oct 27 04:00:50 2002
@@ -1465,12 +1465,12 @@ obj_coff_section (ignore)
 		{
 		case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
 		case 'n': flags &=~ SEC_LOAD; flags |= SEC_NEVER_LOAD; break;
+		case 's': flags |= SEC_SHARED; /* fall through */
 		case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */
 		case 'w': flags &=~ SEC_READONLY; break;
 		case 'a': break; /* For compatability with ELF.  */
 		case 'x': flags |= SEC_CODE | SEC_LOAD; break;
 		case 'r': flags |= SEC_READONLY; break;
-		case 's': flags |= SEC_SHARED; break;
 
 		case 'i': /* STYP_INFO */
 		case 'l': /* STYP_LIB */


http://careers.yahoo.com.au - Yahoo! Careers
- 1,000's of jobs waiting online for you!



More information about the Binutils mailing list