imlib2 svg loader linker option '-Wl,-z,nodelete' fails homebrew compilation on Mac (ld unknown option -z) #8

Closed
opened 2023-04-01 00:48:48 -07:00 by ylh · 3 comments

Homebrew installs imlib2 by default compiled --without-svg.

If compiled from source with svg support, on MacOS (Catalina 10.15) the system linker ld does not understand -Wl,-z,nodelete as specified in

legacy-imlib2/src/modules/loaders/Makefile.am

line 145,

svg_la_LDFLAGS       = -module -avoid-version -Wl,-z,nodelete

It can compile successfully however without any linker options, i.e.,

svg_la_LDFLAGS       = -module -avoid-version
$brew -v 
brew -v
Homebrew 4.0.10-119-g931327d
Homebrew/homebrew-core (git revision 034803b0a4b; last commit 2023-04-01)
Homebrew/homebrew-cask (git revision dc7a670a5f; last commit 2023-04-01)
$ld -v
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 12.0.0, (clang-1200.0.32.29) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 12.0.0 (tapi-1200.0.23.5)
Homebrew installs imlib2 by default compiled `--without-svg`. If compiled from source with `svg` support, on MacOS (Catalina 10.15) the system linker `ld` does not understand `-Wl,-z,nodelete` as specified in legacy-imlib2/src/modules/loaders/Makefile.am line 145, ``` svg_la_LDFLAGS = -module -avoid-version -Wl,-z,nodelete ``` It can compile successfully however without any linker options, i.e., ``` svg_la_LDFLAGS = -module -avoid-version ``` ``` $brew -v brew -v Homebrew 4.0.10-119-g931327d Homebrew/homebrew-core (git revision 034803b0a4b; last commit 2023-04-01) Homebrew/homebrew-cask (git revision dc7a670a5f; last commit 2023-04-01) $ld -v @(#)PROGRAM:ld PROJECT:ld64-609.8 BUILD 15:07:46 Dec 18 2020 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em LTO support using: LLVM version 12.0.0, (clang-1200.0.32.29) (static support for 27, runtime is 27) TAPI support using: Apple TAPI version 12.0.0 (tapi-1200.0.23.5) ```
Owner

Hmm..

At least on linux it seems that the svg library (just checked with librsvg2-2.54.5) does not like to be loaded (dlopen'ed) more than once. libheif has (had?) the same problem.
If you have a git checkout, running
$ make -C test
fails with:

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `29227952`,
 right: `0`: Type RsvgHandle has already been registered', /builddir/build/BUILD/librsvg-2.54.5/vendor/glib/src/subclass/types.rs:902:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
unknown file: Failure
Unknown C++ exception thrown in the test body.
fatal runtime error: Rust panics must be rethrown

Adding the nodelete option when linking the loader module fixes this problem.

Normally loaders will never be loaded more than once. However, if imlib_flush_loaders() is called, then loaders may subsequently be re-loaded.
I would assume that there are no regular applications that call this function, but of course I cannot be sure.
When running the imlib2 test suite this function is called a couple of times for various testing purposes.

I think things will work just fine at your end if you just remove the option.

I'll consider not using the nodelete option and find some other way to handle the problem.

Hmm.. At least on linux it seems that the svg library (just checked with librsvg2-2.54.5) does not like to be loaded (dlopen'ed) more than once. libheif has (had?) the same problem. If you have a git checkout, running $ make -C test fails with: ``` thread '<unnamed>' panicked at 'assertion failed: `(left == right)` left: `29227952`, right: `0`: Type RsvgHandle has already been registered', /builddir/build/BUILD/librsvg-2.54.5/vendor/glib/src/subclass/types.rs:902:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace unknown file: Failure Unknown C++ exception thrown in the test body. fatal runtime error: Rust panics must be rethrown ``` Adding the nodelete option when linking the loader module fixes this problem. Normally loaders will never be loaded more than once. However, if imlib_flush_loaders() is called, then loaders may subsequently be re-loaded. I would assume that there are no regular applications that call this function, but of course I cannot be sure. When running the imlib2 test suite this function is called a couple of times for various testing purposes. I think things will work just fine at your end if you just remove the option. I'll consider not using the nodelete option and find some other way to handle the problem.
Owner

Should be fixed in git now.

Should be fixed in git now.
Author

Should be fixed in git now.

Thank you so much for your quick response and code change!

:)

  1. git clone git branch to local disk

  2. git diff v1.11.0 master > ld.patch

  3. use gnu patch -p1 < ld.patch to merge code to brew imlib2 code

  4. re-run autoreconf -i

  5. brew reinstall -s imlib2

> Should be fixed in git now. Thank you so much for your quick response and code change! :) 1. git clone git branch to local disk 2. git diff v1.11.0 master > ld.patch 3. use gnu patch -p1 < ld.patch to merge code to brew imlib2 code 4. re-run autoreconf -i 5. brew reinstall -s imlib2
kw closed this issue 2023-04-06 00:26:30 -07:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: old/legacy-imlib2#8
No description provided.