<div dir="ltr">On Tue, Sep 3, 2013 at 9:29 AM, Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@bec.de" target="_blank">joerg@bec.de</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: joerg<br>
Date: Tue Sep 3 11:29:02 2013<br>
New Revision: 189826<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=189826&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=189826&view=rev</a><br>
Log:<br>
Add support for --sysroot.<br>
<br>
Modified:<br>
lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h<br>
lld/trunk/lib/Driver/GnuLdDriver.cpp<br>
lld/trunk/lib/Driver/LDOptions.td<br>
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
lld/trunk/test/Driver/libsearch-inputGraph.test<br>
<br>
Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=189826&r1=189825&r2=189826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=189826&r1=189825&r2=189826&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)<br>
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Tue Sep 3 11:29:02 2013<br>
@@ -175,6 +175,11 @@ public:<br>
/// linker command line, using the -fini option.<br>
range<const StringRef *> finiFunctions() const { return _finiFunctions; }<br>
<br>
+ /// \brief Set path to the system root<br>
+ void setSysroot(StringRef path) {<br>
+ _sysrootPath = path;<br>
+ }<br>
+<br>
private:<br>
ELFLinkingContext() LLVM_DELETED_FUNCTION;<br>
<br>
@@ -207,6 +212,7 @@ protected:<br>
StringRef _dynamicLinkerPath;<br>
StringRefVector _initFunctions;<br>
StringRefVector _finiFunctions;<br>
+ StringRef _sysrootPath;<br>
};<br>
} // end namespace lld<br>
<br>
<br>
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=189826&r1=189825&r2=189826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=189826&r1=189825&r2=189826&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)<br>
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Tue Sep 3 11:29:02 2013<br>
@@ -289,6 +289,10 @@ bool GnuLdDriver::parse(int argc, const<br>
break;<br>
}<br>
<br>
+ case OPT_sysroot:<br>
+ ctx->setSysroot(inputArg->getValue());<br>
+ break;<br>
+<br>
default:<br>
break;<br>
} // end switch on option ID<br>
<br>
Modified: lld/trunk/lib/Driver/LDOptions.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/LDOptions.td?rev=189826&r1=189825&r2=189826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/LDOptions.td?rev=189826&r1=189825&r2=189826&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/Driver/LDOptions.td (original)<br>
+++ lld/trunk/lib/Driver/LDOptions.td Tue Sep 3 11:29:02 2013<br>
@@ -116,6 +116,9 @@ defm init: dashEq<"init", "init",<br>
defm fini: dashEq<"fini", "fini",<br>
"Specify a finalizer function">;<br>
<br>
+def sysroot : Joined<["--"], "sysroot=">,<br>
+ HelpText<"Set the system root">;<br></blockquote><div><br></div><div>Could this handle --sysroot <i>dirname</i> as well as --sysroot=<i>dirname</i>?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// extensions<br>
def emit_yaml : Flag<["-"], "emit-yaml">,<br>
HelpText<"Write YAML instead of ELF">;<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=189826&r1=189825&r2=189826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=189826&r1=189825&r2=189826&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Tue Sep 3 11:29:02 2013<br>
@@ -41,7 +41,8 @@ ELFLinkingContext::ELFLinkingContext(<br>
_isStaticExecutable(false), _outputYAML(false), _noInhibitExec(false),<br>
_mergeCommonStrings(false), _runLayoutPass(true),<br>
_useShlibUndefines(false), _dynamicLinkerArg(false),<br>
- _noAllowDynamicLibraries(false), _outputMagic(OutputMagic::DEFAULT) {}<br>
+ _noAllowDynamicLibraries(false), _outputMagic(OutputMagic::DEFAULT),<br>
+ _sysrootPath("") {}<br>
<br>
bool ELFLinkingContext::is64Bits() const { return getTriple().isArch64Bit(); }<br>
<br>
@@ -147,7 +148,12 @@ StringRef ELFLinkingContext::searchLibra<br>
// Search for dynamic library<br>
if (!_isStaticExecutable) {<br>
SmallString<128> dynlibPath;<br>
- dynlibPath.assign(dir);<br>
+ if (dir.startswith("=/")) {<br>
+ dynlibPath.assign(_sysrootPath);<br>
+ dynlibPath.append(dir.substr(1));<br>
+ } else {<br>
+ dynlibPath.assign(dir);<br>
+ }<br></blockquote><div><br></div><div>You might want to add a comment that if the directory for -L begins with =, it'll be replaced with sysroot directory.</div><div><br></div><div>The code does not seems to work if the directory name is just "=".</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
llvm::sys::path::append(dynlibPath, Twine("lib") + libName + ".so");<br>
pathref = dynlibPath.str();<br>
if (llvm::sys::fs::exists(pathref)) {<br>
@@ -157,7 +163,12 @@ StringRef ELFLinkingContext::searchLibra<br>
// Search for static libraries too<br>
if (!foundFile) {<br>
SmallString<128> archivefullPath;<br>
- archivefullPath.assign(dir);<br>
+ if (dir.startswith("=/")) {<br>
+ archivefullPath.assign(_sysrootPath);<br>
+ archivefullPath.append(dir.substr(1));<br>
+ } else {<br>
+ archivefullPath.assign(dir);<br>
+ }<br></blockquote><div><br></div><div>Probably you might want to define a function, maybeReplaceSysrootDirectory() or something, for this code pattern?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
llvm::sys::path::append(archivefullPath, Twine("lib") + libName + ".a");<br>
pathref = archivefullPath.str();<br>
if (llvm::sys::fs::exists(pathref)) {<br>
<br>
Modified: lld/trunk/test/Driver/libsearch-inputGraph.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/libsearch-inputGraph.test?rev=189826&r1=189825&r2=189826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/libsearch-inputGraph.test?rev=189826&r1=189825&r2=189826&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/Driver/libsearch-inputGraph.test (original)<br>
+++ lld/trunk/test/Driver/libsearch-inputGraph.test Tue Sep 3 11:29:02 2013<br>
@@ -4,6 +4,8 @@ RUN: lld -flavor gnu -L%p/../elf/Inputs<br>
RUN: FileCheck %s -check-prefix="WHOLEARCHIVE" < %t1.err<br>
RUN: lld -flavor gnu -L%p/../elf/Inputs --whole-archive --as-needed -lfnarchive -emit-yaml --noinhibit-exec 2> %t2.err<br>
RUN: FileCheck %s -check-prefix="ASNEEDED" < %t2.err<br>
+RUN: lld -flavor gnu --sysroot=%p/../elf -L=/Inputs -lfnarchive -emit-yaml --noinhibit-exec 2> %t3.err<br>
+RUN: FileCheck -check-prefix="SYSROOT" %s < %t3.err<br>
<br>
CHECK: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a<br>
CHECK: Type : ELF File<br>
@@ -32,3 +34,11 @@ ASNEEDED: - asNeeded : true<br>
ASNEEDED: contextPath :<br>
ASNEEDED: - {{[^ ]+}}elf/Inputs<br>
<br>
+SYSROOT: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a<br>
+SYSROOT: Type : ELF File<br>
+SYSROOT: Ordinal : -1<br>
+SYSROOT: Attributes :<br>
+SYSROOT: - wholeArchive : false<br>
+SYSROOT: - asNeeded : false<br>
+SYSROOT: contextPath :<br>
+SYSROOT: - =/Inputs<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>