[cfe-dev] AArch64 ASM / Custom Sections and Common Variables

Tim Northover via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 11 06:37:13 PST 2019


Hi Joel,

On Sat, 9 Nov 2019 at 18:26, Joel Winarske via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> This generates "unsupported relocation type: fixup_aarch64_ldr_pcrel_imm19".  If I comment out the first ldr line, it builds, as FooValue is part of .text.foo2.

To reference a symbol across sections like this, you'd need to add a
relocation to the object file, but some formats (MachO I know) have a
ridiculously small number of permitted relocations and don't have room
for for pc-relative load relocations. I think you're probably hitting
that issue.

You've got two options:

1. Reference FooValue in a way that does have relocations. For example
(on MachO, I'm afraid I don't know the syntax for COFF, and it should
just be working anyway for ELF):

    adrp x0, FooValue at PAGE
    ldr w0, [x0, FooValue at PAGEOFFSET]

2. Use a local symbol with a different name each time (starting with L
on MachO), and defined within the section that references it
(actually, probably before the next global symbol if you're using
.subsections_via_symbols, which you should be):

    .section .text.foo1
foo1:
   ldr w0, LFooValue.foo1
   ret
LFooValue.foo1:
  .word 0

    .section .text.foo2
foo2:
   ldr w0, LFooValue.foo2
   ret
LFooValue.foo2:
  .word 0

Cheers.

Tim.



More information about the cfe-dev mailing list