thom311 / libnl

Netlink Library Suite
GNU Lesser General Public License v2.1
419 stars 311 forks source link

Warnings about missing symbol when building with mold linker #350

Closed kostadinsh closed 1 year ago

kostadinsh commented 1 year ago

It seems that libnl has some issues during the linking phase regarding a symbol not being found when building with the mold linker. I've turned mold's warnings into errors with -Wl,--fatal-warnings, so I can catch them more easily. Below is the last couple of lines from the build log, and I am also adding the complete log as an attachment.

libnl source used is cbafad9ddf24caef5230fef715d34f0539603be0 mold used is commit b04aba89d3a1931470983212925443e7aefca1e1 gcc (Gentoo 13.1.1_p20230527 p3) 13.1.1 20230527

Steps to reproduce:

  1. clone libnl's source and cd into it
  2. run export LDFLAGS="-fuse-ld=mold -Wl,--fatal-warnings"
  3. run autoreconf -vfi and ./configure --prefix=/usr
  4. run make V=1
libtool: link: gcc -shared  -fPIC -DPIC  lib/.libs/libnl_3_la-addr.o lib/.libs/libnl_3_la-attr.o lib/.libs/libnl_3_la-cache.o lib/.libs/libnl_3_la-cache_mngr.o lib/.libs/libnl_3_la-cache_mngt.o lib/.libs/libnl_3_la-data.o lib/.libs/libnl_3_la-error.o lib/.libs/libnl_3_la-handlers.o lib/.libs/libnl_3_la-hash.o lib/.libs/libnl_3_la-hashtable.o lib/.libs/libnl_3_la-mpls.o lib/.libs/libnl_3_la-msg.o lib/.libs/libnl_3_la-nl.o lib/.libs/libnl_3_la-object.o lib/.libs/libnl_3_la-socket.o lib/.libs/libnl_3_la-utils.o lib/.libs/libnl_3_la-version.o   -lpthread  -g -O2 -Wl,--version-script=./libnl-3.sym -fuse-ld=mold -Wl,--fatal-warnings   -Wl,-soname -Wl,libnl-3.so.200 -o lib/.libs/libnl-3.so.200.26.0
mold: error: ./libnl-3.sym: cannot assign version `libnl_3_6` to symbol `rtnl_link_info_ops_get`: symbol not found
collect2: error: ld returned 1 exit status
make: *** [Makefile:2951: lib/libnl-3.la] Error

libnl-github.log

thom311 commented 1 year ago

fixed by 4c681e77075af34e890c2946c3d17d33c9c8a10d.

Thanks.

Nice that mold warns about such errors.

kostadinsh commented 1 year ago

I've just tested again with a fresh clone of the repo without the --fatal-warnings flag, and a couple more appear. I guess when I was building with that option the build failed before these symbols were used. I am also attaching the complete log.

