Patchwork [i386] : always allow for pe-coff that relocations can be put into readonly memory

login
register
mail settings
Submitter Kai Tietz
Date June 27, 2012, 7:47 p.m.
Message ID <CAEwic4ZT4MGh4qvo5ycSsz-3dt43irqVP6F7QQYBW1fEOx+-Kg@mail.gmail.com>
Download mbox | patch
Permalink /patch/167733/
State New
Headers show

Comments

Kai Tietz - June 27, 2012, 7:47 p.m.
Hello,

this patch makes sure that for pe(+)-coff targets always relocations
are allowed in readonly memory.
This fixes for x86_64-w64-mingw32 target some testcases.

ChangeLog

2012-06-27  Kai Tietz

	* config/i386/winnt.c (i386_pe_reloc_rw_mask): New function.
	* config/i386/i386-protos.h (i386_pe_reloc_rw_mask): Add
	prototype.
	* config/i386/cygming.h (TARGET_ASM_RELOC_RW_MASK): Define
	as i386_pe_reloc_rw_mask.

Tested for i686-pc-cygwin, i686-w64-mingw32, and x86_64-w64-mingw32.
Ok for apply?

Regards,
Kai
Richard Henderson - June 27, 2012, 8:13 p.m.
On 06/27/2012 12:47 PM, Kai Tietz wrote:
> 2012-06-27  Kai Tietz
> 
> 	* config/i386/winnt.c (i386_pe_reloc_rw_mask): New function.
> 	* config/i386/i386-protos.h (i386_pe_reloc_rw_mask): Add
> 	prototype.
> 	* config/i386/cygming.h (TARGET_ASM_RELOC_RW_MASK): Define
> 	as i386_pe_reloc_rw_mask.
> 
> Tested for i686-pc-cygwin, i686-w64-mingw32, and x86_64-w64-mingw32.
> Ok for apply?

Plausible.

I suppose this gets handled by the windows loader similar to how
the .data.ro sections get handled by an elf loader with -z relro?
I.e. relocations applied then the page protections reapplied?

Would it be of any use to introduce an .rdata$N section (equivalent
to .data.ro) so that most of the runtime relocations are adjacent,
and more of the executable image is sharable?


r~
Mike Stump - June 27, 2012, 11:50 p.m.
On Jun 27, 2012, at 1:13 PM, Richard Henderson wrote:
> Would it be of any use to introduce an .rdata$N section (equivalent
> to .data.ro) so that most of the runtime relocations are adjacent,
> and more of the executable image is sharable?

I can't help but think that grouping them together would be a win, provided the relocations are allowed...  I know on darwin, we kinda hate those sorts of relocations because they are a performance sap.  This type of performance sap is nasty as it is pervasive and invisible and hard to ever get back.  Would be nice to ensure any change applied doesn't hurt performance...
Kai Tietz - June 28, 2012, 5:41 a.m.
2012/6/27 Richard Henderson <rth@redhat.com>:
> On 06/27/2012 12:47 PM, Kai Tietz wrote:
>> 2012-06-27  Kai Tietz
>>
>>       * config/i386/winnt.c (i386_pe_reloc_rw_mask): New function.
>>       * config/i386/i386-protos.h (i386_pe_reloc_rw_mask): Add
>>       prototype.
>>       * config/i386/cygming.h (TARGET_ASM_RELOC_RW_MASK): Define
>>       as i386_pe_reloc_rw_mask.
>>
>> Tested for i686-pc-cygwin, i686-w64-mingw32, and x86_64-w64-mingw32.
>> Ok for apply?
>
> Plausible.
>
> I suppose this gets handled by the windows loader similar to how
> the .data.ro sections get handled by an elf loader with -z relro?
> I.e. relocations applied then the page protections reapplied?

Correct.

> Would it be of any use to introduce an .rdata$N section (equivalent
> to .data.ro) so that most of the runtime relocations are adjacent,
> and more of the executable image is sharable?

Sounds interesting from perspective of startup-speed.  I wouldn't
assume that it has much effect on memory-saving.  But to check this,
is subject of different patch, but II will give it a try.

> r~

Kai

Patch

Index: config/i386/winnt.c
===================================================================
--- config/i386/winnt.c	(revision 189009)
+++ config/i386/winnt.c	(working copy)
@@ -421,6 +421,14 @@ 
   DECL_SECTION_NAME (decl) = build_string (len, string);
 }

+/* Local and global relocs can be placed always into readonly memory for
+   memory for PE-COFF targets.  */
+int
+i386_pe_reloc_rw_mask (void)
+{
+  return 0;
+}
+
 /* Select a set of attributes for section NAME based on the properties
    of DECL and whether or not RELOC indicates that DECL's initializer
    might contain runtime relocations.
Index: config/i386/i386-protos.h
===================================================================
--- config/i386/i386-protos.h	(revision 189009)
+++ config/i386/i386-protos.h	(working copy)
@@ -264,6 +264,8 @@ 
 extern bool i386_pe_type_dllimport_p (tree);
 extern bool i386_pe_type_dllexport_p (tree);

+extern int i386_pe_reloc_rw_mask (void);
+
 extern rtx maybe_get_pool_constant (rtx);

 extern char internal_label_prefix[16];
Index: config/i386/cygming.h
===================================================================
--- config/i386/cygming.h	(revision 189009)
+++ config/i386/cygming.h	(working copy)
@@ -225,6 +225,11 @@ 

 #define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info

+/* Local and global relocs can be placed always into readonly memory
+   for PE-COFF targets.  */
+#undef TARGET_ASM_RELOC_RW_MASK
+#define TARGET_ASM_RELOC_RW_MASK i386_pe_reloc_rw_mask
+
 /* Output a common block.  */
 #undef ASM_OUTPUT_ALIGNED_DECL_COMMON
 #define ASM_OUTPUT_ALIGNED_DECL_COMMON \