[Lldb-commits] [PATCH] D35784: [LLDB][MIPS] The symbol with NOTYPE and having section type debug doesn't contain any valid address

Greg Clayton via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 11 09:32:06 PDT 2017


clayborg added a comment.

So I looked at the instances of STT_NOTYPE in a few shared libraries on my computer and they do seem to have valid addresses in them.

> there are two sections (.text and .debug_ranges) for the file address 0xbcf0.

I don't see that from the log. I cleaned up the output a bit:

  Section Headers:
    [Nr] Name              Type             Address           Offset   Size              EntSize          Flags  Link  Info  Align
    [ 0]                   NULL             0000000000000000  00000000 0000000000000000  0000000000000000           0     0     0
    [ 1] .MIPS.abiflags    MIPS_ABIFLAGS    00000000000002a8  000002a8 0000000000000018  0000000000000018   A       0     0     8
    [ 2] .MIPS.options     MIPS_OPTIONS     00000000000002c0  000002c0 0000000000000370  0000000000000001  Ao       0     0     8
    [ 3] .dynamic          DYNAMIC          0000000000000630  00000630 0000000000000270  0000000000000010   A       6     0     8
    [ 4] .hash             HASH             00000000000008a0  000008a0 000000000000064c  0000000000000004   A       5     0     8
    [ 5] .dynsym           DYNSYM           0000000000000ef0  00000ef0 0000000000001320  0000000000000018   A       6     2     8
    [ 6] .dynstr           STRTAB           0000000000002210  00002210 0000000000002601  0000000000000000   A       0     0     1
    [ 7] .gnu.version      VERSYM           0000000000004812  00004812 0000000000000198  0000000000000002   A       5     0     2
    [ 8] .gnu.version_r    VERNEED          00000000000049b0  000049b0 0000000000000040  0000000000000000   A       6     2     8
    [ 9] .rel.dyn          REL              00000000000049f0  000049f0 0000000000001ae0  0000000000000010   A       5     0     8
    [10] .text             PROGBITS         000000000000bb80  0000bb80 0000000000054380  0000000000000000  AX       0     0     16
    [11] .MIPS.stubs       PROGBITS         000000000005ff00  0005ff00 0000000000000220  0000000000000000  AX       0     0     8
    [12] .rodata           PROGBITS         0000000000060120  00060120 0000000000003170  0000000000000000   A       0     0     16
    [13] .interp           PROGBITS         0000000000063290  00063290 0000000000000015  0000000000000000   A       0     0     1
    [14] .eh_frame_hdr     PROGBITS         00000000000632a8  000632a8 000000000000079c  0000000000000000   A       0     0     4
    [15] .note.android.ide NOTE             0000000000063a44  00063a44 0000000000000098  0000000000000000   A       0     0     4
    [16] .eh_frame         PROGBITS         0000000000074140  00064140 00000000000031a0  0000000000000000  WA       0     0     16
    [17] .gcc_except_table PROGBITS         00000000000772e0  000672e0 0000000000000c78  0000000000000000  WA       0     0     4
    [18] .preinit_array    PREINIT_ARRAY    0000000000077f58  00067f58 0000000000000010  0000000000000000  WA       0     0     8
    [19] .init_array       INIT_ARRAY       0000000000077f68  00067f68 0000000000000010  0000000000000000  WA       0     0     8
    [20] .fini_array       FINI_ARRAY       0000000000077f78  00067f78 0000000000000010  0000000000000000  WA       0     0     8
    [21] .ctors            PROGBITS         0000000000077f88  00067f88 0000000000000008  0000000000000000  WA       0     0     8
    [22] .dtors            PROGBITS         0000000000077f90  00067f90 0000000000000008  0000000000000000  WA       0     0     8
    [23] .data.rel.ro      PROGBITS         0000000000077fa0  00067fa0 0000000000001060  0000000000000000  WA       0     0     16
    [24] .data             PROGBITS         0000000000079000  00069000 0000000000000040  0000000000000000  WA       0     0     16
    [25] .rld_map          PROGBITS         0000000000079040  00069040 0000000000000008  0000000000000000  WA       0     0     8
    [26] .got              PROGBITS         0000000000079050  00069050 00000000000006b8  0000000000000008 WAp       0     0     16
    [27] .bss              NOBITS           0000000000079710  00069708 0000000000000520  0000000000000000  WA       0     0     16
    [28] .comment          PROGBITS         0000000000000000  00069708 0000000000000064  0000000000000001  MS       0     0     1
    [29] .pdr              PROGBITS         0000000000000000  0006976c 0000000000002ae0  0000000000000000           0     0     4
    [30] .debug_aranges    MIPS_DWARF       0000000000000000  0006c24c 0000000000000560  0000000000000000           0     0     1
    [31] .debug_pubnames   MIPS_DWARF       0000000000000000  0006c7ac 000000000002b3f7  0000000000000000           0     0     1
    [32] .debug_info       MIPS_DWARF       0000000000000000  00097ba3 00000000000972dc  0000000000000000           0     0     1
    [33] .debug_abbrev     MIPS_DWARF       0000000000000000  0012ee7f 0000000000003c5f  0000000000000000           0     0     1
    [34] .debug_line       MIPS_DWARF       0000000000000000  00132ade 0000000000035d51  0000000000000000           0     0     1
    [35] .debug_frame      MIPS_DWARF       0000000000000000  00168830 0000000000002688  0000000000000000           0     0     8
    [36] .debug_str        MIPS_DWARF       0000000000000000  0016aeb8 000000000005a6e3  0000000000000001  MS       0     0     1
    [37] .debug_loc        MIPS_DWARF       0000000000000000  001c559b 000000000006e1e5  0000000000000000           0     0     1
    [38] .debug_macinfo    MIPS_DWARF       0000000000000000  00233780 0000000000000010  0000000000000000           0     0     1
    [39] .debug_pubtypes   MIPS_DWARF       0000000000000000  00233790 0000000000010eaf  0000000000000000           0     0     1
    [40] .debug_ranges     MIPS_DWARF       0000000000000000  0024463f 000000000007b8f0  0000000000000000           0     0     1
    [41] .gnu.attributes   LOOS+ffffff5     0000000000000000  002bff2f 0000000000000010  0000000000000000           0     0     1
    [42] .shstrtab         STRTAB           0000000000000000  002bff3f 00000000000001ea  0000000000000000           0     0     1
    [43] .symtab           SYMTAB           0000000000000000  002c0130 0000000000147f60  0000000000000018          44   55368     8
    [44] .strtab           STRTAB           0000000000000000  00408090 0000000000091037  0000000000000000           0     0     1

