From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 87E9E3852C4A for ; Wed, 23 Nov 2022 16:22:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87E9E3852C4A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=foss.arm.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=foss.arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C51301FB; Wed, 23 Nov 2022 08:22:45 -0800 (PST) Received: from [10.57.5.59] (unknown [10.57.5.59]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A7F643F73B; Wed, 23 Nov 2022 08:22:38 -0800 (PST) Message-ID: <7e7e65b3-bf34-e8b6-0613-0fc9d0beaf33@foss.arm.com> Date: Wed, 23 Nov 2022 16:22:37 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: :got: modifier in assembler Content-Language: en-GB To: Bob Plantz , "gcc-help@gcc.gnu.org" References: From: Richard Earnshaw In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3489.7 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE,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 22/11/2022 19:12, Bob Plantz via Gcc-help wrote: > I'm using the Arm A64 instruction set on a Raspberry Pi running Raspberry Pi 64-bit. Given the C code: > > extern int x, y, z; > > void addTwo(void) > { > > z = x + y; > } > > gcc produces the assembly language: > .arch armv8-a > .file "addTwoGlobal.c" > .text > .align 2 > .global addTwo > .type addTwo, %function > addTwo: > adrp x0, :got:x > ldr x0, [x0, #:got_lo12:x] > ldr w1, [x0] > adrp x0, :got:y > ldr x0, [x0, #:got_lo12:y] > ldr w0, [x0] > add w1, w1, w0 > adrp x0, :got:z > ldr x0, [x0, #:got_lo12:z] > str w1, [x0] > nop > ret > .size addTwo, .-addTwo > .ident "GCC: (Debian 10.2.1-6) 10.2.1 20210110" > .section .note.GNU-stack,"",@progbits > > > > I believe that the :got: and :got_lo12: modifiers tell the linker to use the address for x from the global offset table for the offset values in the > adrp x0, :got:x > ldr x0, [x0, #:got_lo12:x] > > > Instructions. > > Using gdb, I can see that adrp loads the offset from the pc to the page number of x and that #:got_lo12:x is an immediate value that is the offset of x within that page. > > But I cannot find where :got: and :got_lo12: are documented. > > > > > The relocation directives should really be documented in GAS (the assembler), but the text there is pretty short and not very comprehensive [1]. The relocation names are essentially taken from the ELF specification for AArch64 (https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst) and the relocation markers used by GAS largely follow the relocation names described in that document. R. [1] https://sourceware.org/binutils/docs-2.39/as.html#AArch64_002dRelocations