Include version string into ".comment" section.
authorRui Ueyama <ruiu@google.com>
Thu, 10 Nov 2016 20:20:37 +0000 (20:20 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 10 Nov 2016 20:20:37 +0000 (20:20 +0000)
commit3da3f06dd3a0e03053b5921e5dfcceffd9d7d399
treec834d92722edc39cc2c7db0e975fadbd741a275b
parent4a86af07a23a7a8ce0b8f41b912c4e77bbb984d0
Include version string into ".comment" section.

Summary:
This patch adds a ".comment" section to an output. The comment
section contains the linker's version string. You can now
find out whether a binary is created by LLD or not using objdump
command like this.

  $ objdump -s -j .comment foo

  foo:     file format elf64-x86-64

  Contents of section .comment:
   0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
   0010 382e342d 32756275 6e747531 7e31342e  8.4-2ubuntu1~14.
   ...
   00c0 766d2f74 72756e6b 20323835 38343629  vm/trunk 285846)
   00d0 004c696e 6b65723a 204c4c44 20342e30  .Linker: LLD 4.0
   00e0 2e302028 7472756e 6b203238 36343036  .0 (trunk 286406
   00f0 2900                                 ).

Compilers emits .comment section as well, so the output contains
both compiler and linker information.

Alternative considered:

I first tried to add a SHT_NOTE section because GNU gold does that.
A NOTE section starts with a header which contains content type.
It turned out that ld.gold sets type NT_GNU_GOLD_VERSION to their
NOTE section. So the NOTE type is only for GNU gold (surprise!)

Next, I tried to create ".linker-version" section. However, it seems
that reusing the existing ".comment" section is better because 1)
other tools already know about .comment section and is able to strip
it and 2) the result contans not only linker info but also compiler
info.

Differential Revision: https://reviews.llvm.org/D26487

llvm-svn: 286496
25 files changed:
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
lld/test/ELF/aarch64-gnu-ifunc.s
lld/test/ELF/basic-aarch64.s
lld/test/ELF/basic-mips.s
lld/test/ELF/basic-ppc.s
lld/test/ELF/basic.s
lld/test/ELF/basic32.s
lld/test/ELF/basic64be.s
lld/test/ELF/build-id.s
lld/test/ELF/comment-gc.s
lld/test/ELF/gnu-ifunc-i386.s
lld/test/ELF/gnu-ifunc.s
lld/test/ELF/linkerscript/sections-keep.s
lld/test/ELF/linkerscript/sections-sort.s
lld/test/ELF/linkerscript/sections.s
lld/test/ELF/linkerscript/wildcards.s
lld/test/ELF/pie.s
lld/test/ELF/relocatable-bss.s
lld/test/ELF/relocatable.s
lld/test/ELF/section-name.s
lld/test/ELF/shared.s
lld/test/ELF/string-table.s
lld/test/lit.cfg