Looking only at .text and .debug_ranges:

  [Nr] Name              Type             Address           Offset   Size              EntSize          Flags  Link  Info  Align
  [10] .text             PROGBITS         000000000000bb80  0000bb80 0000000000054380  0000000000000000  AX       0     0     16
  [40] .debug_ranges     MIPS_DWARF       0000000000000000  0024463f 000000000007b8f0  0000000000000000           0     0     1

These don't overlap. .debug_ranges doesn't really have any valid addresses. ".debug_ranges" has an address of zero, but that doesn't mean it has an real "file address". We consider a file address to be a valid address that will eventually map into a process when it is loaded. Sections need to have the ability to say "I am never going to be loaded into memory in a process". Then each ObjectFile subclass, when it creates its sections, would need to set this bit correctly. For ObjectFileELF, this would mean we need to check the sh_flags in a section for the SHF_ALLOC bit, This bit, from the ELF spec, is documented as:

> SHF_ALLOC: The section occupies memory during process execution. Some control sections do not reside in the memory image of an object file; this attribute is off for those sections.

The "A" character in the flags column above shows the SHF_ALLOC value for each section. We can see that many sections toward the end do not get loaded and thus should never be included when looking up a file address.

One easy way to say that a section has no file address is to set the Section's file address to LLDB_INVALID_ADDRESS for any ELF section that has sh_flags with SHF_ALLOC not set. So one fix would be to fix ObjectFileELF::CreateSections().

Exising code today is:

  SectionSP section_sp(new Section(
      GetModule(), // Module to which this section belongs.
      this, // ObjectFile to which this section belongs and should read
            // section data from.
      SectionIndex(I),     // Section ID.
      name,                // Section name.
      sect_type,           // Section type.
      header.sh_addr,      // VM address.
      vm_size,             // VM size in bytes of this section.
      header.sh_offset,    // Offset of this section in the file.
      file_size,           // Size of the section as found in the file.
      log2align,           // Alignment of the section
      header.sh_flags,     // Flags for this section.
      target_bytes_size)); // Number of host bytes per target byte

And probably should be:

  const addr_t sect_file_addr = header.sh_flags & SHF_ALLOC ? header.sh_addr : LLDB_INVALID_ADDRESS;
  SectionSP section_sp(new Section(
      GetModule(), // Module to which this section belongs.
      this, // ObjectFile to which this section belongs and should read
            // section data from.
      SectionIndex(I),     // Section ID.
      name,                // Section name.
      sect_type,           // Section type.
      sect_file_addr,      // VM address.
      vm_size,             // VM size in bytes of this section.
      header.sh_offset,    // Offset of this section in the file.
      file_size,           // Size of the section as found in the file.
      log2align,           // Alignment of the section
      header.sh_flags,     // Flags for this section.
      target_bytes_size)); // Number of host bytes per target byte

Maybe back out your current change and try this out?


https://reviews.llvm.org/D35784





More information about the lldb-commits mailing list