[LLVMdev] Implementing the ldr pseudo instruction in ARM integrated assembler

David Peixotto dpeixott at codeaurora.org
Fri Nov 1 13:34:20 PDT 2013


> There's still a problem for Darwin, or any other platform that use
> subsections-via-symbols type layout tricks, though. There's no assembler-
> time way to know how far apart the atoms in the section will be at
> runtime, as the linker can, and will, move things around.

Hmm, yes that does sound quite tricky. How do we currently deal with that
for other pc-relative loads. Say the programmer writes something like this

_foo:
	ldr r1, [pc, #392]
_bar:
	.space 200
_baz:
	.space 200
_some_important_constants: .word 0x12345678

If bar and baz get deleted by the linker the offset would obviously be
wrong. Do we do anything special for this or just rely on the programmer not
to write this code?

> We could, perhaps, always require an explicit directive for all constant
> pools when using subsections-via-symbols and add a diagnostic check at the
> end of parsing (when we're spitting out the non-empty pools) to see if
> there was a subsections-via-symbols directive in there anywhere.

This seems to be a reasonable choice. It seems it would still be difficult
to detect all the cases where we could run into trouble. For example,
something like

_foo:
  ldr r1, =0x12345678
_bar:
  ...
.ltorg

If bar gets deleted we would still have the wrong offsets.

> Anyways, the main point of all of this is to reinforce the "there be
> dragons here" nature of this feature. It interacts with other parts of the
> assembler and the underlying assumptions of the platform in interesting
> ways. Lots of *really* careful test cases will be necessary.

Yes I see your point. Thanks for brining .subsections_via_symbols to my
attention.





More information about the llvm-dev mailing list