public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Please help with __attribute__ weak
@ 2005-07-26 11:17 Dimitry Golubovsky
  0 siblings, 0 replies; 3+ messages in thread
From: Dimitry Golubovsky @ 2005-07-26 11:17 UTC (permalink / raw)
  To: gcc, gcc-help

I need to declare a symbol which is weaker in the executable than in any 
external static or dynamic library.

In other words, the executable provides some fallback function 
implementation (in my example, for "write"). But if the linker or 
dynamic linker resolves it, the symbol definition from an external 
library must be used.

I use:

__f_write_weak_alias(int __fd, __const __ptr_t __buf, size_t __n) 
__attribute__((weak, alias ("write"))); /* alias declaration */

int write(int __fd, __const __ptr_t __buf, size_t __n) {
   printf("Abort\n");
} /* fallback implementation */

But even though "write" is resolved, calling the __f_write_weak_alias 
just prints "Abort" i. e. the symbol "write" was not overridden by the 
library definition.

What is the right way to do this?

Thanks for any advice.

Dimitry Golubovsky
Middletown, CT


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

* Re: Please help with __attribute__ weak
  2005-07-26 11:20 Dimitry Golubovsky
@ 2005-07-26 14:01 ` H. J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H. J. Lu @ 2005-07-26 14:01 UTC (permalink / raw)
  To: Dimitry Golubovsky; +Cc: gcc, gcc-help

On Tue, Jul 26, 2005 at 07:19:43AM -0400, Dimitry Golubovsky wrote:
> 
> I need to declare a symbol which is weaker in the executable than in any
> external static or dynamic library.
> 
> In other words, the executable provides some fallback function
> implementation (in my example, for "write"). But if the linker or
> dynamic linker resolves it, the symbol definition from an external
> library must be used.
> 

The weak symbol is different from the normal one only during creating
executable or shared library if it is in a relocatable file. You
can't use weak symbol for your purpose. But you can mark your symbol in
shared library protected.



H.J.

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

* Please help with __attribute__ weak
@ 2005-07-26 11:20 Dimitry Golubovsky
  2005-07-26 14:01 ` H. J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Dimitry Golubovsky @ 2005-07-26 11:20 UTC (permalink / raw)
  To: gcc, gcc-help


I need to declare a symbol which is weaker in the executable than in any
external static or dynamic library.

In other words, the executable provides some fallback function
implementation (in my example, for "write"). But if the linker or
dynamic linker resolves it, the symbol definition from an external
library must be used.

I use:

__f_write_weak_alias(int __fd, __const __ptr_t __buf, size_t __n)
__attribute__((weak, alias ("write"))); /* alias declaration */

int write(int __fd, __const __ptr_t __buf, size_t __n) {
    printf("Abort\n");
} /* fallback implementation */

But even though "write" is resolved, calling the __f_write_weak_alias
just prints "Abort" i. e. the symbol "write" was not overridden by the
library definition.

What is the right way to do this?

Thanks for any advice.

Dimitry Golubovsky
Middletown, CT



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

end of thread, other threads:[~2005-07-26 14:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-26 11:17 Please help with __attribute__ weak Dimitry Golubovsky
2005-07-26 11:20 Dimitry Golubovsky
2005-07-26 14:01 ` H. J. Lu

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