Sign in Join

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

Mailing lists / fpc-devel / 2021-12

Incorrect debug info for ESP32, linker error?

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Christo Crause

When compiling a simple test for esp32 (xtensa-freertos), the incorrect values for DW_AT_low_PC and DW_AT_high_PC are generated. From my inspection of the generated assembler I cannot see anything wrong, but the values supplied by the linker are wrong. Any ideas on how to fix this?

This can be seen below, where there is no overlap between the unit's low/high PC and main's low/high PC:

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_name : test.pp
<14> DW_AT_producer : Free Pascal 3.3.1 2021/11/27 <31> DW_AT_comp_dir : /home/christo/fpc/xtensa/examples/test/ <59> DW_AT_language : 9 (ANSI Pascal)
<5a> DW_AT_identifier_case: 3 (case_insensitive) <5b> DW_AT_stmt_list : 0x0
<5f> DW_AT_low_pc : 0x400e49e4
<63> DW_AT_high_pc : 0x400e49e4
<1><67>: Abbrev Number: 2 (DW_TAG_subprogram)
<68> DW_AT_name : $main
<6e> DW_AT_prototyped : 1
<6f> DW_AT_external : 1
<70> DW_AT_low_pc : 0x400d0a70
<74> DW_AT_high_pc : 0x400d0ab3

From the compiler generated assembly it appears that the labels for these

values are correctly placed
(DEBUGSTART_$P$TEST placed at start of code):

.globl DEBUGSTART_$P$TEST
DEBUGSTART_$P$TEST:
# End asmlist al_begin
# Begin asmlist al_procedures

.section .text.n_main,"ax"
.balign 4
.globl main
main:
.globl PASCALMAIN
PASCALMAIN:
.Lc2:
# Start of abi_windowed entry localsize=0

Below the label is used in the debug info section:

.section .debug_info
.Ldebug_info0:
.long .Ledebug_info0-.Lf2
.Lf2:
.short 3
.long .Ldebug_abbrev0
.byte 4
.uleb128 1
.ascii "test.pp\000"
.ascii "Free Pascal 3.3.1 2021/11/27\000"
.ascii "/home/christo/fpc/xtensa/examples/test/\000" .byte 9
.byte 3
.long .Ldebug_line0
.long DEBUGSTART_$P$TEST
.long DEBUGEND_$P$TEST

Reply by email

Florian Klämpfl
to Christo Crause
Christo Crause wrote 57 lines
When compiling a simple test for esp32 (xtensa-freertos), the incorrect values for DW_AT_low_PC and DW_AT_high_PC are generated.  From my inspection of the generated assembler I cannot see anything wrong, but the values supplied by the linker are wrong.  Any ideas on how to fix this? This can be seen below, where there is no overlap between the unit's low/high PC and main's low/high PC:  <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)     <c>   DW_AT_name        : test.pp     <14>   DW_AT_producer    : Free Pascal 3.3.1 2021/11/27     <31>   DW_AT_comp_dir    : /home/christo/fpc/xtensa/examples/test/     <59>   DW_AT_language    : 9 (ANSI Pascal)     <5a>   DW_AT_identifier_case: 3 (case_insensitive)     <5b>   DW_AT_stmt_list   : 0x0     <5f>   DW_AT_low_pc      : 0x400e49e4     <63>   DW_AT_high_pc     : 0x400e49e4  <1><67>: Abbrev Number: 2 (DW_TAG_subprogram)     <68>   DW_AT_name        : $main     <6e>   DW_AT_prototyped  : 1     <6f>   DW_AT_external    : 1     <70>   DW_AT_low_pc      : 0x400d0a70     <74>   DW_AT_high_pc     : 0x400d0ab3 From the compiler generated assembly it appears that the labels for these values are correctly placed (DEBUGSTART_$P$TEST placed at start of code): .globl DEBUGSTART_$P$TEST DEBUGSTART_$P$TEST: # End asmlist al_begin # Begin asmlist al_procedures .section .text.n_main,"ax" .balign 4 .globl main main: .globl PASCALMAIN PASCALMAIN: .Lc2: #   Start of abi_windowed entry localsize=0 Below the label is used in the debug info section: .section .debug_info .Ldebug_info0: .long .Ledebug_info0-.Lf2 .Lf2: .short 3 .long .Ldebug_abbrev0 .byte 4 .uleb128 1 .ascii "test.pp\000" .ascii "Free Pascal 3.3.1 2021/11/27\000" .ascii "/home/christo/fpc/xtensa/examples/test/\000" .byte 9 .byte 3 .long .Ldebug_line0 .long DEBUGSTART_$P$TEST .long DEBUGEND_$P$TEST

