blob: d36a1b09d5a99bfd264ede6b1187f82cf112128a [file]
<html lang="en">
<head>
<title>AArch64-Relocations - Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="AArch64-Syntax.html#AArch64-Syntax" title="AArch64 Syntax">
<link rel="prev" href="AArch64_002dRegs.html#AArch64_002dRegs" title="AArch64-Regs">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU Assembler "as".
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the
section entitled ``GNU Free Documentation License''.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="AArch64-Relocations"></a>
<a name="AArch64_002dRelocations"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="AArch64_002dRegs.html#AArch64_002dRegs">AArch64-Regs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="AArch64-Syntax.html#AArch64-Syntax">AArch64 Syntax</a>
<hr>
</div>
<h5 class="subsubsection">9.1.2.3 Relocations</h5>
<p><a name="index-relocations_002c-AArch64-530"></a><a name="index-AArch64-relocations-531"></a><a name="index-MOVN_002c-MOVZ-and-MOVK-group-relocations_002c-AArch64-532"></a>Relocations for &lsquo;<samp><span class="samp">MOVZ</span></samp>&rsquo; and &lsquo;<samp><span class="samp">MOVK</span></samp>&rsquo; instructions can be generated
by prefixing the label with &lsquo;<samp><span class="samp">#:abs_g2:</span></samp>&rsquo; etc.
For example to load the 48-bit absolute address of <var>foo</var> into x0:
<pre class="smallexample"> movz x0, #:abs_g2:foo // bits 32-47, overflow check
movk x0, #:abs_g1_nc:foo // bits 16-31, no overflow check
movk x0, #:abs_g0_nc:foo // bits 0-15, no overflow check
</pre>
<p><a name="index-ADRP_002c-ADD_002c-LDR_002fSTR-group-relocations_002c-AArch64-533"></a>Relocations for &lsquo;<samp><span class="samp">ADRP</span></samp>&rsquo;, and &lsquo;<samp><span class="samp">ADD</span></samp>&rsquo;, &lsquo;<samp><span class="samp">LDR</span></samp>&rsquo; or &lsquo;<samp><span class="samp">STR</span></samp>&rsquo;
instructions can be generated by prefixing the label with
&lsquo;<samp><span class="samp">#:pg_hi21:</span></samp>&rsquo; and &lsquo;<samp><span class="samp">#:lo12:</span></samp>&rsquo; respectively.
<p>For example to use 33-bit (+/-4GB) pc-relative addressing to
load the address of <var>foo</var> into x0:
<pre class="smallexample"> adrp x0, #:pg_hi21:foo
add x0, x0, #:lo12:foo
</pre>
<p>Or to load the value of <var>foo</var> into x0:
<pre class="smallexample"> adrp x0, #:pg_hi21:foo
ldr x0, [x0, #:lo12:foo]
</pre>
<p>Note that &lsquo;<samp><span class="samp">#:pg_hi21:</span></samp>&rsquo; is optional.
<pre class="smallexample"> adrp x0, foo
</pre>
<p>is equivalent to
<pre class="smallexample"> adrp x0, #:pg_hi21:foo
</pre>
</body></html>