Skip to content

Commit

Permalink
Normalize rpath entries to guard against missing default solib dir
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fmeum committed Jan 28, 2022
1 parent 3fb43f1 commit fb71e7a
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 @@ -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);
}

librarySearchDirectories.add(inputArtifact.getExecPath().getParentDirectory().getPathString());
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 fb71e7a

Please sign in to comment.