public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12401] New: G++ generates boguous weak definition of library routine
@ 2003-09-25 12:29 uddeborg at carmen dot se
2003-09-25 14:37 ` [Bug c++/12401] " nathan at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: uddeborg at carmen dot se @ 2003-09-25 12:29 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
Summary: G++ generates boguous weak definition of library routine
Product: gcc
Version: 3.2.3
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: uddeborg at carmen dot se
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
When compiling some code referencing library routines, the generated object file
contains a "W" definition of this library routine.
1.Create a file c.cc containing
#include <stdlib.h>
int f()
{
return atoi <= 0;
}
2. g++ -O -c c.cc
3. nm -gC c.o
This produces:
00000000 W atoi
U __strtol_internal
00000000 T f()
I would expect an "U atoi" instead of the first two.
This occurs on Red Hat Enterprise Linux beta Taroon 2. gcc-c++-3.2.3-19
Witout optimization, one gets the expected result.
One problem this behaviour cases occurs is the object file is placed in an
archive library. If an application which links with this library uses, in this
case, atoi(), then this object file will be included in the end result. Even if
there are no "real" references to it. Which of course means any constructors of
global objects, or other side effects of its inclusion, will also happen.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
@ 2003-09-25 14:37 ` nathan at gcc dot gnu dot org
2003-12-25 3:27 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: nathan at gcc dot gnu dot org @ 2003-09-25 14:37 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
nathan at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
------- Additional Comments From nathan at gcc dot gnu dot org 2003-09-25 12:29 -------
confirmed, this is a duplicate of (part of) 12291 wrt extern inline handling
*** This bug has been marked as a duplicate of 12291 ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
2003-09-25 14:37 ` [Bug c++/12401] " nathan at gcc dot gnu dot org
@ 2003-12-25 3:27 ` pinskia at gcc dot gnu dot org
2003-12-25 4:16 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-25 3:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-25 03:21 -------
This is unrelated to bug 12291.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|DUPLICATE |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
2003-09-25 14:37 ` [Bug c++/12401] " nathan at gcc dot gnu dot org
2003-12-25 3:27 ` pinskia at gcc dot gnu dot org
@ 2003-12-25 4:16 ` pinskia at gcc dot gnu dot org
2003-12-25 4:40 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-25 4:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-25 03:27 -------
Simple testcase:
extern inline void Foo () {}
static void Baz () { Foo (); }
This is not a regression.
Confirmed.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-12-25 03:27:27
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
` (2 preceding siblings ...)
2003-12-25 4:16 ` pinskia at gcc dot gnu dot org
@ 2003-12-25 4:40 ` pinskia at gcc dot gnu dot org
2003-12-25 4:49 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-25 4:40 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-25 03:33 -------
Even 2.91.6 does this.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
` (3 preceding siblings ...)
2003-12-25 4:40 ` pinskia at gcc dot gnu dot org
@ 2003-12-25 4:49 ` pinskia at gcc dot gnu dot org
2004-01-14 16:57 ` uddeborg at carmen dot se
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-25 4:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-25 04:10 -------
Acutally "extern inline" in C++ is difference that GCC's c extesion "extern inline", "extern inline" in
C++ means that the function is extern but is declared in all translation unit as inline.
>From the C++ standard:
7.1.2 Function specifiers
4 An inline function shall be defined in every translation unit in which it is used and shall have
exactly the same definition in every case (3.2). [Note:a call to the inline function may be
encountered before its definition appears in the translation unit. ] If a function with external
linkage is declared inline in one translation unit, it shall be declared inline in all translation units in
which it appears; no diagnostic is required. An inlinefunction with external linkage shall have the
same address in all translation units. Astatic local variable in anextern inlinefunction always refers
to the same object. A string literal in an extern inlinefunction is the same object in different
translation units.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
` (4 preceding siblings ...)
2003-12-25 4:49 ` pinskia at gcc dot gnu dot org
@ 2004-01-14 16:57 ` uddeborg at carmen dot se
2004-01-14 17:36 ` pinskia at gcc dot gnu dot org
2004-01-15 7:52 ` uddeborg at carmen dot se
7 siblings, 0 replies; 9+ messages in thread
From: uddeborg at carmen dot se @ 2004-01-14 16:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From uddeborg at carmen dot se 2004-01-14 16:56 -------
I understand what you say about extern inline in C++. But note that my original
example did not include any explicit such definition. Also note that no weak
definition is generated if a file (translation unit) is compiled without
optimization. (Maybe to simplify debugging.) Let me give a slightly bigger
example to illustrate the problem:
Create a file e.cc which contains a use of atoi, and some object with a side
effect in the constructor:
#include <cstdlib>
#include <iostream>
int f() { return atoi <= 0; }
class sideeffect
{
public:
sideeffect() { std::cout << "Unwanted side effect." << std::endl; }
} s;
and a main program in f.cc which uses atoi:
#include <cstdlib>
#include <iostream>
int main() { std::cout << atoi("5") << std::endl; return 0; }
Now compile e.cc with optimization and put it in an archive library:
c++ -c -O e.cc
ar r libe.a e.o
Compile the main program without optimization, and link with this library:
c++ f.cc -o f libe.a
Running this will have the "unwanted side effect" printed out. I believe the
program itself meets all requirements in the C++ standard. The standard does
not go into such things as optimization flags. So if one wants to be picky I
guess one could argue the same set of flags should be applied to all translation
units.
But is this really a desired behaviour? I found the effects quite surprising
and counter-intuitive, until I understood what was going on.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
` (5 preceding siblings ...)
2004-01-14 16:57 ` uddeborg at carmen dot se
@ 2004-01-14 17:36 ` pinskia at gcc dot gnu dot org
2004-01-15 7:52 ` uddeborg at carmen dot se
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-14 17:36 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-01-14 17:35 -------
You example does via the glibc headers, they are not wrong, not GCC. The problem with the
unwantted side effect is wrong, you cannot depend on if something does not get pulled in or not
pulled.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12401] G++ generates boguous weak definition of library routine
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
` (6 preceding siblings ...)
2004-01-14 17:36 ` pinskia at gcc dot gnu dot org
@ 2004-01-15 7:52 ` uddeborg at carmen dot se
7 siblings, 0 replies; 9+ messages in thread
From: uddeborg at carmen dot se @ 2004-01-15 7:52 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From uddeborg at carmen dot se 2004-01-15 07:52 -------
Ok.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |VERIFIED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-01-15 7:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-25 12:29 [Bug c++/12401] New: G++ generates boguous weak definition of library routine uddeborg at carmen dot se
2003-09-25 14:37 ` [Bug c++/12401] " nathan at gcc dot gnu dot org
2003-12-25 3:27 ` pinskia at gcc dot gnu dot org
2003-12-25 4:16 ` pinskia at gcc dot gnu dot org
2003-12-25 4:40 ` pinskia at gcc dot gnu dot org
2003-12-25 4:49 ` pinskia at gcc dot gnu dot org
2004-01-14 16:57 ` uddeborg at carmen dot se
2004-01-14 17:36 ` pinskia at gcc dot gnu dot org
2004-01-15 7:52 ` uddeborg at carmen dot se
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).