public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bob Plantz <rgplantz@outlook.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: :got: modifier in assembler
Date: Tue, 22 Nov 2022 19:12:16 +0000	[thread overview]
Message-ID: <BYAPR04MB4661BF8FB9381F5AD81CDAE1D40D9@BYAPR04MB4661.namprd04.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1340 bytes --]

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.






             reply	other threads:[~2022-11-22 19:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 19:12 Bob Plantz [this message]
2022-11-23 16:22 ` Richard Earnshaw
2022-11-23 16:38   ` Bob Plantz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BYAPR04MB4661BF8FB9381F5AD81CDAE1D40D9@BYAPR04MB4661.namprd04.prod.outlook.com \
    --to=rgplantz@outlook.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).