Bug 172108 - [PATCH] graphics/ilmbase: libIlmThread is not linked with pthread library
Summary: [PATCH] graphics/ilmbase: libIlmThread is not linked with pthread library
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Rusmir Dusko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-27 05:00 UTC by Dmitry Marakasov
Modified: 2014-03-27 01:08 UTC (History)
0 users

See Also:


Attachments
ilmbase_thread_patch.txt (5.35 KB, text/plain)
2012-10-02 20:16 UTC, Steve Wills
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Marakasov 2012-09-27 05:00:17 UTC
After recent update of ilmbase and OpenEXR, at least one dependent port (graphics/nvidia-texture-tools) was broken:

http://people.freebsd.org/~amdmi3/nvidia-texture-tools-2.0.8.1_1.log

this happened because libIlmImf is no longer linked with thread library

ilmbase-1.0.1/OpenEXR-1.6.1:
% ldd /usr/local/lib/libIlmImf.so
/usr/local/lib/libIlmImf.so:
	libthr.so.3 => /lib/libthr.so.3 (0x8012c2000) <--- gone after update
	libz.so.6 => /lib/libz.so.6 (0x8014e3000)
	libImath.so.6 => /usr/local/lib/libImath.so.6 (0x8016f8000)
	libHalf.so.6 => /usr/local/lib/libHalf.so.6 (0x8018fd000)
	libIlmThread.so.6 => /usr/local/lib/libIlmThread.so.6 (0x801b3f000)
	libIex.so.6 => /usr/local/lib/libIex.so.6 (0x801d46000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x801f5d000)
	libm.so.5 => /lib/libm.so.5 (0x80225a000)
	libc.so.7 => /lib/libc.so.7 (0x800848000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x80247b000)

ilmbase-1.0.2/OpenEXR-1.7.0:
/usr/local/lib/libIlmImf.so:
	libz.so.6 => /lib/libz.so.6 (0x8012d9000)
	libImath.so.6 => /usr/local/lib/libImath.so.6 (0x8014ee000)
	libHalf.so.6 => /usr/local/lib/libHalf.so.6 (0x8016f3000)
	libIlmThread.so.6 => /usr/local/lib/libIlmThread.so.6 (0x801935000)
	libIex.so.6 => /usr/local/lib/libIex.so.6 (0x801b3c000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x801d53000)
	libm.so.5 => /lib/libm.so.5 (0x802050000)
	libc.so.7 => /lib/libc.so.7 (0x800848000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x802271000)

But the problem is actually in libIlmThread, which is not linked
with libthr in both old and new versions:

/usr/local/lib/libIlmThread.so:
	libIex.so.6 => /usr/local/lib/libIex.so.6 (0x801207000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x80141e000)
	libm.so.5 => /lib/libm.so.5 (0x801727000)
	libc.so.7 => /lib/libc.so.7 (0x800848000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801948000)

With that, any linking with it or other library using it without
explicit -pthread will fail:

% echo 'int main(){}' > test.c && gcc test.c -L/usr/local/lib -lIlmThread
/usr/local/lib/libIlmThread.so: undefined reference to `pthread_create'

And why it's not linked with libthr is somehow related to libtool
black magic, as though link command which produces this library
does have -pthread argument:

libtool: link: c++  -fPIC -DPIC -shared -nostdlib /usr/lib/crti.o /usr/lib/crtbeginS.o  .libs/IlmThreadPool.o .libs/IlmThread.o .libs/IlmThreadSemaphore.o .libs/IlmThreadMutex.o .libs/IlmThreadPosix.o .libs/IlmThreadSemaphorePosix.o .libs/IlmThreadSemaphorePosixCompat.o .libs/IlmThreadMutexPosix.o   -Wl,-rpath -Wl,/usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/work/ilmbase-1.0.2/Iex/.libs -Wl,-rpath -Wl,/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/prefix/lib ../Iex/.libs/libIex.so -L/usr/lib -lstdc++ -lm -lc -lgcc_s /usr/lib/crtendS.o /usr/lib/crtn.o  -O2 -march=nocona -pthread -pthread   -pthread -Wl,-soname -Wl,libIlmThread.so.6 -o .libs/libIlmThread.so.6

the resulting library is not linked with libthr. If the command
is (manually) changed to `normal' way of creating a shared library

c++  -fPIC -DPIC -shared .libs/IlmThreadPool.o .libs/IlmThread.o .libs/IlmThreadSemaphore.o .libs/IlmThreadMutex.o .libs/IlmThreadPosix.o .libs/IlmThreadSemaphorePosix.o .libs/IlmThreadSemaphorePosixCompat.o .libs/IlmThreadMutexPosix.o   -Wl,-rpath -Wl,/usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/work/ilmbase-1.0.2/Iex/.libs -Wl,-rpath -Wl,/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/prefix/lib ../Iex/.libs/libIex.so -L/usr/lib -lstdc++ -lm -O2 -march=nocona -pthread -pthread   -pthread -Wl,-soname -Wl,libIlmThread.so.6 -o .libs/libIlmThread.so.6_

it produces correct library:

