SCCS "what" lines are not optimized by the compiler

We are trying to inject a string into binary objects so that we can see the version number for the executable or shared library that has been deployed. Typically, we insert standard CVS identifier information in this row. For example, we can insert:

const char cvsid[] = "@(#)OUR_TEAM_staging_remap_$Revision: 1.30 $ $Name:  $";

inside C. code

From man (1) that:

Which utility looks for each file name to match the @ (#) pattern that the SCCS command receives (see sccs-get (1)) replaces the ID (#) ID keyword and prints the following before the character ",>, NEWLINE, \ or NULL .

There is only one instance of this variable, and it is never mentioned. Someone suggested that this could be optimized by the compiler.

I have been using this technique for many years in both C and C ++ and with various compilers, and I have not yet seen which line is optimized.

Has anyone understood why they are not optimized?

+3
source share
6 answers

Until recently (I discovered a problem in mid-2005), you could use:

static const char sccs[] = "@(#)%W% %E%";

- GCC, . GCC (, GCC 4.0.x, 2005 ), . , , . , , - , , . , :

#ifndef lint
extern const char jlss_id_filename_c[];
const char jlss_id_filename_c[] = "@(#)$Id$";
#endif /* lint */

- ; RCS , - what - ident - what, what, ident . - - . ( , , , . , GCC, , .)

, filename_c . - , .

, 3 .

+2

, , , (, , ).

+2

, , .

, , , , . , , .

​​ , , . . . , , , , . GCC unused, . , - , .

, , .

. .

+2

Microsoft Visual ++ 2005 , , : /OPT:UNREF , /OPT:REF .

static char VersionString[] = "HELLO_WORLD 2.0";

, .

+1

"" , ( extern). C/++ , , .

static, , , , .

, , , , - .

+1

(, , , , ...)

gcc ( , 3.3 ) __attribute__((unused)), ", ", , __attribute__((used)), (, , ), .

, :

static const char what_ident[] __attribute__((used)) = "@(#) $Id$";

linker , , .

static const char what_ident[] __attribute__((section("what"), used)) = "@(#) $Id$";

gcc -Wl,-bkeepfile:file.o, file.c.

+1

Source: https://habr.com/ru/post/1702316/


All Articles