Skip to content

Commit

Permalink
Normalize rpath entries to guard against missing default solib dir (b…
Browse files Browse the repository at this point in the history
…azelbuild#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
  • Loading branch information
fmeum committed Mar 2, 2022
1 parent ed7a10d commit e624aff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ public void testRpathRootIsAddedEvenWithTransitionedDepsOnly() throws Exception
List<String> 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");
Expand Down

0 comments on commit e624aff

Please sign in to comment.