How to define a symbol with absolute address for AArch64?

Sebastian Huber sebastian.huber@embedded-brains.de
Tue Sep 12 12:58:25 GMT 2023



On 12.09.23 13:21, Richard Earnshaw wrote:
> 
> 
> On 12/09/2023 11:02, Sebastian Huber wrote:
>> Hello,
>>
>> I would like to define a global symbol with an absolute address in an 
>> assembly/C source file for the AArch64 target. This works for all 
>> other architectures I tried so far, but not for AArch64:
>>
>> extern char abs_symbol[];
>> extern char abs_symbol_2[];
>>
>> __asm__(
>>    "\t.globl abs_symbol\n"
>>    "\t.set abs_symbol, 0x123\n"
>> );
>>
>> unsigned long f_abs_symbol(void)
>> {
>>    return (unsigned long)abs_symbol;
>> }
>>
>> unsigned long f_abs_symbol_2(void)
>> {
>>    return (unsigned long)abs_symbol_2;
>> }
>>
>> unsigned long _start(void)
>> {
>>    return f_abs_symbol() + f_abs_symbol_2();
>> }
>>
>> aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=abs_symbol_2=291
> 
> Have you tried -mcmodel=large?  With that I get:

I get the same result with -mcmodel=large. With -mcmodel=tiny I get:

aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=abs_symbol_2=291 
-mcmodel=tiny
/tmp/ccKUnvyq.o: in function `f_abs_symbol_2':
abs.c:(.text+0x8): relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 
against symbol `abs_symbol_2' defined in *ABS* section in a.out
collect2: error: ld returned 1 exit status

Is this a tool bug?

Is there some way to make this working with -mcmodel=small?

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the Binutils mailing list