libtool: link: gcc -shared  -fPIC -DPIC  lib/fib_lookup/.libs/libnl_route_3_la-lookup.o lib/fib_lookup/.libs/libnl_route_3_la-request.o lib/route/.libs/libnl_route_3_la-act.o lib/route/act/.libs/libnl_route_3_la-gact.o lib/route/act/.libs/libnl_route_3_la-mirred.o lib/route/act/.libs/libnl_route_3_la-nat.o lib/route/act/.libs/libnl_route_3_la-skbedit.o lib/route/act/.libs/libnl_route_3_la-vlan.o lib/route/.libs/libnl_route_3_la-addr.o lib/route/.libs/libnl_route_3_la-class.o lib/route/.libs/libnl_route_3_la-classid.o lib/route/.libs/libnl_route_3_la-cls.o lib/route/cls/.libs/libnl_route_3_la-basic.o lib/route/cls/.libs/libnl_route_3_la-cgroup.o lib/route/cls/.libs/libnl_route_3_la-ematch.o lib/route/cls/ematch/.libs/libnl_route_3_la-cmp.o lib/route/cls/ematch/.libs/libnl_route_3_la-container.o lib/route/cls/ematch/.libs/libnl_route_3_la-meta.o lib/route/cls/ematch/.libs/libnl_route_3_la-nbyte.o lib/route/cls/ematch/.libs/libnl_route_3_la-text.o lib/route/cls/.libs/libnl_route_3_la-flower.o lib/route/cls/.libs/libnl_route_3_la-fw.o lib/route/cls/.libs/libnl_route_3_la-mall.o lib/route/cls/.libs/libnl_route_3_la-police.o lib/route/cls/.libs/libnl_route_3_la-u32.o lib/route/.libs/libnl_route_3_la-link.o lib/route/link/.libs/libnl_route_3_la-api.o lib/route/link/.libs/libnl_route_3_la-bonding.o lib/route/link/.libs/libnl_route_3_la-bridge.o lib/route/link/.libs/libnl_route_3_la-bridge_info.o lib/route/link/.libs/libnl_route_3_la-can.o lib/route/link/.libs/libnl_route_3_la-dummy.o lib/route/link/.libs/libnl_route_3_la-geneve.o lib/route/link/.libs/libnl_route_3_la-ifb.o lib/route/link/.libs/libnl_route_3_la-inet.o lib/route/link/.libs/libnl_route_3_la-inet6.o lib/route/link/.libs/libnl_route_3_la-ip6gre.o lib/route/link/.libs/libnl_route_3_la-ip6tnl.o lib/route/link/.libs/libnl_route_3_la-ip6vti.o lib/route/link/.libs/libnl_route_3_la-ipgre.o lib/route/link/.libs/libnl_route_3_la-ipip.o lib/route/link/.libs/libnl_route_3_la-ipvlan.o lib/route/link/.libs/libnl_route_3_la-ipvti.o lib/route/link/.libs/libnl_route_3_la-macsec.o lib/route/link/.libs/libnl_route_3_la-macvlan.o lib/route/link/.libs/libnl_route_3_la-ppp.o lib/route/link/.libs/libnl_route_3_la-sit.o lib/route/link/.libs/libnl_route_3_la-sriov.o lib/route/link/.libs/libnl_route_3_la-team.o lib/route/link/.libs/libnl_route_3_la-veth.o lib/route/link/.libs/libnl_route_3_la-vlan.o lib/route/link/.libs/libnl_route_3_la-vrf.o lib/route/link/.libs/libnl_route_3_la-vxlan.o lib/route/link/.libs/libnl_route_3_la-xfrmi.o lib/route/.libs/libnl_route_3_la-mdb.o lib/route/.libs/libnl_route_3_la-neigh.o lib/route/.libs/libnl_route_3_la-neightbl.o lib/route/.libs/libnl_route_3_la-netconf.o lib/route/.libs/libnl_route_3_la-nexthop.o lib/route/.libs/libnl_route_3_la-nexthop_encap.o lib/route/.libs/libnl_route_3_la-nh.o lib/route/.libs/libnl_route_3_la-nh_encap_mpls.o lib/route/.libs/libnl_route_3_la-pktloc.o lib/route/.libs/libnl_route_3_la-qdisc.o lib/route/qdisc/.libs/libnl_route_3_la-blackhole.o lib/route/qdisc/.libs/libnl_route_3_la-cbq.o lib/route/qdisc/.libs/libnl_route_3_la-dsmark.o lib/route/qdisc/.libs/libnl_route_3_la-fifo.o lib/route/qdisc/.libs/libnl_route_3_la-fq_codel.o lib/route/qdisc/.libs/libnl_route_3_la-hfsc.o lib/route/qdisc/.libs/libnl_route_3_la-htb.o lib/route/qdisc/.libs/libnl_route_3_la-ingress.o lib/route/qdisc/.libs/libnl_route_3_la-mqprio.o lib/route/qdisc/.libs/libnl_route_3_la-netem.o lib/route/qdisc/.libs/libnl_route_3_la-plug.o lib/route/qdisc/.libs/libnl_route_3_la-prio.o lib/route/qdisc/.libs/libnl_route_3_la-red.o lib/route/qdisc/.libs/libnl_route_3_la-sfq.o lib/route/qdisc/.libs/libnl_route_3_la-tbf.o lib/route/.libs/libnl_route_3_la-route.o lib/route/.libs/libnl_route_3_la-route_obj.o lib/route/.libs/libnl_route_3_la-route_utils.o lib/route/.libs/libnl_route_3_la-rtnl.o lib/route/.libs/libnl_route_3_la-rule.o lib/route/.libs/libnl_route_3_la-tc.o lib/route/cls/.libs/libnl_route_3_la-ematch_grammar.o lib/route/cls/.libs/libnl_route_3_la-ematch_syntax.o lib/route/.libs/libnl_route_3_la-pktloc_grammar.o lib/route/.libs/libnl_route_3_la-pktloc_syntax.o   -Wl,-rpath -Wl,/home/kshishmanov/libnl/lib/.libs lib/.libs/libnl-3.so -lpthread  -g -O2 -Wl,--version-script=./libnl-route-3.sym -fuse-ld=mold   -Wl,-soname -Wl,libnl-route-3.so.200 -o lib/.libs/libnl-route-3.so.200.26.0
mold: warning: ./libnl-route-3.sym: cannot assign version `libnl_3_8` to symbol `rtnl_nh_clone`: symbol not found
mold: warning: ./libnl-route-3.sym: cannot assign version `libnl_3_8` to symbol `rtnl_nh_compare`: symbol not found
mold: warning: ./libnl-route-3.sym: cannot assign version `libnl_3_8` to symbol `rtnl_nh_dump`: symbol not found

