[lld] r195596 - [Gnu] Set the type of binary that lld would generate.

Rui Ueyama ruiu at google.com
Sun Nov 24 20:26:20 PST 2013


On Sun, Nov 24, 2013 at 8:14 PM, Shankar Easwaran
<shankare at codeaurora.org>wrote:

> Author: shankare
> Date: Sun Nov 24 22:14:38 2013
> New Revision: 195596
>
> URL: http://llvm.org/viewvc/llvm-project?rev=195596&view=rev
> Log:
> [Gnu] Set the type of binary that lld would generate.
>
> This is needed before any of the search paths are searched for.
>
> Added:
>     lld/trunk/test/elf/X86_64/staticlib-search.test
> Modified:
>     lld/trunk/lib/Driver/GnuLdDriver.cpp
>
> Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=195596&r1=195595&r2=195596&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
> +++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sun Nov 24 22:14:38 2013
> @@ -158,12 +158,6 @@ bool GnuLdDriver::parse(int argc, const
>    bool asNeeded = false;
>    bool _outputOptionSet = false;
>
> -  // Create a dynamic executable by default
> -  ctx->setOutputELFType(llvm::ELF::ET_EXEC);
> -  ctx->setIsStaticExecutable(false);
> -  ctx->setAllowShlibUndefines(false);
> -  ctx->setUseShlibUndefines(true);
> -
>    int index = 0;
>
>    // Set sys root path.
> @@ -176,17 +170,23 @@ bool GnuLdDriver::parse(int argc, const
>         it != ie; ++it)
>      ctx->addSearchPath((*it)->getValue());
>
> -  // Process all the arguments and create Input Elements
> -  for (auto inputArg : *parsedArgs) {
> -    switch (inputArg->getOption().getID()) {
> -    case OPT_mllvm:
> -      ctx->appendLLVMOption(inputArg->getValue());
> -      break;
> +  // Create a dynamic executable by default
> +  ctx->setOutputELFType(llvm::ELF::ET_EXEC);
> +  ctx->setIsStaticExecutable(false);
> +  ctx->setAllowShlibUndefines(false);
> +  ctx->setUseShlibUndefines(true);


You might want to move this to ELFLinkingContext as default values, so that
you don't need to explicitly set them in the driver by hand. I'd think
making the linking context to have a reasonable set of default value would
make sense (and for other attributes we do that).

+  // Figure out output kind ( -r, -static, -shared)
> +  if ( llvm::opt::Arg *kind = parsedArgs->getLastArg(OPT_relocatable,
> OPT_static,
> +                                      OPT_shared, OPT_nmagic,
> +                                      OPT_omagic, OPT_no_omagic)) {
> +    switch (kind->getOption().getID()) {
>      case OPT_relocatable:
>        ctx->setOutputELFType(llvm::ELF::ET_REL);
>        ctx->setPrintRemainingUndefines(false);
>        ctx->setAllowRemainingUndefines(true);
>        break;
> +
>      case OPT_static:
>        ctx->setOutputELFType(llvm::ELF::ET_EXEC);
>        ctx->setIsStaticExecutable(true);
> @@ -196,6 +196,36 @@ bool GnuLdDriver::parse(int argc, const
>        ctx->setAllowShlibUndefines(true);
>        ctx->setUseShlibUndefines(false);
>        break;
> +    }
> +  }
> +
> +  // Figure out if the output type is nmagic/omagic
> +  if ( llvm::opt::Arg *kind = parsedArgs->getLastArg(OPT_nmagic,
> OPT_omagic,
> +                                                     OPT_no_omagic)) {
> +    switch (kind->getOption().getID()) {
> +    case OPT_nmagic:
> +      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::NMAGIC);
> +      ctx->setIsStaticExecutable(true);
> +      break;
> +
> +    case OPT_omagic:
> +      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::OMAGIC);
> +      ctx->setIsStaticExecutable(true);
> +      break;
> +
> +    case OPT_no_omagic:
> +      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::DEFAULT);
> +      ctx->setNoAllowDynamicLibraries();
> +      break;
> +    }
> +  }
> +
> +  // Process all the arguments and create Input Elements
> +  for (auto inputArg : *parsedArgs) {
> +    switch (inputArg->getOption().getID()) {
> +    case OPT_mllvm:
> +      ctx->appendLLVMOption(inputArg->getValue());
> +      break;
>      case OPT_e:
>        ctx->setEntrySymbolName(inputArg->getValue());
>        break;
> @@ -233,21 +263,6 @@ bool GnuLdDriver::parse(int argc, const
>        ctx->setInterpreter(inputArg->getValue());
>        break;
>
> -    case OPT_nmagic:
> -      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::NMAGIC);
> -      ctx->setIsStaticExecutable(true);
> -      break;
> -
> -    case OPT_omagic:
> -      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::OMAGIC);
> -      ctx->setIsStaticExecutable(true);
> -      break;
> -
> -    case OPT_no_omagic:
> -      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::DEFAULT);
> -      ctx->setNoAllowDynamicLibraries();
> -      break;
> -
>      case OPT_u:
>        ctx->addInitialUndefinedSymbol(inputArg->getValue());
>        break;
>
> Added: lld/trunk/test/elf/X86_64/staticlib-search.test
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/staticlib-search.test?rev=195596&view=auto
>
> ==============================================================================
> --- lld/trunk/test/elf/X86_64/staticlib-search.test (added)
> +++ lld/trunk/test/elf/X86_64/staticlib-search.test Sun Nov 24 22:14:38
> 2013
> @@ -0,0 +1,6 @@
> +# This tests the functionality for finding the static library libfn.a for
> ELF
> +RUN: lld -flavor gnu -target x86_64 %p/Inputs/main.o -L%p/Inputs/ -lfn -o
> %t \
> +RUN: --noinhibit-exec -static -t 2> %t1
> +RUN: FileCheck %s < %t1
> +
> +CHECK: {{[\/0-9A-Za-z_]+}}libfn.a
>
>
> _______________________________________________
> 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/20131124/4c0fbef3/attachment.html>


More information about the llvm-commits mailing list