Bug 35034 - weakref vs. -combine
Summary: weakref vs. -combine
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure, build, wrong-code
: 38460 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-01-30 22:02 UTC by Bernhard Reutner-Fischer
Modified: 2010-09-17 09:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2
Known to fail: 4.3.0
Last reconfirmed: 2008-01-31 15:08:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Reutner-Fischer 2008-01-30 22:02:17 UTC
There seem to be different, conflicting implementations of size_of_encoded_value():

dwarf2asm.c-int
dwarf2asm.c:size_of_encoded_value (int encoding)

unwind-pe.h-static unsigned int
unwind-pe.h:size_of_encoded_value (unsigned char encoding)


/scratch/obj.i686/gcc-4.3/./gcc/xgcc -B/scratch/obj.i686/gcc-4.3/./gcc/ -B/opt/i
686/gcc-4.3//i686-linux-gnu/bin/ -B/opt/i686/gcc-4.3//i686-linux-gnu/lib/ -isyst
em /opt/i686/gcc-4.3//i686-linux-gnu/include -isystem /opt/i686/gcc-4.3//i686-li
nux-gnu/sys-include -march=pentium4 -mtune=pentium4 -Os -fno-tree-loop-optimize 
-fno-tree-dominator-opts -fno-strength-reduce -fno-branch-count-reg -falign-func
tions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2 -pipe -g3 -
ggdb3 -O2  -O2 -g -O0 -g3 -ggdb3   -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict
-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fP
IC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED   -I. -I. -I../.
././gcc -I../../../../src/gcc-4.3/libgcc -I../../../../src/gcc-4.3/libgcc/. -I..
/../../../src/gcc-4.3/libgcc/../gcc -I../../../../src/gcc-4.3/libgcc/../include 
-I../../../../src/gcc-4.3/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAV
E_CC_TLS -DUSE_TLS -o lib2addeh_static_onestep.o -MT lib2addeh_static_onestep.o 
-MD -MP -MF lib2addeh_static_onestep.dep -fexceptions -c -combine ../../../../sr
c/gcc-4.3/libgcc/../gcc/emutls.c ../../../../src/gcc-4.3/libgcc/../gcc/gthr-gnat
.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-c.c ../../../../src/gcc-4.3/libg
cc/../gcc/unwind-dw2-fde-glibc.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-dw
2.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-sjlj.c -fvisibility=hidden -DHI
DE_EXPORTS
{standard input}: Assembler messages:
{standard input}:49634: Error: symbol `size_of_encoded_value' is already defined
{standard input}:49785: Error: symbol `read_uleb128' is already defined
{standard input}:49828: Error: symbol `read_sleb128' is already defined
{standard input}:49885: Error: symbol `read_encoded_value_with_base' is already 
defined
{standard input}:50121: Error: symbol `get_cie' is already defined
{standard input}:50145: Error: symbol `next_fde' is already defined
make[3]: *** [lib2addeh_static_onestep.o] Error 1
Comment 1 Bernhard Reutner-Fischer 2008-01-30 22:56:53 UTC
Works with -O2, fails with -O0, -O1, -O2 -fno-inline

