We want to make sure that symbol str actually sits directly above
the .string directive. If the str label is defined directly before
the .section .data directive, then the symbol won't point to the
actual string bytes but somewhere above it, and will consequently
print garbage:
Note the discrepancy between 100ca <str> (the address the assembler
thinks its at) and the data actually sitting at 0x110ca.
I think this is because if you look in the default linker script with
riscv32-unknown-elf-ld -verbose ..., the .data section is
preceeded by a page alignment:
* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
Hence the discrepancy of about 0x1000 (4kb). After this change, the
symbols correspond to eachother:
Many thanks for the fix and the great explanation. I'm terrible with linkers and stuff like this so there's a good chance there are more things to fix. Picked and pushed!
Tested on Nexys4 DDR.
We want to make sure that symbol
str
actually sits directly above the.string
directive. If thestr
label is defined directly before the.section .data
directive, then the symbol won't point to the actual string bytes but somewhere above it, and will consequently print garbage:Note the discrepancy between
100ca <str>
(the address the assembler thinks its at) and the data actually sitting at0x110ca
.I think this is because if you look in the default linker script with
riscv32-unknown-elf-ld -verbose ...
, the.data
section is preceeded by a page alignment:Hence the discrepancy of about
0x1000
(4kb). After this change, the symbols correspond to eachother: