Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-07

Bug: Alignment issue with dwarf debug_info on mipsel(-embedded)?? code

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Ring

I have now found out why debug symbols get discarded by pic32mx-elf32-gdb. The problem is a bug in the generation of dwarf-debuginfo. My guess is that the problem should also exist in linux target.

For mips unaligned data in dward debug info needs to be defined as .4byte and .2byte instead of .long and .short.

This is implemented in most places but it seems not everywhere.

When I compile this program:

program hello;
var
   i : integer;
begin
end.

the symbol I has one entry with .long, the resulting binary does not load in gdb with the error-message: Dwarf Error: wrong version in compilation unit header (is 10752, should be 2, 3, or 4)

# Syms - Begin Staticsymtable
# Symbol SYSTEM
# Symbol OBJPAS
# Symbol PIC32MX2XXFXXXC
# Symbol HELLO
# Symbol main
# Symbol I
.uleb128 2
.ascii "I\000"
.byte 5
.byte 3
.long U_$P$HELLO_$$_I
.4byte _$HELLO$_Ld1
# Syms - End Staticsymtable

when I replace the '.long' with '.4byte' and recompile then the resulting hello.elf loads fine into gdb. I could see before with readelf that the dwarf info was misaligned compared to the dwarf imfo when I compile the same code for arm-embedded

Can anybody help with a fix?

Michael

Reply by email

Michael Ring
to Michael Ring

I have now commited my work to svn on the branch mips_embedded so that it is easier to reproduce the problem.

For building the target you need to install binutils for pic32mx from here: https://github.com/chipKIT32/chipKIT-cxx/tree/master/src45x/binutils

Instructions for building the toolchain (only binutils is needed): https://github.com/chipKIT32/chipKIT-cxx/wiki/HOWTO-Build-the-toolchain

currently xc32 binutils from microchip do not work. latest binutils work mostly but they cannot create .hex files

To build use the following commandline:

make clean buildbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=mipsel SUBARCH=pic32mx OPT="" CROSSOPT="-O-" BINUTILSPREFIX=pic32mx-elf32-

and then

sudo make installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=mipsel SUBARCH=pic32mx OPT="" CROSSOPT="-O-" BINUTILSPREFIX=pic32mx-elf32-

to compile use:

ppcrossmipsel -MObjFPC -Scghi -Ch1024 -Cs1024 -Tembedded -Pmipsel -gw2 -vewnhix -l -Cppic32mx -WpPIC32MX220F032C -XPpic32mx-elf32- -FD/usr/local/bin -a -godwarfsets -godwarfmethodclassprefix hello.pas -al -ar

Michael

Michael Ring wrote 49 lines
I have now found out why debug symbols get discarded by pic32mx-elf32-gdb. The problem is a bug in the generation of dwarf-debuginfo. My guess is that the problem should also exist in linux target. For mips unaligned data in dward debug info needs to be defined as .4byte and .2byte instead of .long and .short. This is implemented in most places but it seems not everywhere. When I compile this program: program hello; var i : integer; begin end. the symbol I has one entry with .long, the resulting binary does not load in gdb with the error-message: Dwarf Error: wrong version in compilation unit header (is 10752, should be 2, 3, or 4) # Syms - Begin Staticsymtable # Symbol SYSTEM # Symbol OBJPAS # Symbol PIC32MX2XXFXXXC # Symbol HELLO # Symbol main # Symbol I .uleb128 2 .ascii "I\000" .byte 5 .byte 3 .long U_$P$HELLO_$$_I .4byte _$HELLO$_Ld1 # Syms - End Staticsymtable when I replace the '.long' with '.4byte' and recompile then the resulting hello.elf loads fine into gdb. I could see before with readelf that the dwarf info was misaligned compared to the dwarf imfo when I compile the same code for arm-embedded Can anybody help with a fix? Michael _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Florian Klämpfl
to Michael Ring: I have now found out why debug symbols get discarded by pic32mx-elf32-gdb. The problem is…
Michael Ring wrote 43 lines
I have now found out why debug symbols get discarded by pic32mx-elf32-gdb. The problem is a bug in the generation of dwarf-debuginfo. My guess is that the problem should also exist in linux target. For mips unaligned data in dward debug info needs to be defined as .4byte and .2byte instead of .long and .short. This is implemented in most places but it seems not everywhere. When I compile this program: program hello; var i : integer; begin end. the symbol I has one entry with .long, the resulting binary does not load in gdb with the error-message: Dwarf Error: wrong version in compilation unit header (is 10752, should be 2, 3, or 4) # Syms - Begin Staticsymtable # Symbol SYSTEM # Symbol OBJPAS # Symbol PIC32MX2XXFXXXC # Symbol HELLO # Symbol main # Symbol I .uleb128 2 .ascii "I\000" .byte 5 .byte 3 .long U_$P$HELLO_$$_I .4byte _$HELLO$_Ld1 # Syms - End Staticsymtable when I replace the '.long' with '.4byte' and recompile then the resulting hello.elf loads fine into gdb. I could see before with readelf that the dwarf info was misaligned compared to the dwarf imfo when I compile the same code for arm-embedded Can anybody help with a fix?

