We are observing some discrepancies in the way assembler and compiler
behaves for ARM9
for Position independent coding.
We are using RVDS3.0 tools
Below is the Issue:
Assembler Behavior:
In our ARM9 assembly coding we are accessing lot of global tables as
below
findCRC.s :
LDR R2, =TAB_crcTable
The actual Table is included as "Tables.c" as
const Word16 TAB_crcTable[10] = {54, 64, 72, 72, 72, 72, 72,
72, 72, 40};
For Position independent coding we are using --apcs /ropi/rwpi
assembler options.
With this we are getting linking error in ASM code where ever we are
accessing Tables.
Error : armlink : L6248: findCRC.o(Program) in PI region 'ER_RO'
cannot have address type relocation to TAB_crcTable in PI region
'ER_RO'
Compiler Behavior:
We tried Using C code instead of ASM
findCRC.c :
remainder = TAB_crcTable[data];
For Position independent coding we are using --apcs /ropi/rwpi and --
lower_ropi compiler options.
The actual Table is included as "Tables.c" as above
In this case the linker is not giving any errors.
If we looked at the disassembled code of the above then we noticed
that a Literal Pool
is created after the code and the table is accessed as PC relative
offset.
Why Assembler is not making the Code position independent like the
Compiler??
How to make out ASM code position independent with minimal changes?
thanks
suresh
A compiler does high level transformations while an assembler literally
does what you write. The RVCT assembler is already deemed too high
level by some people. In any case an assembler doesn't know the types
of symbols, so it can't emit the right instruction sequence.
> How to make out ASM code position independent with minimal changes?
Assuming you really need position independence, you could write your
own set of (non-trivial) macros to deal with it.
However the best option is to place the tables in your assembly code and
use ADR/ADRL to access them. This is also faster - that's why you chose
to write optimized assembler code, right?
Wilco