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]

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


 --- Christopher Faylor <cgf@redhat.com> wrote: > On Sun, Jul 27, 2003 at 08:04:56PM +1000, Danny
Smith wrote:
> >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.
> 
> Hmm.  Does this mean that exes can't be relocatable?  I could see a
> reason to make an exe which exports symbols relocatable in the off
> chance that you wanted to use the exe as a dll and reference symbols in
> the exe as you would for a DLL.  It's a very uncommon usage but it seems
> like this patch would get rid of that.  Do the MS tools allow anything
> like this?  It's been a while since I read the link documentation.
> 

There is /FIXED:NO which always builds a .reloc section 
(I think even if there are no exports).  However, this also seems to mark
the .reloc section as discardable.

> >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, 
> 
> Does the effect of this patch mean that normal stripping (which removes
> debug info) will make the DLL non-relocatable?
> 

If the DLL was built with --shared,  the .reloc section is not marked as discardable.
The patch only effects .exe files and dll's built with --dll switch.  

Uh, oh, I see the  problem now.  Some makefiles (eg the mingw runtime rule for
libmingwm10.dll)and libtool still use the 'old' way of building relocatable dll's
with dlltool. eg

gcc -s -Wl,--base-file,mydll.base -o mydll.dll mydll.o -Wl,-e,_mydll_init@12 
dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp --dllname mydll.dll
gcc -s -Wl,--base-file,mydll.base,mydll.exp -o mydll.dll mydll.o -Wl,-e,_mydll_init@12
dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp --dllname mydll.dll
gcc -Wl,mydll.exp -o mydll.dll mydll.o -Wl,-e,_mydll_init@12

or the equivalent using --dll switch.

So I see where my patch will cause problems. I withdraw it.

Perhaps a new switch (--discardable-pe-dll-relocs) could be introduced and
build_filler_bfd would use that?

I suppose --strip -R .reloc isn't too hard, so maybe we just need to
document how to build  a non-relocatable dll now using that.
Also need to note the fact that the gcc -mdll switch is now effectiveley
the same as -shared. 


Danny
Danny

> cgf 


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]