[lld] r295720 - [ELF] - Improve diagnostic messages for move location counter errors.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 06:50:38 PST 2017


Author: grimar
Date: Tue Feb 21 08:50:38 2017
New Revision: 295720

URL: http://llvm.org/viewvc/llvm-project?rev=295720&view=rev
Log:
[ELF] - Improve diagnostic messages for move location counter errors.

Previously LLD would error out just "ld.lld: error: unable to move location counter backward"
What does not really reveal the place of issue,
Patch adds location to the output.

Differential revision: https://reviews.llvm.org/D30187

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/test/ELF/linkerscript/locationcountererr.s
    lld/trunk/test/ELF/linkerscript/locationcountererr2.s
    lld/trunk/test/ELF/linkerscript/out-of-order.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295720&r1=295719&r2=295720&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Feb 21 08:50:38 2017
@@ -91,13 +91,15 @@ static bool isUnderSysroot(StringRef Pat
   return false;
 }
 
-template <class ELFT> void LinkerScript<ELFT>::setDot(Expr E, bool InSec) {
+template <class ELFT>
+void LinkerScript<ELFT>::setDot(Expr E, const Twine &Loc, bool InSec) {
   uintX_t Val = E(Dot);
   if (Val < Dot) {
     if (InSec)
-      error("unable to move location counter backward for: " + CurOutSec->Name);
+      error(Loc + ": unable to move location counter backward for: " +
+            CurOutSec->Name);
     else
-      error("unable to move location counter backward");
+      error(Loc + ": unable to move location counter backward");
   }
   Dot = Val;
   // Update to location counter means update to section size.
@@ -111,7 +113,7 @@ template <class ELFT> void LinkerScript<
 template <class ELFT>
 void LinkerScript<ELFT>::assignSymbol(SymbolAssignment *Cmd, bool InSec) {
   if (Cmd->Name == ".") {
-    setDot(Cmd->Expression, InSec);
+    setDot(Cmd->Expression, Cmd->Location, InSec);
     return;
   }
 
@@ -567,7 +569,7 @@ void LinkerScript<ELFT>::assignOffsets(O
     return;
 
   if (Cmd->AddrExpr && Sec->Flags & SHF_ALLOC)
-    setDot(Cmd->AddrExpr);
+    setDot(Cmd->AddrExpr, Cmd->Location);
 
   // Handle align (e.g. ".foo : ALIGN(16) { ... }").
   if (Cmd->AlignExpr)
@@ -1622,7 +1624,7 @@ SymbolAssignment *ScriptParser::readAssi
       return getSymbolValue(Loc, Name, Dot) + E(Dot);
     };
   }
-  return new SymbolAssignment(Name, E);
+  return new SymbolAssignment(Name, E, getCurrentLocation());
 }
 
 // This is an operator-precedence parser to parse a linker

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=295720&r1=295719&r2=295720&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Tue Feb 21 08:50:38 2017
@@ -89,8 +89,9 @@ struct BaseCommand {
 
 // This represents ". = <expr>" or "<symbol> = <expr>".
 struct SymbolAssignment : BaseCommand {
-  SymbolAssignment(StringRef Name, Expr E)
-      : BaseCommand(AssignmentKind), Name(Name), Expression(E) {}
+  SymbolAssignment(StringRef Name, Expr E, std::string &&Loc)
+      : BaseCommand(AssignmentKind), Name(Name), Expression(E),
+        Location(std::move(Loc)) {}
 
   static bool classof(const BaseCommand *C);
 
@@ -104,6 +105,8 @@ struct SymbolAssignment : BaseCommand {
   // Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN.
   bool Provide = false;
   bool Hidden = false;
+
+  std::string Location;
 };
 
 // Linker scripts allow additional constraints to be put on ouput sections.
@@ -278,7 +281,7 @@ private:
   void assignSymbol(SymbolAssignment *Cmd, bool InSec = false);
   void addSymbol(SymbolAssignment *Cmd);
   void computeInputSections(InputSectionDescription *);
-  void setDot(Expr E, bool InSec = false);
+  void setDot(Expr E, const Twine &Loc, bool InSec = false);
 
   void discard(ArrayRef<InputSectionBase<ELFT> *> V);
 

Modified: lld/trunk/test/ELF/linkerscript/locationcountererr.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/locationcountererr.s?rev=295720&r1=295719&r2=295720&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/locationcountererr.s (original)
+++ lld/trunk/test/ELF/linkerscript/locationcountererr.s Tue Feb 21 08:50:38 2017
@@ -1,8 +1,10 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: echo "SECTIONS { .text 0x2000 : {. = 0x10 ; *(.text) } }" > %t.script
+
+# RUN: echo "SECTIONS {" > %t.script
+# RUN: echo ".text 0x2000 : {. = 0x10 ; *(.text) } }" >> %t.script
 # RUN: not ld.lld %t --script %t.script -o %t1 2>&1 | FileCheck %s
-# CHECK: unable to move location counter backward for: .text
+# CHECK: {{.*}}.script:2: unable to move location counter backward for: .text
 
 .globl _start
 _start:

Modified: lld/trunk/test/ELF/linkerscript/locationcountererr2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/locationcountererr2.s?rev=295720&r1=295719&r2=295720&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/locationcountererr2.s (original)
+++ lld/trunk/test/ELF/linkerscript/locationcountererr2.s Tue Feb 21 08:50:38 2017
@@ -1,8 +1,9 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: echo "SECTIONS { . = 0x20; . = 0x10; }" > %t.script
+# RUN: echo "SECTIONS {" > %t.script
+# RUN: echo ". = 0x20; . = 0x10; }" >> %t.script
 # RUN: not ld.lld %t.o --script %t.script -o %t -shared 2>&1 | FileCheck %s
-# CHECK: unable to move location counter backward
+# CHECK: {{.*}}.script:2: unable to move location counter backward
 
 # RUN: echo "SECTIONS { . = 0x20; . = ASSERT(0x1, "foo"); }" > %t2.script
 # RUN: ld.lld %t.o --script %t2.script -o %t -shared

Modified: lld/trunk/test/ELF/linkerscript/out-of-order.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/out-of-order.s?rev=295720&r1=295719&r2=295720&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/out-of-order.s (original)
+++ lld/trunk/test/ELF/linkerscript/out-of-order.s Tue Feb 21 08:50:38 2017
@@ -3,7 +3,7 @@
 # RUN: echo "SECTIONS { .data 0x4000 : { *(.data) } .text 0x2000 : { *(.text) } }" > %t.script
 # RUN: not ld.lld -o %t.so --script %t.script %t.o -shared 2>&1 | FileCheck %s
 
-# CHECK:  error: unable to move location counter backward
+# CHECK:  error: {{.*}}.script:1: unable to move location counter backward
 
 .quad 0
 .data




More information about the llvm-commits mailing list