Issue
I am working on a project using the Kendryte K210 which is a 64-bit duel-core RISC-V machine. I am using the Kendryte GNU toolchain and the starting point was the Kendryte standalone SDK.
I am experiencing some frustrating core faults. The fault, a misaligned load, is happening after a balr
to _Balloc in _ldtoa_r, where a ld
instruction in _Balloc is attempting to load from an invalid address pointed to by one of the function argument registers (a0 in this case).
I have been trying to figure out when/where/how _Balloc and _ldtoa_r are used, but they are part of libc. My map file shows _ldtoa_r is somehow related to lib_a-ldtoa.o and lib_a-svfprintf.o and _Balloc is somehow related to lib_a-strtod.o and lib_a-mprec.o. I'm not sure because I am new to interpreting map files.
If anyone can help educate me on what _ldtoa_r and _Balloc are, how they are used, their relationship to these object files, and possibly how to properly interpret relevant lines in the map file, then I would be very grateful.
Thank you.
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-strtod.o) (_Balloc)
...
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-ldtoa.o)
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-svfprintf.o) (_ldtoa_r)
...
.text._ldtoa_r
0x0000000080027456 0xa74
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-ldtoa.o)
0x0000000080027456 _ldtoa_r
...
.text._Balloc
0x000000008002814c 0x6c
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-mprec.o)
0x000000008002814c _Balloc
...
.rodata._ldtoa_r.str1.8
0x000000008003cfb8 0x34
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a(lib_a-ldtoa.o)
Solution
Cannyone explain the use of libc functions _ldtoa_r
Is used to convert a long double
value to a string, with many customization options, and is reentrant in the Newlib sense takes _REENT state.
It used for example when printing a double
value.
and _Balloc?
Balloc
allocate an _Bigint
value. _Bigint
represents a floating point value as a "big integer".
It is used in various places, mostly when printing and reading a long double
values from/to a string.
their relationship to these object files
The compiled code is stored in "these object files".
how to properly interpret relevant lines in the map file
.text._ldtoa_r
#^^^^^^^^^^^^^^ - section name
0x0000000080027456 0xa74
# ^^^^^ - length of the section
# ^^^^^^^^^^^^^^^ - location of the section in output file
c:/sysgcc/kendryte/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib\libc.a
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - filename
# .. (lib_a-ldtoa.o)
# ^^^^^^^^^^^^^ - object filename (used when compiling libc)
0x0000000080027456 _ldtoa_r
# ^^^^^^^^ - symbol name
# ^^^^^^^^^^^^^^^^ - location in output file
Answered By - KamilCuk Answer Checked By - Robin (WPSolving Admin)