Bug 18009 - LDR macro on arm can't generate relative address
Summary: LDR macro on arm can't generate relative address
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-23 15:44 UTC by goswin-v-b@web.de
Modified: 2015-02-23 17:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description goswin-v-b@web.de 2015-02-23 15:44:12 UTC
The arm assembly has a LDR macro to load constants:

    ldr r0, =symbol

This works for symbols (or constants, but that isn't the use case I want) in the same file and section and also for symbols in other sections or files. For external symbols it generates an R_ARM_ABS32 linker reference in the next literals block and adds PC relative addressing to load that.

One can also generate a R_ARM_REL32 linker reference writing

1:  .word symbol - 1b

This correctly stores the relative (to the 1 label) offset of the symbol and fills that in at link time (and generates a .rel.dyn entry for shared code).


What does not work is writing

1:  ldr r0, =(symbol - 1b)

boot.S:49: Error: constant expression expected -- `ldr r0,=(symbol-1b)'

this works fine with clangs internal assembler and should work here too. There seems to be no other way to add a R_ARM_REL32 linker reference to the literals block and load that into a register.

An alternate this could be something like

    ldr r0, [pc, =symbol]