Page MenuHomeFreeBSD

Unbreak openoffice-devel build with gcc 4.9
ClosedPublic

Authored by truckman on Jan 23 2015, 2:13 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 3, 2:49 PM
Unknown Object (File)
Nov 25 2024, 9:50 AM
Unknown Object (File)
Nov 24 2024, 3:48 AM
Unknown Object (File)
Nov 22 2024, 10:05 PM
Unknown Object (File)
Nov 22 2024, 8:06 PM
Unknown Object (File)
Nov 22 2024, 12:58 PM
Unknown Object (File)
Nov 21 2024, 4:18 AM
Unknown Object (File)
Nov 20 2024, 10:59 PM
Subscribers
None

Details

Summary

When building openoffice-devel with gcc 4.9, the build fails with these errors:

	  /wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/workdir/CxxObject/svx/source/fmcomp/fmgridif.o: In function `FmXGridControl::createPeer(com::sun::sta
	  r::uno::Reference<com::sun::star::awt::XToolkit> const&, com::sun::star::uno::Reference<com::sun::star::awt::XWindowPeer> const&)':
	  fmgridif.cxx:(.text+0x6f31): undefined reference to `non-virtual thunk to WindowListenerMultiplexer::acquire()'
	  fmgridif.cxx:(.text+0x6f7d): undefined reference to `non-virtual thunk to FocusListenerMultiplexer::acquire()'
	  fmgridif.cxx:(.text+0x6fc9): undefined reference to `non-virtual thunk to KeyListenerMultiplexer::acquire()'
	  fmgridif.cxx:(.text+0x7015): undefined reference to `non-virtual thunk to MouseListenerMultiplexer::acquire()'
	  fmgridif.cxx:(.text+0x7061): undefined reference to `non-virtual thunk to MouseMotionListenerMultiplexer::acquire()'
	  fmgridif.cxx:(.text+0x70ad): undefined reference to `non-virtual thunk to PaintListenerMultiplexer::acquire()'
	  collect2: error: ld returned 1 exit status
	  /wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solenv/gbuild/LinkTarget.mk:259: recipe for target '/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/42
	  0/unxfbsdi.pro/workdir/LinkTarget/Library/libsvxcore.so' failed
	  gmake: *** [/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/workdir/LinkTarget/Library/libsvxcore.so] Error 1
	  gmake: *** Waiting for unfinished jobs....
	  rm /wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/workdir/ExternalHeaders/Library/libxcr.so
	  dmake:  Error code 2, while making 'all'

I found this discussion by the LibreOffice folks:
https://www.mail-archive.com/blfs-support@lists.linuxfromscratch.org/msg00910.html
which leads to this patch:
http://cgit.freedesktop.org/libreoffice/core/commit/?id=bb182b47ca7362b05c03d583d3547643d9a99562
which changes a header file so that it is supposed to mark methods of the classes in question to
be published.

Unfortunately this does not work. I ran an elfdump -s on the library .so file that contains these symbols.
and found that they are flagged as STB_FUNC STB_LOCAL. The patch changes the other methods for these classes
to be STB_GLOBAL, but does not seem to effect the aquire and release methods. If I run nm on the .o file
that contains these symbols, the are of type W instead of type T.

	  000028d8 T _ZN22KeyListenerMultiplexer10keyPressedERKN3com3sun4star3awt8KeyEventE
	  00002aa6 T _ZN22KeyListenerMultiplexer11keyReleasedERKN3com3sun4star3awt8KeyEventE
	  000005b4 T _ZN22KeyListenerMultiplexer14queryInterfaceERKN3com3sun4star3uno4TypeE
	  00000000 W _ZN22KeyListenerMultiplexer7acquireEv
	  00000000 W _ZN22KeyListenerMultiplexer7releaseEv
	  00000038 T _ZN22KeyListenerMultiplexer9disposingERKN3com3sun4star4lang11EventObjectE

Digging further into the code, there are some macros that are used in the header file
that is being patched:

	  #define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
	  class ClassName : public ListenerMultiplexerBase, public InterfaceName \
	  { \
	  public: \
	          ClassName( ::cppu::OWeakObject& rSource ); \
	      ::com::sun::star::uno::Any  SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); \
	          void                                            SAL_CALL acquire() throw()      { ListenerMultiplexerBase::acquire(); } \
	          void                                            SAL_CALL release() throw()      { ListenerMultiplexerBase::release(); } \
	      void                                                SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);

vs.

	  
	  #define DECL_LISTENERMULTIPLEXER_START_DLLPUB( ClassName, InterfaceName ) \
	  class TOOLKIT_DLLPUBLIC ClassName : public ListenerMultiplexerBase, public InterfaceName \
	  { \
	  public: \
	          ClassName( ::cppu::OWeakObject& rSource ); \
	      ::com::sun::star::uno::Any  SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); \
	          void                                            SAL_CALL acquire() throw()      { ListenerMultiplexerBase::acquire(); } \
	          void                                            SAL_CALL release() throw()      { ListenerMultiplexerBase::release(); } \
	      void                                                SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);

As near as I can tell, TOOLKIT_DLLPUBLIC gets expanded to attribute ((visibility("default"))),
assuming HAVE_GCC_VISIBILITY_FEATURE.

The patch changes a number of the classes to use DECL_LISTENERMULTIPLEXER_START_DLLPUB instead
of DECL_LISTENERMULTIPLEXER_START, for instance this one:

	  //      ----------------------------------------------------
	  //      class KeyListenerMultiplexer
	  //      ----------------------------------------------------
	  DECL_LISTENERMULTIPLEXER_START( KeyListenerMultiplexer, ::com::sun::star::awt::XKeyListener )
    	  void SAL_CALL keyPressed( const ::com::sun::star::awt::KeyEvent& e ) throw(::com::sun::star::uno::RuntimeException);
    	  void SAL_CALL keyReleased( const ::com::sun::star::awt::KeyEvent& e ) throw(::com::sun::star::uno::RuntimeException);
	  DECL_LISTENERMULTIPLEXER_END

The patch changes the keyPressed, keyReleased, and queryInterface from STB_LOCAL to STB_GLOBAL,
but acquire and release are unaffected.

I also found this trouble ticket: http://wiki.linuxfromscratch.org/blfs/ticket/5042
which has a different approach to fixing the problem. In this ticket, the problem appears
to only happen on i386 and not amd64, so they wrap the problematical calls in a
#ifndef i386 / #endif wrapper so they don't get compiled on i386. The build
succeeds, but that seems to be the wrong approach. I would worry that the resulting
executable would not operate properly.

I decided to use the first approach. The LibreOffice patch does not apply cleanly,
so I applied it by hand. Then I augmented this patch by adding TOOLKIT_DLLPUBLIC
to the declaration of the acquire and release methods. That allows the build
to succeed.

After testing is completed, I will change the value USE_GCC from 4.9 to yes.

Test Plan

Build and run with both gcc 4.8 and gcc 4.9.

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

truckman retitled this revision from to Unbreak openoffice-devel build with gcc 4.9.
truckman updated this object.
truckman edited the test plan for this revision. (Show Details)
truckman added reviewers: mat, pfg.
truckman edited the test plan for this revision. (Show Details)

Nuke junk files that arc diff --create decided to add to svn.

mat edited edge metadata.

Well, if it works, go for it :-)
Don't forget to change the USE_GCC to yes :-)

This revision is now accepted and ready to land.Jan 23 2015, 10:22 AM
pfg edited edge metadata.

Still doesn't build on FreeBSD 10. Running nm on the .o file shows that the acquire symbols are weak. Running elfdump on libootk.so:

entry: 1268

st_name: _ZN24FocusListenerMultiplexer7acquireEv
st_value: 0x24244e
st_size: 5
st_info: STT_FUNC STB_WEAK
st_shndx: 11

#pragma weak doesn't appear to be used anywhere, and __attribute((weak)) only
shows up in some test code, so why are the acquire symbols weak???

It turns out that the symbols are weak because they are for inline methods and/or because we are compiling with -fvisibility-inlines-hidden, and gcc makes those weak.

Now the question is why are those methods not getting inlined when compiling fmgridif.cxx? Running nm on fmgridif.o shows those symbols as undefined.

The problem appears to be a gcc bug. We are compiling -Os. If I compile fmgridif.cxx with -O2, then these symbols show up in the .o file as weak symbols instead of undefined. -O0 and -O1 are also OK.

I suppose it could be though of as a feature of -Os. In that mode, nothing should get inlined and fmgridif.cxx might expect to link to the copy of the functions in listenermultiplexer.o (from listenermultiplexor.cxx), which implements the classes in the .hxx file. That would work if they were all linked into the executable at once, or at least all in the same shared library.

gcc is indeed known for having occasional broken optimizations :(.

Actually, AOO should be building with gcc-4.2.1 if it were not for some broken inlining in that version of gcc.

It looks like gcc5 will work correctly. If I compile fmgridif.cxx -with -Os, the acquire methods appear not to be inlined and are visible externally as weak symbols, so internal users in this .o file should be happy. With -O0, it appears that the methods are inlined and are not visible externally.

I see four ways forward

  • Stick with USE_GCC=4.8
  • Somehow specify that any gcc other than 4.2.1 or 4.9 is ok to use.
  • Detect that we are building with GCC 4.9 and set the optimization flag to -O0.
  • USE_GCC=yes and hardwire the optimization flag to -O0

Some private feedback from upstream:

"I think this is caused by -O2 causing the inline acquire methods to really be inlined, so their symbol isn't actually needed anymore. On the other hand -Os notices that inlining this stuff would make the code bigger so it avoids the inlining and calls the method instead, which needs the symbol if the call is from another library."

My suggestion would be to leave it as gcc48 for now.

If you can get it to work with clang (upstream already does this for the Mac port and linux) we can get rid of the USE_GCC altogether.

Changing gb_COMPILEROPTFLAGS in solenv/gbuild/platform/freebsd.mk doesn't change the flag everywhere. In particular dbaccess is still compiled with -Os.

Compiling: dbaccess/source/ui/uno/ColumnControl.cxx
g++49  -fmessage-length=0 -c -Os -fno-strict-aliasing -DENABLE_LAYOUT=0 -DENABLE_LAYOUT_EXPERIMENTAL=0   -fvisibility=hidden -I. -I../../../unxfbsdi.pro/inc/uiuno -I../inc -I.. /.././source/inc -I../../../inc/pch -I../../../inc -I../../../unx/inc -I../../../unxfbsdi.pro/inc -I. -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/stl -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/external -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solenv/unxfbsdi/inc -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solenv/inc -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/res -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solenv/inc/Xp31 -I/usr/local/openjdk7/include -I/usr/local/openjdk7/include/freebsd -I/usr/local/openjdk7/include/bsd -I/usr/local/openjdk7/include/linux -I/usr/local/openjdk7/include/native_threads/include -I/usr/local/include  -I/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/offuh -I. -I../../../res -I. -pipe -mtune=pentiumpro -Wl,-rpath=/usr/local/lib/gcc49 -fvisibility-inlines-hidden -g1 -Wall -Wextra -Wendif-labels -Wshadow -Wno-ctor-dtor-privacy     -Wno-non-virtual-dtor   -fpic -DFREEBSD -DUNX -DVCL -DGCC -DC341 -DINTEL -DX86  -D_PTHREADS -D_REENTRANT -DNEW_SOLAR -D_USE_NAMESPACE=1 -DSTLPORT_VERSION=450 -DHAVE_GCC_VISIBILITY_FEATURE -D__DMAKE -DUNIX -DCPPU_ENV=gcc3 -DGXX_INCLUDE_PATH=/usr/local/lib/gcc49/include/c++ -DSUPD=420 -DPRODUCT -DNDEBUG -DOSL_DEBUG_LEVEL=0 -DOPTIMIZE -DCUI -DSOLAR_JAVA   -DDBACCESS_DLLIMPLEMENTATION -DSHAREDLIB -D_DLL_   -fexceptions -fno-enforce-eh-specs -DEXCEPTIONS_ON  -o ../../../unxfbsdi.pro/slo/ColumnControl.o /wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/dbaccess/source/ui/uno/ColumnControl.cxx

[snip]

../unxfbsdi.pro/slo/ColumnControl.o: In function `Reference':
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to WindowListenerMultiplexer::acquire()'
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to FocusListenerMultiplexer::acquire()'
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to KeyListenerMultiplexer::acquire()'
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to MouseListenerMultiplexer::acquire()'
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to MouseMotionListenerMultiplexer::acquire()'
/wrkdirs/usr/ports/editors/openoffice-devel/work/aoo-4.2.0/main/solver/420/unxfbsdi.pro/inc/com/sun/star/uno/Reference.hxx:136: undefined reference to `non-virtual thunk to PaintListenerMultiplexer::acquire()'
collect2: error: ld returned 1 exit status
dmake:  Error code 1, while making '../unxfbsdi.pro/lib/libdbu.so'

Stay with USE_GCC=4.8 for now.

This revision is now accepted and ready to land.Feb 3 2015, 6:49 PM
truckman edited edge metadata.

Change optimization from -Os to -O0 when gcc 4.9 is detected.

Revert to USE_GCC=yes to allow building with 4.9.

This revision now requires review to proceed.Feb 3 2015, 6:51 PM
pfg edited edge metadata.
This revision is now accepted and ready to land.Feb 3 2015, 8:11 PM
mat edited edge metadata.
truckman updated this revision to Diff 3801.

Closed by commit rP379132 (authored by @truckman).