Page MenuHomeFreeBSD

cddl: fix missing ZFS library dependencies
ClosedPublic

Authored by greg_unrelenting.technology on Oct 16 2021, 4:32 PM.

Details

Summary

In 9fae47666 zfsd got a libspl dependency to avoid undefined references.
However that workaround did not help external consumers of libzfs_core.

Fix all missing dependencies lld 13 and the rtld complain about.

Test Plan

e.g. a libzetta-rs based rust app doesn't fail to build anymore with

= note: ld: error: /usr/lib/libzfs_core.so: undefined reference to libspl_assertf [--no-allow-shlib-undefined]
        ld: error: /usr/lib/libzfs_core.so: undefined reference to zfs_ioctl_fd [--no-allow-shlib-undefined]
        ld: error: /usr/lib/libnvpair.so: undefined reference to libspl_assertf [--no-allow-shlib-undefined]
        clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

and doesn't fail to launch with

ld-elf.so.1: /lib/libzfs_core.so.2: Undefined symbol "libspl_assertf"

or

ld-elf.so.1: /lib/libzutil.so.2: Undefined symbol "powl"

or

ld-elf.so.1: /lib/libzutil.so.2: Undefined symbol "g_open"

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

This looks good, but I'm surprised that there aren't more transitive dependencies that can be removed. For example, zfsd doesn't use libzfs_core directly, only through libzfs. Can libzfs_core be removed from its LIBADD?

This looks good, but I'm surprised that there aren't more transitive dependencies that can be removed. For example, zfsd doesn't use libzfs_core directly, only through libzfs. Can libzfs_core be removed from its LIBADD?

Yep, that works. I haven't had the time to thoroughly investigate every zfs dependency in the tree, my goal was to unbreak external consumers of libzfs_core.

This revision is now accepted and ready to land.Oct 19 2021, 4:42 PM

A buildworld fails after applying this patch to main, seems to be while linking libavl:

--- cddl/lib/libavl__L ---
cc -target x86_64-unknown-freebsd14.0 --sysroot=/usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp -B/usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/bin    -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings -Wl,--warn-shared-textrel  -o libavl.so.2.full -Wl,-soname,libavl.so.2 avl.pico  -lspl
...
--- cddl/lib/libavl__L ---  
ld: error: relocation R_X86_64_PC32 cannot be used against symbol __stderrp; recompile with -fPIC                                                                                                                                                                                                                             >>> defined in /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/lib/libc.so.7                                                                                                                                                                                                                                              >>> referenced by assert.c:38 (/usr/home/markj/src/freebsd/sys/contrib/openzfs/lib/libspl/assert.c:38)                                                                                                                                                                                                                        >>>               assert.o:(libspl_assertf) in archive /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/lib/libspl.a                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ld: error: relocation R_X86_64_PC32 cannot be used against symbol __stderrp; recompile with -fPIC                                                                                                                                                                                                                             >>> defined in /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/lib/libc.so.7                                                                                                                                                                                                                                              >>> referenced by assert.c:39 (/usr/home/markj/src/freebsd/sys/contrib/openzfs/lib/libspl/assert.c:39)                                                                                                                                                                                                                        >>>               assert.o:(libspl_assertf) in archive /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/lib/libspl.a                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ld: error: relocation R_X86_64_PC32 cannot be used against symbol __stderrp; recompile with -fPIC                                                                                                                                                                                                                             >>> defined in /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/lib/libc.so.7                                                                                                                                                                                                                                              >>> referenced by assert.c:40 (/usr/home/markj/src/freebsd/sys/contrib/openzfs/lib/libspl/assert.c:40)                                                                                                                                                                                                                        >>>               assert.o:(libspl_assertf) in archive /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/lib/libspl.a                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ld: error: can't create dynamic relocation R_X86_64_32 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output                                                                                                                            >>> defined in /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/lib/libspl.a(assert.o)                                                                                                                                                                                                                                 >>> referenced by assert.c:40 (/usr/home/markj/src/freebsd/sys/contrib/openzfs/lib/libspl/assert.c:40)                                                                                                                                                                                                                        >>>               assert.o:(libspl_assertf) in archive /usr/obj/usr/home/markj/src/freebsd/amd64.amd64/tmp/usr/lib/libspl.a

Also add to Makefile.inc1 and SUBDIR_DEPEND_*. Should always work now.

git patch with metadata in case pulling that out from differential fails: P527

This revision now requires review to proceed.Sun, Nov 14, 3:19 PM
This revision was not accepted when it landed; it landed in state Needs Review.Mon, Nov 15, 2:43 PM
This revision was automatically updated to reflect the committed changes.