Re: MingW + GCC 4.5.2 + Relocate libpq.dll = SegFault - Mailing list pgsql-hackers

From Pavel Golub
Subject Re: MingW + GCC 4.5.2 + Relocate libpq.dll = SegFault
Date
Msg-id 1234245616.20110118114541@gf.microolap.com
Whole thread Raw
In response to MingW + GCC 4.5.2 + Relocate libpq.dll = SegFault  (Charlie Savage <cfis@interserv.com>)
List pgsql-hackers
Hello, Charlie.

Can you please express your opinion about my request "Warning
compiling pg_dump (MinGW, Windows XP)" to pgsql-hackers on Thu, 13 Jan
2011. Do you have the same warnings using MinGW environment?

You wrote:

CS> I'm compiling postgresql 9.0.2 using msys + mingw + gcc 4.5.2 (latest 
CS> official release from mingw).  This is on Windows 7 64-bit.

CS> Unfortunately the built dlls, at least libpq.dll, crash if they need to
CS> be relocated.  This happens to me when loading libpq.dll into a project
CS> that has a number of other dll requirements.  Note this does NOT happen
CS> when building with gcc 3.4.5.

CS> Using GDB to track down the problem, the error occurs in 
CS> __gcc_register_frame and looks to be the same error described here:

CS> http://old.nabble.com/Bad-DLL-relocation---reproducible-w--test-case-td18292380.html

CS> Note a similar sounding error described, and fixed, in newer releases of
CS> binutils (which mingw provides and I am using) is described here:

CS> http://lists-archives.org/mingw-users/11369-error-0xc0000005-is-now-fixed.html

CS> Looking at the postgresql Makefiles, the dlls are built using dllwrap.
CS> In particular, see src/Makefile.shlib line 413 and src/Makefile.port 
CS> line 25.

CS> When I change these to not use dllwrap and instead just use gcc -shared
CS> the problem goes away.  Therefore I'd like to propose:

CS> 1.  Change line 413 in src/Makefile.shlib

CS> $(DLLWRAP) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def 
CS> $(DLL_DEFFILE) $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)

CS> To:

CS> $(CC) -shared -o $@ $(DLL_DEFFILE) $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) 
CS> $(SHLIB_LINK)

CS> 2.  Changle line 73 in src/Makefile.port:

CS> $(DLLWRAP) -o $@ --def $*.def $< $(LDFLAGS) $(LDFLAGS_SL) $(BE_DLLLIBS)

CS> To:

CS> $(CC) -shared -o $@ $*.def $< $(LDFLAGS) $(LDFLAGS_SL) $(BE_DLLLIBS)

CS> I tested this by intentionally compiling libpq.dll using the link flag
CS> -Wl,--image-base to make sure that its base address conflicted with 
CS> another dll loaded by my program.  With the proposed changes, windows 
CS> successfully relocated libpq.dll without causing a segmentation fault.

CS> I don't claim to know why dllwrap is producing dlls that can't be 
CS> relocated while gcc -shared is.  But it appears to have been deprecated
CS> back in 2006 according to the binutils mailing list:

CS> http://www.mail-archive.com/bug-binutils@gnu.org/msg01470.html

CS> So between being deprecated and not producing relocatable dlls, it seems
CS> like its best to stop using dllwrap.  If this seems like a reasonable 
CS> change I can put together a quick patch if that helps.

CS> Thanks,

CS> Charlie




-- 
With best wishes,Pavel                          mailto:pavel@gf.microolap.com



pgsql-hackers by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: REVIEW: Extensions support for pg_dump
Next
From: Fujii Masao
Date:
Subject: Re: pg_basebackup for streaming base backups