How does the debug info section look like for a gcc generated program?

Reply by email

Christo Crause
to Florian Klämpfl

On Sat, Dec 4, 2021 at 5:23 PM Florian Klämpfl via fpc-devel <

Show quoted text 67 lines
wrote: Am 04.12.2021 um 14:04 schrieb Christo Crause via fpc-devel: > When compiling a simple test for esp32 (xtensa-freertos), the incorrect values for DW_AT_low_PC and DW_AT_high_PC are > generated. From my inspection of the generated assembler I cannot see anything wrong, but the values supplied by the > linker are wrong. Any ideas on how to fix this? > > This can be seen below, where there is no overlap between the unit's low/high PC and main's low/high PC: > > <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) > <c> DW_AT_name : test.pp > <14> DW_AT_producer : Free Pascal 3.3.1 2021/11/27 > <31> DW_AT_comp_dir : /home/christo/fpc/xtensa/examples/test/ > <59> DW_AT_language : 9 (ANSI Pascal) > <5a> DW_AT_identifier_case: 3 (case_insensitive) > <5b> DW_AT_stmt_list : 0x0 > <5f> DW_AT_low_pc : 0x400e49e4 > <63> DW_AT_high_pc : 0x400e49e4 > <1><67>: Abbrev Number: 2 (DW_TAG_subprogram) > <68> DW_AT_name : $main > <6e> DW_AT_prototyped : 1 > <6f> DW_AT_external : 1 > <70> DW_AT_low_pc : 0x400d0a70 > <74> DW_AT_high_pc : 0x400d0ab3 > > From the compiler generated assembly it appears that the labels for these values are correctly placed > (DEBUGSTART_$P$TEST placed at start of code): > > .globl DEBUGSTART_$P$TEST > DEBUGSTART_$P$TEST: > # End asmlist al_begin > # Begin asmlist al_procedures > > .section .text.n_main,"ax" > .balign 4 > .globl main > main: > .globl PASCALMAIN > PASCALMAIN: > .Lc2: > # Start of abi_windowed entry localsize=0 > > Below the label is used in the debug info section: > > .section .debug_info > .Ldebug_info0: > .long .Ledebug_info0-.Lf2 > .Lf2: > .short 3 > .long .Ldebug_abbrev0 > .byte 4 > .uleb128 1 > .ascii "test.pp\000" > .ascii "Free Pascal 3.3.1 2021/11/27\000" > .ascii "/home/christo/fpc/xtensa/examples/test/\000" > .byte 9 > .byte 3 > .long .Ldebug_line0 > .long DEBUGSTART_$P$TEST > .long DEBUGEND_$P$TEST How does the debug info section look like for a gcc generated program?

The debug info for the main file in the project (other file information looks similar):

Compilation Unit @ offset 0xf7476:
Length: 0x6347 (32-bit)
Version: 4
Abbrev Offset: 0xe85d
Pointer Size: 4
<0><f7481>: Abbrev Number: 1 (DW_TAG_compile_unit) <f7482> DW_AT_producer : (indirect string, offset: 0xa4): GNU C99 8.4.0 -mlongcalls -ggdb -Og -std=gnu99 -ffunction-sections -fdata-sections -fstrict-volatile-bitfields
<f7486> DW_AT_language : 12 (ANSI C99)
<f7487> DW_AT_name : (indirect string, offset: 0x14b84): ../main/sd_card_example_main.c
<f748b> DW_AT_comp_dir : (indirect string, offset: 0x689): /home/christo/xtensa/examples/sd_card/build
<f748f> DW_AT_ranges : 0x3148
<f7493> DW_AT_low_pc : 0x0
<f7497> DW_AT_stmt_list : 0x59c73
<1><f749b>: Abbrev Number: 2 (DW_TAG_base_type)

Reply by email

