[PATCH] D129142: [LLD][ELF] Drop duplicates from rpath
Stephan Bergmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 06:23:42 PDT 2022
sberg created this revision.
sberg added a reviewer: ruiu.
sberg added a project: lld.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
sberg requested review of this revision.
Herald added a subscriber: StephenFan.
Herald added a project: LLVM.
...to better align with the behavior of at least GNU Binutils ld.bfd (see `/* First see whether OPTARG is already in the path. */` ever since https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=252b5132c753830d5fd56823373aed85f2a0db63 "19990502 sourceware import") and ld.gold (see `// Eliminate duplicates.` since https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=41f542e70b89b9ea2875c438b0c9a60ac46092dd "Add support for -rpath.")
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129142
Files:
lld/ELF/Driver.cpp
lld/test/ELF/rpath.test
Index: lld/test/ELF/rpath.test
===================================================================
--- /dev/null
+++ lld/test/ELF/rpath.test
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -rpath=/path1 -rpath=/path12 -rpath=/path2 -rpath=/path2 -rpath=/path1 -shared -o %t
+// RUN: llvm-readobj --dynamic-table %t | FileCheck %s
+
+// Degenerate case where an -rpath argument already contains a colon:
+// RUN: ld.lld %t.o -rpath=/path1 -rpath=/path1:/path2 -rpath=/path2 -shared -o %t
+// RUN: llvm-readobj --dynamic-table %t | FileCheck --check-prefix=DEGENERATE %s
+
+// CHECK: Library runpath: [/path1:/path12:/path2]
+
+// DEGENERATE: Library runpath: [/path1:/path1:/path2:/path2]
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -47,6 +47,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/UniqueVector.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
@@ -594,7 +595,10 @@
static std::string getRpath(opt::InputArgList &args) {
std::vector<StringRef> v = args::getStrings(args, OPT_rpath);
- return llvm::join(v.begin(), v.end(), ":");
+ llvm::UniqueVector<StringRef> u;
+ for (StringRef p : v)
+ u.insert(p);
+ return llvm::join(u.begin(), u.end(), ":");
}
// Determines what we should do if there are remaining unresolved
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129142.442275.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/8b22cea6/attachment.bin>
More information about the llvm-commits
mailing list