Bug 24795 - eu-unstrip doesn't recognize MIPS_DWARF as debug section
Summary: eu-unstrip doesn't recognize MIPS_DWARF as debug section
Status: NEW
Alias: None
Product: elfutils
Classification: Unclassified
Component: tools (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 23902
Blocks:
  Show dependency treegraph
 
Reported: 2019-07-09 21:41 UTC by Tom de Vries
Modified: 2019-07-10 10:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2019-07-09 21:41:54 UTC
Consider the section header table of a hello world exec on debian 7 MIPS:
...
$ readelf -S hello
There are 42 section headers, starting at offset 0xcf4:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        00400154 000154 00000d 00   A  0   0  1
  [ 2] .note.ABI-tag     NOTE            00400164 000164 000020 00   A  0   0  4
  [ 3] .reginfo          MIPS_REGINFO    00400184 000184 000018 18   A  0   0  4
  [ 4] .note.gnu.build-i NOTE            0040019c 00019c 000024 00   A  0   0  4
  [ 5] .dynamic          DYNAMIC         004001c0 0001c0 0000f8 08   A  8   0  4
  [ 6] .hash             HASH            004002b8 0002b8 000040 04   A  7   0  4
  [ 7] .dynsym           DYNSYM          004002f8 0002f8 0000b0 10   A  8   1  4
  [ 8] .dynstr           STRTAB          004003a8 0003a8 000085 00   A  0   0  1
  [ 9] .gnu.version      VERSYM          0040042e 00042e 000016 02   A  7   0  2
  [10] .gnu.version_r    VERNEED         00400444 000444 000020 00   A  8   1  4
  [11] .rel.plt          REL             00400464 000464 000008 08   A  7  13  4
  [12] .init             PROGBITS        0040046c 00046c 000068 00  AX  0   0  4
  [13] .plt              PROGBITS        004004e0 0004e0 000030 00  AX  0   0 32
  [14] .text             PROGBITS        00400510 000510 000290 00  AX  0   0 16
  [15] .MIPS.stubs       PROGBITS        004007a0 0007a0 000020 00  AX  0   0  4
  [16] .fini             PROGBITS        004007c0 0007c0 000038 00  AX  0   0  4
  [17] .rodata           PROGBITS        00400800 000800 000020 00   A  0   0 16
  [18] .eh_frame         PROGBITS        00400820 000820 000004 00   A  0   0  4
  [19] .ctors            PROGBITS        00410824 000824 000008 00  WA  0   0  4
  [20] .dtors            PROGBITS        0041082c 00082c 000008 00  WA  0   0  4
  [21] .jcr              PROGBITS        00410834 000834 000004 00  WA  0   0  4
  [22] .data             PROGBITS        00410840 000840 000010 00  WA  0   0 16
  [23] .rld_map          PROGBITS        00410850 000850 000004 00  WA  0   0  4
  [24] .got.plt          PROGBITS        00410854 000854 00000c 00  WA  0   0  4
  [25] .got              PROGBITS        00410860 000860 000028 04 WAp  0   0 16
  [26] .sdata            PROGBITS        00410888 000888 000004 00 WAp  0   0  4
  [27] .bss              NOBITS          00410890 00088c 000010 00  WA  0   0 16
  [28] .comment          PROGBITS        00000000 00088c 000039 01  MS  0   0  1
  [29] .pdr              PROGBITS        00000000 0008c8 000060 00      0   0  4
  [30] .debug_aranges    MIPS_DWARF      00000000 000928 000020 00      0   0  1
  [31] .debug_info       MIPS_DWARF      00000000 000948 000088 00      0   0  1
  [32] .debug_abbrev     MIPS_DWARF      00000000 0009d0 00003f 00      0   0  1
  [33] .debug_line       MIPS_DWARF      00000000 000a0f 000064 00      0   0  1
  [34] .debug_frame      MIPS_DWARF      00000000 000a74 00002c 00      0   0  4
  [35] .debug_str        MIPS_DWARF      00000000 000aa0 000095 01  MS  0   0  1
  [36] .debug_loc        MIPS_DWARF      00000000 000b35 00002c 00      0   0  1
  [37] .gnu.attributes   LOOS+ffffff5    00000000 000b61 000010 00      0   0  1
  [38] .mdebug.abi32     PROGBITS        00000000 000b71 000000 00      0   0  1
  [39] .shstrtab         STRTAB          00000000 000b71 000181 00      0   0  1
  [40] .symtab           SYMTAB          00000000 001384 000550 10     41  58  4
  [41] .strtab           STRTAB          00000000 0018d4 000273 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
...

After doing:
...
eu-strip hello -o hello.stripped -f hello.debug
...

we have:
...
$ readelf -S hello.debug | grep NOBITS
  [ 1] .interp           NOBITS          00400154 000154 00000d 00   A  0   0  1
  [ 3] .reginfo          NOBITS          00400184 000174 000018 18   A  0   0  4
  [ 5] .dynamic          NOBITS          004001c0 000198 0000f8 08   A  8   0  4
  [ 6] .hash             NOBITS          004002b8 000198 000040 04   A  7   0  4
  [ 7] .dynsym           NOBITS          004002f8 000198 0000b0 10   A  8   1  4
  [ 8] .dynstr           NOBITS          004003a8 000198 000085 00   A  0   0  1
  [ 9] .gnu.version      NOBITS          0040042e 000198 000016 02   A  7   0  2
  [10] .gnu.version_r    NOBITS          00400444 000198 000020 00   A  8   1  4
  [11] .rel.plt          NOBITS          00400464 000198 000008 08   A  7  13  4
  [12] .init             NOBITS          0040046c 000198 000068 00  AX  0   0  4
  [13] .plt              NOBITS          004004e0 0001a0 000030 00  AX  0   0 32
  [14] .text             NOBITS          00400510 0001a0 000290 00  AX  0   0 16
  [15] .MIPS.stubs       NOBITS          004007a0 0001a0 000020 00  AX  0   0  4
  [16] .fini             NOBITS          004007c0 0001a0 000038 00  AX  0   0  4
  [17] .rodata           NOBITS          00400800 0001a0 000020 00   A  0   0 16
  [18] .eh_frame         NOBITS          00400820 0001a0 000004 00   A  0   0  4
  [19] .ctors            NOBITS          00410824 0001a0 000008 00  WA  0   0  4
  [20] .dtors            NOBITS          0041082c 0001a0 000008 00  WA  0   0  4
  [21] .jcr              NOBITS          00410834 0001a0 000004 00  WA  0   0  4
  [22] .data             NOBITS          00410840 0001a0 000010 00  WA  0   0 16
  [23] .rld_map          NOBITS          00410850 0001a0 000004 00  WA  0   0  4
  [24] .got.plt          NOBITS          00410854 0001a0 00000c 00  WA  0   0  4
  [25] .got              NOBITS          00410860 0001a0 000028 04 WAp  0   0 16
  [26] .sdata            NOBITS          00410888 0001a0 000004 00 WAp  0   0  4
  [27] .bss              NOBITS          00410890 0001a0 000010 00  WA  0   0 16
  [28] .comment          NOBITS          00000000 0001a0 000039 01  MS  0   0  1
  [30] .debug_aranges    NOBITS          00000000 000200 000020 00      0   0  1
  [31] .debug_info       NOBITS          00000000 000200 000088 00      0   0  1
  [32] .debug_abbrev     NOBITS          00000000 000200 00003f 00      0   0  1
  [33] .debug_line       NOBITS          00000000 000200 000064 00      0   0  1
  [34] .debug_frame      NOBITS          00000000 000200 00002c 00      0   0  4
  [35] .debug_str        NOBITS          00000000 000200 000095 01  MS  0   0  1
  [36] .debug_loc        NOBITS          00000000 000200 00002c 00      0   0  1
  [37] .gnu.attributes   NOBITS          00000000 000200 000010 00      0   0  1
...

The .debug_* section should not be NOBITS here.

This is with an old eu-strip (0.152), but I don't manage building from git for now, so atm I cannot say whether this is fixed on trunk or not.
Comment 1 Mark Wielaard 2019-07-09 21:54:16 UTC
(In reply to Tom de Vries from comment #0)
> Consider the section header table of a hello world exec on debian 7 MIPS:

BTW. Isn't Debian 7 really old?

> This is with an old eu-strip (0.152), but I don't manage building from git
> for now,

See the README:

 To build a git checkout do:
   autoreconf -i -f && \
   ./configure --enable-maintainer-mode && \
   make && make check

Please let us know what issues you are seeing.

> so atm I cannot say whether this is fixed on trunk or not.

It isn't. elfutils doesn't have a MIPS backend and so knows nothing about special MIPS ELF constructs.
Comment 2 Tom de Vries 2019-07-09 22:08:43 UTC
(In reply to Mark Wielaard from comment #1)
> (In reply to Tom de Vries from comment #0)
> > Consider the section header table of a hello world exec on debian 7 MIPS:
> 
> BTW. Isn't Debian 7 really old?
> 

Yep, initial release 2013.

> > This is with an old eu-strip (0.152), but I don't manage building from git
> > for now,
> 
> See the README:
> 
>  To build a git checkout do:
>    autoreconf -i -f && \
>    ./configure --enable-maintainer-mode && \
>    make && make check
> 

Ah, ok.

> Please let us know what issues you are seeing.
> 

I tried elfutils-latest.tar.bz2 instead, and ran into the use of aligned_alloc, which is supported starting glibc v2.16, while debian 7 has glibc v2.13.

> > so atm I cannot say whether this is fixed on trunk or not.
> 
> It isn't. elfutils doesn't have a MIPS backend and so knows nothing about
> special MIPS ELF constructs.

Ah, I see indeed at https://sourceware.org/elfutils/ that mips is missing:
...
Included backends for machine specific ELF handling:
aarch64 alpha arm bpf i386 ia64 m68k ppc ppc64 s390 s390x sh sparc sparc64 tilegx x32 x86_64
...
Comment 3 Mark Wielaard 2019-07-10 10:41:29 UTC
(In reply to Tom de Vries from comment #2)
> I tried elfutils-latest.tar.bz2 instead, and ran into the use of
> aligned_alloc, which is supported starting glibc v2.16, while debian 7 has
> glibc v2.13.

BTW. Unrelated to the MIPS issue, but this has indeed been fixed in git:

commit 6bd060a23f43a842fbc37dd1bb8d6d7964eda36e
Author: Mark Wielaard <mark@klomp.org>
Date:   Thu Mar 7 17:31:53 2019 +0100

    libelf: Use posix_memalign instead of aligned_alloc.
    
    Older glibc might not have aligned_alloc (it is C11).
    Use posix_memalign instead. posix_memalign requires the alignment to
    be a multiple of sizeof (void *). So use malloc for smaller alignments.
    
    Signed-off-by: Mark Wielaard <mark@klomp.org>
Comment 4 Mark Wielaard 2019-07-10 10:44:23 UTC
See also https://sourceware.org/bugzilla/show_bug.cgi?id=23902 for a reference to a partial MIPS backend.