public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* seg fault on override of a weak symbol in g++
@ 2014-08-04 21:09 Keith Clifford
  0 siblings, 0 replies; only message in thread
From: Keith Clifford @ 2014-08-04 21:09 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 4577 bytes --]

Hi,
I was trying to build the ppl 1.1 library and got a seg fault when running
one of the tests. I've narrowed it down to the attached test case.

System: CYGWIN_NT-6.1 Keith-PC 1.7.31(0.272/5/3) 2014-07-25 11:26 x86_64
Cygwin

Both the following GCC's exhibit the problem Cygwin:
Using built-in specs.
COLLECT_GCC=i686-pc-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-mingw32/4.7.3/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with:
/usr/src/packages/mingw-gcc/64/mingw-gcc-4.7.3-1/src/gcc-4.7.3/configure
--srcdir=/usr/src/packages/mingw-gcc/64/mingw-gcc-4.7.3-1/src/gcc-4.7.3
--prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var
--sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/mingw-gcc
-C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=i686-pc-mingw32
--without-libiconv-prefix --without-libintl-prefix
--with-sysroot=/usr/i686-pc-mingw32/sys-root
--with-build-sysroot=/usr/i686-pc-mingw32/sys-root
--enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions
--with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry
--enable-libstdcxx-debug --disable-build-poststage1-with-cxx
--enable-version-specific-runtime-libs --disable-multilib
--enable-decimal-float=bid --disable-werror --enable-lto
Thread model: win32
gcc version 4.7.3 (GCC)

Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.8.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with:
/cygdrive/i/szsz/tmpp/cygwin64/mingw64-i686/mingw64-i686-gcc-4.8.3-1/src/gcc
-4.8.3/configure
--srcdir=/cygdrive/i/szsz/tmpp/cygwin64/mingw64-i686/mingw64-i686-gcc-4.8.3-
1/src/gcc-4.8.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin
--sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share
--localstatedir=/var --sysconfdir=/etc --libdir=/usr/lib
--datarootdir=/usr/share --docdir=/usr/share/doc/mingw64-i686-gcc
--htmldir=/usr/share/doc/mingw64-i686-gcc/html -C --build=x86_64-pc-cygwin
--host=x86_64-pc-cygwin --target=i686-w64-mingw32 --without-libiconv-prefix
--without-libintl-prefix --with-sysroot=/usr/i686-w64-mingw32/sys-root
--with-build-sysroot=/usr/i686-w64-mingw32/sys-root --disable-multilib
--disable-win32-registry
--enable-languages=c,ada,c++,fortran,lto,objc,obj-c++
--enable-fully-dynamic-strings --enable-graphite --enable-libgomp
--enable-libquadmath --enable-libquadmath-support --enable-libssp
--enable-version-specific-runtime-libs --with-dwarf2 --with-gnu-ld
--with-gnu-as --with-tune=generic
--with-cloog-include=/usr/include/cloog-isl --with-system-zlib
--libexecdir=/usr/lib
Thread model: win32
gcc version 4.8.3 (GCC)


When built with the default Cygwin compiler the problem doesn't occur.
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with:
/cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.3-2/src/gcc-4.8.3/configure
--srcdir=/cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.3-2/src/gcc-4.8.3
--prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var
--sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share
--docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C
--build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin
--without-libiconv-prefix --without-libintl-prefix --enable-shared
--enable-shared-libgcc --enable-static
--enable-version-specific-runtime-libs --enable-bootstrap
--disable-__cxa_atexit --with-dwarf2 --with-tune=generic
--enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite
--enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm
--enable-libquadmath --enable-libquadmath-support --enable-libssp
--enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers
--with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as
--with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix
--without-libintl-prefix --with-system-zlib --libexecdir=/usr/lib
Thread model: posix
gcc version 4.8.3 (GCC)

In the attached files in weak.cpp if the line
	static ios_base::Init __ioinit;
is commented out the seg fault doesn't occur. Doing a disassembly of weak.o
(objdump -d weak.o) shows that the call includes a nonzero offset that gets
applied when the weak symbol is overridden by the function in strong.o. The
offset is zero if the above mentioned line is commented out. 

Regards,
Keith



[-- Attachment #2: strong.cpp --]
[-- Type: text/plain, Size: 83 bytes --]

#include <stdio.h>

extern "C"
void weak_strong(void)
{
  printf( "STRONG\n" );
}


[-- Attachment #3: weak.cpp --]
[-- Type: text/plain, Size: 297 bytes --]

#include <stdio.h>

#include <istream>

namespace std _GLIBCXX_VISIBILITY(default)
{
  static ios_base::Init __ioinit;
} // namespace

extern "C" void
weak_strong(void)
  __attribute__((weak));

void weak_strong(void)
{
  printf( "WEAK\n" );
}

int main( void )
{
  weak_strong();
  
  return 0;
}

[-- Attachment #4: Makefile --]
[-- Type: application/octet-stream, Size: 335 bytes --]

CPP = i686-pc-mingw32-g++
# CPP = i686-w64-mingw32-g++

all: weak.exe

weak.exe: weak.o strong.o
	$(CPP) -o weak.exe weak.o strong.o

.cpp.o:
	$(CPP) -DHAVE_CONFIG_H -I. -I..  -I.. -I../src -I/home/cross-gcc/4.9.1/cross-local/include   -g -O2 -frounding-math -O2 -pipe -W -Wall -c -o $@ $<
  
clean:
	rm weak.o strong.o


[-- Attachment #5: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-04 21:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04 21:09 seg fault on override of a weak symbol in g++ Keith Clifford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).