This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

preserving static, global (ident) strings in 3.4.x?


Hello,

I'm used to keeping global strings in all my modules, defined via a macro. This allows me to identify how (what compiler, flags, date, etc) each component of my programmes was compiled, using tools like ident or what.

A kludge (see below) ensured that these strings were not stripped (they are typically not used) by the compiler/linker; this worked up to and including gcc 3.3.2 .
In gcc 3.4.0, this works no longer, unless I call xg_id_string_stub() or refer to xg_id_string directly, or unless I compile without optimisation.

Is there a compiler flag that will deactivate this "agressive" pruning, or is there some other possibility to preserve this information (a pragma or the like)?

Thanks!
R.

For example:

#if !defined(IDENTIFY)

#ifndef SWITCHES
#    ifdef DEBUG
#         define _IDENTIFY(s,i)    static char *xg_id_string= "$Id: @(#) XGraph v" STRING(VERSION_MAJOR) STRING(VERSION_MINOR) STRING(VERSION_PATCHL) " '" __FILE__ "'-[" __DATE__ "," __TIME__ "]-(\015\013\t\t" s "\015\013\t) DEBUG version" i " $"
#    else
#         define _IDENTIFY(s,i)    static char *xg_id_string= "$Id: @(#) XGraph v" STRING(VERSION_MAJOR) STRING(VERSION_MINOR) STRING(VERSION_PATCHL) " '" __FILE__ "'-[" __DATE__ "," __TIME__ "]-(\015\013\t\t" s "\015\013\t)" i " $"
#    endif
#else
  /* SWITCHES contains the compiler name and the switches given to the compiler.     */
#    define _IDENTIFY(s,i)    static char *xg_id_string= "$Id: @(#) XGraph v" STRING(VERSION_MAJOR) STRING(VERSION_MINOR) STRING(VERSION_PATCHL) " '" __FILE__ "'-[" __DATE__ "," __TIME__ "]-(\015\013\t\t" s "\015\013\t)["SWITCHES"]" " $"
#endif
 
#define __IDENTIFY(s,i)\
static char *xg_id_string_stub(){ _IDENTIFY(s,i);\
     static char called=0;\ 
     if( !called){\
          called=1;\
          return(xg_id_string_stub());\
     }\
     else{\
          called= 0;\
          return(xg_id_string);\
     }}

#ifdef __GNUC__
#    define IDENTIFY(s)  __IDENTIFY(s," (gcc)")
#else 
#    define IDENTIFY(s)  __IDENTIFY(s," (cc)")
#endif

#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]