Skip to content

Commit e624aff

Browse files
authored
Normalize rpath entries to guard against missing default solib dir (bazelbuild#14929)
When all dynamic deps in a build are built in transitioned configurations, the default solib dir is not created. However, while resolving paths, the dynamic linker stops at the first directory that does not exist, even when followed by `../`. Before this commit, all rpath entries would consist of the relative path to the default solib dir followed by the relative path to the particular library's solib dir. Thus, if the default solib dir was missing, the dynamic linker wouldn't resolve any of these paths. This commit ensures that the relative path entries are normalized and thus contain no references to non-existing directories assuming the normalized path itself exists. Work towards bazelbuild#13819. Closes bazelbuild#14660. PiperOrigin-RevId: 431671888
1 parent ed7a10d commit e624aff

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,13 @@ private void addDynamicInputLinkOptions(
331331
commonParent = commonParent.getParentDirectory();
332332
}
333333

334-
rpathRootsForExplicitSoDeps.add(
335-
rpathRoot + dotdots + libDir.relativeTo(commonParent).getPathString());
334+
// When all dynamic deps are built in transitioned configurations, the default solib dir is
335+
// not created. While resolving paths, the dynamic linker stops at the first directory that
336+
// does not exist, even when followed by "../". We thus have to normalize the relative path.
337+
String relativePathToRoot =
338+
rpathRoot + dotdots + libDir.relativeTo(commonParent).getPathString();
339+
String normalizedPathToRoot = PathFragment.create(relativePathToRoot).getPathString();
340+
rpathRootsForExplicitSoDeps.add(normalizedPathToRoot);
336341

337342
// Unless running locally, libraries will be available under the root relative path, so we
338343
// should add that to the rpath as well.

src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ public void testRpathRootIsAddedEvenWithTransitionedDepsOnly() throws Exception
21782178
List<String> linkArgv = action.getLinkCommandLine().arguments();
21792179
assertThat(linkArgv).contains("-Wl,-rpath,$ORIGIN/../_solib_k8/");
21802180
assertThat(Joiner.on(" ").join(linkArgv))
2181-
.contains("-Wl,-rpath,$ORIGIN/../_solib_k8/../../../k8-fastbuild-ST-");
2181+
.contains("-Wl,-rpath,$ORIGIN/../../../k8-fastbuild-ST-");
21822182
assertThat(Joiner.on(" ").join(linkArgv))
21832183
.contains("-L" + TestConstants.PRODUCT_NAME + "-out/k8-fastbuild-ST-");
21842184
assertThat(Joiner.on(" ").join(linkArgv)).containsMatch("-lST-[0-9a-f]+_transition_Slibdep2");

0 commit comments

Comments
 (0)