[PATCH] Let -rpath work
Joerg Sonnenberger
joerg at NetBSD.org
Tue Sep 3 10:25:01 PDT 2013
Hi shankarke, ruiu,
Implement the code generation side of -rpath.
http://llvm-reviews.chandlerc.com/D1583
Files:
test/elf/dynamic.test
include/lld/ReaderWriter/ELFLinkingContext.h
lib/Driver/GnuLdDriver.cpp
lib/ReaderWriter/ELF/OutputELFWriter.h
Index: test/elf/dynamic.test
===================================================================
--- test/elf/dynamic.test
+++ test/elf/dynamic.test
@@ -1,6 +1,7 @@
# Checks functionality of dynamic executables
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \
-RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined
+RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \
+RUN: -rpath /l1:/l2 -rpath /l3
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -emit-yaml -o %t2 --allow-shlib-undefined \
RUN: --noinhibit-exec
@@ -59,7 +60,7 @@
CHECK-NEXT: Type: Function
CHECK: }
-CHECK: DynamicSection [ (14 entries)
+CHECK: DynamicSection [ (15 entries)
CHECK: Tag Type Name/Value
CHECK: 0x0000000000000004 HASH
CHECK: 0x0000000000000005 STRTAB
@@ -74,5 +75,6 @@
CHECK: 0x0000000000000014 PLTREL RELA
CHECK: 0x0000000000000017 JMPREL
CHECK: 0x0000000000000001 NEEDED SharedLibrary (shared.so-x86-64)
+CHECK: 0x000000000000000F RPATH /l1:/l2:/l3
CHECK: 0x0000000000000000 NULL 0x0
CHECK: ]
Index: include/lld/ReaderWriter/ELFLinkingContext.h
===================================================================
--- include/lld/ReaderWriter/ELFLinkingContext.h
+++ include/lld/ReaderWriter/ELFLinkingContext.h
@@ -180,6 +180,14 @@
_sysrootPath = path;
}
+ void addRpath(StringRef path) {
+ _rpathList.push_back(path);
+ }
+
+ const StringRefVector &getRpathList() const {
+ return _rpathList;
+ }
+
private:
ELFLinkingContext() LLVM_DELETED_FUNCTION;
@@ -213,6 +221,7 @@
StringRefVector _initFunctions;
StringRefVector _finiFunctions;
StringRef _sysrootPath;
+ StringRefVector _rpathList;
};
} // end namespace lld
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -289,6 +289,14 @@
break;
}
+ case OPT_rpath: {
+ SmallVector<StringRef, 2> rpaths;
+ StringRef(inputArg->getValue()).split(rpaths, ":");
+ for (auto path : rpaths)
+ ctx->addRpath(path);
+ break;
+ }
+
case OPT_sysroot:
ctx->setSysroot(inputArg->getValue());
break;
Index: lib/ReaderWriter/ELF/OutputELFWriter.h
===================================================================
--- lib/ReaderWriter/ELF/OutputELFWriter.h
+++ lib/ReaderWriter/ELF/OutputELFWriter.h
@@ -160,6 +160,19 @@
dyn.d_un.d_val = _dynamicStringTable->addString(loadName.getKey());
_dynamicTable->addEntry(dyn);
}
+ const auto &rpathList = _context.getRpathList();
+ if (!rpathList.empty()) {
+ auto rpath = new (_alloc) std::string;
+ for (const auto &path : rpathList) {
+ rpath->append(path);
+ rpath->append(":");
+ }
+ rpath->resize(rpath->size() - 1);
+ Elf_Dyn dyn;
+ dyn.d_tag = DT_RPATH;
+ dyn.d_un.d_val = _dynamicStringTable->addString(*rpath);
+ _dynamicTable->addEntry(dyn);
+ }
// The dynamic symbol table need to be sorted earlier because the hash
// table needs to be built using the dynamic symbol table. It would be
// late to sort the symbols due to that in finalize. In the dynamic symbol
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1583.1.patch
Type: text/x-patch
Size: 3327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130903/9bc43b91/attachment.bin>
More information about the llvm-commits
mailing list