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