Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 466312 - x11-libs/wxGTK:2.8 fails to compile with gcc-4.7.2 -flto / LTO enabled - configure tests are not LTO save and deliver wrong results
Summary: x11-libs/wxGTK:2.8 fails to compile with gcc-4.7.2 -flto / LTO enabled - conf...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: Normal normal with 1 vote (vote)
Assignee: Gentoo wxWidgets Herd
URL:
Whiteboard: https://github.com/wxWidgets/wxWidget...
Keywords: PATCH
Depends on:
Blocks: systemwide-clang lto
  Show dependency tree
 
Reported: 2013-04-18 02:58 UTC by cmuelle8
Modified: 2018-07-16 00:26 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build log thread.h error - 1366160365-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz (1366160365-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz,8.00 KB, application/octet-stream)
2013-04-18 03:01 UTC, cmuelle8
Details
build log -ldl error - 1366163053-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz (1366163053-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz,22.50 KB, application/octet-stream)
2013-04-18 03:02 UTC, cmuelle8
Details
files/wxGTK-2.8.12.1-setconcurrency-backport.patch (wxGTK-2.8.12.1-setconcurrency-backport.patch,1.13 KB, patch)
2013-04-18 03:09 UTC, cmuelle8
Details | Diff
wxGTK-2.8.12.1.ebuild.patch (wxGTK-2.8.12.1.ebuild.patch,1.05 KB, patch)
2013-04-18 03:13 UTC, cmuelle8
Details | Diff
wxGTK-2.8.12.1.ebuild.patch (wxGTK-2.8.12.1.ebuild.patch,1.25 KB, patch)
2013-05-08 02:51 UTC, cmuelle8
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description cmuelle8 2013-04-18 02:58:56 UTC
# cave show -f wxGTK:2.8::gentoo
* x11-libs/wxGTK:2.8::gentoo
    ::gentoo                  2.8.12.1* {:2.8}
    x11-libs/wxGTK-2.8.12.1:2.8::gentoo
    Description               GTK+ version of wxWidgets, a cross-platform C++ GUI toolkit
    Homepage                  http://wxwidgets.org/
    Herds                     wxwidgets
    Maintainers               <wxwidgets@gentoo.org> (All modifications to this package must be approved by the wxwidgets herd.)
    Use flags                 X (-aqua) -debug doc gnome gstreamer -odbc opengl pch sdl tiff build_options: symbols=strip dwarf_compress -optional_tests -trace work=tidyup 

So far I've not seen these issues with wxGTK:2.9 - knock on wood



SYMPTOM thr_setconcurrency)
  src/unix/threadpsx.cpp includes thread.h since configure enables..
    #define HAVE_THR_SETCONCURRENCY
  ..when it should not (-fno-lto does not define it)

#### zgrep -B 1 error.*thread.h 1366160365-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz
x86_64-pc-linux-gnu-g++ -c -o basedll_threadpsx.o -I./.pch/wxprec_basedll -D__WXGTK__     -DWXBUILDING      -I/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/src/regex  -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -fPIC -DPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -I/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/wx/include/gtk2-unicode-release-2.8 -I/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/include -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng15 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread -I/usr/include/gstreamer-0.10 -I/usr/include/libxml2 -I/usr/include/gconf/2 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -DWX_PRECOMP -pthread -Wall -Wundef -Wno-ctor-dtor-privacy -O2 -fno-strict-aliasing -pthread -I/usr/include/libgnomeprintui-2.2 -I/usr/include/libgnomeprint-2.2 -I/usr/include/libxml2 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gail-1.0 -I/usr/include/libart-2.0 -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng15 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -march=native -pipe -O2 -mfpmath=sse -flto=4 -floop-block -floop-interchange -floop-strip-mine -fuse-linker-plugin -fno-strict-aliasing /var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/src/unix/threadpsx.cpp
/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/src/unix/threadpsx.cpp:51:24: fatal error: thread.h: No such file or directory




SYMPTOM dlopen)
  dlopen without -ldl ..
  dlerror without -ldl ..
  ..is checked positive by configure when it should not (running configure with -fno-lto results in "no")

