Writing an assembly code and want to make the ASLR (Address Space Layout Randomisation) complaint code.
armb8le platform (64 bit)
Previously was using LDR command to load the fork function as below:
ldr x4,=ASM_NAME(forkx)
From the ARM manual came to know that the for PC relative jump we need to use the ADR command and which will make it ASLR complaint. So now using ADRP command as below, chosen ADRP because of relative jump is more in this case, also ADR command used to give error.
adrp x4, ASM_NAME(forkx)
After doing this, now my binary generated the free of textrel segment and ASLR complaint.
But when i load the image it is getting crashed and traceback point to the function where this changes are done.
Also after loading x4 is getting used with load and store operation.
Please can anyone help in this? is there any problem in using these instruction like this?
Step #4 is correct in itself, the result of ADRP is a value with lower 12-bits set to zero, as its role is to calculate the base of a 4KB page.
However I don't understand the subsequent code and how it relates to calculating the address of fork. I don't know which compiler generated this code, or the source that generated it, but I'm not sure I can decipher from the info supplied.
Thanks for the input ronan, as you told it is expected behaviour, actually this code generated was wrong to get the forkx address we need to have 2 instructions:
add x4,x4, :lo12:ASM_NAME(forkx)
by adding the second instruction manually it is fine now. Thanks for the support.
Was this hand written assembler code, or compiler generated? If the compiler, could you provide a simple code sample that can be used to replicate this, so that it can be fixed.
This was a assembly code generated by intermittent translator that is used. i got only the assembly code generated to check the crash. have to check the tool doing this.