Bug 93643 - [10 Regression] Static function pointer inside inline function with "C" linkage is not mangled
Summary: [10 Regression] Static function pointer inside inline function with "C" linka...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P1 blocker
Target Milestone: 10.0
Assignee: Jason Merrill
URL:
Keywords: assemble-failure, ice-checking, ice-on-valid-code, wrong-code
Depends on:
Blocks:
 
Reported: 2020-02-09 18:49 UTC by Iñaki Ucar
Modified: 2020-02-13 21:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-02-10 00:00:00


Attachments
Assembler (474 bytes, text/plain)
2020-02-09 18:49 UTC, Iñaki Ucar
Details
test.ii (203 bytes, text/plain)
2020-02-10 13:37 UTC, Iñaki Ucar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Iñaki Ucar 2020-02-09 18:49:19 UTC
Created attachment 47807 [details]
Assembler

Consider the following example (a simplification of a real case):

$ cat test.cpp 
void* callback(const char* name);

extern "C" {

inline void f1()
{
        static void (*f)();
        f = (void(*)()) callback("f1");
        f();
}

inline void f2()
{
        static void (*f)();
        f = (void(*)()) callback("f2");
        f();
}

} // extern "C"

int main()
{
        f1();
        f2();
}
$ g++ -save-temps test.cpp
g++ -save-temps test.cpp 
test.s: Assembler messages:
test.s:41: Error: symbol `f' is already defined

As you can see in the attached test.s, symbol "f" for functions f1 and f2 is not mangled, and thus collides. Previous versions of GCC produce mangled identifiers _ZZ2f1E1f and _ZZ2f2E1f.

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200130 (Red Hat 10.0.1-0.7) (GCC)
Comment 1 Jakub Jelinek 2020-02-10 10:48:01 UTC
Started with r10-6110-g8158a4640819dbb3210326e37786fb874f450272 , before that the vars have been mangled - _ZZ2f1E1f, _ZZ2f2E1f .
BTW, I get an ICE instead of assembler-failure:
pr93643.C:25:1: error: Two symbols with same comdat_group are not linked by the same_comdat_group list.
   25 | }
      | ^
f/2 (void (* f)()) @0x7f7f7a699200
  Type: variable definition analyzed
  Visibility: no_reorder public weak comdat comdat_group:f one_only
  previous sharing asm name: 0
  References: 
  Referring: f2/3 (write)f2/3 (read)
  Availability: not-ready
  Varpool flags:
f/0 (void (* f)()) @0x7f7f7a699180
  Type: variable definition analyzed
  Visibility: no_reorder public weak comdat comdat_group:f one_only
  next sharing asm name: 2
  References: 
  Referring: f1/1 (write)f1/1 (read)
  Availability: not-ready
  Varpool flags:
pr93643.C:25:1: internal compiler error: symtab_node::verify failed
0xe54eff symtab_node::verify_symtab_nodes()
	../../gcc/symtab.c:1342
0xe7cf94 symtab_node::checking_verify_symtab_nodes()
	../../gcc/cgraph.h:667
0xe7b065 symbol_table::compile()
	../../gcc/cgraphunit.c:2720
0xe7b696 symbol_table::finalize_compilation_unit()
	../../gcc/cgraphunit.c:2984
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
assembler-failure only if -fno-checking.
Comment 2 Iñaki Ucar 2020-02-10 13:37:40 UTC
Created attachment 47811 [details]
test.ii
Comment 3 Iñaki Ucar 2020-02-10 13:42:31 UTC
I got no backtrace, just the output shown in my first comment, at least with the gcc version included in Fedora Rawhide. I've just attached the test.ii file too. With -v:

$ g++ -v -save-temps test.cpp 
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200130 (Red Hat 10.0.1-0.7) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1plus -E -quiet -v -D_GNU_SOURCE test.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/10/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10
 /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward
 /usr/lib/gcc/x86_64-redhat-linux/10/include
 /usr/local/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o test.s
GNU C++14 (GCC) version 10.0.1 20200130 (Red Hat 10.0.1-0.7) (x86_64-redhat-linux)
        compiled by GNU C version 10.0.1 20200130 (Red Hat 10.0.1-0.7), GMP version 6.1.2, MPFR version 4.0.2-p1, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 10.0.1 20200130 (Red Hat 10.0.1-0.7) (x86_64-redhat-linux)
        compiled by GNU C version 10.0.1 20200130 (Red Hat 10.0.1-0.7), GMP version 6.1.2, MPFR version 4.0.2-p1, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 80355902cebbb142e87c9570dbf4f6a2
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o test.o test.s
GNU assembler version 2.34 (x86_64-redhat-linux) using BFD version version 2.34-1.fc32
test.s: Assembler messages:
test.s:41: Error: symbol `f' is already defined
Comment 4 Andrew Pinski 2020-02-10 20:58:46 UTC
(In reply to Iñaki Ucar from comment #3)
> I got no backtrace, just the output shown in my first comment, at least with
> the gcc version included in Fedora Rawhide. I've just attached the test.ii
> file too. With -v:


Yes that is because the GCC is configured with "--enable-checking=release".
Comment 5 Jason Merrill 2020-02-13 21:32:56 UTC
Fixed.
Comment 6 GCC Commits 2020-02-13 21:33:08 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:abc79c6498a99e9c39e6056f432796c6dde3a887

commit r10-6628-gabc79c6498a99e9c39e6056f432796c6dde3a887
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 13 16:42:04 2020 +0100

    c++: Fix static local vars in extern "C".
    
    Since my patch for PR 91476 moved visibility determination sooner, a local
    static in a vague linkage function now gets TREE_PUBLIC set before
    retrofit_lang_decl calls set_decl_linkage, which was making decl_linkage
    think that it has external linkage.  It still has no linkage according to
    the standard.
    
    gcc/cp/ChangeLog
    2020-02-13  Jason Merrill  <jason@redhat.com>
    
    	PR c++/93643
    	PR c++/91476
    	* tree.c (decl_linkage): Always lk_none for locals.