[PATCH] D33176: ELF: --gdb-index: Change findSection to return an InputSection.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 14 16:37:31 PDT 2017


pcc created this revision.

We should only ever expect this function to return a regular
InputSection; I would not expect a function definition to be in a
MergeInputSection or EhInputSection. We were previously crashing
in writeTo if this function returned a section that was not an
InputSection because we do not set OutSec for such sections.

This can happen in practice if a function is defined in an empty
section which shares its offset-in-file with a MergeInputSection,
as in the provided test case.


https://reviews.llvm.org/D33176

Files:
  lld/ELF/GdbIndex.h
  lld/ELF/SyntheticSections.cpp
  lld/test/ELF/Inputs/gdb-index-empty.o
  lld/test/ELF/Inputs/gdb-index-empty.o.sh
  lld/test/ELF/gdb-index-empty.test


Index: lld/test/ELF/gdb-index-empty.test
===================================================================
--- /dev/null
+++ lld/test/ELF/gdb-index-empty.test
@@ -0,0 +1,4 @@
+RUN: ld.lld --gdb-index --gc-sections -o %t %S/Inputs/gdb-index-empty.o
+RUN: llvm-dwarfdump -debug-dump=gdb_index %t | FileCheck %s
+
+CHECK: Address area offset = 0x28, has 0 entries:
Index: lld/test/ELF/Inputs/gdb-index-empty.o.sh
===================================================================
--- /dev/null
+++ lld/test/ELF/Inputs/gdb-index-empty.o.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "void _start() { __builtin_unreachable(); }" | \
+clang -Os -g -c -o gdb-index-empty.o -x c - -Xclang -fdebug-compilation-dir -Xclang .
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -1701,13 +1701,13 @@
   return Ret;
 }
 
-static InputSectionBase *findSection(ArrayRef<InputSectionBase *> Arr,
-                                     uint64_t Offset) {
+static InputSection *findSection(ArrayRef<InputSectionBase *> Arr,
+                                 uint64_t Offset) {
   for (InputSectionBase *S : Arr)
-    if (S && S != &InputSection::Discarded && S->Live)
+    if (S && isa<InputSection>(S) && S != &InputSection::Discarded && S->Live)
       if (Offset >= S->getOffsetInFile() &&
           Offset < S->getOffsetInFile() + S->getSize())
-        return S;
+        return cast<InputSection>(S);
   return nullptr;
 }
 
@@ -1721,7 +1721,7 @@
 
     ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
     for (std::pair<uint64_t, uint64_t> &R : Ranges)
-      if (InputSectionBase *S = findSection(Sections, R.first))
+      if (InputSection *S = findSection(Sections, R.first))
         Ret.push_back({S, R.first - S->getOffsetInFile(),
                        R.second - S->getOffsetInFile(), CurrentCU});
     ++CurrentCU;
Index: lld/ELF/GdbIndex.h
===================================================================
--- lld/ELF/GdbIndex.h
+++ lld/ELF/GdbIndex.h
@@ -21,7 +21,7 @@
 
 // Struct represents single entry of address area of gdb index.
 struct AddressEntry {
-  InputSectionBase *Section;
+  InputSection *Section;
   uint64_t LowAddress;
   uint64_t HighAddress;
   size_t CuIndex;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33176.98937.patch
Type: text/x-patch
Size: 2325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170514/4c289ebc/attachment.bin>


More information about the llvm-commits mailing list