🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3476

Re: use of weak_alias or strong_alias in application code?

#3476
From: seyong_choi
Date: Wed, 12 Jul 2006 22:34
69 lines
3757 bytes
Thanks for your suggestion. It works perfectly!

Just wonder: It seems gcc manual also specifies pragma weak
(http://gcc.gnu.org/onlinedocs/gcc/Weak-Pragmas.html) But, it seems
that "#pragma weak special_subroutine_1 = special_subroutine" can't
create a weak alias. can you explain why it does not work?

Please take a look:
#cat mylibrary.c
//====================
// file: mylibrary.c
#pragma weak special_subroutine_1 = special_subroutine
#pragma weak special_subroutine_1 = special_subroutine
int special_subroutine(){
     int i =0;
     return i;
}
//====================
#gcc -c mylibrary.c
#nm mylibrary.o
00000000 T special_subroutine

PS: By contract, your suggestion works!
#cat mylibrary.c
//====================
// file: mylibrary.c
int special_subroutine_1 () __attribute__ ((weak, alias
("special_subroutine")));
int special_subroutine_2 () __attribute__ ((weak, alias
("special_subroutine")));
int special_subroutine(){
     int i =0;
     return i;
}
//====================
#gcc -c mylibrary.c
#nm mylibrary.o
00000000 T special_subroutine
00000000 W special_subroutine_1
00000000 W special_subroutine_2
Roger Leigh wrote:
> On 2006-07-12, Keith Thompson <kst-u@mib.org> wrote:
> > "seyong_choi@hotmail.com" <seyong_choi@hotmail.com> writes:
> >> I want to use alias to call a defined function (special_subroutine in
> >> this example) using different names (special_subroutine_1 and
> >> special_subroutine_2 in this example), is it doable? --I tried the
> >> following way, and it did not work when I tried to  compile it with
> >> gcc. I guess weak_alias is only valid for glibc, or maybe the way I use
> >> it was wrong.
> >>
> >> Can someone give me a suggestion?
> >
> > There is nothing called "weak_alias" or "strong_alias" in standard C.
>
> It's a feature specific to ELF platforms.  GCC lets you define
> such functions using function attributes.
>
> The GCC manual shows exactly how to do this:
> info gcc 'C Extensions' 'Function Attributes'
>
>
> Regards,
> Roger
>
> --
>   .''`.  Roger Leigh
>  : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
>  `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
>    `-    GPG Public Key: 0x25BFB848   Please sign and encrypt your mail.
Technical Details
Message-ID: <1152743676.769164.321340@m73g2000cwd.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m73g2000cwd.googlegroups.com!not-for-mail
References: <1152735698.884580.224300@m73g2000cwd.googlegroups.com> <ln3bd6bl0e.fsf@nuthaus.mib.org> <slrnebas1v.arv.rleigh@hardknott.home.whinlatter.ukfsn.org>

Show Full Headers
Complete Article Headers
X-Google-Thread: fc89c,3c63dba3672bf253
X-Google-Thread: 11318c,7bdeeefb193ae3b8,start
X-Google-Attributes: gidfc89c,gid11318c,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m73g2000cwd.googlegroups.com!not-for-mail
From: "seyong_choi@hotmail.com" <seyong_choi@hotmail.com>
Newsgroups: comp.unix.programmer,gnu.gcc.help
Subject: Re: use of weak_alias or strong_alias in application code?
Date: 12 Jul 2006 15:34:36 -0700
Organization: http://groups.google.com
Lines: 70
Message-ID: <1152743676.769164.321340@m73g2000cwd.googlegroups.com>
References: <1152735698.884580.224300@m73g2000cwd.googlegroups.com>
   <ln3bd6bl0e.fsf@nuthaus.mib.org>
   <slrnebas1v.arv.rleigh@hardknott.home.whinlatter.ukfsn.org>
NNTP-Posting-Host: 128.46.212.51
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1152743682 30193 127.0.0.1 (12 Jul 2006 22:34:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 12 Jul 2006 22:34:42 +0000 (UTC)
In-Reply-To: <slrnebas1v.arv.rleigh@hardknott.home.whinlatter.ukfsn.org>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060414 Red Hat/1.7.13-1.1.3.1,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: m73g2000cwd.googlegroups.com; posting-host=128.46.212.51;
   posting-account=Q7BdpA0AAAACiZ0V0woI8PQMIClK9Xra