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

built shared objects with --library-type cdylib do not have an SONAME on musl #267

Closed
nekopsykose opened this issue Jul 22, 2022 · 3 comments · Fixed by #268
Closed

built shared objects with --library-type cdylib do not have an SONAME on musl #267

nekopsykose opened this issue Jul 22, 2022 · 3 comments · Fixed by #268

Comments

@nekopsykose
Copy link
Contributor

nekopsykose commented Jul 22, 2022

(cargo-c 0.9.11)

building a library (libimagequant in this case) with:

	cargo cbuild --release \
		--prefix /usr \
		--library-type cdylib

	cargo cinstall --release \
		--prefix /usr \
		--destdir "$pkgdir" \
		--library-type cdylib

(like here)
(cdylib only needed because of #180)

then generated a library without an SONAME:

$ readelf -d /usr/lib/libimagequant.so.0 
Dynamic section at offset 0x74920 contains 24 entries:
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../../../../../../../../../../../../usr/lib/rustlib/x86_64-alpine-linux-musl/lib]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.musl-x86_64.so.1]
 0x000000000000001e (FLAGS)              ORIGIN BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW ORIGIN
 0x0000000000000007 (RELA)               0x1830
 0x0000000000000008 (RELASZ)             24816 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffff9 (RELACOUNT)          967
 0x0000000000000017 (JMPREL)             0x7920
 0x0000000000000002 (PLTRELSZ)           120 (bytes)
 0x0000000000000003 (PLTGOT)             0x771f8
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000006 (SYMTAB)             0x270
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000005 (STRTAB)             0xfe4
 0x000000000000000a (STRSZ)              2122 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0xe50
 0x000000000000000c (INIT)               0x1cb6c
 0x000000000000000d (FINI)               0x1cb79
 0x000000006ffffff0 (VERSYM)             0xd38
 0x000000006ffffffe (VERNEED)            0xe20
 0x000000006fffffff (VERNEEDNUM)         1
 0x0000000000000000 (NULL)               0x0

the exact same build from arch has a valid soname:


[root@c90bcc27e007 /]# readelf -d /usr/lib/libimagequant.so.0

Dynamic section at offset 0x98308 contains 30 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000000e (SONAME)             Library soname: [libimagequant.so.0]
 0x000000000000000c (INIT)               0xa000
 0x000000000000000d (FINI)               0x76bf0
 0x0000000000000019 (INIT_ARRAY)         0x94e60
 0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x94e70
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x298
 0x0000000000000005 (STRTAB)             0x10b0
 0x0000000000000006 (SYMTAB)             0x4e0
 0x000000000000000a (STRSZ)              2387 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x99528
 0x0000000000000002 (PLTRELSZ)           48 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x91e0
 0x0000000000000007 (RELA)               0x1c50
 0x0000000000000008 (RELASZ)             30096 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)           
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x1b00
 0x000000006fffffff (VERNEEDNUM)         4
 0x000000006ffffff0 (VERSYM)             0x1a04
 0x000000006ffffff9 (RELACOUNT)          1177
 0x0000000000000000 (NULL)               0x0
@nekopsykose nekopsykose changed the title build shared objects with --library-type cdylib do not have an SONAME on musl built shared objects with --library-type cdylib do not have an SONAME on musl Jul 22, 2022
@nekopsykose
Copy link
Contributor Author

nekopsykose commented Jul 22, 2022

of course, the issue comes from

cargo-c/src/target.rs

Lines 74 to 81 in f6d4984

} else if env != "musl"
&& (os == "linux"
|| os == "freebsd"
|| os == "dragonfly"
|| os == "netbsd"
|| os == "haiku")
{
lines.push(format!("-Wl,-soname,lib{}.so.{}", lib_name, major));

why on earth would this get skipped just because the target is musl (.so's should always have an soname? musl is not special here, and i assume this code doesn't get reached when building a .a in default-static), i have no idea

@lu-zero
Copy link
Owner

lu-zero commented Jul 24, 2022

Because historically musl was managed in a different way upstream.

@nekopsykose
Copy link
Contributor Author

well, nothing changed with regards to that that i can see (discussions aside); the default -musl rustup toolchains still cannot create a cdylib on linux. this is relevant to cdylib targets only, not musl specifically.

perhaps shared_object_link_args was somehow invoked even when not making a cdylib, and someone thought to add the check there? because otherwise it was just a stray addition that was never hit (no cdylib on musl hence != musl check is always true since cannot even make a .so)

lu-zero pushed a commit that referenced this issue Jul 25, 2022
the musl platform also supports shared objects having an SONAME, and
this function is called only when making a 'shared object', so this
should always be added

fixes 04a92bc where this was removed
even when generating a dynamic library forcefully by setting library
type to cdylib

fixes #267
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

Successfully merging a pull request may close this issue.

2 participants