@@ -125,6 +125,59 @@ This model is similar to the medium any code model, but uses the
125125 l[w|d] a0, %pcrel_lo(.Ltmp3)(a0)
126126----
127127
128+ === Large code model
129+
130+ The `large` code model allows the code to address the whole RV64 address space.
131+ Thus, this model is only available for RV64. By putting object addresses
132+ into literal pools, a 64-bit address literal can be loaded from the pool.
133+
134+ NOTE: Because calculating the pool entry address must use `aupic` and
135+ `addi` or `ld`, each pool entry has to be located within the range
136+ between -2GiB and +2GiB from its access intructions. In general, the pool
137+ is appeneded in .text section or put into .rodata section.
138+
139+ [,asm]
140+ ----
141+ # Get address of a symbol
142+ # Literal pool
143+ .LCPI0:
144+ .8byte symbol
145+ ...
146+ .Ltmp0: auipc a0, %pcrel_hi(.LCPI0)
147+ ld a0, %pcrel_lo(.Ltmp0)(a0)
148+ ----
149+
150+ This model also changes the function call patterns. An external function
151+ address must be loaded from a literal pool entry, and use `jalr` to jump to
152+ the target function.
153+
154+
155+ NOTE: Same as getting address of symbol, each pool entry has to be located
156+ within the range between -2GiB and +2GiB from its access intructions. The
157+ function call can reach the whole 64-bit address space.
158+
159+ NOTE: The code generation of function call may be changed after the range
160+ extension thunk is implemented. The compiler can emit `call` directly,
161+ and leave the model variation to the linker which could decide to jump
162+ via the literal pool or not.
163+
164+ [,asm]
165+ ----
166+ # Function call
167+ # Literal pool
168+ .LCPI1:
169+ .8byte function
170+ ...
171+ .Ltmp1: auipc a0, %pcrel_hi(.LCPI1)
172+ ld a0, %pcrel_lo(.Ltmp1)(a0)
173+ jalr a0
174+ ----
175+
176+ NOTE: Large code model is disallowed to be used with PIC code model.
177+
178+ NOTE: There will be more different code generation strategies for different
179+ usage purposes in the future.
180+
128181== Dynamic Linking
129182
130183Any functions that use registers in a way that is incompatible with
0 commit comments