[lld] r303975 - [ELF] - Do not produce duplicate values in .gdb_index's constant pool area.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 05:09:27 PDT 2017


Author: grimar
Date: Fri May 26 07:09:26 2017
New Revision: 303975

URL: http://llvm.org/viewvc/llvm-project?rev=303975&view=rev
Log:
[ELF] - Do not produce duplicate values in .gdb_index's constant pool area.

I found this when builded llc binary using gcc 5.4.1 + LLD.
gcc produces duplicate entries in .debug_gnu_pubtypes section, ex:

UnifyFunctionExitNodes.cpp.o has:
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"

clang produces single entry here:
0x0000d291 EXTERNAL TYPE "std::__success_type<void *>"

If we link output from gcc with LLD, that would produce excessive duplicate
entries in .gdb_index constant pool area. That does not seem affect gdb work,
but makes .gdb_index larger than it can be.

I also checked that gold filters out such duplicates too. Patch fixes it.

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

Added:
    lld/trunk/test/ELF/gdb-index-dup-types.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=303975&r1=303974&r2=303975&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri May 26 07:09:26 2017
@@ -1781,8 +1781,7 @@ void GdbIndexSection::readDwarf(InputSec
       CuVectors.push_back({});
     }
 
-    CuVectors[Sym->CuVectorIndex].push_back((Pair.second << 24) |
-                                            (uint32_t)CuId);
+    CuVectors[Sym->CuVectorIndex].insert(CuId | (Pair.second << 24));
   }
 }
 
@@ -1806,7 +1805,7 @@ void GdbIndexSection::finalizeContents()
   ConstantPoolOffset =
       SymTabOffset + SymbolTable.getCapacity() * SymTabEntrySize;
 
-  for (std::vector<uint32_t> &CuVec : CuVectors) {
+  for (std::set<uint32_t> &CuVec : CuVectors) {
     CuVectorsOffset.push_back(CuVectorsSize);
     CuVectorsSize += OffsetTypeSize * (CuVec.size() + 1);
   }
@@ -1859,7 +1858,7 @@ void GdbIndexSection::writeTo(uint8_t *B
   }
 
   // Write the CU vectors into the constant pool.
-  for (std::vector<uint32_t> &CuVec : CuVectors) {
+  for (std::set<uint32_t> &CuVec : CuVectors) {
     write32le(Buf, CuVec.size());
     Buf += 4;
     for (uint32_t Val : CuVec) {

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=303975&r1=303974&r2=303975&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri May 26 07:09:26 2017
@@ -27,6 +27,8 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/MC/StringTableBuilder.h"
 
+#include <set>
+
 namespace lld {
 namespace elf {
 
@@ -515,7 +517,7 @@ public:
   GdbHashTab SymbolTable;
 
   // The CU vector portion of the constant pool.
-  std::vector<std::vector<uint32_t>> CuVectors;
+  std::vector<std::set<uint32_t>> CuVectors;
 
   std::vector<AddressEntry> AddressArea;
 

Added: lld/trunk/test/ELF/gdb-index-dup-types.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gdb-index-dup-types.s?rev=303975&view=auto
==============================================================================
--- lld/trunk/test/ELF/gdb-index-dup-types.s (added)
+++ lld/trunk/test/ELF/gdb-index-dup-types.s Fri May 26 07:09:26 2017
@@ -0,0 +1,60 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld --gdb-index %t.o -o %t
+# RUN: llvm-dwarfdump -debug-dump=gdb_index %t | FileCheck %s
+
+## Testcase is based on output produced by gcc version 5.4.1 20160904
+## it has duplicate entries in .debug_gnu_pubtypes which seems to be
+## compiler bug. In that case it is useless to have them in .gdb_index
+## and we filter such entries out to reduce size of .gdb_index.
+
+## CHECK: Constant pool offset = {{.*}}, has 1 CU vectors:
+## CHECK-NOT: 0(0x0): 0x90000000 0x90000000
+
+.section .debug_abbrev,"", at progbits
+ .byte 1                       # Abbreviation Code
+ .byte 17                      # DW_TAG_compile_unit
+ .byte 0                       # DW_CHILDREN_no
+ .byte 16                      # DW_AT_stmt_list
+ .byte 23                      # DW_FORM_sec_offset
+ .ascii "\260B"                # DW_AT_GNU_dwo_name
+ .byte 14                      # DW_FORM_strp
+ .byte 27                      # DW_AT_comp_dir
+ .byte 14                      # DW_FORM_strp
+ .ascii "\264B"                # DW_AT_GNU_pubnames
+ .byte 25                      # DW_FORM_flag_present
+ .ascii "\261B"                # DW_AT_GNU_dwo_id
+ .byte 7                       # DW_FORM_data8
+ .ascii "\263B"                # DW_AT_GNU_addr_base
+ .byte 23                      # DW_FORM_sec_offset
+ .byte 0                       # EOM(1)
+ .byte 0                       # EOM(2)
+ .byte 0                       # EOM(3)
+
+.section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long 32                       # Length of Unit
+ .short 4                       # DWARF version number
+ .long .debug_abbrev            # Offset Into Abbrev. Section
+ .byte 8                        # Address Size (in bytes)
+ .byte 1                        # Abbrev [1] 0xb:0x19 DW_TAG_compile_unit
+ .long 0                        # DW_AT_stmt_list
+ .long 0                        # DW_AT_GNU_dwo_name
+ .long 0                        # DW_AT_comp_dir
+ .quad 0                        # DW_AT_GNU_dwo_id
+ .long 0                        # DW_AT_GNU_addr_base
+
+.section .debug_gnu_pubtypes,"", at progbits
+.long .LpubTypes_end0-.LpubTypes_begin0 # Length of Public Types Info
+.LpubTypes_begin0:
+ .short 2                      # DWARF Version
+ .long .Lcu_begin0             # Offset of Compilation Unit Info
+ .long 36                      # Compilation Unit Length
+ .long 36                      # DIE offset
+ .byte 144                     # Kind: TYPE, STATIC
+ .asciz "int"                  # External Name
+ .long 36                      # DIE offset
+ .byte 144                     # Kind: TYPE, STATIC
+ .asciz "int"                  # External Name
+ .long 0                       # End Mark
+.LpubTypes_end0:




More information about the llvm-commits mailing list