Newer gcc swallow version control keywords
Elazar Leibovich
elazarl at gmail.com
Fri Oct 21 15:23:11 IST 2011
On Tue, Oct 18, 2011 at 1:50 PM, Oleg Goldshmidt <pub at goldshmidt.org> wrote:
> > I didn't understand how, eg, my C++ scheme don't work. I think it should
> > work even if you're including the $Id$ strings in the headers files.
>
> Apart from the fact that you assume that main.cc is mine (what if my
> product is a library?),
There's an important point here.
If your product is an .so, all you need to do, is to expose the ident
objects to the library users (of course, in this case the names of the
variables must be unique per file version). This way, the linker is forced
to leave those strings intact.
If you're product is an .a archive, well, your out of luck. The same method
for so files will work of course for the .a archive, but, the client who
links to your program, is free to use a whole program optimizer, which might
wipe off your program. I'm not sure it's even possible to mark those strings
as "always include" in the object file.
I really recommend this piece[1] by Meyers, who shows that fighting with the
optimizer, is doomed to misery.
[1] PDF: http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf Bottom
of page 6, Ctrl-F "In essence, you’ve just fired the opening salvo"
> depends on a whole lot of things I wouldn't
> necessarily need for any other purpose, makes the strings global
Not too global. The global list of strings is exposed only in the main() and
in the implementation of the Ident class. If you hate global variables -
make it a static variable of the Ident class.
> and
> mutable,
The list of strings is mutable, right? The stings can be immutable. Also it
is possible to use a push-only queue instead of vector. But I'm nitpicking
now ;-)
> and won't pick up, e.g., the case of wrong header I mentioned
> before (I checked)?
>
I don't understand why is that.
See here <https://github.com/elazarl/ident-for-cpp>[2] for an implementation
which Works For Me (TM), with no non-static global variables, and it works
for header files.
[2] https://github.com/elazarl/ident-for-cpp
>
> This is a good idea in general, but it's not really an improvement.
> The trusted old scheme has all the needed properties and if gcc had an
> option to disable this particular kind of optimization selectively I
> wouldn't have a problem.
>
If I understood correctly, the problem was how to port the GCC
optimization-turn-off to other compilers without macro hackeries. I believe
this is a good portable way. I'm trying to find a sane way to do that in
portable C, but I'm not sure it's possible without too much effort.
That said, the macro+gcc attribute seems the most reasonable approach given
that VS have a way to disable this optimization. However, it spoils all the
fun.
>
> --
> Oleg Goldshmidt | pub at goldshmidt.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20111021/100c3c70/attachment.html>
More information about the Linux-il
mailing list