-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARM - dealing with large programs / global arrays - invalid constant (XXXX) after fixup #619
Comments
Hi Tiago, |
While I was developing this code, I tried something similar to the following to see if it would work:
The compiler did complain (as expected... but hope is the last to die):
Providing Hp (unitialized...) did not work as well:
The idea:
Questions:
|
I not sure that what I say is correct, but I think a systematic way of doing this kind of access, will be to replace |
I believe it should be
otherwise we're taking the address of |
I tried to explore a bit the solutions to this issue, and here are my findings. First note that we have the problem both with LDR and ADR, depending on whether we want to access directly a constant or get its address. When looking on the web, 2 solutions were mentioned:
I found it strange that we cannot delegate the task of choosing the right assembly instruction to the assembler, just like we do with RISC-V and its pseudo-instructions. It turns out that we can:
Maybe the right solution is to rely on the pseudo-instructions, but that means we need to be able to produce different outputs depending on the toolchain used (ARM tool, GCC, maybe LLVM). |
@sarranz What do you think? |
I found the following issue while developing SHA256 for ARM. It isn't an issue right now for that particular implementation, but I will share my notes here as they might be of use and to see if there is a different way of handling these cases or if the language/compiler needs improvement.
Consider the following program:
We have a global array
H
, from which we get the address intoHp
and then use it once. BetweenHp = H;
and theglob_data:
section, there are 1 load, 1 move, 2042 add instructions, and a pop instruction. When I try to runarm-linux-gnueabi-gcc -g -static -mcpu=cortex-m4 -o example example.s
, whereexample.s
contains the result of compiling the previous program, I get:The assembly instruction corresponding to
Hp = H;
isADR r0, glob_data+0
. ForL = 2041
, the program compiles and when observing the result ofobjdump
one can see:Accordingly to p.197 of this manual it seems that the T2 encoding is used, and we get 12 bits (4095) to use (I compared the bits from
f60f 70fc
with the ones from the pdf).Going back to
L = 2042
. The reported value by the compiler is 0x101c, corresponding to 4124 in decimal. The calculation goes as follows, if I'm not mistaken: 4 bytes forHp = H;
, 6 bytes fort = Hp[0]; v=0;
, 4084 bytes corresponding to the for loop (2 bytes per instruction), and 2 bytes for the lastpop
. Total of 4096 bytes (not considering the assembly code beforeHp = H;
)Due to the
.p2align 5
directive beforeglob_data:
, this seems to putglob_data
at a distance of 4124 from the ADR instruction. Hence, this constant does not fit possible encodings for the instruction.Questions:
Some final notes regarding the SHA256 implementation:
The text was updated successfully, but these errors were encountered: