aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.cc
diff options
context:
space:
mode:
authorGiuliano Belinassi <gbelinassi@suse.de>2022-05-06 23:37:52 -0300
committerGiuliano Belinassi <gbelinassi@suse.de>2022-05-17 14:34:21 -0300
commit7a3f38a966a52893fb5bae301a1a3d56961358fb (patch)
treedf14ac7daa89f5beeed9584761f482d3d5be9985 /gcc/varasm.cc
parent941efd87e22b1b88e3488b8e681d14d0d66e45ac (diff)
downloadgcc-7a3f38a966a52893fb5bae301a1a3d56961358fb.zip
gcc-7a3f38a966a52893fb5bae301a1a3d56961358fb.tar.gz
gcc-7a3f38a966a52893fb5bae301a1a3d56961358fb.tar.bz2
PR105169 Fix references to discarded sections
When -fpatchable-function-entry= is enabled, certain C++ codes fails to link because of generated references to discarded sections in __patchable_function_entry section. This commit fixes this problem by puting those references in a COMDAT section. 2022-05-06 Giuliano Belinassi <gbelinassi@suse.de> gcc/ChangeLog PR c++/105169 * targhooks.cc (default_print_patchable_function_entry_1): Handle COMDAT case. * varasm.cc (switch_to_comdat_section): New (handle_vtv_comdat_section): Call switch_to_comdat_section. * varasm.h: Declare switch_to_comdat_section. gcc/testsuite/ChangeLog 2022-05-06 Giuliano Belinassi <gbelinassi@suse.de> PR c++/105169 * g++.dg/modules/pr105169.h: New file. * g++.dg/modules/pr105169_a.C: New test. * g++.dg/modules/pr105169_b.C: New file.
Diffstat (limited to 'gcc/varasm.cc')
-rw-r--r--gcc/varasm.cc33
1 files changed, 20 insertions, 13 deletions
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index c41f17d..6454f1c 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -8457,25 +8457,21 @@ default_asm_output_ident_directive (const char *ident_str)
fprintf (asm_out_file, "%s\"%s\"\n", ident_asm_op, ident_str);
}
-
-/* This function ensures that vtable_map variables are not only
- in the comdat section, but that each variable has its own unique
- comdat name. Without this the variables end up in the same section
- with a single comdat name.
-
+/* Switch to a COMDAT section with COMDAT name of decl.
+
FIXME: resolve_unique_section needs to deal better with
decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
that is fixed, this if-else statement can be replaced with
a single call to "switch_to_section (sect)". */
-static void
-handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
+void
+switch_to_comdat_section (section *sect, tree decl)
{
#if defined (OBJECT_FORMAT_ELF)
targetm.asm_out.named_section (sect->named.name,
sect->named.common.flags
| SECTION_LINKONCE,
- DECL_NAME (decl));
+ decl);
in_section = sect;
#else
/* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
@@ -8490,18 +8486,18 @@ handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
{
char *name;
- if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
+ if (TREE_CODE (decl) == IDENTIFIER_NODE)
name = ACONCAT ((sect->named.name, "$",
- IDENTIFIER_POINTER (DECL_NAME (decl)), NULL));
+ IDENTIFIER_POINTER (decl), NULL));
else
name = ACONCAT ((sect->named.name, "$",
- IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))),
+ IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)),
NULL));
targetm.asm_out.named_section (name,
sect->named.common.flags
| SECTION_LINKONCE,
- DECL_NAME (decl));
+ decl);
in_section = sect;
}
else
@@ -8509,4 +8505,15 @@ handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
#endif
}
+/* This function ensures that vtable_map variables are not only
+ in the comdat section, but that each variable has its own unique
+ comdat name. Without this the variables end up in the same section
+ with a single comdat name. */
+
+static void
+handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
+{
+ switch_to_comdat_section(sect, DECL_NAME (decl));
+}
+
#include "gt-varasm.h"