Florian Klämpfl
to Christo Crause
Show quoted text 81 lines
Am 05.12.2021 um 06:09 schrieb Christo Crause via fpc-devel : On Sat, Dec 4, 2021 at 5:23 PM Florian Klämpfl via fpc-devel < > wrote: Am 04.12.2021 um 14:04 schrieb Christo Crause via fpc-devel: > When compiling a simple test for esp32 (xtensa-freertos), the incorrect values for DW_AT_low_PC and DW_AT_high_PC are > generated. From my inspection of the generated assembler I cannot see anything wrong, but the values supplied by the > linker are wrong. Any ideas on how to fix this? > > This can be seen below, where there is no overlap between the unit's low/high PC and main's low/high PC: > > <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) > <c> DW_AT_name : test.pp > <14> DW_AT_producer : Free Pascal 3.3.1 2021/11/27 > <31> DW_AT_comp_dir : /home/christo/fpc/xtensa/examples/test/ > <59> DW_AT_language : 9 (ANSI Pascal) > <5a> DW_AT_identifier_case: 3 (case_insensitive) > <5b> DW_AT_stmt_list : 0x0 > <5f> DW_AT_low_pc : 0x400e49e4 > <63> DW_AT_high_pc : 0x400e49e4 > <1><67>: Abbrev Number: 2 (DW_TAG_subprogram) > <68> DW_AT_name : $main > <6e> DW_AT_prototyped : 1 > <6f> DW_AT_external : 1 > <70> DW_AT_low_pc : 0x400d0a70 > <74> DW_AT_high_pc : 0x400d0ab3 > > From the compiler generated assembly it appears that the labels for these values are correctly placed > (DEBUGSTART_$P$TEST placed at start of code): > > .globl DEBUGSTART_$P$TEST > DEBUGSTART_$P$TEST: > # End asmlist al_begin > # Begin asmlist al_procedures > > .section .text.n_main,"ax" > .balign 4 > .globl main > main: > .globl PASCALMAIN > PASCALMAIN: > .Lc2: > # Start of abi_windowed entry localsize=0 > > Below the label is used in the debug info section: > > .section .debug_info > .Ldebug_info0: > .long .Ledebug_info0-.Lf2 > .Lf2: > .short 3 > .long .Ldebug_abbrev0 > .byte 4 > .uleb128 1 > .ascii "test.pp\000" > .ascii "Free Pascal 3.3.1 2021/11/27\000" > .ascii "/home/christo/fpc/xtensa/examples/test/\000" > .byte 9 > .byte 3 > .long .Ldebug_line0 > .long DEBUGSTART_$P$TEST > .long DEBUGEND_$P$TEST How does the debug info section look like for a gcc generated program? The debug info for the main file in the project (other file information looks similar): Compilation Unit @ offset 0xf7476: Length: 0x6347 (32-bit) Version: 4 Abbrev Offset: 0xe85d Pointer Size: 4 <0><f7481>: Abbrev Number: 1 (DW_TAG_compile_unit) <f7482> DW_AT_producer : (indirect string, offset: 0xa4): GNU C99 8.4.0 -mlongcalls -ggdb -Og -std=gnu99 -ffunction-sections -fdata-sections -fstrict-volatile-bitfields <f7486> DW_AT_language : 12 (ANSI C99) <f7487> DW_AT_name : (indirect string, offset: 0x14b84): ../main/sd_card_example_main.c <f748b> DW_AT_comp_dir : (indirect string, offset: 0x689): /home/christo/xtensa/examples/sd_card/build <f748f> DW_AT_ranges : 0x3148 <f7493> DW_AT_low_pc : 0x0 <f7497> DW_AT_stmt_list : 0x59c73 <1><f749b>: Abbrev Number: 2 (DW_TAG_base_type)

You can try adding tf_dwarf_relative_addresses in i_freertos.pas line 660, it appears that xtensa-freertos uses relative addresses.

Reply by email

Christo Crause
to Florian Klämpfl

On Sun, Dec 5, 2021 at 11:45 AM Florian Klämpfl via fpc-devel <

Show quoted text 6 lines
wrote: You can try adding tf_dwarf_relative_addresses in i_freertos.pas line 660, it appears that xtensa-freertos uses relative addresses.

Including this flag results in an unresolved symbol error:

/home/christo/fpc/gitlab-cc/compiler/ppcrossxtensa -Cplx6 -Ur -Tfreertos -Pxtensa
-XP/home/christo/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf- -Ur -Xs -O2 -n -Fi../inc -Fi../xtensa -FE.
-FU/home/christo/fpc/gitlab-cc/rtl/units/xtensa-freertos -dxtensa -dRELEASE -Cfhard -g xtensa/esp32.pp
/home/christo/fpc/gitlab-cc/rtl/units/xtensa-freertos/esp32.s: Assembler messages:
/home/christo/fpc/gitlab-cc/rtl/units/xtensa-freertos/esp32.s:1454: Error: can't resolve `.debug_info' {.debug_info section} - `.Ldebug_infosection0' {*UND* section}
esp32.pp(78) Error: Error while assembling exitcode 1

A similar error is also reported for esp8266.

Reply by email