This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Add an option to suppress output of llvm.ident
ClosedPublic

Authored by miyuki on Apr 4 2018, 5:08 AM.

Details

Summary

By default Clang outputs its version (including git commit hash, in
case of trunk builds) into object and assembly files. It might be
useful to have an option to disable this, especially for debugging
purposes.
This patch implements new command line flags -Qn and -Qy (the names
are chosen for compatibility with GCC). -Qn disables output of
the 'llvm.ident' metadata string and the 'producer' debug info. -Qy
(enabled by default) does the opposite.

Diff Detail

Event Timeline

miyuki created this revision.Apr 4 2018, 5:08 AM

What's your use-case for this?

test/CodeGen/no-ident-version.c
5

You'll also want to check for something positive, otherwise this test will succeed even if clang is symlinked to /bin/true :-)

miyuki updated this revision to Diff 142165.Apr 12 2018, 6:59 AM

Updated the test case

miyuki added a comment.EditedApr 12 2018, 7:06 AM

One use case for this is debugging: this flag makes it easier to find out which revisions of LLVM introduce changes in codegen and/or debug information without having to filter out .ident/producer metadata manually. Some users can also use this flag (or an equivalent, -fno-ident) to reduce code size: https://github.com/niXman/mingw-builds/issues/412 (.ident strings are embedded into each object file and don't get merged during linking, so the difference can be noticeable).

miyuki marked an inline comment as done.Apr 12 2018, 7:09 AM

There is a flag -fno-ident that has the same effect in GCC https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fno-ident although it involves also ignoring the #ident.

A quick look seems to suggest that #ident is just ignored in the usual PP callbacks used by the parser so in practice -fno-ident would be the same as -Qn

JDevlieghere added inline comments.Apr 19 2018, 8:00 AM
test/CodeGen/no-ident-version.c
2

Please test both -Qy and -Qn as well as the default case.

Does gcc's Qy/Qn option also affect the generated debug information? Clang is embedding the version number also into the DICompileUnit's producer string; I wonder if that should be affected by this option, too.

Does gcc's Qy/Qn option also affect the generated debug information?

No, it does not. Do you think it would be better to leave debug information unchanged as well?

I'm not sure. Compatibility with GCC and getting identical output for debugging purposes seem to be at odds here. I personally lean slightly towards stripping it from the debug info as well.

miyuki updated this revision to Diff 143327.Apr 20 2018, 9:16 AM

Updated the test

miyuki marked an inline comment as done.Apr 20 2018, 9:16 AM
aprantl accepted this revision.Apr 20 2018, 9:23 AM
This revision is now accepted and ready to land.Apr 20 2018, 9:23 AM

I’m happy with the test, thanks!

I'm not sure. Compatibility with GCC and getting identical output for debugging purposes seem to be at odds here. I personally lean slightly towards stripping it from the debug info as well.

If it were the other way around I’d agree with you, but given that -Qn becomes the default, I think we should not strip it from the debug info.

This revision was automatically updated to reflect the committed changes.

If it were the other way around I’d agree with you, but given that -Qn becomes the default, I think we should not strip it from the debug info.

No, the default is -Qy

If it were the other way around I’d agree with you, but given that -Qn becomes the default, I think we should not strip it from the debug info.

No, the default is -Qy

Ah, right, I was confused by the CHECK-NONE prefix, I would have merged it with the default case. In that case I agree with Adrian. :-)