public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry
@ 2021-02-23 11:37 huangpei at loongson dot cn
  2021-02-23 19:44 ` [Bug target/99217] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-02-23 11:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

            Bug ID: 99217
           Summary: [MIPS] wrong function entry with
                    -fpatchable-function-entry
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: huangpei at loongson dot cn
  Target Milestone: ---

On Debian AMD64 unstable,
-----------------
depaulose@localhost:~$ cat a.c
void f() {}
depaulose@localhost:~$ gcc -fpatchable-function-entry=3  -c a.c

depaulose@localhost:~$ objdump -d a.o

a.o:     file format elf64-tradlittlemips


Disassembly of section .text:

0000000000000000 <f-0xc>:
        ...

000000000000000c <f>:
   c:   67bdfff0        daddiu  sp,sp,-16
  10:   ffbe0008        sd      s8,8(sp)
  14:   03a0f025        move    s8,sp
  18:   00000000        nop
  1c:   03c0e825        move    sp,s8
  20:   dfbe0008        ld      s8,8(sp)
  24:   67bd0010        daddiu  sp,sp,16
  28:   03e00008        jr      ra
  2c:   00000000        nop
depaulose@localhost:~$ readelf -s a.o

Symbol table '.symtab' contains 14 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS a.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    2
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    8
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    9
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT   12
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     9: 0000000000000000     0 SECTION LOCAL  DEFAULT    5
    10: 0000000000000000     0 SECTION LOCAL  DEFAULT    6
    11: 0000000000000000     0 SECTION LOCAL  DEFAULT   11
    12: 0000000000000000     0 SECTION LOCAL  DEFAULT   13
    13: 000000000000000c    36 FUNC    GLOBAL DEFAULT    1 f
depaulose@localhost:~$ gcc --version
gcc (Debian 10.2.1-6) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

depaulose@localhost:~$ as --version
GNU assembler (GNU Binutils for Debian) 2.35.2
Copyright (C) 2020 Free Software Foundation, Inc.
This assembler was configured for a target of `mips64el-linux-gnuabi64'.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `mips64el-linux-gnuabi64'.

------------------


It turned out that function address is wrong. It is expected that the function
entry is 0 not 0xc

On Debian 10 , for arm64, same file

--------------------------

ambrosehua@ambrosehua-HP-xw6600-Workstation:Downloads$ aarch64-linux-gnu-gcc-8
-fpatchable-function-entry=3 -c a.c
ambrosehua@ambrosehua-HP-xw6600-Workstation:Downloads$
aarch64-linux-gnu-objdump -d a.o

a.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <f>:
   0:   d503201f        nop
   4:   d503201f        nop
   8:   d503201f        nop
   c:   d503201f        nop
  10:   d65f03c0        ret
ambrosehua@ambrosehua-HP-xw6600-Workstation:Downloads$ readelf -s a.o

Symbol table '.symtab' contains 12 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS a.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    2
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     5: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 $x
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    7
     8: 0000000000000014     0 NOTYPE  LOCAL  DEFAULT    8 $d
     9: 0000000000000000     0 SECTION LOCAL  DEFAULT    8
    10: 0000000000000000     0 SECTION LOCAL  DEFAULT    6
    11: 0000000000000000    20 FUNC    GLOBAL DEFAULT    1 f
----------------------

here function address of f  is right

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
@ 2021-02-23 19:44 ` pinskia at gcc dot gnu.org
  2021-03-04  2:07 ` huangpei at loongson dot cn
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-02-23 19:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
          Component|c                           |target
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2021-02-23
             Target|                            |mips*-linux-gnu

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
        .globl  f
        .section        __patchable_function_entries,"aw",@progbits
        .align  3
        .8byte  .LPFE1
        .text
.LPFE1:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
.LFB0 = .
        .cfi_startproc
        .set    nomips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:

---- CUT ---
AARCH64 does:
f:
        .section        __patchable_function_entries,"aw",@progbits
        .align  3
        .8byte  .LPFE1
        .text
