struct Configuration {
llvm::StringRef OutputFile;
llvm::StringRef DynamicLinker;
+ std::string RPath;
};
extern Configuration *Config;
#include "SymbolTable.h"
#include "Writer.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/FileSystem.h"
using namespace llvm;
if (auto *Arg = Args.getLastArg(OPT_dynamic_linker))
Config->DynamicLinker = Arg->getValue();
+ std::vector<StringRef> RPaths;
+ for (auto *Arg : Args.filtered(OPT_rpath))
+ RPaths.push_back(Arg->getValue());
+ if (!RPaths.empty())
+ Config->RPath = llvm::join(RPaths.begin(), RPaths.end(), ":");
+
// Create a list of input files.
std::vector<MemoryBufferRef> Inputs;
def dynamic_linker : Separate<["-"], "dynamic-linker">,
HelpText<"Which dynamic linker to use">;
+
+def rpath : Separate<["-"], "rpath">,
+ HelpText<"Which dynamic linker to use">;
++NumEntries; // DT_STRTAB
++NumEntries; // DT_STRSZ
+ StringRef RPath = Config->RPath;
+ if (!RPath.empty()) {
+ ++NumEntries; // DT_RUNPATH
+ DynStrSec.add(RPath);
+ }
+
const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
SymTab.getSharedFiles();
for (const std::unique_ptr<SharedFileBase> &File : SharedFiles)
P->d_un.d_val = DynStrSec.data().size();
++P;
+ StringRef RPath = Config->RPath;
+ if (!RPath.empty()) {
+ P->d_tag = DT_RUNPATH;
+ P->d_un.d_val = DynStrSec.getFileOff(RPath);
+ ++P;
+ }
+
const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
SymTab.getSharedFiles();
for (const std::unique_ptr<SharedFileBase> &File : SharedFiles) {
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
-// RUN: lld -flavor gnu2 -dynamic-linker /lib64/ld-linux-x86-64.so.2 %t.o %p/Inputs/i686-simple-library.so -o %t
+// RUN: lld -flavor gnu2 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar %t.o %p/Inputs/i686-simple-library.so -o %t
// RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck %s
// REQUIRES: x86
// CHECK-NEXT: 0x00000006 SYMTAB [[DYNSYMADDR]]
// CHECK-NEXT: 0x00000005 STRTAB [[DYNSTRADDR]]
// CHECK-NEXT: 0x0000000A STRSZ
+// CHECK-NEXT: 0x0000001D RUNPATH foo:bar
// CHECK-NEXT: 0x00000001 NEEDED SharedLibrary ({{.*}}/Inputs/i686-simple-library.so)
// CHECK-NEXT: 0x00000000 NULL 0x0
// CHECK-NEXT: ]