-O0:
$ /scratch/obj.i686/gcc-4.3/./gcc/xgcc -B/scratch/obj.i686/gcc-4.3/./gcc/ -B/opt/i686/gcc-4.3//i686-linux-gnu/bin/ -B/opt/i686/gcc-4.3//i686-linux-gnu/lib/ -isystem /opt/i686/gcc-4.3//i686-linux-gnu/include -isystem /opt/i686/gcc-4.3//i686-linux-gnu/sys-include   -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED   -I. -I. -I../.././gcc -I../../../../src/gcc-4.3/libgcc -I../../../../src/gcc-4.3/libgcc/. -I../../../../src/gcc-4.3/libgcc/../gcc -I../../../../src/gcc-4.3/libgcc/../include -I../../../../src/gcc-4.3/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o lib2addeh_static_onestep.o -MT lib2addeh_static_onestep.o -MD -MP -MF lib2addeh_static_onestep.dep -fexceptions -combine ../../../../src/gcc-4.3/libgcc/../gcc/emutls.c ../../../../src/gcc-4.3/libgcc/../gcc/gthr-gnat.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-c.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-dw2-fde-glibc.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-dw2.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-sjlj.c -fvisibility=hidden -DHIDE_EXPORTS -c -O0
/tmp/ccidDTzT.s: Assembler messages:
/tmp/ccidDTzT.s:5738: Error: symbol `size_of_encoded_value' is already defined
/tmp/ccidDTzT.s:5889: Error: symbol `read_uleb128' is already defined
/tmp/ccidDTzT.s:5932: Error: symbol `read_sleb128' is already defined
/tmp/ccidDTzT.s:5989: Error: symbol `read_encoded_value_with_base' is already defined
/tmp/ccidDTzT.s:6224: Error: symbol `get_cie' is already defined
/tmp/ccidDTzT.s:6248: Error: symbol `next_fde' is already defined


-O1:
$ /scratch/obj.i686/gcc-4.3/./gcc/xgcc -B/scratch/obj.i686/gcc-4.3/./gcc/ -B/opt/i686/gcc-4.3//i686-linux-gnu/bin/ -B/opt/i686/gcc-4.3//i686-linux-gnu/lib/ -isystem /opt/i686/gcc-4.3//i686-linux-gnu/include -isystem /opt/i686/gcc-4.3//i686-linux-gnu/sys-include   -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED   -I. -I. -I../.././gcc -I../../../../src/gcc-4.3/libgcc -I../../../../src/gcc-4.3/libgcc/. -I../../../../src/gcc-4.3/libgcc/../gcc -I../../../../src/gcc-4.3/libgcc/../include -I../../../../src/gcc-4.3/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o lib2addeh_static_onestep.o -MT lib2addeh_static_onestep.o -MD -MP -MF lib2addeh_static_onestep.dep -fexceptions -combine ../../../../src/gcc-4.3/libgcc/../gcc/emutls.c ../../../../src/gcc-4.3/libgcc/../gcc/gthr-gnat.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-c.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-dw2-fde-glibc.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-dw2.c ../../../../src/gcc-4.3/libgcc/../gcc/unwind-sjlj.c -fvisibility=hidden -DHIDE_EXPORTS -c -O1
/tmp/ccNNdoTR.s: Assembler messages:
/tmp/ccNNdoTR.s:5207: Error: symbol `read_uleb128' is already defined
/tmp/ccNNdoTR.s:5260: Error: symbol `read_sleb128' is already defined
/tmp/ccNNdoTR.s:5329: Error: symbol `read_encoded_value_with_base' is already defined
Comment 2 Richard Biener 2008-01-31 10:35:00 UTC
I suppose the static function

static const unsigned char *
read_uleb128 (const unsigned char *p, _uleb128_t *val)
{

in unwind-pe.h should be marked 'inline', otherwise it will be emitted
multiple times to the asm file by -combine.
Comment 3 Jakub Jelinek 2008-01-31 10:44:51 UTC
The static size_of_encoded_value's are supposed to be mangled when --combine,
like size_of_encoded_value.12521 and on a simple testcase with --combine
on x86_64-linux/trunk they are.
Comment 4 Bernhard Reutner-Fischer 2008-01-31 14:47:43 UTC
Smaller testcase:
-----------------------------------
$ cat pr35034-1.c
/* PR 35034 - fails to mangle function names for different TUs.  */
/* { dg-do compile } */
/* { dg-options "-combine -O0" } */
/* { dg-additional-sources pr35034-2.c } */
typedef int int_t;

static void
size_of_encoded_value (void)
{
};
extern int pthread_once (int_t *__once_control,
    void (*__init_routine) (void));
static __typeof(pthread_once) __gthrw_pthread_once __attribute__ ((__weakref__("pthread_once")));

-----------------------------------
$ cat pr35034-2.c 
void size_of_encoded_value (void)
{
};
-----------------------------------


Gives with current trunk:
$ gcc-4.3-HEAD pr35034-1.c pr35034-2.c -O0 -c -o foo.o -combine -pipe
{standard input}: Assembler messages:
{standard input}:12: Error: symbol `size_of_encoded_value' is already defined
$ gcc-4.3-HEAD pr35034-1.c pr35034-2.c -O0 -S -o - -combine -pipe
        .file   "pr35034-1.c"
        .text
        .type   size_of_encoded_value, @function
