Page MenuHomePhabricator

Include version string into ".comment" section.
ClosedPublic

Authored by ruiu on Nov 9 2016, 9:18 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 77441.Nov 9 2016, 9:18 PM
ruiu retitled this revision from to Include version string into ".comment" section..
ruiu updated this object.
ruiu added reviewers: davide, rafael, emaste.
ruiu added a subscriber: llvm-commits.
rafael accepted this revision.Nov 10 2016, 7:19 AM
rafael edited edge metadata.

LGTM.Thanks!

This revision is now accepted and ready to land.Nov 10 2016, 7:19 AM
davide accepted this revision.Nov 10 2016, 11:13 AM
davide edited edge metadata.

lg

This revision was automatically updated to reflect the committed changes.