I don't think the symbols are surviving through compilation to make it to the 
link phase.  Subject line is a little misleading - seems this has nothing to do 
with __attribute__((used)).  I tried to do a couple of things using a map file 
without success.  It's quite possible that I don't know what I'm doing there :-(

Here's a working example:

=== Src code.  ===

#define CONCAT(a, b)    a ## _ ## b
#define TRACE_VARNAME(line)     CONCAT(_pds_tracefn, line)
#define TRACE_VARDECL() { static const char * TRACE_VARNAME(__LINE__) = 
__func__; }

func()
{
        TRACE_VARDECL();
}

main(int argc, char **argv)
{
        TRACE_VARDECL();
        func();
}

=== code after preprocessing


psg-solaris-01$ cc -E foo.c
# 1 "foo.c"



# 7

func()
{
         { static const char * _pds_tracefn_10 = __func__ ; };
}

main(int argc, char **argv)
{
         { static const char * _pds_tracefn_15 = __func__ ; };
        func();
}
#ident "acomp: Sun C 5.9 SunOS_i386 Patch 124868-10 2009/04/30"

=== Symbols are gone after compilation
psg-solaris-01$ cc -S foo.c
psg-solaris-01$ grep pds foo.s
psg-solaris-01$

=== Same experiment using gcc 3.4.3:
psg-solaris-01$ gcc -S foo.c
psg-solaris-01$ grep pds foo.s
        .type   _pds_tracefn_10.1, @object
        .size   _pds_tracefn_10.1, 4
_pds_tracefn_10.1:
        .type   _pds_tracefn_15.3, @object
        .size   _pds_tracefn_15.3, 4
_pds_tracefn_15.3:



________________________________
From: Bart Smaalders <[email protected]>
To: [email protected]
Cc: [email protected]; [email protected]
Sent: Thu, April 22, 2010 8:37:56 PM
Subject: Re: [tools-compilers] equivalent for gcc __attribute__ ((used))

On 04/22/10 18:15, Mark Maule wrote:
> We don't know the symbol names ahead of time - they are generated and include 
> __LINE__ as part of the generated name.
> 
> I'm not rote on the mapfile - is there wildcarding to apply scoping to a set 
> of symbols?
> Sent from my Verizon Wireless BlackBerry

You can explicitly export the symbols you want made global, and
everything else can be local.

Or, add something to part of the symbol name that would let you recognize the 
symbols to be made local, link it once and then
figure out what symbols to make local and then link it again...

- Bart


-- Bart Smaalders            Solaris Kernel Performance
[email protected]    http://blogs.sun.com/barts
"You will contribute more with mercurial than with thunderbird."



      
_______________________________________________
tools-compilers mailing list
[email protected]

Reply via email to