From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id D2D593858D3C for ; Tue, 12 Sep 2023 13:46:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2D593858D3C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1694526380; bh=nVKgbkCp3CYiz5E1uSV2xB73FzX9TentlQd8LDbsV70=; h=Subject:From:To:Date:In-Reply-To:References:From; b=krzUsB189k7y0w2VjktveksFp/mTwScBckvNnAlkIGdbXvLOgVb83WcVPxcy3aMm3 dFifbAx3I2Tp/l1KGt6KnP7CsgMPb80fKGO+mefsLt/JJAnI8PD78m4sS5qN78890J ZVaHA4Luna6X82w1q8/J0fETpRfSQQwGkJzjeEn0= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 4288D659C0; Tue, 12 Sep 2023 09:46:20 -0400 (EDT) Message-ID: Subject: Re: How to define a symbol with absolute address for AArch64? From: Xi Ruoyao To: Sebastian Huber , Richard Earnshaw , binutils Date: Tue, 12 Sep 2023 21:46:18 +0800 In-Reply-To: <57bfc9fd-e7b2-40b0-aeac-0447d6d0245e@embedded-brains.de> 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> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no 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 Tue, 2023-09-12 at 14:58 +0200, Sebastian Huber wrote: > On 12.09.23 13:21, Richard Earnshaw wrote: > >=20 > >=20 > > On 12/09/2023 11:02, Sebastian Huber wrote: > > > Hello, > > >=20 > > > I would like to define a global symbol with an absolute address in an= =20 > > > assembly/C source file for the AArch64 target. This works for all=20 > > > other architectures I tried so far, but not for AArch64: > > >=20 > > > extern char abs_symbol[]; > > > extern char abs_symbol_2[]; > > >=20 > > > __asm__( > > > =C2=A0=C2=A0 "\t.globl abs_symbol\n" > > > =C2=A0=C2=A0 "\t.set abs_symbol, 0x123\n" > > > ); > > >=20 > > > unsigned long f_abs_symbol(void) > > > { > > > =C2=A0=C2=A0 return (unsigned long)abs_symbol; > > > } > > >=20 > > > unsigned long f_abs_symbol_2(void) > > > { > > > =C2=A0=C2=A0 return (unsigned long)abs_symbol_2; > > > } > > >=20 > > > unsigned long _start(void) > > > { > > > =C2=A0=C2=A0 return f_abs_symbol() + f_abs_symbol_2(); > > > } > > >=20 > > > aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=3Dabs_symbol_= 2=3D291 > >=20 > > Have you tried -mcmodel=3Dlarge?=C2=A0 With that I get: >=20 > I get the same result with -mcmodel=3Dlarge. With -mcmodel=3Dtiny I get: >=20 > aarch64-rtems6-gcc abs.c -Wl,--gc-sections -Wl,--defsym=3Dabs_symbol_2=3D= 291=20 > -mcmodel=3Dtiny > /tmp/ccKUnvyq.o: in function `f_abs_symbol_2': > abs.c:(.text+0x8): relocation truncated to fit: R_AARCH64_ADR_PREL_LO21= =20 > against symbol `abs_symbol_2' defined in *ABS* section in a.out > collect2: error: ld returned 1 exit status >=20 > Is this a tool bug? No, it's how code models are defined. GCC documentation says clearly: -mcmodel=3Dtiny Generate code for the tiny code model. The program and = its statically defined symbols must be within 1MB of each oth= er. Programs can be statically or dynamically linked. Here the text is located at 0x400000 but abs_symbol_2 is at 0x123, thus violating the definition of -mcmodel=3Dtiny. > Is there some way to make this working with -mcmodel=3Dsmall? No because -mcmodel=3Dsmall only assumes the program and the symbols are within *a* 4GB range - for example it's allowed to be [47GB, 51GB).=20 This is different from the default code model of RISC-V (- mcmodel=3Dmedlow) where the symbols must be in [-2GB, 2GB). 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. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University