On Fri, May 07, 2021 at 07:24:02PM -0500, Segher Boessenkool wrote:
> Looks good with those things tweaked.

Except that the patch chose the wrong section to emit the label,
because the decl is wrong.  But of course I was using the same decl as
used in existing SHF_LINK_ORDER support, so it was already broken.
You can see this on x86_64 gcc/testsuite/g++.dg/pr93195a.C output for
bar().

        .globl  _Z3barv
        .type   _Z3barv, @function
_Z3barv:
.LFB1:
        .cfi_startproc
        .section        __patchable_function_entries,"awo",@progbits,_Z3foov
        .align 8
        .quad   .LPFE2
        .text
.LPFE2:
        nop
        pushq   %rbp

Note the reference to _Z3foov!  Tracking down why this happens isn't
hard.  The first get_section ("__patchable_function_entries", ...)
saves the decl for foo, which is the one then used on all subsequent
calls.  Oops.  Jakub, commit 134afa38f0be didn't quite do the right
thing.

This problem can be fixed with a simplification of the patch I posted,
relying on the fact that currently in the only place that wants to
emit SHF_LINK_ORDER sections we've already switched to the correct
function code section.

Regression testing in progress.

        PR target/98125
        * varasm.c (default_elf_asm_named_section): Use a function
        code label rather than the function symbol as the "o" argument.

diff --git a/gcc/varasm.c b/gcc/varasm.c
index 97c1e6fff25..6f10ac7762e 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -6866,6 +6866,15 @@ default_elf_asm_named_section (const char *name, 
unsigned int flags,
       *f = '\0';
     }
 
+  char func_label[256];
+  if (flags & SECTION_LINK_ORDER)
+    {
+      static int func_code_labelno;
+      func_code_labelno++;
+      ASM_GENERATE_INTERNAL_LABEL (func_label, "LPFC", func_code_labelno);
+      ASM_OUTPUT_LABEL (asm_out_file, func_label);
+    }
+
   fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
 
   /* default_section_type_flags (above) knows which flags need special
@@ -6893,11 +6902,8 @@ default_elf_asm_named_section (const char *name, 
unsigned int flags,
        fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
       if (flags & SECTION_LINK_ORDER)
        {
-         tree id = DECL_ASSEMBLER_NAME (decl);
-         ultimate_transparent_alias_target (&id);
-         const char *name = IDENTIFIER_POINTER (id);
-         name = targetm.strip_name_encoding (name);
-         fprintf (asm_out_file, ",%s", name);
+         fprintf (asm_out_file, ",");
+         assemble_name_raw (asm_out_file, func_label);
        }
       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
        {

-- 
Alan Modra
Australia Development Lab, IBM

Reply via email to