This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
forcing a static char string into libs and executables
- From: Bruce Allen <ballen at gravity dot phys dot uwm dot edu>
- To: gcc-help at gcc dot gnu dot org
- Cc: Bruce Allen <ballen at gravity dot phys dot uwm dot edu>
- Date: Sun, 2 Jan 2005 08:38:59 -0600 (CST)
- Subject: forcing a static char string into libs and executables
I've searched the standard places, manuals and mailing lists and not found
the answer to this.
I use the 'ident' utility to parse CVS strings from libs and executables.
It's a convenient tool for tracking version information: Typical output
looks like this (get file is an executable):
ident get_file
get_file:
$Id: get_file.C,v 1.4 2004/12/08 00:39:22 ballen Exp $
The string are embedded typically with a declaration like this:
static volatile const char __attribute__((unused))
*BOINCrcsid= $Id: get_file.C,v 1.4 2004/12/08 00:39:22 ballen Exp $";
The 'volatile' is a (perhaps misguided) attempt to force the
compiler-assembler-linker chain to preserve this quantity even under
agressive optimization. The __attribute((unused)) is to avoid compiler
warnings about BOINCrcsid, which is used nowhere in the code.
This worked with gcc 3.2.2 and earlier but fails with gcc 3.4.2. With gcc
3.4.3, I get:
ident get_file
get_file:
ident warning: no id keywords in get_file
If I change to __attribute__((used)) then my const char string comes back
and ident works correctly. So:
(1) Is there a better way? which will work with older and newer gcc
versions?
(2) At which gcc version did __attribute__((used)) start being supported?
I can't find it documented. If someone can point me to the file or
directory in gcc CVS I'll happily track this down.
I don't subscribe to this list: replies copied to ballen@uwm.edu would be
greatly appreciated.
Cheers,
Bruce