Carl Lowenstein wrote:
For about as long as RCS has been around, like 20 years, I have been
putting ID strings into C program source files using a statement such
as:

static char *rcsid="$Id:$";

The RCS program ci(1) fills in the $Id:$ template with the current
version and date of the program.  The character string is compiled
into the object file and shows up in the linked runnable program. and
can be displayed with the command ident(1).  You all know this
already.

Starting recently, GCC seems to optimize this string away if it is not
referred to anywhere in the program.  This happens with gcc 4.2.1, as
I discovered this morning.   A previous version, gcc 3.4.4, does not
do this.

The obvious sloppy workaround is to make the program slightly more
verbose by actually using rcsid.
fprintf (stderr, "%s\n", rcsid);

Less obvious, where foo is some other char* that has been defined
already, and can be temporarily clobbered:
foo = rcsid;

Anyone have a better idea?


Not a better idea for solving the immediate problem, but an idea:

Submit a bug report to wherever one submits bug reports about gcc (I'd assume somewhere on the GNU web site).

On another related note. I've found that many compilers recently have been causing numerous problems when selecting various optimization settings. We had (at QUAKE, where I was working) a few embedded compilers where the improved versions broke code because of whatever they did when optimizing. In fact, the code I was debugging on Thur. had such an issue.

It seems the compiler would render the code inoperable if anything other than -o0 was selected. it screwed up some critical timing loops for one thing - it may have removed some nops from the code, I'm not sure as I didn't get far enough to fix it - and who knows what else. The previous version did not cause a problem.

Sometimes I long for the days of compilers that weren't so "smart".

PGA
--
Paul G. Allen, BSIT/SE
Owner, Sr. Engineer
Random Logic Consulting Services
www.randomlogic.com

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to