From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 820B83858D3C for ; Tue, 12 Sep 2023 14:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 820B83858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy05.your-server.de ([78.46.172.2]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qg4Ig-000OIE-JT; Tue, 12 Sep 2023 16:23:34 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qg4Ig-000QUA-FG; Tue, 12 Sep 2023 16:23:34 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 1EB7748022D; Tue, 12 Sep 2023 16:23:34 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10032) with ESMTP id 6o06S86JUfJn; Tue, 12 Sep 2023 16:23:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id B2A2248022B; Tue, 12 Sep 2023 16:23:33 +0200 (CEST) X-Virus-Scanned: amavis at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10026) with ESMTP id ee735iY4ku-C; Tue, 12 Sep 2023 16:23:33 +0200 (CEST) Received: from [10.10.171.34] (unknown [10.10.171.34]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 5B9B0480175; Tue, 12 Sep 2023 16:23:33 +0200 (CEST) Message-ID: <2706d31f-7f35-46f9-9a20-78cf069e9602@embedded-brains.de> Date: Tue, 12 Sep 2023 16:23:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: How to define a symbol with absolute address for AArch64? Content-Language: en-US To: Xi Ruoyao , Richard Earnshaw , binutils References: <2d247374-92a2-463b-ba23-8a6dc36d13c0@embedded-brains.de> <580f9122-f63d-628e-4503-dfcefbb1b304@foss.arm.com> <57bfc9fd-e7b2-40b0-aeac-0447d6d0245e@embedded-brains.de> From: Sebastian Huber In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldi-networks.de X-Virus-Scanned: Clear (ClamAV 0.103.8/27029/Tue Sep 12 09:38:51 2023) X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12.09.23 15:46, Xi Ruoyao wrote: > On Tue, 2023-09-12 at 14:58 +0200, Sebastian Huber wrote: >> 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 a= n >>>> 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__( >>>> =C2=A0=C2=A0 "\t.globl abs_symbol\n" >>>> =C2=A0=C2=A0 "\t.set abs_symbol, 0x123\n" >>>> ); >>>> >>>> unsigned long f_abs_symbol(void) >>>> { >>>> =C2=A0=C2=A0 return (unsigned long)abs_symbol; >>>> } >>>> >>>> unsigned long f_abs_symbol_2(void) >>>> { >>>> =C2=A0=C2=A0 return (unsigned long)abs_symbol_2; >>>> } >>>> >>>> unsigned long _start(void) >>>> { >>>> =C2=A0=C2=A0 return f_abs_symbol() + f_abs_symbol_2(); >>>> } >>>> >>>> aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=3Dabs_symbol= _2=3D291 >>> Have you tried -mcmodel=3Dlarge?=C2=A0 With that I get: >> I get the same result with -mcmodel=3Dlarge. With -mcmodel=3Dtiny I ge= t: >> >> aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=3Dabs_symbol_2= =3D291 >> -mcmodel=3Dtiny >> /tmp/ccKUnvyq.o: in function `f_abs_symbol_2': >> abs.c:(.text+0x8): relocation truncated to fit: R_AARCH64_ADR_PREL_LO2= 1 >> against symbol `abs_symbol_2' defined in*ABS* section in a.out >> collect2: error: ld returned 1 exit status >> >> Is this a tool bug? > No, it's how code models are defined. GCC documentation says clearly: >=20 > -mcmodel=3Dtiny > Generate code for the tiny code model. The program = and its > statically defined symbols must be within 1MB of eac= h other. > Programs can be statically or dynamically linked. >=20 > Here the text is located at 0x400000 but abs_symbol_2 is at 0x123, thus > violating the definition of -mcmodel=3Dtiny. Yes, this makes sense. >=20 >> Is there some way to make this working with -mcmodel=3Dsmall? > No because -mcmodel=3Dsmall only assumes the program and the symbols ar= e > within*a* 4GB range - for example it's allowed to be [47GB, 51GB). > This is different from the default code model of RISC-V (- > mcmodel=3Dmedlow) where the symbols must be in [-2GB, 2GB). >=20 > If you really think GCC should support this you can ask GCC for adding = a > new code model. Anyway this is not a linker issue because the adrp-add > pairs are generated by GCC. Thanks for the explanation. I guess what reliably works across code models is using the address of=20 an existing symbol and then add a constant which fits into the code=20 model. To retrieve the constant, we just have to subtract the address of=20 the other symbol. --=20 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=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/