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

Shankar Easwaran shankare at codeaurora.org
Sun Nov 24 20:14:39 PST 2013


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);
+
+  // 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





More information about the llvm-commits mailing list