#### zgrep "error\|dlopen" 1366163053-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz
checking for dlopen... yes
checking for dlerror... yes
x86_64-pc-linux-gnu-gcc -c -o wxregex_regerror.o -D__WXGTK__  -fPIC -DPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -I/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/wx/include/gtk2-unicode-release-2.8 -I/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/include -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng15 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread -I/usr/include/gstreamer-0.10 -I/usr/include/libxml2 -I/usr/include/gconf/2 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread -Wall -Wundef -O2 -fno-strict-aliasing -pthread -I/usr/include/libgnomeprintui-2.2 -I/usr/include/libgnomeprint-2.2 -I/usr/include/libxml2 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gail-1.0 -I/usr/include/libart-2.0 -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng15 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -march=native -pipe -O2 -mfpmath=sse -flto=4 -floop-block -floop-interchange -floop-strip-mine -fuse-linker-plugin -fno-strict-aliasing /var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/src/regex/regerror.c
x86_64-pc-linux-gnu-ar rcu /var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/libwxregexu-2.8.a wxregex_regcomp.o wxregex_regexec.o wxregex_regerror.o wxregex_regfree.o
/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/libwx_baseu-2.8.so: error: undefined reference to 'dlopen'
/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/libwx_baseu-2.8.so: error: undefined reference to 'dlsym'
/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/libwx_baseu-2.8.so: error: undefined reference to 'dlerror'
/var/tmp/paludis/x11-libs-wxGTK-2.8.12.1/work/wxPython-src-2.8.12.1/wxgtk_build/lib/libwx_baseu-2.8.so: error: undefined reference to 'dlclose'
collect2: error: ld returned 1 exit status



RESOLUTION)
  The AC_CHECK_FUNC and AC_CHECK_FUNCS emit a bunch of test programs and dump them into configure.  These test programs are not LTO save, the function definitions do not survive the optimizer.  They are stripped out and function pointer f does not get a place in the symbol table, as illustrated below with dlopen for example:

-->8------------------------acsample.c
#undef dlopen

/* Override any gcc2 internal prototype to avoid an error.  */
#ifdef __cplusplus
extern "C"
{
#endif
/* We use char because int might match the return type of a gcc2
   builtin and then its argument prototype would still apply.  */
char dlopen ();
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined (__stub_dlopen) || defined (__stub___dlopen)
choke me
#else
char (*f) () = dlopen;
#endif
#ifdef __cplusplus
}
#endif

int
main ()
{
return f != dlopen;
  ;
  return 0;
}
--8<------------------------acsample.c

#### gcc -flto -O2 -o acsample acsample.c
#### ./acsample && echo $?
0
#### # --> wrong result (program incomplete)

#### objdump -t acsample | grep "f$"
#### # --> because symbol f is missing


#### vim acsample.c
#### diff -ur acsample.c~ acsample.c
--- acsample.c~     2013-04-18 04:10:47.442264985 +0200
+++ acsample.c      2013-04-18 04:12:16.811141467 +0200
@@ -14,7 +14,7 @@
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
-char (*f) () = dlopen;
+char (*f) () __attribute__((used)) = dlopen;
 #endif
 #ifdef __cplusplus
 }

#### gcc -flto -O2 -o acsample acsample.c
/tmp/cc0VlSzR.ltrans0.ltrans.o:cc0VlSzR.ltrans0.o:function f: error: undefined reference to 'dlopen'
/tmp/cc0VlSzR.ltrans0.ltrans.o:cc0VlSzR.ltrans0.o:function main: error: undefined reference to 'dlopen'
collect2: Fehler: ld gab 1 als Ende-Status zurück
#### # --> correct result, this is what we want for the configure test, i.e. to fail if dlopen is not available
#### # (and this is what happens in the non-lto case as well)

#### objdump -t acsample | grep "f$"
0000000000401980 g     O .data  0000000000000008              f

#### gcc -flto -O2 -o acsample acsample.c -ldl
#### # --> compiles fine, (but) this is checked in a subsequent configure test



CHANGES)
  How do we make the whole configure file LTO save for AC_CHECK_FUNC emited programs in this case?  sed to the rescue..

sed -e '/^char *(.f) *() *=/ s:():() __attribute__((used)):' -i configure

  ..will do.  Originally I patched the function definition as well, but the above suffices:
  -e '/^char *\($ac_func\|[[:alnum:]]*\|(.f)\) *() *[;=]/ s:():() __attribute__((used)):'

For configure test cases covered by this patch, results shouldn't differ anymore comparing -fno-lto and -flto runs.
For thr_setconcurrency I backported the usage of pthread_setconcurrency from wxGTK:2.9.
Please find the backport patch and ebuild patch attached.


Greetings

Reproducible: Always
Comment 1 cmuelle8 2013-04-18 03:01:05 UTC
Created attachment 345850 [details]
build log thread.h error - 1366160365-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz
Comment 2 cmuelle8 2013-04-18 03:02:24 UTC
Created attachment 345852 [details]
build log -ldl error - 1366163053-install-x11-libs_wxGTK-2.8.12.1:2.8::gentoo.out.gz
Comment 3 cmuelle8 2013-04-18 03:09:33 UTC
Created attachment 345854 [details, diff]
files/wxGTK-2.8.12.1-setconcurrency-backport.patch

backport pthread_setconcurrency usage from 2.9*
Comment 4 cmuelle8 2013-04-18 03:13:53 UTC
Created attachment 345856 [details, diff]
wxGTK-2.8.12.1.ebuild.patch

