[PATCH] D26487: Include version string into ".comment" section.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 21:18:49 PST 2016


ruiu created this revision.
ruiu added reviewers: davide, rafael, emaste.
ruiu added a subscriber: llvm-commits.
Herald added a subscriber: nemanjai.

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.


https://reviews.llvm.org/D26487

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26487.77441.patch
Type: text/x-patch
Size: 35636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161110/a3bd5df4/attachment.bin>


More information about the llvm-commits mailing list