Bug 9665 - waf buildsystem produces incorrect installnames when linking on MacOS against dynamic libraries
Summary: waf buildsystem produces incorrect installnames when linking on MacOS against...
Status: NEW
Alias: None
Product: Samba 4.0
Classification: Unclassified
Component: Build (show other bugs)
Version: 4.0.6
Hardware: All Mac OS X
: P5 normal (vote)
Target Milestone: ---
Assignee: Björn Jacke
QA Contact: Samba QA Contact
URL:
Keywords:
: 11056 (view as bug list)
Depends on: 10885
Blocks: 11056
  Show dependency treegraph
 
Reported: 2013-02-14 17:41 UTC by Misty De Meo
Modified: 2015-10-28 12:40 UTC (History)
2 users (show)

See Also:


Attachments
otool -L output for `samba` binary (10.25 KB, text/plain)
2013-02-14 17:42 UTC, Misty De Meo
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Misty De Meo 2013-02-14 17:41:31 UTC
When using the waf buildsystem, dynamic linking incorrectly uses paths from the build path rather than from the install prefix. As a result, none of the samba binaries can find their libraries and they will fail to work post-make install.

I tested this on samba 4.0.3 using Mac OS X 10.6.8, and I can also reproduce on samba 4.0.0. To build, I used the following steps:

./configure --prefix=/usr/local/Cellar/samba/4.0.3
make
make install

While I specified an install prefix, the same thing happens if no prefix is specified to ./configure.

I've attached, as an example, the `otool -L` output for the `samba` binary from 4.0.0.
Comment 1 Misty De Meo 2013-02-14 17:42:25 UTC
Created attachment 8554 [details]
otool -L output for `samba` binary
Comment 2 Misty De Meo 2013-06-07 16:29:52 UTC
Taking a look at the verbose build output, it looks like the problem is that the linking isn't specifying an installname. According to Apple's ld manpage:

     -install_name name
                 Sets an internal "install path" (LC_ID_DYLIB) in a dynamic library. Any clients linked against the library will record that path as the way dyld should locate this library.  If this option is not specified, then the -o path will be used.  This option is also called -dylib_install_name for compatibility.

The waf buildscript is a) not specifying an installname, and b) calling -o with the full path to the library in its temporary location. For example:

11:16:12 runner cc default/lib/async_req/async_sock_1.o default/libcli/smb/read_smb_1.o -o /tmp/samba-RX4S/samba-4.0.6/bin/default/libcli/smb/libsmb_transport.dylib -framework CoreFoundation -lpthread -dynamiclib -Wl,-rpath,/tmp/samba-RX4S/samba-4.0.6/bin/shared -Wl,-rpath,/tmp/samba-RX4S/samba-4.0.6/bin/shared/private -Ldefault/lib/replace -Ldefault/lib/tevent -Ldefault/lib/talloc -Ldefault/libcli/util -Ldefault/lib/util -L/usr/local/lib -lsamba-util -lerrors -ltalloc -ltevent-util -ltevent -lutil_setid -lreplace -liconv

As a result, this lib records "/tmp/samba-RX4S/samba-4.0.6/bin/default/libcli/smb/libsmb_transport.dylib" as its installname instead of "$PREFIX/lib/private/libsmp_transport.dylib" or "libsmp_transport.dylib", and any other libraries linking against it will pick up that name. For example, the `otool -L` output of samab shows it links against libsmp_transport in this way:

/usr/local/sbin/samba:
...
	/tmp/samba-RX4S/samba-4.0.6/bin/default/libcli/smb/libsmb_transport.dylib (compatibility version 0.0.0, current version 0.0.0)
Comment 3 Misty De Meo 2013-06-07 16:31:10 UTC
I also notice that ld is being called with -rpath from the temporary build directory, not the install prefix.
Comment 4 BySabi Files 2015-01-15 19:11:55 UTC
This bug is still here.
I can compile Samba 4.1.16 on OSX 10.9.5 but dynamic linking stuck on "build path".
What file must be patch to install on OSX?
Comment 5 Andrew Bartlett 2015-04-16 04:52:28 UTC
*** Bug 11056 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Bartlett 2015-04-16 05:47:45 UTC
If it helps, here is a bit of an explanation of how the waf build works:
 - We build and link one during 'make', and then re-link to the final system location in 'make install'

 - an is_install flag is used to change some build options between BUILD and INSTALL modes

Patches are welcome (I don't have modern mac), it should probably be to the code in buildtools/wafsamba, probably buildtools/wafsamba/samba_install.py