Bug 69801 - Fail to build with GNU libtool 2.4.2 on OpenBSD 5.3
Summary: Fail to build with GNU libtool 2.4.2 on OpenBSD 5.3
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: All All
: medium normal
Assignee: Simon McVittie
QA Contact: D-Bus Maintainers
URL:
Whiteboard: review+
Keywords: patch
Depends on:
Blocks:
 
Reported: 2013-09-25 10:07 UTC by Chengwei Yang
Modified: 2017-04-10 11:53 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Autotools build: Use pkg-config to find libexpat (1.94 KB, patch)
2017-04-07 13:09 UTC, Simon McVittie
Details | Splinter Review
build: Remove indirection from uses of Expat (6.23 KB, patch)
2017-04-07 13:09 UTC, Simon McVittie
Details | Splinter Review

Description Chengwei Yang 2013-09-25 10:07:45 UTC
the libtool(non GNU libtool) of OpenBSD 5.3 fail to build DBus like below.

gcc -DHAVE_CONFIG_H -I. -I..  -I..  -I/usr/X11R6/include -DDBUS_COMPILATION -DDBUS_MACHINE_UUID_FILE=\""/usr/local/var/lib/dbus/machine-id"\"    -Wall -Wextra -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wno-address -Wfloat-equal -Wdeclaration-after-statement -Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare -Wno-pointer-sign -fno-common -fno-strict-aliasing -I/usr/local/include -MT dbus-run-session.o -MD -MP -MF .deps/dbus-run-session.Tpo -c -o dbus-run-session.o dbus-run-session.c
mv -f .deps/dbus-run-session.Tpo .deps/dbus-run-session.Po
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -Wall -Wextra -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wno-address -Wfloat-equal -Wdeclaration-after-statement -Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare -Wno-pointer-sign -fno-common -fno-strict-aliasing -I/usr/local/include -export-dynamic -L/usr/local/lib -o dbus-run-session dbus-run-session.o ../dbus/libdbus-1.la  
libtool: link: gcc -Wall -Wextra -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wno-address -Wfloat-equal -Wdeclaration-after-statement -Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare -Wno-pointer-sign -fno-common -fno-strict-aliasing -I/usr/local/include -o .libs/dbus-run-session dbus-run-session.o -Wl,-E  -L/usr/local/lib -L../dbus/.libs -ldbus-1 -lpthread -Wl,-rpath,/usr/local/lib
/usr/local/lib/libdbus-1.so.10.2: warning: vsprintf() is often misused, please use vsnprintf()
dbus-run-session.o(.text+0x1eb): In function `exec_dbus_daemon':
: warning: sprintf() is often misused, please use snprintf()
dbus-run-session.o(.text+0x9f5): In function `main':
: undefined reference to `dbus_setenv'
dbus-run-session.o(.text+0xa0a): In function `main':
: undefined reference to `dbus_setenv'
dbus-run-session.o(.text+0xa1f): In function `main':
: undefined reference to `dbus_setenv'
dbus-run-session.o(.text+0xa34): In function `main':
: undefined reference to `dbus_setenv'
dbus-run-session.o(.text+0xa49): In function `main':
: undefined reference to `dbus_setenv'
collect2: ld returned 1 exit status
gmake[2]: *** [dbus-run-session] Error 1
gmake[2]: Leaving directory `/home/chengwei/Upstream/dbus.git/tools'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/home/chengwei/Upstream/dbus.git'
gmake: *** [all] Error 2

