Bug 24270 - dwarf error wrong version in compilation unit header
Summary: dwarf error wrong version in compilation unit header
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-26 17:18 UTC by justin
Modified: 2019-02-27 15:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-02-26 00:00:00


Attachments
original .c file (236 bytes, text/x-csrc)
2019-02-26 17:18 UTC, justin
Details
pristine .s file (works) (1.39 KB, text/plain)
2019-02-26 17:18 UTC, justin
Details
broken .s file (causes an error in gdb when assembled) (1.43 KB, text/plain)
2019-02-26 17:19 UTC, justin
Details
w/ partially removed debug_info changes, no errors but wrong stack offsets (1.39 KB, text/plain)
2019-02-26 17:19 UTC, justin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description justin 2019-02-26 17:18:19 UTC
Created attachment 11647 [details]
original .c file

I'm seeing strange behavior in the assembler being invoked by gcc.  Hopefully this is the right place to report this, please let me know if not.  I have a .s file that when assembled is getting an error when read by gdb.  The .s file was generated by gcc, and I've modified it slightly to change the stack offsets used for some variables (the reason for these modifications I can't really get into, but it is important for my use and I believe a valid .s file)

The issue occurs when I also update the debug info to match these offsets.  I've attached 4 files:
- lemon_simple.c, the original .c file
- lemon_simple.s, the pristine .s file generated by gcc -ggdb lemon_simple.c -S  This file is read w/o errors by gdb
- lemon_simple.broken.s, a .s file that gdb reports an error on but I believe has correct info
- lemon_simple.partial.s, a .s file w/o two of the debug info changes that gdb loads successfully (but which has incorrect stack offsets)

I'm using the following versions on Ubuntu 18.04
as: GNU assembler (GNU Binutils) 2.31.51.20181203
gcc: 8.2.0 <-- built from source by me
gdb: 8.2, also tried Ubuntu version 8.1-0ubuntu3

I don't believe the exact versions of gcc/gdb matter here.  Not sure if it is supposed to happen, but these small changes between lemon_simple.s.broken and lemon_simple.s.partial produce vastly different executable files.

Below is the output I get, I've omitted the gcc output, the .c compiles w/o warnings, and the .s also goes fine.  You can see in the first gdb run that just loading a.out has a error.

$ gcc -ggdb lemon_simple.c -S  
<output omitted>

<fiddle with the lemon_simple.s file to produce lemon_simple.broken.s and lemon_simple.partial.s>

$ gcc -ggdb  lemon_simple.broken.s
<output omitted>
$ gdb ./a.out
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...Dwarf Error: wrong version in compilation unit header (is 110, should be 2, 3, 4 or 5) [in module <snip>/a.out]
(no debugging symbols found)...done.
>>> quit

$ gcc -ggdb  lemon_simple.partial.s
<output omitted>
$ gdb ./a.out
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
>>> quit

$ gcc -ggdb  lemon_simple.s
<output omitted>
$ gdb ./a.out
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
>>> quit
Comment 1 justin 2019-02-26 17:18:44 UTC
Created attachment 11648 [details]
pristine .s file (works)
Comment 2 justin 2019-02-26 17:19:18 UTC
Created attachment 11649 [details]
broken .s file (causes an error in gdb when assembled)
Comment 3 justin 2019-02-26 17:19:48 UTC
Created attachment 11650 [details]
w/ partially removed debug_info changes, no errors but wrong stack offsets
Comment 4 H.J. Lu 2019-02-26 23:20:39 UTC
How did you generate lemon_simple.broken.s? I got

[hjl@gnu-cfl-1 gdb]$ readelf -w bad.o > /dev/null 
readelf: Warning: Corrupt unit length (0x0) found in section .debug_info
readelf: Warning: Corrupt unit length (0x0) found in section .debug_info
readelf: Warning: Corrupt unit length (0x0) found in section .debug_info
[hjl@gnu-cfl-1 gdb]$ 

.debug_info has bad DWARF info.
Comment 5 justin 2019-02-27 15:48:35 UTC
apologies, it does seem the uleb128 indicating the DW_AT_location's length was incorrect.  Appreciate the help.