Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/rattler_build_core/src/post_process/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ pub fn perform_linking_checks(

tracing::trace!("Package files: {package_files:#?}");

let canonical_new_files: HashSet<PathBuf> = new_files
.iter()
.filter_map(|file| dunce::canonicalize(file).ok())
.collect();

let mut linked_packages = Vec::new();
for package in package_files.iter() {
let mut link_info = PackageLinkInfo {
Expand Down Expand Up @@ -697,8 +702,14 @@ pub fn perform_linking_checks(
continue;
}

// Check if the package itself has the shared library.
if new_files.iter().any(|file| file.ends_with(lib)) {
// Check if the package itself has the shared library. `new_files`
// holds only regular files, while `lib` is usually the SONAME
// symlink (e.g. `lib/libfoo.so.1` -> `libfoo.so.1.2.3`), so also
// accept a symlink in the package whose target is one of them.
if new_files.iter().any(|file| file.ends_with(lib))
|| dunce::canonicalize(tmp_prefix.join(lib))
.is_ok_and(|target| canonical_new_files.contains(&target))
{
link_info.linked_packages.push(LinkedPackage {
name: lib.to_path_buf(),
link_origin: LinkOrigin::PackageItself,
Expand Down
19 changes: 19 additions & 0 deletions test-data/recipes/linking-own-soname-symlink/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package:
name: linking-own-soname-symlink
version: "1.0"

build:
script: |
mkdir -p $PREFIX/lib
echo 'int a(void) { return 1; }' > a.c
echo 'int a(void); int b(void) { return a(); }' > b.c
$CC -shared -fPIC a.c -Wl,-soname,liba.so.3 -o $PREFIX/lib/liba.so.3.0.0
ln -s liba.so.3.0.0 $PREFIX/lib/liba.so.3
ln -s liba.so.3 $PREFIX/lib/liba.so
$CC -shared -fPIC b.c -L$PREFIX/lib -la -Wl,-rpath,'$ORIGIN' -o $PREFIX/lib/libb.so
dynamic_linking:
overlinking_behavior: error

requirements:
build:
- ${{ compiler('c') }}
17 changes: 17 additions & 0 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,23 @@ def test_linking_symlinked_soname(
assert "lib/libgomp.so.1 (_openmp_mutex)" in output


@pytest.mark.skipif(platform.system() != "Linux", reason="Linux-only test")
def test_linking_own_soname_symlink(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
):
"""`libb.so` links `liba.so.3`, a SONAME symlink in the same package that
points to `liba.so.3.0.0`. The link must count as the package itself rather
than as overlinking.
"""
args = rattler_build.build_args(
recipes / "linking-own-soname-symlink",
tmp_path,
extra_args=["--target-platform", "linux-64"],
)
output = rattler_build(*args, stderr=STDOUT)
assert "lib/liba.so.3 (package)" in output


@pytest.mark.skipif(platform.system() != "Linux", reason="Linux-only test")
def test_allow_missing_dso(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
args = rattler_build.build_args(
Expand Down
Loading