Even GNU libtool installed, the built-in libtool used. I think we need a fix or document update to let user workaround with this.
Comment 1 Simon McVittie 2013-09-25 12:32:53 UTC
(In reply to comment #0)
> libtool: link: gcc [...] -I/usr/local/include -o
> .libs/dbus-run-session dbus-run-session.o -Wl,-E  -L/usr/local/lib
> -L../dbus/.libs -ldbus-1 -lpthread -Wl,-rpath,/usr/local/lib

This is explicitly linking the executable against /usr/local/lib/libdbus-1.so (further up the search path than ../dbus/.libs)...

> dbus-run-session.o(.text+0x9f5): In function `main':
> : undefined reference to `dbus_setenv'

... and your installed libdbus-1.so is an older version that doesn't export dbus_setenv(), so, unsurprisingly, the link fails.

> Even GNU libtool installed, the built-in libtool used.

If "the built-in libtool" is broken, I'm not going to work around it.
Comment 2 Simon McVittie 2013-09-25 12:37:10 UTC
In the same situation (linking within the tree), I believe GNU libtool explicitly tells the linker to link ../dbus/.libs/libdbus-1.so (by name, instead of via -L... -ldbus-1). That's the correct thing here.

I suspect that any project that builds a library and some utilities that use that library, and uses recent library API in those utilities, will suffer a similar problem with this libtool implementation. Quite a lot of projects do that.

If you run "glibtoolize" (libtoolize with GNU libtool), it might fix this. I'd accept a patch that made autogen.sh try glibtoolize before libtoolize; or one that documented that we specifically need *GNU* libtool, not some imitation.
Comment 3 Chengwei Yang 2013-09-25 12:42:35 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > libtool: link: gcc [...] -I/usr/local/include -o
> > .libs/dbus-run-session dbus-run-session.o -Wl,-E  -L/usr/local/lib
> > -L../dbus/.libs -ldbus-1 -lpthread -Wl,-rpath,/usr/local/lib
> 
> This is explicitly linking the executable against
> /usr/local/lib/libdbus-1.so (further up the search path than
> ../dbus/.libs)...
> 
> > dbus-run-session.o(.text+0x9f5): In function `main':
> > : undefined reference to `dbus_setenv'
> 
> ... and your installed libdbus-1.so is an older version that doesn't export
> dbus_setenv(), so, unsurprisingly, the link fails.

That's it, however, it's an issue why libtool doesn't use the one in build tree but the installed one.

I just checked that the libtool is GNU libtool, generated from ltmain.sh which is from the GNU libtool, diff says they're identical.

> 
> > Even GNU libtool installed, the built-in libtool used.
> 
> If "the built-in libtool" is broken, I'm not going to work around it.

False issue, the GNU libtool was used but cause the above failure.
Comment 4 Simon McVittie 2013-09-25 12:46:54 UTC
Do you have a non-empty LDFLAGS or LD_LIBRARY_PATH?

This:

> -L/usr/local/lib

is probably the root cause. How is that getting onto your compiler command line?
Comment 5 Chengwei Yang 2013-09-25 12:51:22 UTC
(In reply to comment #4)
> Do you have a non-empty LDFLAGS or LD_LIBRARY_PATH?
> 
> This:
> 
> > -L/usr/local/lib
> 
> is probably the root cause. How is that getting onto your compiler command
> line?

Yes, in *BSD favour, all of packages installed with prefix /usr/local, so I need configure CFLAGS=-I/usr/local/include and LDFLAGS=-L/usr/local/lib to make it find header/libs.

That's just the same on FreeBSD 9.1.1, so far, not checked the status on NetBSD.
Comment 6 Chengwei Yang 2013-09-25 13:30:12 UTC
Within the configure generated on OpenBSD 5.3, below lines do cause the problem

    openbsd*)
      if test -f /usr/libexec/ld.so; then
        hardcode_direct=yes
        hardcode_shlibpath_var=no
        hardcode_direct_absolute=yes
Comment 7 Chengwei Yang 2013-09-25 13:45:11 UTC
(In reply to comment #6)
> Within the configure generated on OpenBSD 5.3, below lines do cause the
> problem
> 
>     openbsd*)
>       if test -f /usr/libexec/ld.so; then
>         hardcode_direct=yes
>         hardcode_shlibpath_var=no
>         hardcode_direct_absolute=yes

Still the case at libtool master branch, I'll send an email to its community for help.
Comment 8 Simon McVittie 2013-09-25 14:34:14 UTC
You could try changing the check for Expat to use pkg-config, something like this (untested):

PKG_CHECK_MODULES([EXPAT], [expat])

then replacing XML_CFLAGS, XML_LIBS with EXPAT_CFLAGS, EXPAT_LIBS throughout.

The .pc file is new in Expat 2.1.0, but that was released in 2012, and users of older platforms can use EXPAT_CFLAGS and EXPAT_LIBS to set the location of Expat. This would only be OK on the development branch, obviously.
Comment 9 Simon McVittie 2013-09-25 14:35:26 UTC
(In reply to comment #8)
> PKG_CHECK_MODULES([EXPAT], [expat])
> 
> then replacing XML_CFLAGS, XML_LIBS with EXPAT_CFLAGS, EXPAT_LIBS throughout

... which would hopefully mean you didn't need to set CFLAGS or LDFLAGS (which are too broad, especially LDFLAGS).

In particular, LDFLAGS is the wrong place to put -L - you can sometimes get into precedence problems like this one.
Comment 10 Simon McVittie 2017-04-07 13:09:23 UTC
Created attachment 130744 [details] [review]
Autotools build: Use pkg-config to find libexpat

The version of expat that added the .pc file was released in 2012.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69801
Signed-off-by: Simon McVittie <smcv@collabora.com>

---

I think this will fix the bug by making it unnecessary to use LDFLAGS=-L/usr/local/lib. It's a good change in any case.
Comment 11 Simon McVittie 2017-04-07 13:09:43 UTC
Created attachment 130745 [details] [review]
build: Remove indirection from uses of Expat

We haven't supported XML libraries other than Expat since 2013.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69801
Signed-off-by: Simon McVittie <smcv@collabora.com>
Comment 12 Simon McVittie 2017-04-07 13:26:36 UTC
There are a lot of compiler warnings, but with --enable-compile-warnings=yes (instead of the default error) it does seem to work.
Comment 13 Philip Withnall 2017-04-07 23:37:08 UTC
Comment on attachment 130744 [details] [review]
Autotools build: Use pkg-config to find libexpat

Review of attachment 130744 [details] [review]:
-----------------------------------------------------------------

r+
Comment 14 Philip Withnall 2017-04-07 23:38:44 UTC
Comment on attachment 130745 [details] [review]
build: Remove indirection from uses of Expat

Review of attachment 130745 [details] [review]:
-----------------------------------------------------------------

r+
Comment 15 Simon McVittie 2017-04-10 11:53:35 UTC
Thanks, fixed in git for 1.11.14.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.