build.log

thom311 commented 1 year ago

fixed that too by f475c3b2b10dbab2dde8128e12b4187eafb9c12a. thanks!!

thom311 commented 1 year ago

I tried to enable a test in github actions, but it doesn't seem to fail. See https://github.com/thom311/libnl/actions/runs/5749583232/job/15584671802, the "Link with mold" step passes (although it shouldn't). Logfile here. The test does:

      - name: Link with mold
        run: |
          sudo apt-get -y --no-install-recommends install \
            mold
          git clean -fdx
          export LDFLAGS="-fuse-ld=mold -Wl,--fatal-warnings"
          ./autogen.sh
          ./configure
          make -j 5 V=1

Could that depend on the mold version? This is ubuntu 22.04, mold-1.0.3+dfsg-2

Any idea?

kostadinsh commented 1 year ago

I did some limited amount of testing, and from what I could find out, the first version that emitted the warnings at all was v1.8.0.

https://github.com/rui314/mold/releases/tag/v1.8.0

You could also try adding-Wl,--no-undefined-version,--fatal-warnings to the LDFLAGS in your clang builds, lld should warn about the same thing too, this has become the default behavior with LLVM/lld 16.

https://reviews.llvm.org/D135402

thom311 commented 1 year ago

thank you. Very helpful!!

I'll see to add a test for that.

kostadinsh commented 1 year ago

You are welcome! :-) I just checked and the --no-undefined-version flag should also be available with GCC/ld, so it is up to you to see which one would work out best for you. :D

thom311 commented 1 year ago

I did https://github.com/thom311/libnl/commit/391063096b5091a1b61dff8e5b4a9a49b01f5abe

Thanks again for your pointers.

thesamesam commented 1 year ago

@thom311 Could I trouble you for a new release perhaps? The patches don't apply cleanly (I admit they're probably easy to rebase though) so figured it was worth asking.

thom311 commented 1 year ago

a new release will happen soon.

thesamesam commented 1 year ago

Thank you!