This is the mail archive of the binutils@sources.redhat.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]
Other format: [Raw text]

[patch/RFC] ld/pe-dll.c: mark .reloc section as discardable unless building a relocatable dll


Hi,

{Charles, I am cc'ing you because of prior posts re: non-relocatable dll's) 

1) The patch to allow  pe .exe files to export symbols

http://sources.redhat.com/ml/binutils-cvs/2003-04/msg00024.html.

has changed the meaning of the -dll switch.

Previously, the -dll switch just set the image base to the dll default.  It did not
enable any of the relocatability magic.

In past, the -dll switch  could be use to produce a
non-relocatable dll with something like this:

$ dlltool --def code1.def --dllname dll1-nr.dll --output-lib libdll1.a --output-exp dll1.exp
$ gcc -mdll -o dll1-nr.dll dll1.exp code1.c

where the -mdll gcc switch passed this to ld:
--dll -e _DllMainCRTStartup@12

Now, the --dll switch does exactly the same thing as  --shared: it produces a
.reloc section and a relocatable dll

We can still change a relocatable dll to a non-relocatable one by
stripping the .reloc section, eg:
strip -R .reloc foo.dll, but this is not explicitly documented. 

2) The patch to allow .exe fills to export symbols also put a .reloc section
into .exe files that export symbols. As far as I can see, this .reloc
info is not needed for .exe's, and can be discarded with strip -R .reloc
with no adverse effects.

OK, the MS linker has a switch /FIXED which keeps, but flags the .reloc
section as MEM_DISCARDABLE when run in 'debug' mode, but strips the
.reloc section when run in 'release' mode. This allow testing and
tweaking of the image base whilst debugging, but optimisimg by
discarding the .reloc section for release. Also, when exporting symbols
from .exe files, , by default, the MS linker marks the .reloc section as
MEM_DISCARDABLE in debug mode, and strips the section in relaese mode. 

The following patch marks the .reloc section with the SEC_DEBUGGING flag
(equivalent to MEM_DISCARDABLE for pe targets) to make discarding of
.reloc sections  for  non-reloc .dlls and .exes easier, 

The exception (which is actually the most common case) is when building
a shared (relocatable) library.  In this case, there is no change of
behaviour and the reloc section is _not_ marked as discardable.

I have left the behavior of pe-dll.c:pe_exe_build_sections as is. i386-pe targets
no longer use this function. I am not familiar enough with other pe
targets to suggest that we should change the behaviour there as well,
but it can be changed independently, if needed.

An alternative would be to mark the .reloc section as SEC_EXCLUDE, when
_not_ building a shared library. However, at least one memory profiling
utility (Purify for Windows) actually depend on the presence of a
[discardable] .reloc section for instrumentation.

ChangeLog

	* pe-dll.c (build_filler_data): Add parameter discardable_reloc.
	Add SEC_DEBUGGING to section flags for .reloc section if
	discardable_reloc. 
	(pe_exe_build_sections): Call build_filler_data with
	discardable_reloc set to 0.
	(pe_dll_build_sections): Call build_filler_data with
	discardable_reloc set to !link_info.shared.

Index: pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.60
diff -c -3 -p -r1.60 pe-dll.c
*** pe-dll.c	17 Jul 2003 15:47:49 -0000	1.60
--- pe-dll.c	27 Jul 2003 08:32:12 -0000
*************** process_def_file (bfd *abfd ATTRIBUTE_UN
*** 744,752 ****
  /* Build the bfd that will contain .edata and .reloc sections.  */
  
  static void
! build_filler_bfd (int include_edata)
  {
    lang_input_statement_type *filler_file;
    filler_file = lang_add_input_file ("dll stuff",
  				     lang_input_file_is_fake_enum,
  				     NULL);
--- 744,754 ----
  /* Build the bfd that will contain .edata and .reloc sections.  */
  
  static void
! build_filler_bfd (int include_edata, int discardable_reloc)
  {
    lang_input_statement_type *filler_file;
+   flagword flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
+ 		    | SEC_KEEP | SEC_IN_MEMORY);
    filler_file = lang_add_input_file ("dll stuff",
  				     lang_input_file_is_fake_enum,
  				     NULL);
*************** build_filler_bfd (int include_edata)
*** 764,775 ****
      {
        edata_s = bfd_make_section_old_way (filler_bfd, ".edata");
        if (edata_s == NULL
! 	  || !bfd_set_section_flags (filler_bfd, edata_s,
! 				     (SEC_HAS_CONTENTS
! 				      | SEC_ALLOC
! 				      | SEC_LOAD
! 				      | SEC_KEEP
! 				      | SEC_IN_MEMORY)))
  	{
  	  einfo ("%X%P: can not create .edata section: %E\n");
  	  return;
--- 766,772 ----
      {
        edata_s = bfd_make_section_old_way (filler_bfd, ".edata");
        if (edata_s == NULL
! 	  || !bfd_set_section_flags (filler_bfd, edata_s, flags))
  	{
  	  einfo ("%X%P: can not create .edata section: %E\n");
  	  return;
*************** build_filler_bfd (int include_edata)
*** 778,790 ****
      }
  
    reloc_s = bfd_make_section_old_way (filler_bfd, ".reloc");
    if (reloc_s == NULL
!       || !bfd_set_section_flags (filler_bfd, reloc_s,
! 				 (SEC_HAS_CONTENTS
! 				  | SEC_ALLOC
! 				  | SEC_LOAD
! 				  | SEC_KEEP
! 				  | SEC_IN_MEMORY)))
      {
        einfo ("%X%P: can not create .reloc section: %E\n");
        return;
--- 775,787 ----
      }
  
    reloc_s = bfd_make_section_old_way (filler_bfd, ".reloc");
+ 
+   /* Allow .reloc section to be stripped. */
+   if (discardable_reloc) 
+     flags |= SEC_DEBUGGING;
+ 
    if (reloc_s == NULL
!       || !bfd_set_section_flags (filler_bfd, reloc_s, flags))
      {
        einfo ("%X%P: can not create .reloc section: %E\n");
        return;
*************** pe_dll_build_sections (bfd *abfd, struct
*** 2608,2621 ****
      return;
  
    generate_edata (abfd, info);
!   build_filler_bfd (1);
  }
  
  void
  pe_exe_build_sections (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
  {
    pe_dll_id_target (bfd_get_target (abfd));
!   build_filler_bfd (0);
  }
  
  void
--- 2605,2618 ----
      return;
  
    generate_edata (abfd, info);
!   build_filler_bfd (1, !info->shared);
  }
  
  void
  pe_exe_build_sections (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
  {
    pe_dll_id_target (bfd_get_target (abfd));
!   build_filler_bfd (0, 0);
  }
  
  void

http://personals.yahoo.com.au - Yahoo! Personals
-  New people, new possibilities! Try Yahoo! Personals, FREE for a limited period!


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