Question about the hifive1 linker script

Hi, I am trying to understand the hifive1 revB linker script and I got a question: why do we have ALIGN(8) in bss, data and itim sections ? is ALIGN(4) not enough ?

Doubles and long long get 64-bit alignment as per the ABI. To make that work, any section containing a double or long long needs 8-byte alignment. While a rv32imac target doesn’t have any hardware instructions that require 8-byte alignment, the compiler will still take the ABI required 8-byte alignment into account when generating code. So for instance the compiler will assume that adding 4 to the address of a double or long long to address the second half of it is always safe, because with 8-byte alignment adding 4 can’t overflow the addi immediate field. But if the address is only 4-byte aligned, then adding 4 can overflow and the code fails at run-time.

1 Like