aboutsummaryrefslogtreecommitdiff
path: root/gas/config/tc-riscv.c
diff options
context:
space:
mode:
authorNelson Chu <nelson@rivosinc.com>2024-07-31 13:00:11 +0800
committerNelson Chu <nelson@rivosinc.com>2024-08-09 10:38:34 +0800
commit04c9cf0a8c5f03e5a1bb91a954cc42eb83a3e493 (patch)
treea7a78b232bf954d596c35ae53143553798e6025f /gas/config/tc-riscv.c
parent2fba6c8908c230a5ecd8096b5c9b331eaddb2a30 (diff)
downloadgdb-04c9cf0a8c5f03e5a1bb91a954cc42eb83a3e493.zip
gdb-04c9cf0a8c5f03e5a1bb91a954cc42eb83a3e493.tar.gz
gdb-04c9cf0a8c5f03e5a1bb91a954cc42eb83a3e493.tar.bz2
RISC-V: PR32014, .option directives shuoldn't affect elf attribute.
The .option arch/rvc/norvc/push/pop directives can only take effect for a small/large specific code region, so they are not file-level architecture setting. They should only affect the mapping symbols only rather than the file-level elf architecture attribute. Otherwise, the elf architecture attribute will appear to missing some extensions when -flto merges files with different .option architecture settings. gas/ PR 32014 * config/tc-riscv.c (file_arch_str): New const char *, rather than the arch_str in the riscv_rps_as.subset_list, it's file-level so only be affected by .attribute arch directive. (riscv_reset_subsets_list_arch_str): Renamed to riscv_set_arch_str, and also can handle both file_arch_str and arch_str in subset_list, just give the pointer address as the input. (riscv_set_arch): Called by -march and .attribute arch, so set both file_arch_str and arch_str in subset_list. (s_riscv_option): Updated .option arch/rvc/norvc/push/pop that only set the arch_str in subset_list. (riscv_write_out_attrs): Output elf architecture attribute according to file_arch_str. Freed file_arch_str. * doc/c-riscv.texi: Added destrbution that .option directives shouldn't affect the elf attribute settings. * testsuite/gas/riscv/option-arch.s: From option-arch-01/02/03 merged. * testsuite/gas/riscv/option-arch-dis.d: Likewise, for dis-assembler. * testsuite/gas/riscv/option-arch-attr.d: Likewise, to check readelf -A.
Diffstat (limited to 'gas/config/tc-riscv.c')
-rw-r--r--gas/config/tc-riscv.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 779e0b8..15244be 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -162,6 +162,7 @@ struct riscv_ip_error
static const char default_arch[] = DEFAULT_ARCH;
static const char *default_arch_with_ext = DEFAULT_RISCV_ARCH_WITH_EXT;
+static const char *file_arch_str = NULL;
static enum riscv_spec_class default_isa_spec = ISA_SPEC_CLASS_NONE;
static enum riscv_spec_class default_priv_spec = PRIV_SPEC_CLASS_NONE;
@@ -305,15 +306,17 @@ static riscv_parse_subset_t riscv_rps_as =
true, /* check_unknown_prefixed_ext. */
};
-/* Update the architecture string in the subset_list. */
+/* Update file/function-level architecture string according to the
+ subset_list. */
static void
-riscv_reset_subsets_list_arch_str (void)
+riscv_set_arch_str (const char **arch_str_p)
{
riscv_subset_list_t *subsets = riscv_rps_as.subset_list;
- if (subsets->arch_str != NULL)
- free ((void *) subsets->arch_str);
- subsets->arch_str = riscv_arch_str (xlen, subsets);
+ const char *arch_str = *arch_str_p;
+ if (arch_str != NULL)
+ free ((void *) arch_str);
+ *arch_str_p = riscv_arch_str (xlen, subsets);
}
/* This structure is used to hold a stack of .option values. */
@@ -347,7 +350,8 @@ riscv_set_arch (const char *s)
}
riscv_release_subset_list (riscv_rps_as.subset_list);
riscv_parse_subset (&riscv_rps_as, s);
- riscv_reset_subsets_list_arch_str ();
+ riscv_set_arch_str (&file_arch_str);
+ riscv_set_arch_str (&riscv_rps_as.subset_list->arch_str);
riscv_set_rvc (false);
if (riscv_subset_supports (&riscv_rps_as, "c")
@@ -4837,13 +4841,13 @@ s_riscv_option (int x ATTRIBUTE_UNUSED)
if (strcmp (name, "rvc") == 0)
{
riscv_update_subset (&riscv_rps_as, "+c");
- riscv_reset_subsets_list_arch_str ();
+ riscv_set_arch_str (&riscv_rps_as.subset_list->arch_str);
riscv_set_rvc (true);
}
else if (strcmp (name, "norvc") == 0)
{
riscv_update_subset (&riscv_rps_as, "-c");
- riscv_reset_subsets_list_arch_str ();
+ riscv_set_arch_str (&riscv_rps_as.subset_list->arch_str);
riscv_set_rvc (false);
}
else if (strcmp (name, "pic") == 0)
@@ -4864,7 +4868,7 @@ s_riscv_option (int x ATTRIBUTE_UNUSED)
if (ISSPACE (*name) && *name != '\0')
name++;
riscv_update_subset (&riscv_rps_as, name);
- riscv_reset_subsets_list_arch_str ();
+ riscv_set_arch_str (&riscv_rps_as.subset_list->arch_str);
riscv_set_rvc (false);
if (riscv_subset_supports (&riscv_rps_as, "c")
@@ -5389,7 +5393,7 @@ s_riscv_insn (int x ATTRIBUTE_UNUSED)
static void
riscv_write_out_attrs (void)
{
- const char *arch_str, *priv_str, *p;
+ const char *priv_str, *p;
/* versions[0]: major version.
versions[1]: minor version.
versions[2]: revision version. */
@@ -5397,10 +5401,10 @@ riscv_write_out_attrs (void)
unsigned int i;
/* Re-write architecture elf attribute. */
- arch_str = riscv_rps_as.subset_list->arch_str;
- if (!bfd_elf_add_proc_attr_string (stdoutput, Tag_RISCV_arch, arch_str))
+ if (!bfd_elf_add_proc_attr_string (stdoutput, Tag_RISCV_arch, file_arch_str))
as_fatal (_("error adding attribute: %s"),
bfd_errmsg (bfd_get_error ()));
+ free ((void *) file_arch_str);
/* For the file without any instruction, we don't set the default_priv_spec
according to the privileged elf attributes since the md_assemble isn't