public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PR7455: What is expected behavior for #pragma weak.
@ 2004-01-11 22:23 Steven Bosscher
  2004-01-12  0:37 ` Richard Henderson
  2004-01-12  0:39 ` Ian Lance Taylor
  0 siblings, 2 replies; 4+ messages in thread
From: Steven Bosscher @ 2004-01-11 22:23 UTC (permalink / raw)
  To: gcc

Hi,

Bug 7455 is a "wrong-code" bug about weak symbols.  In the past,
the following code:
_____________________________
#pragma weak bar = foo
_____________________________

would give:

        .file   "t.c"
        .version        "01.01"
gcc2_compiled.:
        .weak   bar
        .set    bar,foo
        .ident  "GCC: (GNU) 2.95.4 20011002 (Debian prerelease)"

Newer GCCs do not write the weak symbol:

        .file   "t.c"
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.0 20040111 (experimental)"

Notice how the test case does not actually declare bar.  The following
cases do work with all recent GCCs:
_____________________________
#pragma weak bar = foo
extern int bar (void);
_____________________________

gives:
        .file   "t.c"
        .weak   bar
        .set    bar,foo
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.0 20040111 (experimental)"

But this one,
_____________________________
extern int bar (void) __attribute__ ((weak));
_____________________________

gives:
        .file   "t.c"
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.0 20040111 (experimental)"

What is the expected result in each of these cases, and especially the
last one of them?  The documentation on weak symbols doesn't help a lot.

Gr.
Steven


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

* Re: PR7455: What is expected behavior for #pragma weak.
  2004-01-11 22:23 PR7455: What is expected behavior for #pragma weak Steven Bosscher
@ 2004-01-12  0:37 ` Richard Henderson
  2004-01-12  0:39 ` Ian Lance Taylor
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2004-01-12  0:37 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: gcc

On Sun, Jan 11, 2004 at 11:26:18PM +0100, Steven Bosscher wrote:
> Hi,
> 
> Bug 7455 is a "wrong-code" bug about weak symbols.  In the past,
> the following code:
> _____________________________
> #pragma weak bar = foo
> _____________________________
> 
> would give:
> 
>         .file   "t.c"
>         .version        "01.01"
> gcc2_compiled.:
>         .weak   bar
>         .set    bar,foo
>         .ident  "GCC: (GNU) 2.95.4 20011002 (Debian prerelease)"
> 
> Newer GCCs do not write the weak symbol:

Correct.  The the assembly above is meaningless.  It "works" in that it
assembles, but it doesn't do anything useful.  One could even argue that
it's a bug that it assembles.

> But this one,
> _____________________________
> extern int bar (void) __attribute__ ((weak));
> _____________________________
> 
> gives:
>         .file   "t.c"
>         .section        .note.GNU-stack,"",@progbits
>         .ident  "GCC: (GNU) 3.4.0 20040111 (experimental)"

This is correct as well.  Bar should be marked weak if it is used, but
since it is not used there's no need for it to be mentioned at all.


r~

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

* Re: PR7455: What is expected behavior for #pragma weak.
  2004-01-11 22:23 PR7455: What is expected behavior for #pragma weak Steven Bosscher
  2004-01-12  0:37 ` Richard Henderson
@ 2004-01-12  0:39 ` Ian Lance Taylor
  2004-01-12  0:50   ` Richard Henderson
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2004-01-12  0:39 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: gcc

Steven Bosscher <s.bosscher@student.tudelft.nl> writes:

> #pragma weak bar = foo

Hmmm.  The SUN documentation here:
    http://docs.sun.com/db/doc/805-4955/6j4mg806k?a=view
says that the function must be declared before it is used in #pragma
weak.  Since #pragma weak exists for compatibility purposes--the gcc
way to handle it is attributes--it is probably fine that gcc requires
a declaration here, since that is compatible.

> extern int bar (void) __attribute__ ((weak));

This is different, since it does not declare bar to be an alias.  In
this case there is no need to actually say anything about bar if it is
not declared and if nothing references it.

Note that

extern int bar (void) __attribute__ ((weak, alias ("foo")));

should emit bar as a weak alias for foo--and, in the current sources,
it does.

Ian

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

* Re: PR7455: What is expected behavior for #pragma weak.
  2004-01-12  0:39 ` Ian Lance Taylor
@ 2004-01-12  0:50   ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2004-01-12  0:50 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Steven Bosscher, gcc

On Sun, Jan 11, 2004 at 07:39:13PM -0500, Ian Lance Taylor wrote:
> Note that
> 
> extern int bar (void) __attribute__ ((weak, alias ("foo")));
> 
> should emit bar as a weak alias for foo--and, in the current sources,
> it does.

It should also generate an error if foo is never defined.


r~

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

end of thread, other threads:[~2004-01-12  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-11 22:23 PR7455: What is expected behavior for #pragma weak Steven Bosscher
2004-01-12  0:37 ` Richard Henderson
2004-01-12  0:39 ` Ian Lance Taylor
2004-01-12  0:50   ` Richard Henderson

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