% ldd .libs/libIlmThread.so.6 .libs/libIlmThread.so.6_
.libs/libIlmThread.so.6:
	libIex.so.6 => /usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/work/ilmbase-1.0.2/Iex/.libs/libIex.so.6 (0x801207000)
	libstdc++.so.6 => /usr/local/lib/gcc46/libstdc++.so.6 (0x80141e000)
	libm.so.5 => /lib/libm.so.5 (0x80171b000)
	libc.so.7 => /lib/libc.so.7 (0x800848000)
	libgcc_s.so.1 => /usr/local/lib/gcc46/libgcc_s.so.1 (0x80193c000)
.libs/libIlmThread.so.6_:
	libIex.so.6 => /usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/work/ilmbase-1.0.2/Iex/.libs/libIex.so.6 (0x801207000)
	libstdc++.so.6 => /usr/local/lib/gcc46/libstdc++.so.6 (0x80141e000)
	libm.so.5 => /lib/libm.so.5 (0x80171b000)
	libgcc_s.so.1 => /usr/local/lib/gcc46/libgcc_s.so.1 (0x80193c000)
	libthr.so.3 => /lib/libthr.so.3 (0x801b51000)
	libc.so.7 => /lib/libc.so.7 (0x800848000)

I'm not familiar with libtool workings, but my guess is that it should be taught to not use `-nostdlib /usr/lib/crti.o /usr/lib/crtbeginS.o ... -lc -lgcc_s /usr/lib/crtendS.o /usr/lib/crtn.o' magic, so the library is linked correctly.

Generated with FreeBSD Port Tools 0.99_6 (mode: change, diff: ports)
Comment 1 Steve Wills freebsd_committer freebsd_triage 2012-09-27 18:59:55 UTC
Responsible Changed
From-To: freebsd-ports-bugs->swills

I'll take it.
Comment 2 Steve Wills freebsd_committer freebsd_triage 2012-10-02 20:16:35 UTC
Hi,

This will require two fixes. One is a fix to libtool, which is in PR 
ports/172275. The other is a fix to ilmbase, which is attached. This patch
is sufficient, but not ideal. It causes all the libs to be built with
-pthread, not just the IlmThread lib. This shouldn't be a huge problem,
but isn't quite correct. Not sure yet if this is acceptable or if further
patches are necessary.

Steve
Comment 3 Rusmir Dusko freebsd_committer freebsd_triage 2014-03-26 14:13:46 UTC
Now are in FreeBSD Ports tree

pkg info | grep ilmbase
ilmbase-2.1.0                  ILM Base libraries a.k.a. Half, IlmThread, Imath, and Iex

pkg info | grep OpenEXR
OpenEXR-2.1.0_1                High dynamic-range (HDR) image file format


ldd /usr/local/lib/libIlmImf.so
/usr/local/lib/libIlmImf.so:
        libz.so.6 => /lib/libz.so.6 (0x801752000)
        libImath-2_1.so.11 => /usr/local/lib/libImath-2_1.so.11 (0x801967000)
        libHalf.so.11 => /usr/local/lib/libHalf.so.11 (0x801b77000)
        libIexMath-2_1.so.11 => /usr/local/lib/libIexMath-2_1.so.11 (0x801dba000)
        libIlmThread-2_1.so.11 => /usr/local/lib/libIlmThread-2_1.so.11 (0x801fbd000)
        libIex-2_1.so.11 => /usr/local/lib/libIex-2_1.so.11 (0x8021c3000)
        libc++.so.1 => /usr/local/lib/libc++.so.1 (0x8023db000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x802698000)
        libm.so.5 => /lib/libm.so.5 (0x8028b2000)
        libc.so.7 => /lib/libc.so.7 (0x80081d000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x802ad8000)
        libthr.so.3 => /lib/libthr.so.3 (0x802ce5000) <--- is here
        librt.so.1 => /usr/lib/librt.so.1 (0x802f0a000)


ldd /usr/local/lib/libIlmThread.so 
/usr/local/lib/libIlmThread.so:
        libIex-2_1.so.11 => /usr/local/lib/libIex-2_1.so.11 (0x801606000)
        libc++.so.1 => /usr/local/lib/libc++.so.1 (0x80181e000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x801adb000)
        libm.so.5 => /lib/libm.so.5 (0x801cf5000)
        libc.so.7 => /lib/libc.so.7 (0x80081d000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801f1b000)
        libthr.so.3 => /lib/libthr.so.3 (0x802128000) <--- is here
        librt.so.1 => /usr/lib/librt.so.1 (0x80234d000)


echo 'int main(){}' > test.c && gcc47 test.c -L/usr/local/lib -lIlmThread                                         
echo 'int main(){}' > test.c && gcc48 test.c -L/usr/local/lib -lIlmThread
echo 'int main(){}' > test.c && gcc49 test.c -L/usr/local/lib -lIlmThread
echo 'int main(){}' > test.c && clang test.c -L/usr/local/lib -lIlmThread

No one wrong message.

This PR is obsolete now.

-- 
Best regards,
Rusmir Dusko
Comment 4 Rusmir Dusko freebsd_committer freebsd_triage 2014-03-26 14:43:36 UTC
Responsible Changed
From-To: swills->nemysis

I'll take it.
Comment 5 Rusmir Dusko freebsd_committer freebsd_triage 2014-03-27 01:08:39 UTC
State Changed
From-To: open->closed

After commmit IlmBase r349312 works good build