From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 30CE33857822; Thu, 7 Apr 2022 16:05:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30CE33857822 From: "matz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105169] Compiling C++ code with -fpatchable-function-entry=16,14 results in references to discarded sections Date: Thu, 07 Apr 2022 16:05:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: link-failure X-Bugzilla-Severity: normal X-Bugzilla-Who: matz at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2022 16:05:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105169 Michael Matz changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matz at gcc dot gnu.org --- Comment #8 from Michael Matz --- Something like this would be needed. It's proof-of-concept. It actually j= ust copy-pastes code from default_function_rodata_section without proper integration and caring for other cases handled there. To be done properly it would need abstracting what default_function_rodata_section does, just with a choosable prefix. Additionally the whole section dealing in GCC should be changed su= ch that internally not the section name is the only differentiator for the sec= tion hash table: currently that's the reason the comdat name has to be appended to the section name, although ELF doesn't need this for comdat sections. S= o, terrible hack, but ... diff --git a/gcc/targhooks.c b/gcc/targhooks.c index c9b5208853d..1ca5a4c3592 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1963,14 +1963,36 @@ default_print_patchable_function_entry_1 (FILE *fil= e, char buf[256]; static int patch_area_number; section *previous_section =3D in_section; + section *sect; const char *asm_op =3D integer_asm_op (POINTER_SIZE_UNITS, false); gcc_assert (asm_op !=3D NULL); patch_area_number++; ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE", patch_area_number); - switch_to_section (get_section ("__patchable_function_entries", - flags, current_function_decl)); + if (DECL_COMDAT_GROUP (current_function_decl) && HAVE_COMDAT_GROUP) + { + const char *dot; + size_t len; + char* rname; + const char *sname =3D "__patchable_function_entries"; + const char *name =3D DECL_SECTION_NAME (current_function_decl); + + dot =3D strchr (name + 1, '.'); + if (!dot) + dot =3D name; + len =3D strlen (dot) + strlen (sname) + 1; + rname =3D (char *) alloca (len); + + strcpy (rname, sname); + strcat (rname, dot); + sect =3D get_section (rname, (SECTION_LINKONCE | flags), + current_function_decl); + } + else + sect =3D get_section ("__patchable_function_entries", flags, + current_function_decl); + switch_to_section (sect); assemble_align (POINTER_SIZE); fputs (asm_op, file); assemble_name_raw (file, buf);=