public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32511]  New: GCC inlines weak function
@ 2007-06-26  5:30 sabre at nondot dot org
  2007-06-26 20:32 ` [Bug c/32511] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: sabre at nondot dot org @ 2007-06-26  5:30 UTC (permalink / raw)
  To: gcc-bugs

GCC generally doesn't inline weak functions, because their body may be
redefined by the linker: if the compiler inlined the call, the linker changing
the behavior of the function wouldn't change the inlined copy.  For example,
GCC does not inline this:

void bar () __attribute__((weak));
void bar () {}
void foo() { bar(); } 

However, GCC apparently overrides this if the inline keyword is added (and
potentially if the weak function is defined in a c++ class where it would be
implicit inline?).  As such, it cause the following to be inlined:

inline void bar () __attribute__((weak));
void bar () {}
void foo() { bar(); } 

However, again, this breaks the semantics of weak linkage.  If bar is redefined
at link-time, the inlined copy is not updated.  Because 'inline' is an
optimization request, not a requirement, it seems best for the compiler to
ignore the inline request in this case.

-Chris


-- 
           Summary: GCC inlines weak function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sabre at nondot dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
@ 2007-06-26 20:32 ` pinskia at gcc dot gnu dot org
  2008-02-17 19:38 ` hubicka at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-26 20:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-06-26 20:32 -------
Considering inline candidate bar.
 Inlining bar into foo.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
  2007-06-26 20:32 ` [Bug c/32511] " pinskia at gcc dot gnu dot org
@ 2008-02-17 19:38 ` hubicka at gcc dot gnu dot org
  2008-02-17 19:49 ` sabre at nondot dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2008-02-17 19:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hubicka at gcc dot gnu dot org  2008-02-17 19:37 -------
I think this is feature.  If users explicitely declares as inline, then we do
that, otherwise we doesn't:
  /* Don't auto-inline anything that might not be bound within
     this unit of translation.  */
  else if (!DECL_DECLARED_INLINE_P (fn)
           && DECL_REPLACEABLE_P (fn))
    inlinable = false;
otherwise we won't inline much e.g. with -fpic.

Honza


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
  2007-06-26 20:32 ` [Bug c/32511] " pinskia at gcc dot gnu dot org
  2008-02-17 19:38 ` hubicka at gcc dot gnu dot org
@ 2008-02-17 19:49 ` sabre at nondot dot org
  2008-02-17 21:05 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sabre at nondot dot org @ 2008-02-17 19:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from sabre at nondot dot org  2008-02-17 19:48 -------
I understand the desire to optimize with -fpic, but miscompiling the code seems
unreasonable...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (2 preceding siblings ...)
  2008-02-17 19:49 ` sabre at nondot dot org
@ 2008-02-17 21:05 ` rguenth at gcc dot gnu dot org
  2008-02-17 21:06 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-17 21:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-02-17 21:05 -------
Well, I think we should error for the inline + weak combination, as it doesn't
make sense.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (3 preceding siblings ...)
  2008-02-17 21:05 ` rguenth at gcc dot gnu dot org
@ 2008-02-17 21:06 ` rguenth at gcc dot gnu dot org
  2008-02-18  7:36 ` sabre at nondot dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-17 21:06 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid, wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-02-17 21:05:49
               date|                            |
            Version|unknown                     |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (4 preceding siblings ...)
  2008-02-17 21:06 ` rguenth at gcc dot gnu dot org
@ 2008-02-18  7:36 ` sabre at nondot dot org
  2008-02-18 10:44 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sabre at nondot dot org @ 2008-02-18  7:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from sabre at nondot dot org  2008-02-18 07:35 -------
That works for me.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (5 preceding siblings ...)
  2008-02-18  7:36 ` sabre at nondot dot org
@ 2008-02-18 10:44 ` rguenth at gcc dot gnu dot org
  2008-03-27 16:35 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-18 10:44 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-02-17 21:05:49         |2008-02-18 10:44:02
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (6 preceding siblings ...)
  2008-02-18 10:44 ` rguenth at gcc dot gnu dot org
@ 2008-03-27 16:35 ` rguenth at gcc dot gnu dot org
  2008-03-27 16:36 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-27 16:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2008-03-27 16:35 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (7 preceding siblings ...)
  2008-03-27 16:35 ` rguenth at gcc dot gnu dot org
@ 2008-03-27 16:36 ` rguenth at gcc dot gnu dot org
  2010-07-01 19:28 ` jason at gcc dot gnu dot org
  2010-07-12 13:46 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-27 16:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2008-03-27 16:35 -------
Subject: Bug 32511

Author: rguenth
Date: Thu Mar 27 16:34:55 2008
New Revision: 133646

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133646
Log:
2008-03-27  Richard Guenther  <rguenther@suse.de>

        PR c/32511
        * c-common.c (handle_weak_attribute): Reject combination of
        weak and inline.

        * gcc.dg/attr-weak-1.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/attr-weak-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] GCC inlines weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (8 preceding siblings ...)
  2008-03-27 16:36 ` rguenth at gcc dot gnu dot org
@ 2010-07-01 19:28 ` jason at gcc dot gnu dot org
  2010-07-12 13:46 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-07-01 19:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2010-07-01 19:28 -------
I think this change is wrong; weak definitions are also used to allow
definitions in multiple translation units without linker errors.  C++ inlines
are emitted as weak symbols, and it seems rather odd to prohibit in C something
that the C++ front end does routinely.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

* [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function
  2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
                   ` (9 preceding siblings ...)
  2010-07-01 19:28 ` jason at gcc dot gnu dot org
@ 2010-07-12 13:46 ` jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-07-12 13:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jason at gcc dot gnu dot org  2010-07-12 13:46 -------
Marking as regression.  Weak symbols have multiple uses: allowing replacement
is one, but they are also used to allow equivalent definitions in multiple
translation units without linker errors.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid, wrong-code |rejects-valid
            Summary|GCC inlines weak function   |[4.4/4.5/4.6 regression] GCC
                   |                            |rejects inline+weak function


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

end of thread, other threads:[~2010-07-12 13:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
2007-06-26 20:32 ` [Bug c/32511] " pinskia at gcc dot gnu dot org
2008-02-17 19:38 ` hubicka at gcc dot gnu dot org
2008-02-17 19:49 ` sabre at nondot dot org
2008-02-17 21:05 ` rguenth at gcc dot gnu dot org
2008-02-17 21:06 ` rguenth at gcc dot gnu dot org
2008-02-18  7:36 ` sabre at nondot dot org
2008-02-18 10:44 ` rguenth at gcc dot gnu dot org
2008-03-27 16:35 ` rguenth at gcc dot gnu dot org
2008-03-27 16:36 ` rguenth at gcc dot gnu dot org
2010-07-01 19:28 ` jason at gcc dot gnu dot org
2010-07-12 13:46 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function jason at gcc dot gnu dot org

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).