.LPFE1:
        nop
        nop
        nop
.LFB0:

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
  2021-02-23 19:44 ` [Bug target/99217] " pinskia at gcc dot gnu.org
@ 2021-03-04  2:07 ` huangpei at loongson dot cn
  2021-03-04  3:20 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-03-04  2:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

--- Comment #2 from huangpei at loongson dot cn <huangpei at loongson dot cn> ---
my colleague Xu Chenghua (xuchenghua@loongson.cn) add a patch to address this

--------------------
diff --git a/src/gcc/config/mips/mips-protos.h
b/src/gcc/config/mips/mips-protos.h
index aba1f8222..253c5b6f5 100644
--- a/src/gcc/config/mips/mips-protos.h
+++ b/src/gcc/config/mips/mips-protos.h
@@ -394,4 +394,6 @@ extern void mips_expand_vec_cond_expr (machine_mode,
machine_mode, rtx *);
 /* Routines implemented in mips-d.c  */
 extern void mips_d_target_versions (void);

+extern void mips_declare_function_name (FILE *, const char *, tree);
+
 #endif /* ! GCC_MIPS_PROTOS_H */
diff --git a/src/gcc/config/mips/mips.c b/src/gcc/config/mips/mips.c
index de69400d1..f94028e55 100644
--- a/src/gcc/config/mips/mips.c
+++ b/src/gcc/config/mips/mips.c
@@ -12002,6 +12002,23 @@ mips_output_cplocal (void)
     output_asm_insn (".cplocal %+", 0);
 }

+/* Implement ASM_DECLARE_FUNCTION_NAME. */
+
+void mips_declare_function_name(FILE *stream ATTRIBUTE_UNUSED,
+                               const char *name, tree fndecl ATTRIBUTE_UNUSED)
+{
+
+  /* Get the function name the same way that toplev.c does before calling
+     assemble_start_function.  This is needed so that the name used here
+     exactly matches the name used in ASM_DECLARE_FUNCTION_NAME.  */
+  //fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
+  mips_start_function_definition (name, TARGET_MIPS16);
+
+  //ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function");
+  //ASM_OUTPUT_LABEL (stream, name);
+}
+
+
 /* Implement TARGET_OUTPUT_FUNCTION_PROLOGUE.  */

 static void
@@ -12016,12 +12033,6 @@ mips_output_function_prologue (FILE *file)
       && crtl->args.info.fp_code != 0)
     mips16_build_function_stub ();

