[lld] r360679 - [ELF] --gdb-index: fix SIGSEGV when a DWARFAddressRange has invalid SectionIndex

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue May 14 07:41:20 PDT 2019


Author: maskray
Date: Tue May 14 07:41:20 2019
New Revision: 360679

URL: http://llvm.org/viewvc/llvm-project?rev=360679&view=rev
Log:
[ELF] --gdb-index: fix SIGSEGV when a DWARFAddressRange has invalid SectionIndex

See D61891: llvm had a bug that might create invalid (DW_AT_low_pc,DW_AT_high_pc) pairs or range list entries due to missing DW_AT_addr_base.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D61889

Added:
    lld/trunk/test/ELF/gdb-index-invalid-section-index.yaml
Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=360679&r1=360678&r2=360679&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue May 14 07:41:20 2019
@@ -2367,6 +2367,8 @@ readAddressAreas(DWARFContext &Dwarf, In
 
     ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
     for (DWARFAddressRange &R : *Ranges) {
+      if (R.SectionIndex == -1ULL)
+        continue;
       InputSectionBase *S = Sections[R.SectionIndex];
       if (!S || S == &InputSection::Discarded || !S->Live)
         continue;

Added: lld/trunk/test/ELF/gdb-index-invalid-section-index.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gdb-index-invalid-section-index.yaml?rev=360679&view=auto
==============================================================================
--- lld/trunk/test/ELF/gdb-index-invalid-section-index.yaml (added)
+++ lld/trunk/test/ELF/gdb-index-invalid-section-index.yaml Tue May 14 07:41:20 2019
@@ -0,0 +1,140 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld --gdb-index %t.o -o /dev/null
+
+## We used to crash if a DWARFAddressRange has invalid SectionIndex (-1).
+## Such DWARFAddressRange can be produced by clang -c -gdwarf-5 -gmlt before r360678.
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000010
+    Content:         31C0C3
+  - Name:            .debug_str_offsets
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         '1000000005000000000000000000000000000000'
+  - Name:            .rela.debug_str_offsets
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    EntSize:         0x0000000000000018
+    Info:            .debug_str_offsets
+    Relocations:
+      - Offset:          0x0000000000000008
+        Symbol:          .debug_str
+        Type:            R_X86_64_32
+      - Offset:          0x000000000000000C
+        Symbol:          .debug_str
+        Type:            R_X86_64_32
+        Addend:          1
+      - Offset:          0x0000000000000010
+        Symbol:          .debug_str
+        Type:            R_X86_64_32
+        Addend:          6
+  - Name:            .debug_str
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x0000000000000001
+    EntSize:         0x0000000000000001
+    Content:         00612E6363002F746D7000
+  - Name:            .debug_abbrev
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         011100252513050325721710171B25111B1206000000
+  - Name:            .debug_info
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         1B000000050001080000000001000400010000000000000000020003000000
+  - Name:            .rela.debug_info
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    EntSize:         0x0000000000000018
+    Info:            .debug_info
+    Relocations:
+      - Offset:          0x0000000000000008
+        Symbol:          .debug_abbrev
+        Type:            R_X86_64_32
+      - Offset:          0x0000000000000011
+        Symbol:          .debug_str_offsets
+        Type:            R_X86_64_32
+        Addend:          8
+      - Offset:          0x0000000000000015
+        Symbol:          .debug_line
+        Type:            R_X86_64_32
+  - Name:            .debug_addr
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         0C000000050008000000000000000000
+  - Name:            .rela.debug_addr
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    EntSize:         0x0000000000000018
+    Info:            .debug_addr
+    Relocations:
+      - Offset:          0x0000000000000008
+        Symbol:          .text
+        Type:            R_X86_64_64
+  - Name:            .debug_line
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         2D0000000500080025000000010101FB0E0D00010101010000000100000101011F010000000002011F020F010000000000
+  - Name:            .rela.debug_line
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    EntSize:         0x0000000000000018
+    Info:            .debug_line
+    Relocations:
+      - Offset:          0x0000000000000022
+        Symbol:          .debug_line_str
+        Type:            R_X86_64_32
+      - Offset:          0x000000000000002C
+        Symbol:          .debug_line_str
+        Type:            R_X86_64_32
+        Addend:          5
+  - Name:            .debug_line_str
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x0000000000000001
+    EntSize:         0x0000000000000001
+    Content:         2F746D7000612E636300
+Symbols:
+  - Name:            a.ll
+    Type:            STT_FILE
+    Index:           SHN_ABS
+  - Name:            .text
+    Type:            STT_SECTION
+    Section:         .text
+  - Name:            .debug_str_offsets
+    Type:            STT_SECTION
+    Section:         .debug_str_offsets
+  - Name:            .debug_str
+    Type:            STT_SECTION
+    Section:         .debug_str
+  - Name:            .debug_abbrev
+    Type:            STT_SECTION
+    Section:         .debug_abbrev
+  - Name:            .debug_info
+    Type:            STT_SECTION
+    Section:         .debug_info
+  - Name:            .debug_line
+    Type:            STT_SECTION
+    Section:         .debug_line
+  - Name:            .debug_line_str
+    Type:            STT_SECTION
+    Section:         .debug_line_str
+  - Name:            foo
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+    Size:            0x0000000000000003
+...




More information about the llvm-commits mailing list