1# RUN: echo -n abcd > %t.x-txt
2# Preserve input to verify it is not modified
3# RUN: cp %t.x-txt %t-copy.txt
4# RUN: llvm-objcopy -I binary -O elf64-x86-64 %t.x-txt %t.o
5# RUN: llvm-readobj --sections --symbols %t.o | FileCheck %s
6# RUN: cmp %t.x-txt %t-copy.txt
7
8# CHECK:      Sections [
9# CHECK-NEXT:   Section {
10# CHECK-NEXT:     Index: 0
11# CHECK-NEXT:     Name:  (0)
12# CHECK-NEXT:     Type: SHT_NULL (0x0)
13# CHECK-NEXT:     Flags [ (0x0)
14# CHECK-NEXT:     ]
15# CHECK-NEXT:     Address: 0x0
16# CHECK-NEXT:     Offset:
17# CHECK-NEXT:     Size:
18# CHECK-NEXT:     Link: 0
19# CHECK-NEXT:     Info: 0
20# CHECK-NEXT:     AddressAlignment: 0
21# CHECK-NEXT:     EntrySize: 0
22# CHECK-NEXT:   }
23# CHECK-NEXT:   Section {
24# CHECK-NEXT:     Index: 1
25# CHECK-NEXT:     Name: .strtab
26# CHECK-NEXT:     Type: SHT_STRTAB (0x3)
27# CHECK-NEXT:     Flags [ (0x0)
28# CHECK-NEXT:     ]
29# CHECK-NEXT:     Address: 0x0
30# CHECK-NEXT:     Offset:
31# CHECK-NEXT:     Size:
32# CHECK-NEXT:     Link: 0
33# CHECK-NEXT:     Info: 0
34# CHECK-NEXT:     AddressAlignment: 1
35# CHECK-NEXT:     EntrySize: 0
36# CHECK-NEXT:   }
37# CHECK-NEXT:   Section {
38# CHECK-NEXT:     Index: 2
39# CHECK-NEXT:     Name: .symtab
40# CHECK-NEXT:     Type: SHT_SYMTAB (0x2)
41# CHECK-NEXT:     Flags [ (0x0)
42# CHECK-NEXT:     ]
43# CHECK-NEXT:     Address: 0x0
44# CHECK-NEXT:     Offset:
45# CHECK-NEXT:     Size:
46# CHECK-NEXT:     Link: 1
47# CHECK-NEXT:     Info: 1
48# CHECK-NEXT:     AddressAlignment: 8
49# CHECK-NEXT:     EntrySize: 24
50# CHECK-NEXT:   }
51# CHECK-NEXT:   Section {
52# CHECK-NEXT:     Index: 3
53# CHECK-NEXT:     Name: .data
54# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
55# CHECK-NEXT:     Flags [ (0x3)
56# CHECK-NEXT:       SHF_ALLOC (0x2)
57# CHECK-NEXT:       SHF_WRITE (0x1)
58# CHECK-NEXT:     ]
59# CHECK-NEXT:     Address: 0x0
60# CHECK-NEXT:     Offset:
61# CHECK-NEXT:     Size: 4
62# CHECK-NEXT:     Link: 0
63# CHECK-NEXT:     Info: 0
64# CHECK-NEXT:     AddressAlignment: 1
65# CHECK-NEXT:     EntrySize: 0
66# CHECK-NEXT:   }
67# CHECK-NEXT: ]
68
69# Note: the symbol names are derived from the full path (with non-alnum values
70# replaced with "_"), e.g. "/tmp/a-b.c" should yield
71# _binary__tmp_a_b_c_{start,end,size}.
72# Just check for _binary_{{[_a-zA-Z0-9]*}}_x_txt_{start,end,size} to avoid
73# making assumptions about how this test is run.
74
75# CHECK:      Symbols [
76# CHECK-NEXT:   Symbol {
77# CHECK-NEXT:     Name:
78# CHECK-NEXT:     Value: 0x0
79# CHECK-NEXT:     Size: 0
80# CHECK-NEXT:     Binding: Local (0x0)
81# CHECK-NEXT:     Type: None (0x0)
82# CHECK-NEXT:     Other: 0
83# CHECK-NEXT:     Section: Undefined (0x0)
84# CHECK-NEXT:   }
85# CHECK-NEXT:   Symbol {
86# CHECK-NEXT:     Name: _binary_{{[_a-zA-Z0-9]*}}_x_txt_start
87# CHECK-NEXT:     Value: 0x0
88# CHECK-NEXT:     Size: 0
89# CHECK-NEXT:     Binding: Global (0x1)
90# CHECK-NEXT:     Type: None (0x0)
91# CHECK-NEXT:     Other: 0
92# CHECK-NEXT:     Section: .data
93# CHECK-NEXT:   }
94# CHECK-NEXT:   Symbol {
95# CHECK-NEXT:     Name: _binary_{{[_a-zA-Z0-9]*}}_x_txt_end
96# CHECK-NEXT:     Value: 0x4
97# CHECK-NEXT:     Size: 0
98# CHECK-NEXT:     Binding: Global (0x1)
99# CHECK-NEXT:     Type: None (0x0)
100# CHECK-NEXT:     Other: 0
101# CHECK-NEXT:     Section: .data
102# CHECK-NEXT:   }
103# CHECK-NEXT:   Symbol {
104# CHECK-NEXT:     Name: _binary_{{[_a-zA-Z0-9]*}}_x_txt_size
105# CHECK-NEXT:     Value: 0x4
106# CHECK-NEXT:     Size: 0
107# CHECK-NEXT:     Binding: Global (0x1)
108# CHECK-NEXT:     Type: None (0x0)
109# CHECK-NEXT:     Other: 0
110# CHECK-NEXT:     Section: Absolute
111# CHECK-NEXT:   }
112# CHECK-NEXT: ]
113
114## The alignment can be changed by --set-section-alignment.
115# RUN: llvm-objcopy -I binary -O elf64-x86-64 --set-section-alignment .data=8 %t.x-txt %t2.o
116# RUN: llvm-readobj --sections %t2.o | FileCheck --check-prefix=ALIGN %s
117
118# ALIGN:      Name: .data
119# ALIGN:      AddressAlignment:
120# ALIGN-SAME:                   8{{$}}
121