Do I understand it correctly, that it is sufficient so replace .long by .4byte and .short by .2byte at all locations? Does it apply to all targets?

Reply by email

Michael Ring
to Florian Klämpfl

I guess this applies at least to all dwarf related code in mips targets. I found the following post:

http://sourceware.org/ml/binutils/2010-07/msg00096.html

there the author says:

A brief look at the contents of your .debug_info section reveals non-standard usage of platform-specific GAS directives to emit DWARF-2 records. You should be using .2byte, .4byte, etc., that have been invented specifically for DWARF records, rather than .short, .long, etc., whose behaviour (size, alignment) is target-dependent.

also, .2byte and .4byte and .8byte are already (kind of) implemented in aggas.pas:

{ Generic unaligned pseudo-instructions, seems ELF specific } use_ua_elf_systems =
[system_mipsel_linux,system_mipseb_linux,system_mipsel_embedded,system_mipseb_embedded]; ait_ua_elf_const2str :
array[aitconst_16bit_unaligned..aitconst_64bit_unaligned] of string[20]=(
#9'.2byte'#9,#9'.4byte'#9,#9'.8byte'#9

         );
Florian Klämpfl wrote 51 lines
Am 05.07.2013 22:23, schrieb Michael Ring: > I have now found out why debug symbols get discarded by > pic32mx-elf32-gdb. The problem is a bug in the generation of > dwarf-debuginfo. My guess is that the problem should also exist in linux > target. > > For mips unaligned data in dward debug info needs to be defined as > .4byte and .2byte instead of .long and .short. > > This is implemented in most places but it seems not everywhere. > > When I compile this program: > > program hello; > var > i : integer; > begin > end. > > the symbol I has one entry with .long, the resulting binary does not > load in gdb with the error-message: Dwarf Error: wrong version in > compilation unit header (is 10752, should be 2, 3, or 4) > > # Syms - Begin Staticsymtable > # Symbol SYSTEM > # Symbol OBJPAS > # Symbol PIC32MX2XXFXXXC > # Symbol HELLO > # Symbol main > # Symbol I > .uleb128 2 > .ascii "I\000" > .byte 5 > .byte 3 > .long U_$P$HELLO_$$_I > .4byte _$HELLO$_Ld1 > # Syms - End Staticsymtable > > when I replace the '.long' with '.4byte' and recompile then the > resulting hello.elf loads fine into gdb. I could see before with readelf > that the dwarf info was misaligned compared to the dwarf imfo when I > compile the same code for arm-embedded > > Can anybody help with a fix? Do I understand it correctly, that it is sufficient so replace .long by .4byte and .short by .2byte at all locations? Does it apply to all targets? _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Florian Klaempfl
to Michael Ring
>> Can anybody help with a fix? > Do I understand it correctly, that it is sufficient so replace .long by > .4byte and .short by .2byte at all locations? Does it apply to all targets?

Please tell me if r25054 helps.

Reply by email

Michael Ring
to Florian Klaempfl

This is looking good now, I can also compile the rtl with enabled debuginfo and this now also loads without error into gdb, thank you very much!

Michael

Florian Klaempfl wrote 11 lines
>>> Can anybody help with a fix? >> Do I understand it correctly, that it is sufficient so replace .long by >> .4byte and .short by .2byte at all locations? Does it apply to all >> targets? Please tell me if r25054 helps. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email