FS#77224 - [libtiff] static linking is not possible due to jbigkit missing as a dependency

Attached to Project: Arch Linux
Opened by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 01:33 GMT
Last edited by David Runge (dvzrv) - Saturday, 02 September 2023, 15:48 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Jelle van der Waa (jelly)
David Runge (dvzrv)
Levente Polyak (anthraxx)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description: When using libtiff in static compilation libjbig cannot be found and compilation errors out


Additional info:
* Version: 4.5.0-1

Steps to reproduce:

Create a file that links to libtiff and try the following:

$ gcc tiff.c $(pkg-config --cflags --libs --static libtiff-4)
/usr/bin/ld: cannot find -ljbig: No such file or directory
collect2: error: ld returned 1 exit status

The problem is jbigkit is a makedepend and triggers this check in autotools[1]. Curiously, libtiff is usable as a shared library, I don't really know how that works. Someone I talked to said it could be a gcc bug with --as-needed.

[1] https://gitlab.com/libtiff/libtiff/-/blob/master/configure.ac#L679-691
This task depends upon

Closed by  David Runge (dvzrv)
Saturday, 02 September 2023, 15:48 GMT
Reason for closing:  Fixed
Additional comments about closing:  Fixed with jbigkit 2.1-7. Further rebuilds are required and are tracked in https://archlinux.org/todo/rebuild-again st-jbigkit-shared-libraries/
Comment by Toolybird (Toolybird) - Sunday, 22 January 2023, 20:29 GMT
Static libs (*.a files) are not provided for the vast majority of pkgs because static linking is not supported. It's a security thing and has been for years in most mainstream distros. Interestingly, I can't find much Arch documentation to refer to...apart from [1]. libtiff is probably the last pkg you would want to link statically because of its history of exploits [2].

[1] https://archlinux.org/todo/remove-static-libraries/
[2] https://en.wikipedia.org/wiki/LibTIFF#Exploits
Comment by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 21:19 GMT
  • Field changed: Percent Complete (100% → 0%)
I think you've misunderstood this issue. I am not asking for a static library, nor am I saying there is a static library missing on arch. When using libtiff in something *I* am statically compiling, the --static flag returns libraries that *do not exist* on the system due to a bug in packaging.

This is trivial to reproduce, and I explained how to fix it in the issue. There is actually a second bug here that gcc is not linking libjbig to libtiff.so, but right now the broken .pc file is the biggest issue.
Comment by Toolybird (Toolybird) - Sunday, 22 January 2023, 21:20 GMT
Ok, sorry for the misunderstanding. But I still don't see how this is an Arch packaging bug. What is your proposed fix?
Comment by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 21:35 GMT
The fix is that jbigkit is a depend, or that it isn't used as a makedepend. Again, the core issue is that during build time libtiff is detecting jbigkit and creating static lib flags for it in the .pc file[1]. Yes, no libtiff.a is shipped with libtiff, but downstream if you use --static when building something that depends on libtiff, you get the linker error I put in the OP. Because in libtiff-4.pc, this is the Libs.private line:

Libs.private: -lzstd -llzma -ljbig -ljpeg -lz -lm

the -ljbig part is the issue here.

[1] https://gitlab.com/libtiff/libtiff/-/blob/master/configure.ac#L679-691
Comment by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 21:39 GMT
Ok I just discovered another part to this, and why ldd does not show jbigkit in the dependencies. Apparently arch compiles jbigkit as a static lib[1]?? And it's just linked in at build time silently? So, this seems like a packaging error for sure. The other possibility is getting Libs.private removed in libtiff's .pc file, or modified because libjbig is statically compiled into libtiff.so

[1] https://github.com/archlinux/svntogit-community/blob/packages/jbigkit/trunk/PKGBUILD#L24
Comment by loqs (loqs) - Sunday, 22 January 2023, 21:49 GMT
@LaserEyes is this what you had in find?
Edit:
Another option what be to convert jbigkit to a shared library as Fedora [1] and Debian [2] have done.
Edit2:
If you remove the --static flag from the pkgconf / pkg-config invocation is the build correct?

[1] https://src.fedoraproject.org/rpms/jbigkit/blob/rawhide/f/jbigkit-2.1-shlib.patch
[2] https://sources.debian.org/data/main/j/jbigkit/2.1-6.1/debian/patches/improve-upstream-Makefiles.diff
Comment by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 22:06 GMT
Yes, that would work. I have no preference on which is better, but given what Toolybird said above, since arch doesn't want static packages it should make jbigkit a shared lib.
Comment by Toolybird (Toolybird) - Sunday, 22 January 2023, 22:19 GMT
Ok, thanks for the clarifications, and thanks @loqs for your input too. I will let the libtiff and jbigkit PM's determine any course of action.
Comment by LaserEyess (LaserEyess) - Sunday, 22 January 2023, 23:14 GMT
@loqs Yes, without --static it works as expected. My simple example was a bit misguided, where I'm seeing this issue is when building a static library for mpv. If I were to link that with:

$ gcc my_mpv_app.c $(pkg-config --cflags --libs --static my-libmpv)

Then when resolving the dependencies of ffpmeg->libtiff, it would propagate the --static flag, and thus -ljbig would be included and cause the error. Technically, -ljbig is not necessary here, since ffmpeg and libtiff are shared libs. However, in this particular case, because libjbig was statically compiled into libtiff.so, and because Libs.Private exists even though libtiff.a does not, you get the error.
Comment by David Runge (dvzrv) - Saturday, 02 September 2023, 15:44 GMT
I have rebuilt jbigkit to track shared instead of static libs in staging.

I will open a rebuild TODO for the dependents.

Loading...