Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson does not set soname of built Rust cdylibs #13537

Open
lf- opened this issue Aug 12, 2024 · 0 comments
Open

Meson does not set soname of built Rust cdylibs #13537

lf- opened this issue Aug 12, 2024 · 0 comments

Comments

@lf-
Copy link
Contributor

lf- commented Aug 12, 2024

Describe the bug
When building Rust cdylibs, meson does not set the soname, producing libraries that do not get found properly by downstream users.

There are some bug filings upstream but they are simply a matter of setting a link flag on the Meson side when building a Rust cdylib (plausibly also dylib? unsure but I am about to find out because I'm ✨using both✨) target.

rust-lang/rust#37529

To Reproduce

File: meow.cc

extern "C" void crab_rave();
extern "C" void merely_irate();

void do_it() {
    crab_rave();
    merely_irate();
}

File: meson.build

project('bug', 'cpp', 'rust', version: '0.0.0')
subdir('crabby')
subdir('merely-irate')
library('meow', files('meow.cc'), link_with: [crabby, merely_irate])

File: crabby/crabby.rs

#[no_mangle]
pub extern "C" fn crab_rave() {
    println!("crab rave!");
}

File: crabby/meson.build

crabby = library(
  'crabby',
  files('crabby.rs'),
  rust_abi : 'c',
)

File: merely-irate/merely-irate.cc

#include <iostream>

extern "C" void merely_irate() {
    std::cout << "bad c++ user, no crab raves for you\n";
}

File: merely-irate/meson.build

merely_irate = library(
  'merely_irate',
  files('merely-irate.cc'),
)

Setup and build:

meson/bug .venv » meson setup build
The Meson build system
Version: 1.5.99
Source dir: /home/jade/src/co/meson/bug
Build dir: /home/jade/src/co/meson/bug/build
Build type: native build
Project name: bug
Project version: 0.0.0
C++ compiler for the host machine: sccache c++ (gcc 14.2.1 "c++ (GCC) 14.2.1 20240805")
C++ linker for the host machine: c++ ld.bfd 2.43.0
nRust compiler for the host machine: rustc -C linker=cc (rustc 1.78.0)
Rust linker for the host machine: rustc -C linker=cc ld.bfd 2.43.0
inHost machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 3

Found ninja-1.12.1 at /usr/bin/ninja                                                                                               
meson/bug .venv » ninja -C build
ninja: Entering directory `build'
[7/7] Linking target libmeow.so

Observe bad thing: crabby/libcrabby.so does not have a soname set. In the output below it should read libcrabby.so rather than crabby/libcrabby.so. Meson would set this soname if it were C++, and you can see it doing so by libmerely_irate.so not having the subdirectory.

meson/bug .venv » readelf -d build/libmeow.so

Dynamic section at offset 0x2e08 contains 24 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [crabby/libcrabby.so]
 0x0000000000000001 (NEEDED)             Shared library: [libmerely_irate.so]
 0x000000000000000e (SONAME)             Library soname: [libmeow.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/crabby:$ORIGIN/merely-irate]
 0x000000000000000c (INIT)               0x1000
 0x000000000000000d (FINI)               0x112c
 0x0000000000000019 (INIT_ARRAY)         0x3df8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x3e00
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x300
 0x0000000000000005 (STRTAB)             0x3e8
 0x0000000000000006 (SYMTAB)             0x328
 0x000000000000000a (STRSZ)              204 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x3fe8
 0x0000000000000002 (PLTRELSZ)           48 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x560
 0x0000000000000007 (RELA)               0x4b8
 0x0000000000000008 (RELASZ)             168 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffff9 (RELACOUNT)          3
 0x0000000000000000 (NULL)               0x0

Expected behavior

I expect libcrabby.so to be listed as merely libcrabby.so rather than crabby/libcrabby.so since it should have a soname set, in a similar fashion to libmerely_irate.so.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? Native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Arch Linux
  • what Python version are you using? 3.12.4
  • what meson --version 8ef4e34 (1.5.99, installed in a venv)
  • what ninja --version if it's a Ninja build 1.12.1
@lf- lf- changed the title Rust does not set soname of built cdylibs Meson does not set soname of built Rust cdylibs Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant