From b459cfe857f33ccac6a68de04875169f7ec3965d Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 28 Jan 2022 08:01:54 +0100 Subject: [PATCH] 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 #13819. --- .../build/lib/rules/cpp/LibrariesToLinkCollector.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 b5e4d5ac2c2e84..039a5052c00a3a 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); } librarySearchDirectories.add(inputArtifact.getExecPath().getParentDirectory().getPathString());