-  /* Get the function name the same way that toplev.c does before calling
-     assemble_start_function.  This is needed so that the name used here
-     exactly matches the name used in ASM_DECLARE_FUNCTION_NAME.  */
-  fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
-  mips_start_function_definition (fnname, TARGET_MIPS16);
-
   /* Output MIPS-specific frame information.  */
   if (!flag_inhibit_size_directive)
     {
diff --git a/src/gcc/config/mips/mips.h b/src/gcc/config/mips/mips.h
index dccfae52c..cb8ab602a 100644
--- a/src/gcc/config/mips/mips.h
+++ b/src/gcc/config/mips/mips.h
@@ -2955,7 +2955,8 @@ while (0)
    is not declared before the .ent directive elsewhere.  */

 #undef ASM_DECLARE_FUNCTION_NAME
-#define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL)
+#define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL) \
+  mips_declare_function_name(STREAM,NAME,DECL)

 /* This is how to store into the string LABEL
    the symbol_ref name of an internal numbered label where
diff --git a/src/gcc/targhooks.c b/src/gcc/targhooks.c
index fafcc6c51..9a6baaf4b 100644
--- a/src/gcc/targhooks.c
+++ b/src/gcc/targhooks.c
@@ -1806,7 +1806,7 @@ default_print_patchable_function_entry (FILE *file,

   unsigned i;
   for (i = 0; i < patch_area_size; ++i)
-    fprintf (file, "\t%s\n", nop_templ);
+    output_asm_insn (nop_templ, NULL);
 }

 bool

--------------------------

With this and fix for bug 93242, -fpatchable-function-entry works on linux
kernel 5.10

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
  2021-02-23 19:44 ` [Bug target/99217] " pinskia at gcc dot gnu.org
  2021-03-04  2:07 ` huangpei at loongson dot cn
@ 2021-03-04  3:20 ` pinskia at gcc dot gnu.org
  2021-03-05  7:22 ` huangpei at loongson dot cn
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-04  3:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to huangpei@loongson.cn from comment #2)
> my colleague Xu Chenghua (xuchenghua@loongson.cn) add a patch to address this

This patch is close, though it needs to move the call to
mips16_build_function_stub also.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
                   ` (2 preceding siblings ...)
  2021-03-04  3:20 ` pinskia at gcc dot gnu.org
@ 2021-03-05  7:22 ` huangpei at loongson dot cn
  2021-12-04  7:54 ` huangpei at loongson dot cn
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-03-05  7:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

--- Comment #4 from huangpei at loongson dot cn <huangpei at loongson dot cn> ---

what do you mean " move the call to mips16_build_function_stub" ?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
                   ` (3 preceding siblings ...)
  2021-03-05  7:22 ` huangpei at loongson dot cn
@ 2021-12-04  7:54 ` huangpei at loongson dot cn
  2021-12-15 10:00 ` huangpei at loongson dot cn
  2021-12-15 10:01 ` huangpei at loongson dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-12-04  7:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

--- Comment #5 from huangpei at loongson dot cn <huangpei at loongson dot cn> ---
Hi, with this fix and bug 93242 fixed, a.c with mips16 is OK,

ambrosehua@3A1000-800M:~$ gcc -fpatchable-function-entry=3  -mips16 -mabi=32  
-c a.c -S  -o a.1.s
ambrosehua@3A1000-800M:~$ cat a.1.s
        .file   1 "a.c"
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=xx
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        .section        __patchable_function_entries,"a",@progbits
        .4byte  $LPFE1
        .text
$LPFE1:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        .size   f, .-f
        .ident  "GCC: (Debian 8.3.0-8.lnd.4) 8.3.0"

ambrosehua@3A1000-800M:~$ objdump -tdr a.1.o 

a.1.o:     file format elf32-tradlittlemips

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 a.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .mdebug.abi32  00000000 .mdebug.abi32
00000000 l    d  __patchable_function_entries   00000000
__patchable_function_entries
00000000 l       .text  00000000 0xf0 $LPFE1
00000000 l    d  .reginfo       00000000 .reginfo
00000000 l    d  .MIPS.abiflags 00000000 .MIPS.abiflags
00000000 l    d  .pdr   00000000 .pdr
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .gnu.attributes        00000000 .gnu.attributes
00000000 g     F .text  00000012 f



Disassembly of section .text:

00000000 <f>:
   0:   6500            nop
   2:   6500            nop
   4:   6500            nop
   6:   6491            save    8,s1
   8:   673d            move    s1,sp
   a:   6500            nop
   c:   65b9            move    sp,s1
   e:   6411            restore 8,s1
  10:   e8a0            jrc     ra
  12:   6500            nop
  14:   6500            nop
  16:   6500            nop
  18:   6500            nop
  1a:   6500            nop
  1c:   6500            nop
  1e:   6500            nop

but, with b.c,

ambrosehua@3A1000-800M:~$ cat b.c
void f(float a, float b) 
{
}

it is much more complicated.

ambrosehua@3A1000-800M:~$ gcc -fpatchable-function-entry=3  -mips16 -mabi=32  
-c b.c -S  -o b.1.s
ambrosehua@3A1000-800M:~$ cat b.1.s 

        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=xx
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        .section        __patchable_function_entries,"a",@progbits
        .4byte  $LPFE1
        .text
$LPFE1:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        # Stub function for f (float, float)
        .section        .mips16.fn.f,"ax",@progbits
        .align  2
        .set    mips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .section        __patchable_function_entries
        .4byte  $LPFE2
        .section        .mips16.fn.f
$LPFE2:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    nomips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    noreorder
        .cpload $25
        .set    reorder
        .reloc  0,R_MIPS_NONE,f
        la      $25,__fn_local_f
        mfc1    $4,$f12
        mfc1    $5,$f14
        jr      $25
        .end    __fn_stub_f
        __fn_local_f = f
        .text
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        sw      $4,8($17)
        sw      $5,12($17)
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        .size   f, .-f
        .ident  "GCC: (Debian 8.3.0-8.lnd.4) 8.3.0"


for comparison, without -fpatchable-function-entry=3

ambrosehua@3A1000-800M:~$ gcc  -mips16 -mabi=32   -c b.c -S  -o b.2.s
ambrosehua@3A1000-800M:~$ cat b.2.s
        .file   1 "b.c"
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=xx
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        # Stub function for f (float, float)
        .section        .mips16.fn.f,"ax",@progbits
        .align  2
        .set    mips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    nomips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    noreorder
        .cpload $25
        .set    reorder
        .reloc  0,R_MIPS_NONE,f
        la      $25,__fn_local_f
        mfc1    $4,$f12
        mfc1    $5,$f14
        jr      $25
        .end    __fn_stub_f
        __fn_local_f = f
        .text
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        sw      $4,8($17)
        sw      $5,12($17)
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        .size   f, .-f
        .ident  "GCC: (Debian 8.3.0-8.lnd.4) 8.3.0"

 with original gcc 8.3 in Debian10,

depaulose@3A1000-800M:/home/ambrosehua$ gcc -mabi=32 -c b.c -S -o b.3.s 
-mips16  
depaulose@3A1000-800M:/home/ambrosehua$ cat b.3.s 
        .file   1 "b.c"
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=xx
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        # Stub function for f (float, float)
        .section        .mips16.fn.f,"ax",@progbits
        .align  2
        .set    nomips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    noreorder
        .cpload $25
        .set    reorder
        .reloc  0,R_MIPS_NONE,f
        la      $25,__fn_local_f
        mfc1    $4,$f12
        mfc1    $5,$f14
        jr      $25
        .end    __fn_stub_f
        __fn_local_f = f
        .text
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        sw      $4,8($17)
        sw      $5,12($17)
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        .size   f, .-f
        .ident  "GCC: (Debian 8.3.0-6) 8.3.0"

I think there is somthing wrong here with handling stub for O32 MIPS16 floating
parameter.

+. Point 1, with b.3.s, the func entry should be __fn_stub_f instead of f,
which I mean the f in symbol table should point to the __fn_stub_f in the b.3.s
, and __fn_local_f in symbol table should point to the f in the b.3.s ;

+. Point 2, if Point 1 is right, the b.2.s should be just like Point 1, but it
is not right now, and we need fix this at first;

+. Point 3, if Point 1 is right, b.1.s should has only 3 nops in the  mip32 32
stub code, instead of both in mips32 stub code and mip16 code.

Did I get it right?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
                   ` (4 preceding siblings ...)
  2021-12-04  7:54 ` huangpei at loongson dot cn
@ 2021-12-15 10:00 ` huangpei at loongson dot cn
  2021-12-15 10:01 ` huangpei at loongson dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-12-15 10:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

huangpei at loongson dot cn <huangpei at loongson dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |huangpei at loongson dot cn

--- Comment #6 from huangpei at loongson dot cn <huangpei at loongson dot cn> ---
Created attachment 52005
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52005&action=edit
fix -fpatch-function-entry on MIPS

Patch 0001 fix -fpatchable-function-entry on non-MIPS16, but it cause 
compiling b.c (see previous comment) with duplicate __fn_stub_f* in asm output
in MIPS16

Patch 0002 remove the duplicate __fn_stub_f* by filter __fn_stub_ in 
ASM_DECLARE_FUNCTION_NAME. However, implenmenting ASM_DECLARE_FUNCTION_NAME
cause asm generation of function f interleave with __fn_stub_f, which cause
error even without -fpatchable-function-entry on MIPS16. Patch 0002 
separates asm generation of f from its stub by delay
"mips16_build_function_stub" till "mips_output_function_epilogue", and no error
on MIPS16 without -fpatchable-function-entry.

But it is not perfect.

+. without -fpatchable-function-entry, asm  output of b.c like this

        .file   1 "b.c"
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module oddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        sw      $4,8($17)
        sw      $5,12($17)
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        !!!! .size f, .-f  should be here
        # Stub function for f (float, float)
        .section        .mips16.fn.f,"ax",@progbits
        .align  2
        .set    nomips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    noreorder
        .cpload $25
        .set    reorder
        .reloc  0,R_MIPS_NONE,f
        la      $25,__fn_local_f
        mfc1    $4,$f12
        mfc1    $5,$f14
        jr      $25
        .end    __fn_stub_f
        __fn_local_f = f
        .text
        .size   f, .-f          !!! .size should be not be here
        .ident  "GCC: (GNU) 8.3.0"

+. with -fpatchable-functione-entry=3, asm output of b.c like this,

       .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module oddspreg
        .abicalls
        .text
        .align  2
        .globl  f
        .set    mips16
        .set    nomicromips
        .ent    f
        .type   f, @function
f:
        .section        __patchable_function_entries,"a",@progbits
        .4byte  $LPFE1
        .text
!!! f should not be patched with nop, since this is the first entry from
caller's point
$LPFE1:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .frame  $17,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x00020000,-4
        .fmask  0x00000000,0
        save    8,$17
        move    $17,$sp
        sw      $4,8($17)
        sw      $5,12($17)
        .set    noreorder
        nop
        .set    reorder
        move    $sp,$17
        restore 8,$17
        jr      $31
        .end    f
        # Stub function for f (float, float)
        .section        .mips16.fn.f,"ax",@progbits
        .align  2
        .section        __patchable_function_entries
        .4byte  $LPFE2
        .section        .mips16.fn.f
$LPFE2:
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    noreorder
        nop
        .set    reorder
        .set    nomips16
        .set    nomicromips
        .ent    __fn_stub_f
        .type   __fn_stub_f, @function
__fn_stub_f:
        .set    noreorder
        .cpload $25
        .set    reorder
        .reloc  0,R_MIPS_NONE,f
        la      $25,__fn_local_f
        mfc1    $4,$f12
        mfc1    $5,$f14
        jr      $25
        .end    __fn_stub_f
        __fn_local_f = f
        .text
        .size   f, .-f
        .ident  "GCC: (GNU) 8.3.0"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/99217] [MIPS] wrong function entry with -fpatchable-function-entry
  2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
                   ` (5 preceding siblings ...)
  2021-12-15 10:00 ` huangpei at loongson dot cn
@ 2021-12-15 10:01 ` huangpei at loongson dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: huangpei at loongson dot cn @ 2021-12-15 10:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99217

--- Comment #7 from huangpei at loongson dot cn <huangpei at loongson dot cn> ---
Created attachment 52006
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52006&action=edit
patch 0001

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-15 10:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23 11:37 [Bug c/99217] New: [MIPS] wrong function entry with -fpatchable-function-entry huangpei at loongson dot cn
2021-02-23 19:44 ` [Bug target/99217] " pinskia at gcc dot gnu.org
2021-03-04  2:07 ` huangpei at loongson dot cn
2021-03-04  3:20 ` pinskia at gcc dot gnu.org
2021-03-05  7:22 ` huangpei at loongson dot cn
2021-12-04  7:54 ` huangpei at loongson dot cn
2021-12-15 10:00 ` huangpei at loongson dot cn
2021-12-15 10:01 ` huangpei at loongson dot cn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).