Skip to content

Commit 9eadfe6

Browse files
Hsiangkaijrtc27
andcommitted
Add support for variant calling conventions for lazily-bound functions
Currently, we save/restore a0-a7 and fa0-fa7 in the glibc and FreeBSD run-time linker lazy resolvers to avoid clobbering any function arguments. In order to define the vector calling convention, we need to specify the behavior of the resolver in the dynamic linker. Vector registers may have a large size and saving/restoring vector argument registers may occupy a large portion of stack space during run-time resolving. It is unreasonable to save/restore all these vector argument registers in the resolver. In this patch, we define STO_RISCV_VARIANT_CC, a special symbol attribute to mark symbols as using a calling convention that passes arguments in registers other than a0-a7 and fa0-fa7 (such as the vector calling convention), which run-time linkers can use to eagerly bind such functions. We also define DT_RISCV_VARIANT_CC, an additional dynamic tag to indicate there are symbols with the special attribute in the dynamic symbol table of the object used for PLT-based calls as a quick way for run-time linkers to skip iterating over the table at load time when no symbols need to be eagerly bound. Co-authored-by: Jessica Clarke <[email protected]>
1 parent 0bb85bd commit 9eadfe6

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

riscv-elf.md

+42-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [Named ABIs](#named-abis)
1515
* [Default ABIs](#default-abis)
1616
* [Code models](#code-models)
17+
* [Dynamic Linking](#dynamic-linking)
1718
3. [C/C++ type details](#c-types)
1819
* [C/C++ type sizes and alignments](#c-type-sizes)
1920
* [C/C++ type representations](#c-type-representation)
@@ -28,7 +29,7 @@
2829
* [Thread Local Storage](#thread-local-storage)
2930
* [Program Header Table](#program-header-table)
3031
* [Note Sections](#note-sections)
31-
* [Dynamic Table](#dynamic-table)
32+
* [Dynamic Section](#dynamic-section)
3233
* [Hash Table](#hash-table)
3334
* [Attributes](#Attributes)
3435
5. [DWARF](#dwarf)
@@ -371,6 +372,21 @@ a signed 32-bit offset, relative to the value of the `pc` register,
371372
can be produced.
372373
This code model is position independent.
373374

375+
## <a name=dynamic-linking></a>Dynamic Linking
376+
377+
Run-time linkers that use lazy binding must preserve all argument registers
378+
used in the standard calling convention for the ABI in use. Any functions that
379+
use additional argument registers must be annotated with
380+
`STO_RISCV_VARIANT_CC`, as defined in [Symbol Table](#symbol-table).
381+
382+
> NOTE:
383+
> Vector registers have a variable size depending on the hardware
384+
> implementation and can be quite large. Saving/restoring all these vector
385+
> arguments in a run-time linker's lazy resolver would use a large amount of
386+
> stack space and hurt performance. This attribute allows vector registers to
387+
> not be part of the standard calling convention so run-time linkers are not
388+
> required to save/restore them and can instead eagerly bind such functions.
389+
374390
# <a name=c-types></a>C/C++ type details
375391

376392
## <a name=c-type-sizes></a>C/C++ type sizes and alignments
@@ -519,7 +535,20 @@ There are no RISC-V specific definitions relating to ELF string tables.
519535

520536
## <a name=symbol-table></a>Symbol Table
521537

522-
There are no RISC-V specific definitions relating to ELF symbol tables.
538+
* st_other: The lower 2 bits are used to specify a symbol's visibility. The
539+
remaining 6 bits have no defined meaning in the ELF gABI. We use the highest
540+
bit to mark functions that do not follow the standard calling convention for
541+
the ABI in use.
542+
543+
The defined processor-specific `st_other` flags are listed in the following
544+
table.
545+
546+
Name | Mask
547+
:------------------- | :----
548+
STO_RISCV_VARIANT_CC | 0x80
549+
550+
See [Dynamic Linking](#dynamic-linking) for the meaning of
551+
`STO_RISCV_VARIANT_CC`.
523552

524553
## <a name=relocations></a>Relocations
525554

@@ -1023,9 +1052,18 @@ PT_RISCV_ATTRIBUTES | 0x70000003 | RISC-V ELF attribute section.
10231052

10241053
There are no RISC-V specific definitions relating to ELF note sections.
10251054

1026-
## <a name=dynamic-table></a>Dynamic Table
1055+
## <a name=dynamic-section></a>Dynamic Section
1056+
1057+
The defined processor-specific dynamic array tags are listed in the following
1058+
table.
1059+
1060+
Name | Value | d_un | Executable | Shared Object
1061+
:------------------ | :--------- | :---- | :---------------- | :-----------------
1062+
DT_RISCV_VARIANT_CC | 0x70000001 | d_val | Platform specific | Platform specific
10271063

1028-
There are no RISC-V specific definitions relating to dynamic tables.
1064+
An object with the dynamic tag `DT_RISCV_VARIANT_CC` has one or more
1065+
`R_RISCV_JUMP_SLOT` relocations against symbols with the `STO_RISCV_VARIANT_CC`
1066+
attribute.
10291067

10301068
## <a name=hash-table></a>Hash Table
10311069

0 commit comments

Comments
 (0)