Skip to content

Commit 0b1beef

Browse files
fmeumcopybara-github
authored andcommitted
Normalize rpath entries to guard against missing default solib dir
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 1ec1068 commit 0b1beef

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,13 @@ private void addDynamicInputLinkOptions(
330330
commonParent = commonParent.getParentDirectory();
331331
}
332332

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

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ public void testRpathRootIsAddedEvenWithTransitionedDepsOnly() throws Exception
22232223
List<String> linkArgv = action.getLinkCommandLine().arguments();
22242224
assertThat(linkArgv).contains("-Wl,-rpath,$ORIGIN/../_solib_k8/");
22252225
assertThat(Joiner.on(" ").join(linkArgv))
2226-
.contains("-Wl,-rpath,$ORIGIN/../_solib_k8/../../../k8-fastbuild-ST-");
2226+
.contains("-Wl,-rpath,$ORIGIN/../../../k8-fastbuild-ST-");
22272227
assertThat(Joiner.on(" ").join(linkArgv))
22282228
.contains("-L" + TestConstants.PRODUCT_NAME + "-out/k8-fastbuild-ST-");
22292229
assertThat(Joiner.on(" ").join(linkArgv)).containsMatch("-lST-[0-9a-f]+_transition_Slibdep2");

0 commit comments

Comments
 (0)