Skip to content

Commit 50ddcb4

Browse files
committed
arcv: gas: apex: Add APEX instruction ELF metadata section.
Introduce arcv_apex_get_metadata_section () to retrieve the ELF section used to hold APEX instruction metadata. Section names encode the enabled instruction formats, the fixed Custom-0 value (=11), and sub-opcode. For example, an instruction declared as: .extInstruction foo,7,XS,XC maps to: .riscvapex.<XS|XC>.11.<function_code> and concretely: .riscvapex.10.11.7 APEX metadata sections are placed in COMDAT groups so the linker retains only one copy when multiple compilation units define the same section. The group name is derived from the section name but omits the "riscv" prefix. Signed-off-by: Luis Silva <luiss@synopsys.com>
1 parent c8c73ea commit 50ddcb4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

gas/config/tc-riscv.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5886,6 +5886,49 @@ riscv_pop_insert (void)
58865886
pop_insert (riscv_pseudo_table);
58875887
}
58885888

5889+
/* Create and get a read-only COMDAT section for an APEX instruction.
5890+
5891+
Section names encode the instruction format flags (XD=1<<0, XS=1<<1,
5892+
XI=1<<2, XC=1<<3), followed by the fixed Custom-0 value (11) and the
5893+
instruction opcode.
5894+
5895+
For example, an instruction declared as:
5896+
.extInstruction foo,7,XS,XC
5897+
maps to:
5898+
.riscvapex.<XS|XC>.11.<function_code>
5899+
and concretely:
5900+
.riscvapex.10.11.7
5901+
5902+
The section is placed in a COMDAT group so that the linker keeps only
5903+
one copy when multiple compilation units define the same section.
5904+
The COMDAT group name is derived from the section name, prefixed with
5905+
".apex.". */
5906+
5907+
static segT
5908+
arcv_apex_get_metadata_section (unsigned int insn_format,
5909+
unsigned int sub_opcode)
5910+
{
5911+
unsigned int custom_0 = 0xb;
5912+
5913+
/* Allocate buffer for full section name. */
5914+
const char *section_name = xasprintf (".riscvapex.%u.%u.%u",
5915+
insn_format, custom_0, sub_opcode);
5916+
5917+
/* Create a new section with appropriate flags. */
5918+
segT apex_section = subseg_new (section_name, 0);
5919+
bfd_set_section_flags (apex_section,
5920+
SEC_READONLY | SEC_HAS_CONTENTS | SEC_LINK_ONCE);
5921+
5922+
/* Build the COMDAT group name for the section, prefixed with ".apex.". */
5923+
const char *group_name = xasprintf (".apex.%u.%u.%u",
5924+
insn_format, custom_0, sub_opcode);
5925+
5926+
/* Attach the group name to the section. */
5927+
elf_set_group_name (apex_section, group_name);
5928+
5929+
return apex_section;
5930+
}
5931+
58895932
/* Allocate and register an APEX instruction.
58905933
58915934
Allocates a riscv_opcode structure, initializes it according to the

0 commit comments

Comments
 (0)