size_of_encoded_value:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   size_of_encoded_value, .-size_of_encoded_value
.globl size_of_encoded_value
        .type   size_of_encoded_value, @function
size_of_encoded_value:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   size_of_encoded_value, .-size_of_encoded_value
        .weakref        __gthrw_pthread_once,pthread_once
        .ident  "GCC: (GNU) 4.3.0 20080131 (experimental)"
        .section        .note.GNU-stack,"",@progbits

Comment 5 Bernhard Reutner-Fischer 2008-01-31 15:05:07 UTC
Works with gcc-4.1.2 (if one prunes the 'static' of the weakref; They were required to be public back then):

$ gcc-4.1 pr35034-1.c pr35034-2.c -O0 -S -o - -combine -pipe
        .file   "pr35034-1.c"
        .text
.globl size_of_encoded_value
        .type   size_of_encoded_value, @function
size_of_encoded_value:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   size_of_encoded_value, .-size_of_encoded_value
        .weakref        __gthrw_pthread_once,pthread_once
        .ident  "GCC: (GNU) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)"
        .section        .note.GNU-stack,"",@progbits
Comment 6 Richard Biener 2008-01-31 15:08:10 UTC
Confirmed.  The following also fails with optimization:

t1.c:
static void __attribute__((used))
size_of_encoded_value (void)
{
};
static int __gthrw_pthread_once __attribute__ ((__weakref__("pthread_once")));

t2.c:
void size_of_encoded_value (void)
{
};


Not a regression.
Comment 7 Richard Biener 2008-01-31 15:10:04 UTC
Fails with 4.1.2 for me as well, with the static.  w/o 4.1 complains

t1.c:5: error: '__gthrw_pthread_once' defined both normally and as an alias
Comment 8 Bernhard Reutner-Fischer 2008-01-31 15:11:22 UTC
(In reply to comment #2)
> I suppose the static function
> 
> static const unsigned char *
> read_uleb128 (const unsigned char *p, _uleb128_t *val)
> {
> 
> in unwind-pe.h should be marked 'inline', otherwise it will be emitted
> multiple times to the asm file by -combine.

unwind-pe.h as a header should provide an interface to and not implementations of the required functions. Apart from fixing the functions in IMA, unwind-pe.h should split it's implementations off into a e.g. unwind-pe.c that exports the common helpers.

Does somebody know if it is really intended that dwarf2asm.c has grown (or kept) a different impl of size_of_encoded_value() than all the rest?
Comment 9 Bernhard Reutner-Fischer 2008-01-31 15:18:23 UTC
(In reply to comment #7)
> Fails with 4.1.2 for me as well, with the static.  w/o 4.1 complains
> 
> t1.c:5: error: '__gthrw_pthread_once' defined both normally and as an alias
> 

Works flawlessly for me (without the static, on debian with the debian-patched cc):
$ gcc-4.1 pr35034-1.c pr35034-2.c -O0 -c -o foo.o -combine -pipe ; echo $?
0

Comment 10 Richard Biener 2008-01-31 15:20:11 UTC
That's a accepts-invalid problem on 4.1, try the same thing with the reduced
testcase from comment #6.
Comment 11 Andrew Pinski 2008-12-29 14:26:48 UTC
*** Bug 38460 has been marked as a duplicate of this bug. ***
Comment 12 Richard Biener 2010-09-17 09:06:35 UTC
-combine has been removed from GCC 4.6 in favor of LTO, closing as WONTFIX.