0010-Fix-library-inclusion-order-when-building-statically.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 7a912823158a4113256c3113a34c38d6b241d275 Mon Sep 17 00:00:00 2001
  2. From: Alexey Brodkin <abrodkin@synopsys.com>
  3. Date: Wed, 13 Jan 2016 20:15:36 +0300
  4. Subject: [PATCH] Fix library inclusion order when building statically
  5. When building application statically it's important to keep
  6. libraries we're linking against in order. Otherwise if libA depends on
  7. libB but it is mentioned after libB in linker command line
  8. there will be unresolved symbols.
  9. Consider real example - configuration of Qt with glib for static build.
  10. Initially reported by Buildroot autobuilder here:
  11. http://autobuild.buildroot.net/results/174/174c6e47eb761f9897275b6fedff742ace2f3081
  12. What happens here:
  13. [1] Qt's configuration script tries to build glib test app
  14. (in config.tests/unix/glib)
  15. [2] For that it first asks which libs to use during linkage this way:
  16. QT_LIBS_GLIB=`$PKG_CONFIG --libs glib-2.0 gthread-2.0 2>/dev/null`
  17. In our case we're getting something like this:
  18. -L/.../sysroot/usr/lib -lintl -lgthread-2.0 -pthread -lglib-2.0 \
  19. -lintl -pthread -lintl
  20. Note "-lintl" is mentioned 3 times because libgthread depends on
  21. libthread and both of them plus libglib all depend on libintl - so
  22. we're getting "lintl" for each separate library mentioned above.
  23. [3] Now we execute "compileTest" for real heavy lifting this way:
  24. compileTest unix/glib "Glib" $QT_CFLAGS_GLIB $QT_LIBS_GLIB ...
  25. [4] compileTest (the one for unix) parses command-line passed to it
  26. groups all entries with "-l" prefix and puts them in LFLAGS
  27. variable. And finally executes qmake passing it that kind of
  28. construction:
  29. $OUTDIR/bin/qmake ..."LIBS*=$LFLAGS"
  30. [5] When qmake sees construction "MYVAR*=MYVAL" it populates MYVAR with
  31. unique values from MYVAL string.
  32. [6] As a result qmake generated Makefile with the following:
  33. LIBS = $(SUBLIBS) -pthread -L/.../sysroot/usr/lib -lintl -lgthread-2.0 \
  34. -lglib-2.0
  35. [7] And essentially on attempt to link glib test app a failure happens
  36. because libglib needs libintl, i.e. "-lintl" must follow "-lglib-2.0":
  37. -------------------->8------------------
  38. linking glib
  39. g++ -static -Wl,-O1 -o glib glib.o -pthread -L/.../sysroot/usr/lib \
  40. -lintl -lgthread-2.0 -lglib-2.0
  41. /.../sysroot/usr/lib/libglib-2.0.a(libglib_2_0_la-ggettext.o): In function '_g_dgettext_should_translate':
  42. ggettext.c:(.text+0x28): undefined reference to `libintl_textdomain'
  43. ggettext.c:(.text+0x36): undefined reference to `libintl_gettext'
  44. /.../sysroot/usr/lib/libglib-2.0.a(libglib_2_0_la-ggettext.o): In function `ensure_gettext_initialized':
  45. ggettext.c:(.text+0xe6): undefined reference to `libintl_bindtextdomain'
  46. ggettext.c:(.text+0xf6): undefined reference to `libintl_bind_textdomain_codeset'
  47. /.../sysroot/usr/lib/libglib-2.0.a(libglib_2_0_la-ggettext.o): In function `g_dgettext':
  48. ggettext.c:(.text+0x148): undefined reference to `libintl_dgettext'
  49. /.../sysroot/usr/lib/libglib-2.0.a(libglib_2_0_la-ggettext.o): In function `g_dcgettext':
  50. ggettext.c:(.text+0x2dc): undefined reference to `libintl_dcgettext'
  51. /.../sysroot/usr/lib/libglib-2.0.a(libglib_2_0_la-ggettext.o): In function `g_dngettext':
  52. ggettext.c:(.text+0x32a): undefined reference to `libintl_dngettext'
  53. collect2: error: ld returned 1 exit status
  54. Makefile:99: recipe for target 'glib' failed
  55. make: *** [glib] Error 1
  56. Glib disabled.
  57. Glib support cannot be enabled due to functionality tests!
  58. Turn on verbose messaging (-v) to ./configure to see the final report.
  59. If you believe this message is in error you may use the continue
  60. switch (-continue) to ./configure to continue.
  61. -------------------->8------------------
  62. Solution to this problem is simple we have to pass all libraries exactly
  63. in order of their initial mention by upper layers.
  64. Change-Id: I7ff00901031a8eb85b4fbd7889b0e0c02be806bb
  65. This fix was sent to Qt Gerrit for review here:
  66. https://codereview.qt-project.org/#/c/145967/
  67. ---
  68. config.tests/unix/compile.test | 2 +-
  69. 1 file changed, 1 insertion(+), 1 deletion(-)
  70. diff --git a/config.tests/unix/compile.test b/config.tests/unix/compile.test
  71. index f484f03..dac0a4f 100755
  72. --- a/config.tests/unix/compile.test
  73. +++ b/config.tests/unix/compile.test
  74. @@ -73,7 +73,7 @@ test -r Makefile && $MAKE distclean >/dev/null 2>&1
  75. rm -f "$EXE" "${EXE}.exe"
  76. echo "QT_BUILD_TREE = $OUTDIR" > "$OUTDIR/$TEST/.qmake.cache"
  77. -"$OUTDIR/bin/qmake" -spec "$QMKSPEC" "CONFIG+=$QMAKE_CONFIG" "CONFIG-=debug_and_release" "LIBS*=$LFLAGS" "LIBS+=$MAC_ARCH_LFLAGS" "INCLUDEPATH*=$INCLUDEPATH" "QMAKE_CXXFLAGS*=$CXXFLAGS" "QMAKE_CXXFLAGS+=$MAC_ARCH_CXXFLAGS" "$SRCDIR/$TEST/$EXE.pro" -o "$OUTDIR/$TEST/Makefile"
  78. +"$OUTDIR/bin/qmake" -spec "$QMKSPEC" "CONFIG+=$QMAKE_CONFIG" "CONFIG-=debug_and_release" "LIBS=$LFLAGS" "LIBS+=$MAC_ARCH_LFLAGS" "INCLUDEPATH*=$INCLUDEPATH" "QMAKE_CXXFLAGS*=$CXXFLAGS" "QMAKE_CXXFLAGS+=$MAC_ARCH_CXXFLAGS" "$SRCDIR/$TEST/$EXE.pro" -o "$OUTDIR/$TEST/Makefile"
  79. if [ "$VERBOSE" = "yes" ]; then
  80. $MAKE
  81. --
  82. 2.4.3