mesonbuild / mesonbuild/meson

Linking against native libs with ldc and bfd as linker is broken

Open
#6,987 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug language:D
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

Describe the bug
When linking against native (C) libs in D projects the linkage is broken with ldc.

I'm linking against libssl in my project (its a dependency of a static lib), meson calls ldc2 like so:

ldc2  -of=tests/apkd_dbus_server/test_apkd_dbus_server_update_d_exe 'tests/apkd_dbus_server/2c061b1@@test_apkd_dbus_server_update_d_exe@exe/update.d.o' -L=-rpath '-L=$ORIGIN/../../src/apkd_common:$ORIGIN/../../src/apkd:$ORIGIN/../../subprojects/apk-tools/src:$ORIGIN/../../subprojects/apk-tools/libfetch:$ORIGIN/../../src/apkd_dbus_server:$ORIGIN/../apkd_test_common:/usr/local/lib' -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/src/apkd_common -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/src/apkd -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/subprojects/apk-tools/src -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/subprojects/apk-tools/libfetch -L=-rpath-link -L=/usr/local/lib -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/src/apkd_dbus_server -L=-rpath-link -L=/home/rasmus/Projects/apk-polkit/_build/tests/apkd_test_common -L=--allow-shlib-undefined -L=--start-group -link-defaultlib-shared -L=src/apkd_common/libapkd_common.so -L=src/apkd/libapkd.so -L=src/apkd_dbus_server/libapkd-dbus-server.so -L=src/apkd_dbus_server/libapkd-dbus-client.so -L=tests/apkd_test_common/libapkd_tests_common.so -L=subprojects/apk-tools/src/libapk.a -L=subprojects/apk-tools/libfetch/libfetch.a /usr/lib/libglibd-2.0.so -L=--export-dynamic /usr/lib/libgmodule-2.0.so /usr/lib/libglib-2.0.so /usr/lib/libgio-2.0.so /usr/lib/libgobject-2.0.so /usr/lib/libintl.so /usr/local/lib/libpolkit-gobjectd-1.so /usr/lib/libpolkit-gobject-1.so /usr/local/lib/libapk-toolsd.so /usr/lib/libssl.so /usr/lib/libcrypto.so /lib/libz.so -L=--end-group

Which doesn't work, it throws errors because it can't find libssl's symbols:

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: subprojects/apk-tools/src/libapk.a(database.c.o): in function `apk_checksum_evp':
/home/rasmus/Projects/apk-polkit/_build/../subprojects/apk-tools/src/apk_blob.h:55: undefined reference to `EVP_md5'

If I put a -L=-ssl in front of the --end-group on ldc2's command line it works. It also works fine with dmd.

To Reproduce

Currently only reproducible in https://gitlab.alpinelinux.org/Cogitri/apk-polkit/-/tree/ci . I'll see if I can get a minimal project together if required.

Expected behavior
Meson should pass the right linking parameters to ldc2

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? Native build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Linux
  • what meson --version 0.54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the apk-polkit CI branch and the Meson-generated ldc2 command shown in the report. Trace how Meson handles native-library linker arguments for ldc2 with the bfd linker, then verify that the OpenSSL symbols link without the manual -L=-ssl workaround and add regression coverage if the project provides a suitable test location.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.