Just run "gcc -c test.c" on this: #pragma weak __pthread_initialize extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, int __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern __typeof (memcpy) memcpy __asm__ ("" "__GI_memcpy") __attribute__ ((visibility ("hidden"))); void f(void) {} $ gcc -c test.c test.c:5: warning: asm declaration ignored due to conflict with previous rename With "#pragma weak __pthread_initialize" line commented out, it does not happen. $ gcc -v Using built-in specs. Target: i386-pc-linux-gnu Configured with: ../gcc-4.2.1/configure --prefix=/usr/app/gcc-4.2.1 --exec-prefix=/usr/app/gcc-4.2.1 --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/app/gcc-4.2.1/libexec --datadir=/usr/app/gcc-4.2.1/share --sysconfdir=/etc --sharedstatedir=/usr/app/gcc-4.2.1/var/com --localstatedir=/usr/app/gcc-4.2.1/var --libdir=/usr/lib --includedir=/usr/include --infodir=/usr/info --mandir=/usr/man --with-slibdir=/usr/app/gcc-4.2.1/lib --with-local-prefix=/usr/local --with-gxx-include-dir=/usr/app/gcc-4.2.1/include/g++-v3 --enable-languages=c,c++ --without-system-zlib --disable-nls --enable-threads=posix i386-pc-linux-gnu Thread model: posix gcc version 4.2.1
Simplified case: #pragma weak __pthread_initialize extern void *memcpy(void *dest, const void *src, int n); extern typeof(memcpy) memcpy asm("__GI_memcpy"); void f(void) {}
this warning also triggers with current head/4.5.0
Confirmed. Still the same with gcc version 4.7.2 (Debian 4.7.2-5): $ cat <<EOF | gcc -x c -c - -o /dev/null #pragma weak __pthread_initialize extern void *memcpy(void *dest, const void *src, int n); extern typeof(memcpy) memcpy asm("__GI_memcpy"); EOF <stdin>:2:14: warning: conflicting types for built-in function ‘memcpy’ [enabled by default] <stdin>:3:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas]
(In reply to comment #3) > Confirmed. > > Still the same with gcc version 4.7.2 (Debian 4.7.2-5): > $ cat <<EOF | gcc -x c -c - -o /dev/null > #pragma weak __pthread_initialize > extern void *memcpy(void *dest, const void *src, int n); > extern typeof(memcpy) memcpy asm("__GI_memcpy"); > EOF > <stdin>:2:14: warning: conflicting types for built-in function ‘memcpy’ > [enabled by default] > <stdin>:3:1: warning: asm declaration ignored due to conflict with previous > rename [-Wpragmas] Works as expected if one provides a decl before the #pragma: $ cat <<EOF | gcc -fno-builtin -x c -c - -o /dev/null extern void __pthread_initialize (void); #pragma weak __pthread_initialize extern void *memcpy(void *dest, const void *src, int n); extern typeof(memcpy) memcpy asm("__GI_memcpy"); EOF $ cat <<EOF | gcc -fno-builtin -x c -c - -o /dev/null #pragma weak __pthread_initialize extern void __pthread_initialize (void); extern void *memcpy(void *dest, const void *src, int n); extern typeof(memcpy) memcpy asm("__GI_memcpy"); EOF <stdin>:4:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas] Honza, does that ring a bell, by chance?
$ gcc-3.4 -fno-exceptions -fomit-frame-pointer -fno-builtin -S pr36282.c -o ok.s $ gcc-4.7 -fno-exceptions -fomit-frame-pointer -fno-builtin -S pr36282.c -o nak.s pr36282.c:3:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas] $ cat pr36282.c #pragma weak __pthread_initialize extern void *memcpy(void *dest, const void *src, int n); extern typeof(memcpy) memcpy asm("__GI_memcpy"); char *usr(void) { char ch[2]; return memcpy(&ch, "x", 2); } $ cat ok.s .file "pr36282.c" .section .rodata .LC0: .string "x" .text .globl usr .type usr, @function usr: .LFB2: subq $24, %rsp .LCFI0: movq %rsp, %rdi movl $2, %edx movl $.LC0, %esi call __GI_memcpy addq $24, %rsp ret .LFE2: .size usr, .-usr .section .eh_frame,"a",@progbits .Lframe1: .long .LECIE1-.LSCIE1 .LSCIE1: .long 0x0 .byte 0x1 .string "" .uleb128 0x1 .sleb128 -8 .byte 0x10 .byte 0xc .uleb128 0x7 .uleb128 0x8 .byte 0x90 .uleb128 0x1 .align 8 .LECIE1: .LSFDE1: .long .LEFDE1-.LASFDE1 .LASFDE1: .long .LASFDE1-.Lframe1 .quad .LFB2 .quad .LFE2-.LFB2 .byte 0x4 .long .LCFI0-.LFB2 .byte 0xe .uleb128 0x20 .align 8 .LEFDE1: .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.6 (Debian 3.4.6-10)" $ cat nak.s .file "pr36282.c" .section .rodata .LC0: .string "x" .text .globl usr .type usr, @function usr: .LFB0: .cfi_startproc subq $24, %rsp .cfi_def_cfa_offset 32 movq %rsp, %rax movl $2, %edx movl $.LC0, %esi movq %rax, %rdi call memcpy addq $24, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE0: .size usr, .-usr .ident "GCC: (Debian 4.7.2-5) 4.7.2" .section .note.GNU-stack,"",@progbits
GCC 4.7.3 is being released, adjusting target milestone.
Created attachment 32345 [details] gcc49-pr36282.patch Untested fix. If this turns out to be too expensive (though, I think #pragma weak is rare and the patch should at most double the time to compute DECL_ASSEMBLER_NAME), perhaps we could use some spare bit in decl_with_vis to mean DECL_ASSEMBLER_NAME_SET_P (in addition to the current two tests). Then we could keep the computed assembler name cached and still pretend the name has not been set, decl_assembler_name would set that bit. We'd need to handle with care the cases when the bit is unset and say we rename the symbol though, then of course we'd need to first SET_DECL_ASSEMBLER_NAME to NULL.
Author: jakub Date: Thu Mar 13 20:56:06 2014 New Revision: 208557 URL: http://gcc.gnu.org/viewcvs?rev=208557&root=gcc&view=rev Log: PR middle-end/36282 * c-pragma.c (apply_pragma_weak): Only look at TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) if DECL_ASSEMBLER_NAME_SET_P (decl). (maybe_apply_pending_pragma_weaks): Exit early if vec_safe_is_empty (pending_weaks) rather than only when !pending_weaks. (maybe_apply_pragma_weak): Likewise. If !DECL_ASSEMBLER_NAME_SET_P, set assembler name back to NULL afterwards. * c-c++-common/pr36282-1.c: New test. * c-c++-common/pr36282-2.c: New test. * c-c++-common/pr36282-3.c: New test. * c-c++-common/pr36282-4.c: New test. Added: trunk/gcc/testsuite/c-c++-common/pr36282-1.c trunk/gcc/testsuite/c-c++-common/pr36282-2.c trunk/gcc/testsuite/c-c++-common/pr36282-3.c trunk/gcc/testsuite/c-c++-common/pr36282-4.c Modified: trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c-pragma.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk.
Author: jakub Date: Thu Apr 10 07:47:55 2014 New Revision: 209263 URL: http://gcc.gnu.org/viewcvs?rev=209263&root=gcc&view=rev Log: Backport from mainline 2014-03-13 Jakub Jelinek <jakub@redhat.com> PR middle-end/36282 * c-pragma.c (apply_pragma_weak): Only look at TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) if DECL_ASSEMBLER_NAME_SET_P (decl). (maybe_apply_pending_pragma_weaks): Exit early if vec_safe_is_empty (pending_weaks) rather than only when !pending_weaks. (maybe_apply_pragma_weak): Likewise. If !DECL_ASSEMBLER_NAME_SET_P, set assembler name back to NULL afterwards. * c-c++-common/pr36282-1.c: New test. * c-c++-common/pr36282-2.c: New test. * c-c++-common/pr36282-3.c: New test. * c-c++-common/pr36282-4.c: New test. Added: branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-1.c branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-2.c branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-3.c branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-4.c Modified: branches/gcc-4_8-branch/gcc/c-family/ChangeLog branches/gcc-4_8-branch/gcc/c-family/c-pragma.c branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Fixed also for 4.8.3+.
Fixed in 4.8.3
.
*** Bug 37266 has been marked as a duplicate of this bug. ***
*** Bug 35606 has been marked as a duplicate of this bug. ***