- add sed commands to make AC_CHECK_FUNC configure tests lto save
- test for pthread_setconcurrency instead of thr_setconcurrency
Comment 5 Sasha Medvedev 2013-04-28 05:47:07 UTC
If wxGTK is compiled with lto (with the help of the patches here), then sci-visualization/gnuplot  with wxwidgets use flag can't be linked.
Comment 6 Ryan Hill (RETIRED) gentoo-dev 2013-04-28 06:15:27 UTC
While I appreciate the analysis and work you've done here, we don't support systemwide lto.  It has unfortunate consequences not only when linking in other libraries but also during compiler upgrades.  Maybe upstream is interested?
Comment 7 cmuelle8 2013-04-28 12:38:53 UTC
(In reply to comment #6)
> While I appreciate the analysis and work you've done here, we don't support
> systemwide lto.  It has unfortunate consequences not only when linking in
> other libraries but also during compiler upgrades.  Maybe upstream is
> interested?

'During' CC upgrades?  iirc wxGTK is not part of a cc toolchain.

You do not _force_ anyone to actually use it by applying the patch.  You just give people the choice to more easily tinker around with it and see what goes.  Gentoo is about choices, the patch does not break usual builds, so I do not understand your rejection.

As for linking issue with gnuplot:  I do not seem to have this issue.  Compiling gnuplot with lto'd wxGTK:2.8 works here.
Comment 8 cmuelle8 2013-04-29 00:32:27 UTC
(In reply to comment #5)
> If wxGTK is compiled with lto (with the help of the patches here), then
> sci-visualization/gnuplot  with wxwidgets use flag can't be linked.

Can you open another bug for this and attach the build log there?  I cannot seem to reproduce this, just double checked.

gcc-4.8.0 ebuild says:
LTO support is still experimental and unstable. Any bug reports
about LTO that do not include an upstream patch will be closed as
invalid.

Apparently this bug fell victim to this policy.  Since upstream is unlikely to patch up on released versions, as experienced previously, we'll gladly wait another one to two years until the lto playground is labeled safe to play with by the authorities.

Greetings
Comment 9 cmuelle8 2013-04-29 00:34:01 UTC
sorry, changing state was unintentional, people should try hard to find this.
Comment 10 cmuelle8 2013-05-08 02:51:33 UTC
Created attachment 347688 [details, diff]
wxGTK-2.8.12.1.ebuild.patch

- revised patch that checks {C,CXX,LD}FLAGS for "flto" or "-O4" (clang -O4 implies flto)
- build files are made lto-save depending on *FLAGS

tested successfully on amd64/x86 with gcc -flto and clang -O4
Comment 11 cmuelle8 2013-05-08 03:08:17 UTC
(In reply to comment #8)
> (In reply to comment #5)
> > If wxGTK is compiled with lto (with the help of the patches here), then
> > sci-visualization/gnuplot  with wxwidgets use flag can't be linked.
> 
> Can you open another bug for this and attach the build log there?

Again, I cannot confirm this.  Neither on amd64 nor x86.  On both archs gnuplot builds fine with lto'd wxGTK:2.8 - regardless of whether it has been built using "gcc -flto" or "clang -O4".  Use flags in use here

# cave show -f sci-visualization/gnuplot
    sci-visualization/gnuplot-4.6.2-r1:0::installed
    Description               Command-line driven interactive plotting program
    Homepage                  http://www.gnuplot.info/
    From repositories         gentoo
    Installed time            Wed May 08 04:58:28 CEST 2013
    Installed using           paludis-1.2.0
    License                   gnuplot GPL-2 bitmap? ( free-noncomm )
    Use flags                 (X) (-aqua) (-bitmap) (cairo) (doc) (-emacs) (examples) (gd) (ggi) (latex) (lua) (plotutils) (qt4) (readline) (-svga) (-thin-splines) (wxwidgets) (-xemacs) build_options: -trace 




Upstream is unlikely to add this to 2.8 branch since it's long been released.  This isn't security related, it's more a "feature" request wrt build system.

Requesting a second review, see revised ebuild patch.
Comment 12 Ryan Hill (RETIRED) gentoo-dev 2013-05-08 03:28:53 UTC
They still make 2.8 releases.

I suppose I'll have a look at this.  I just hate messing around in wxGTK's build system.  It's such a mess.
Comment 13 Ryan Hill (RETIRED) gentoo-dev 2013-08-10 05:33:44 UTC
Comment on attachment 347688 [details, diff]
wxGTK-2.8.12.1.ebuild.patch

>+		sed	-e '/^for ac_func in thr_/ s:thr:pthread:' \

Is this just because of the broken eautoreconf?  I'd rather backport the full patch from upstream if we can.
Comment 14 David Kredba 2013-08-11 09:50:29 UTC
cmuelle8: Thank you. I really appreciate your effort on this.
(I am one of that lto system wide guys.)
Comment 15 Mart Raudsepp gentoo-dev 2018-07-16 00:26:52 UTC
wxGTK:2.8 has been last rited in bug 661284, thus marking this bug here as obsolete, as presumably the referenced commit in whiteboard would be in the 3.0 versions