Hi,

Earlier versions of gcc retain static character strings in object files
which can be used for identification via ident (RCS) or what (SCCS).
Gcc 4.0.0 removes them above optimization level 1.  Global strings
are retained, of course, but that may lead to namespace collisions.
#ident doesn't work on some architectures, and functionality can't
be determined at preprocessor time.  #sccs doesn't work at all.  The
bottom line is that identification which worked with earlier versions
of gcc is broken under 4.0.0.  See attached C source code example.
/* the following works with SCCS (what) and RCS et al (ident) with gcc 3.x and
      earlier 
   string symbol is local (static) to object file and does not clash
      with symbols similarly defined in other files in the same package
      or in library archives used with a package
   gcc 4.0.0 with optimization level 2 or greater elides the symbol and string,
      breaking identification; -fkeep-static-consts is ineffective with
      optimization turned on
*/
static const char rcs_sccs_id[] =
    "$Id: @(#)%M% %I% 20%E% %U% copyright 2005 %Q% string1\\ $";

/* the following works with gcc 4.0.0, but leaves a globally-visible symbol in
      object files where it can clash with other symbols in a package or in an
      object file in a library archive
*/
const char idtest_c_rcs_sccs_id2[] =
    "$Id: @(#)%M% %I% 20%E% %U% copyright 2005 %Q% string2\\ $";

/* gross hack as a workaround for gcc 4.0.0 issue; ID string
      symbol is static, but this won't work for a file with no
      externally-visible executable functions (e.g. a version file)
*/
static const char idtest_c_rcs_sccs_id3[] =
    "$Id: @(#)%M% %I% 20%E% %U% copyright 2005 %Q% string3\\ $";
void some_function(void); /* prototype to shut gcc TF up */
void some_function(void) {
    const char *unused = idtest_c_rcs_sccs_id3; /* workaround for gcc 4.0.0 issue */
/* ... */ /* real code goes here */
}

/* the following doesn't work on all architectures, and is non-standard
   there is no way to test whether it will work at preprocessing time (so that
      one of the other methods might be used)
   if -fno-ident is specified, it is ineffective even if supported on an
      architecture
*/
#ident "$Id: @(#)%M% %I% 20%E% %U% copyright 2005 %Q% string4\\\\ $"

/* the following doesn't work at all with gcc; it's also non-standard
*/
#sccs "$Id: @(#)%M% %I% 20%E% %U% copyright 2005 %Q% string5\\\\ $"

Reply via email to