[PATCH] D27335: [ELF] Print file:line for unknown PHDR error

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 08:48:55 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL288678: [ELF] Print file:line for unknown PHDR error (authored by evgeny777).

Changed prior to commit:
  https://reviews.llvm.org/D27335?vs=80049&id=80275#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27335

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/ELF/LinkerScript.h
  lld/trunk/test/ELF/linkerscript/phdrs.s


Index: lld/trunk/ELF/LinkerScript.h
===================================================================
--- lld/trunk/ELF/LinkerScript.h
+++ lld/trunk/ELF/LinkerScript.h
@@ -124,6 +124,7 @@
   std::vector<StringRef> Phdrs;
   uint32_t Filler = 0;
   ConstraintKind Constraint = ConstraintKind::NoConstraint;
+  std::string Location;
 };
 
 // This struct represents one section match pattern in SECTIONS() command.
@@ -268,7 +269,7 @@
   ScriptConfiguration &Opt = *ScriptConfig;
 
   std::vector<size_t> getPhdrIndices(StringRef SectionName);
-  size_t getPhdrIndex(StringRef PhdrName);
+  size_t getPhdrIndex(const Twine &Loc, StringRef PhdrName);
 
   uintX_t Dot;
   uintX_t LMAOffset = 0;
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -972,21 +972,21 @@
 
     std::vector<size_t> Ret;
     for (StringRef PhdrName : Cmd->Phdrs)
-      Ret.push_back(getPhdrIndex(PhdrName));
+      Ret.push_back(getPhdrIndex(Cmd->Location, PhdrName));
     return Ret;
   }
   return {};
 }
 
 template <class ELFT>
-size_t LinkerScript<ELFT>::getPhdrIndex(StringRef PhdrName) {
+size_t LinkerScript<ELFT>::getPhdrIndex(const Twine &Loc, StringRef PhdrName) {
   size_t I = 0;
   for (PhdrsCommand &Cmd : Opt.PhdrsCommands) {
     if (Cmd.Name == PhdrName)
       return I;
     ++I;
   }
-  error("section header '" + PhdrName + "' is not listed in PHDRS");
+  error(Loc + ": section header '" + PhdrName + "' is not listed in PHDRS");
   return 0;
 }
 
@@ -1441,6 +1441,7 @@
 OutputSectionCommand *
 ScriptParser::readOutputSectionDescription(StringRef OutSec) {
   OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec);
+  Cmd->Location = getCurrentLocation();
 
   // Read an address expression.
   // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html#Output-Section-Address
Index: lld/trunk/test/ELF/linkerscript/phdrs.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/phdrs.s
+++ lld/trunk/test/ELF/linkerscript/phdrs.s
@@ -39,6 +39,14 @@
 # RUN: ld.lld -o %t1 --script %t.script %t
 # RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s
 
+## Check that error is reported when trying to use phdr which is not listed 
+## inside PHDRS {} block
+## TODO: If script doesn't contain PHDRS {} block then default phdr is always 
+## created and error is not reported.
+# RUN: echo "PHDRS { all PT_LOAD; } \
+# RUN:       SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script
+# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s
+
 # CHECK:     ProgramHeaders [
 # CHECK-NEXT:  ProgramHeader {
 # CHECK-NEXT:    Type: PT_LOAD (0x1)
@@ -120,6 +128,8 @@
 # DEFHDR-NEXT:      PF_X (0x1)
 # DEFHDR-NEXT:    ]
 
+# BADHDR:       {{.*}}.script:1: section header 'bar' is not listed in PHDRS
+
 .global _start
 _start:
  nop


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27335.80275.patch
Type: text/x-patch
Size: 2978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161205/4043544f/attachment.bin>


More information about the llvm-commits mailing list