<div dir="ltr"><div dir="ltr"><div dir="ltr">What target (in particular OS, object file format) are you trying to assemble for? Your example assembles without error for me with this command line:<div> clang --target=aarch64-none-eabi -c test.s -o test.o</div><div><br></div><div>That is generating ELF output, it's possible that other formats don't have the necessary relocations to represent the first LDR instruction, or LLVM doesn't know how to emit them.</div><div><br></div><div>It's also worth noting that a single LDR instruction only has a range of +-1MiB, which might not be what you want. I often find the easiest way to find reasonable assembly sequences is to compile a C file which does what you want and look at the assembly output. For example, with this C file:</div><div><div> long FooValue = 0x0;</div><div><br></div><div> __attribute((section(".text.foo1")))</div><div> long foo1() {</div><div> return FooValue;</div><div> }</div><div><br></div><div> __attribute((section(".text.foo2")))</div><div> long foo2() {</div><div> return FooValue;</div><div> }</div></div><div><br></div><div>clang emits this assembly:</div><div><div> .text</div><div> .file "test2.c"</div><div> .section .text.foo1,"ax",@progbits</div><div> .globl foo1 // -- Begin function foo1</div><div> .p2align 2</div><div> .type foo1,@function</div><div> foo1: // @foo1</div><div> // %bb.0: // %entry</div><div> adrp x8, FooValue</div><div> ldr x0, [x8, :lo12:FooValue]</div><div> ret</div><div> .Lfunc_end0:</div><div> .size foo1, .Lfunc_end0-foo1</div><div> // -- End function</div><div> .section .text.foo2,"ax",@progbits</div><div> .globl foo2 // -- Begin function foo2</div><div> .p2align 2</div><div> .type foo2,@function</div><div> foo2: // @foo2</div><div> // %bb.0: // %entry</div><div> adrp x8, FooValue</div><div> ldr x0, [x8, :lo12:FooValue]</div><div> ret</div><div> .Lfunc_end1:</div><div> .size foo2, .Lfunc_end1-foo2</div><div> // -- End function</div><div> .type FooValue,@object // @FooValue</div><div> .bss</div><div> .globl FooValue</div><div> .p2align 3</div><div> FooValue:</div><div> .xword 0 // 0x0</div><div> .size FooValue, 8</div><div><br></div><div> .ident "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 36937ec7fb8e20b81adbac40bd48c6ed7ac6df61)"</div><div> .section ".note.GNU-stack","",@progbits</div><div> .addrsig</div></div><div><br></div><div>Note the use of the ADRP/LDR pair of instructions, which has a range of +-4GiB.</div><div><br></div><div>Oliver</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 9 Nov 2019 at 18:26, Joel Winarske via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>What is the proper way to have a variable common between two custom-defined sections?</div><div><br></div><div>Example:</div><div><br></div> .global foo1<br> .section .text.foo1, "ax"<br>foo1:<br> ldr w0, FooValue<br> ret<br><br> .global foo2<br> .section .text.foo2, "ax"<br>foo2:<br> ldr w0, FooValue<br> ret<br><br><div>FooValue: .word 0x00</div><div><br></div><div>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.</div><div><br></div><div>If I define FooValue twice, once for each section it complains it's already defined.</div><div><br></div><div><br></div><div>Joel<br></div><div><br></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>