diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java index c74c10a583309f..aead9a2063ebe4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java @@ -330,8 +330,13 @@ private void addDynamicInputLinkOptions( commonParent = commonParent.getParentDirectory(); } - rpathRootsForExplicitSoDeps.add( - rpathRoot + dotdots + libDir.relativeTo(commonParent).getPathString()); + // When all dynamic deps are built in transitioned configurations, the default solib dir is + // not created. While resolving paths, the dynamic linker stops at the first directory that + // does not exist, even when followed by "../". We thus have to normalize the relative path. + String relativePathToRoot = + rpathRoot + dotdots + libDir.relativeTo(commonParent).getPathString(); + String normalizedPathToRoot = PathFragment.create(relativePathToRoot).getPathString(); + rpathRootsForExplicitSoDeps.add(normalizedPathToRoot); // Unless running locally, libraries will be available under the root relative path, so we // should add that to the rpath as well. diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index 8dfa7b5e9bea18..d9657b453870c4 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -2223,7 +2223,7 @@ public void testRpathRootIsAddedEvenWithTransitionedDepsOnly() throws Exception List linkArgv = action.getLinkCommandLine().arguments(); assertThat(linkArgv).contains("-Wl,-rpath,$ORIGIN/../_solib_k8/"); assertThat(Joiner.on(" ").join(linkArgv)) - .contains("-Wl,-rpath,$ORIGIN/../_solib_k8/../../../k8-fastbuild-ST-"); + .contains("-Wl,-rpath,$ORIGIN/../../../k8-fastbuild-ST-"); assertThat(Joiner.on(" ").join(linkArgv)) .contains("-L" + TestConstants.PRODUCT_NAME + "-out/k8-fastbuild-ST-"); assertThat(Joiner.on(" ").join(linkArgv)).containsMatch("-lST-[0-9a-f]+_transition_Slibdep2");