On 10/31/24 21:26, Kito Cheng wrote:
On Thu, Oct 31, 2024 at 6:59 PM Yangyu Chen <c...@cyyself.name> wrote:
On Oct 31, 2024, at 18:14, Kito Cheng <kito.ch...@gmail.com> wrote:

diff --git a/gcc/config/riscv/riscv-target-attr.cc 
b/gcc/config/riscv/riscv-target-attr.cc
index 087fbae77b0..4c85ad60b72 100644
--- a/gcc/config/riscv/riscv-target-attr.cc
+++ b/gcc/config/riscv/riscv-target-attr.cc
@@ -239,10 +239,6 @@ riscv_target_attr_parser::update_settings (struct 
gcc_options *opts) const
     {
       std::string local_arch = m_subset_list->to_string (true);
       const char* local_arch_str = local_arch.c_str ();
-      struct cl_target_option *default_opts
-       = TREE_TARGET_OPTION (target_option_default_node);
-      if (opts->x_riscv_arch_string != default_opts->x_riscv_arch_string)
-       free (CONST_CAST (void *, (const void *) opts->x_riscv_arch_string));

Could you give a little more context why you decide to remove those logics?


That's because when we have target_version features, the riscv_arch_string
may need to be stored in the DECL_FUNCTION_SPECIFIC_TARGET. If we
free the arch string, it may have use-after-free bugs. I came across
this bug even without ASAN.

I know that if we didn't free it, it might cause a memory leak. But
for GCC, it’s OK, I think. It's also complex to add something like
std::shared_ptr or std::string to the global options.

If this explanation is OK, I will add a comment about this in this
source file.

Thanks for the explanation, then let's keep the original code and wrap
it with `#if 0` and leave some comments there :)


Update: I found this use-after-free bug no longer happens after I restored default_opts to global_options in the function parse_features_for_version in this patch. These lines were just added when I was debugging this UAF bug. Since they are no longer needed, I will drop these lines in the next revision.

Reply via email to