Files
clang-p2996/lld/test/ELF/linkerscript/wildcards.s
Rui Ueyama 3da3f06dd3 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
2016-11-10 20:20:37 +00:00

84 lines
2.6 KiB
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
## Default case: abc and abx included in text.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .abx) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t
# RUN: llvm-objdump -section-headers %t.out | \
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
# SEC-DEFAULT: Sections:
# SEC-DEFAULT-NEXT: Idx Name Size
# SEC-DEFAULT-NEXT: 0 00000000
# SEC-DEFAULT-NEXT: 1 .text 00000008
# SEC-DEFAULT-NEXT: 2 .abcd 00000004
# SEC-DEFAULT-NEXT: 3 .ad 00000004
# SEC-DEFAULT-NEXT: 4 .ag 00000004
# SEC-DEFAULT-NEXT: 5 .comment 00000008 {{[0-9a-f]*}}
# SEC-DEFAULT-NEXT: 6 .symtab 00000030
# SEC-DEFAULT-NEXT: 7 .shstrtab 00000038
# SEC-DEFAULT-NEXT: 8 .strtab 00000008
## Now replace the symbol with '?' and check that results are the same.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .ab?) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t
# RUN: llvm-objdump -section-headers %t.out | \
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
## Now see how replacing '?' with '*' will consume whole abcd.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .ab*) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t
# RUN: llvm-objdump -section-headers %t.out | \
# RUN: FileCheck -check-prefix=SEC-ALL %s
# SEC-ALL: Sections:
# SEC-ALL-NEXT: Idx Name Size
# SEC-ALL-NEXT: 0 00000000
# SEC-ALL-NEXT: 1 .text 0000000c
# SEC-ALL-NEXT: 2 .ad 00000004
# SEC-ALL-NEXT: 3 .ag 00000004
# SEC-ALL-NEXT: 4 .comment 00000008
# SEC-ALL-NEXT: 5 .symtab 00000030
# SEC-ALL-NEXT: 6 .shstrtab 00000032
# SEC-ALL-NEXT: 7 .strtab 00000008
## All sections started with .a are merged.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.a*) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t
# RUN: llvm-objdump -section-headers %t.out | \
# RUN: FileCheck -check-prefix=SEC-NO %s
# SEC-NO: Sections:
# SEC-NO-NEXT: Idx Name Size
# SEC-NO-NEXT: 0 00000000
# SEC-NO-NEXT: 1 .text 00000014
# SEC-NO-NEXT: 2 .comment 00000008
# SEC-NO-NEXT: 3 .symtab 00000030
# SEC-NO-NEXT: 4 .shstrtab 0000002a
# SEC-NO-NEXT: 5 .strtab 00000008
.text
.section .abc,"ax",@progbits
.long 0
.text
.section .abx,"ax",@progbits
.long 0
.text
.section .abcd,"ax",@progbits
.long 0
.text
.section .ad,"ax",@progbits
.long 0
.text
.section .ag,"ax",@progbits
.long 0
.globl _start
_start: