Compiler used to build LLVM

Hello,

We’d like to keep track of which clang version was used to build our LLVM binaries. We use cmake and ninja with clang to build. What do you people think would be the cleanest way to know which version of clang is used, on a user’s machine, to build those binaries. I’m hoping to script this. I was thinking that getting cmake/ninja to spit out this information, if possible, would probably be best.

Thank you for your help,

- Maxime

I’d like to make LLD embed version information so that we can determine if an executable was created by LLD and if that’s the case which version of LLD.
ld.bfd doesn’t seem to embed any information, so we cannot tell whether an executable was linked by ld.bfd or not easily.

ld.gold embeds a string “GNU gold ” as “.note.gnu.gold-version” section contents.

Echoing another thread, there seems to be a way to embed host compiler toolchain info in the assembly.-Kevin

Isn’t the information already available in .comment section?

This is working already:

$ objdump -x -s -j .comment ./opt

Contents of section .comment:
0000 4743433a 2028474e 55292036 2e312e31 GCC: (GNU) 6.1.1
0010 20323031 36303632 31202852 65642048 20160621 (Red H
0020 61742036 2e312e31 2d332900 636c616e at 6.1.1-3).clan
0030 67207665 7273696f 6e20342e 302e3020 g version 4.0.0
0040 28747275 6e6b2032 38353332 36292028 (trunk 285326) (
0050 6c6c766d 2f747275 6e6b2032 38353331 llvm/trunk 28531
0060 38290063 6c616e67 20766572 73696f6e 8).clang version
0070 20342e30 2e302028 7472756e 6b203238 4.0.0 (trunk 28
0080 34323239 2920286c 6c766d2f 7472756e 4229) (llvm/trun
0090 6b203238 34323438 2900636c 616e6720 k 284248).clang
00a0 76657273 696f6e20 342e302e 30202874 version 4.0.0 (t
00b0 72756e6b 20323832 30383929 20286c6c runk 282089) (ll
00c0 766d2f74 72756e6b 20323832 30393829 vm/trunk 282098)
00d0 00636c61 6e672076 65727369 6f6e2034 .clang version 4
00e0 2e302e30 20287472 756e6b20 32383335 .0.0 (trunk 2835
00f0 37342920 286c6c76 6d2f7472 756e6b20 74) (llvm/trunk
0100 32383335 39392900 283599).

It should be easy to enable for your platform if it's disabled/not there.

It is disabled on MachO / Darwin though.

Maxime: please ping this rdar://problem/28847727

Hello,

We’d like to keep track of which clang version was used to build our LLVM binaries. We use cmake and ninja with clang to build. What do you people think would be the cleanest way to know which version of clang is used, on a user’s machine, to build those binaries. I’m hoping to script this. I was thinking that getting cmake/ninja to spit out this information, if possible, would probably be best.

This is working already:

$ objdump -x -s -j .comment ./opt

Contents of section .comment:
0000 4743433a 2028474e 55292036 2e312e31 GCC: (GNU) 6.1.1
0010 20323031 36303632 31202852 65642048 20160621 (Red H
0020 61742036 2e312e31 2d332900 636c616e at 6.1.1-3).clan
0030 67207665 7273696f 6e20342e 302e3020 g version 4.0.0
0040 28747275 6e6b2032 38353332 36292028 (trunk 285326) (
0050 6c6c766d 2f747275 6e6b2032 38353331 llvm/trunk 28531
0060 38290063 6c616e67 20766572 73696f6e 8).clang version
0070 20342e30 2e302028 7472756e 6b203238 4.0.0 (trunk 28
0080 34323239 2920286c 6c766d2f 7472756e 4229) (llvm/trun
0090 6b203238 34323438 2900636c 616e6720 k 284248).clang
00a0 76657273 696f6e20 342e302e 30202874 version 4.0.0 (t
00b0 72756e6b 20323832 30383929 20286c6c runk 282089) (ll
00c0 766d2f74 72756e6b 20323832 30393829 vm/trunk 282098)
00d0 00636c61 6e672076 65727369 6f6e2034 .clang version 4
00e0 2e302e30 20287472 756e6b20 32383335 .0.0 (trunk 2835
00f0 37342920 286c6c76 6d2f7472 756e6b20 74) (llvm/trunk
0100 32383335 39392900 283599).

It should be easy to enable for your platform if it’s disabled/not there.

It is disabled on MachO / Darwin though.

Maxime: please ping this rdar://problem/28847727

If you have the dSYM for the binary available then you can get the clang version from there.

For example:

xcrun llvm-dwarfdump -debug-dump=all llvm-tblgen.dSYM/Contents/Resources/DWARF/llvm-tblgen | grep clang

produces:

DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "Apple LLVM version 8.0.0 (clang-800.0.38)”)

Depends if you the have the dSYM of course, but hopefully in most cases you will.

Cheers,
Pete