1## Here we document how yaml2obj handles relocation addend descriptions.
2
3## Case 1: Check a 64-bit object.
4
5## Case 1.1: Document we accept any hex/decimal addends in [INT64_MIN, UINT64_MAX].
6
7## INT64_MIN   == -9223372036854775808
8## UINT64_MAX  == 0xffffffffffffffff
9
10## Addend == UINT64_MAX.
11# RUN: yaml2obj %s -o %t64.decimal.max -DADDEND=18446744073709551615
12# RUN: llvm-readobj -r %t64.decimal.max | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFFFFFFFFFF
13# RUN: yaml2obj %s -o %t64.hex.max -DADDEND=0xFFFFFFFFFFFFFFFF
14# RUN: llvm-readobj -r %t64.hex.max | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFFFFFFFFFF
15
16## Addend == first positive integer.
17# RUN: yaml2obj %s -o %t64.decimal.first.pos -DADDEND=1
18# RUN: llvm-readobj -r %t64.decimal.first.pos | FileCheck %s --check-prefix=TEST -DADDEND=0x1
19# RUN: yaml2obj %s -o %t64.hex.first.pos -DADDEND=0x1
20# RUN: llvm-readobj -r %t64.hex.first.pos | FileCheck %s --check-prefix=TEST -DADDEND=0x1
21
22## Addend == 0.
23# RUN: yaml2obj %s -o %t64.decimal.null -DADDEND=0
24# RUN: llvm-readobj -r %t64.decimal.null | FileCheck %s --check-prefix=TEST -DADDEND=0x0
25# RUN: yaml2obj %s -o %t64.hex.null -DADDEND=0x0
26# RUN: llvm-readobj -r %t64.hex.null | FileCheck %s --check-prefix=TEST -DADDEND=0x0
27
28## Addend == first negative integer.
29# RUN: yaml2obj %s -o %t64.decimal.first.neg -DADDEND=-1
30# RUN: llvm-readobj -r %t64.decimal.first.neg | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFFFFFFFFFF
31## We do not accept negative hex addends.
32# RUN: not yaml2obj %s -o /dev/null -DADDEND=-0x1 2>&1 | FileCheck %s --check-prefix=ERR
33
34## Addend == INT64_MIN.
35# RUN: yaml2obj %s -o %t64.decimal.min -DADDEND=-9223372036854775808
36# RUN: llvm-readobj -r %t64.decimal.min | FileCheck %s --check-prefix=TEST -DADDEND=0x8000000000000000
37# TEST: 0x0 R_{{.*}}_PC32 foo [[ADDEND]]
38
39# Case 1.2: Document we do not accept any hex/decimal addends outside of the range specified.
40
41## Addend == 2^64.
42# RUN: not yaml2obj %s -o /dev/null -DADDEND=18446744073709551616 2>&1 | FileCheck %s --check-prefix=ERR
43# RUN: not yaml2obj %s -o /dev/null -DADDEND=0x10000000000000000 2>&1 | FileCheck %s --check-prefix=ERR
44
45## Addend == INT64_MIN - 1.
46# RUN: not yaml2obj %s -o /dev/null -DADDEND=-9223372036854775809 2>&1 | FileCheck %s --check-prefix=ERR
47
48# ERR: invalid number
49
50--- !ELF
51FileHeader:
52  Class:   ELFCLASS64
53  Data:    ELFDATA2LSB
54  Type:    ET_REL
55  Machine: EM_X86_64
56Sections:
57  - Name: .text
58    Type: SHT_PROGBITS
59  - Name: .rela.text
60    Type: SHT_RELA
61    Info: .text
62    Link: .symtab
63    Relocations:
64      - Type:   R_X86_64_PC32
65        Symbol: foo
66        Addend: [[ADDEND]]
67Symbols:
68  - Name: foo
69
70## Case 2: Check a 32-bit object.
71
72## INT32_MIN   == -2147483648
73## UINT32_MAX  == 0xffffffff
74
75## Case 2.1: Document we accept any hex/decimal addends in [INT32_MIN, UINT32_MAX].
76
77## Addend == UINT32_MAX.
78# RUN: yaml2obj --docnum=2 %s -o %t32.decimal.max -DADDEND=4294967295
79# RUN: llvm-readobj -r %t32.decimal.max | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFF
80# RUN: yaml2obj --docnum=2 %s -o %t32.hex.max -DADDEND=0xFFFFFFFF
81# RUN: llvm-readobj -r %t32.hex.max | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFF
82
83## Addend == first positive integer.
84# RUN: yaml2obj --docnum=2 %s -o %t32.decimal.first.pos -DADDEND=1
85# RUN: llvm-readobj -r %t32.decimal.first.pos | FileCheck %s --check-prefix=TEST -DADDEND=0x1
86# RUN: yaml2obj --docnum=2 %s -o %t32.hex.first.pos -DADDEND=0x1
87# RUN: llvm-readobj -r %t32.hex.first.pos | FileCheck %s --check-prefix=TEST -DADDEND=0x1
88
89## Addend == 0.
90# RUN: yaml2obj --docnum=2 %s -o %t32.decimal.null -DADDEND=0
91# RUN: llvm-readobj -r %t32.decimal.null | FileCheck %s --check-prefix=TEST -DADDEND=0x0
92# RUN: yaml2obj --docnum=2 %s -o %t32.hex.null -DADDEND=0x0
93# RUN: llvm-readobj -r %t32.hex.null | FileCheck %s --check-prefix=TEST -DADDEND=0x0
94
95## Addend == first negative integer.
96# RUN: yaml2obj --docnum=2 %s -o %t32.decimal.first.neg -DADDEND=-1
97# RUN: llvm-readobj -r %t32.decimal.first.neg | FileCheck %s --check-prefix=TEST -DADDEND=0xFFFFFFFF
98## We do not accept negative hex addends.
99# RUN: not yaml2obj --docnum=2 %s -o /dev/null -DADDEND=-0x1 2>&1 | FileCheck %s --check-prefix=ERR
100
101## Addend == INT32_MIN
102# RUN: yaml2obj --docnum=2 %s -o %t32.decimal.min -DADDEND=-2147483648
103# RUN: llvm-readobj -r %t32.decimal.min | FileCheck %s --check-prefix=TEST -DADDEND=0x80000000
104
105# Case 2.2: Document we do not accept any hex/decimal addends outside of the range specified.
106
107## Addend == 2^32.
108# RUN: not yaml2obj --docnum=2 %s -o /dev/null -DADDEND=4294967296 2>&1 | FileCheck %s --check-prefix=ERR
109# RUN: not yaml2obj --docnum=2 %s -o /dev/null -DADDEND=0x100000000 2>&1 | FileCheck %s --check-prefix=ERR
110
111## Addend == INT32_MIN - 1.
112# RUN: not yaml2obj --docnum=2 %s -o /dev/null -DADDEND=-2147483649 2>&1 | FileCheck %s --check-prefix=ERR
113
114--- !ELF
115FileHeader:
116  Class:   ELFCLASS32
117  Data:    ELFDATA2LSB
118  Type:    ET_REL
119  Machine: EM_386
120Sections:
121  - Name: .text
122    Type: SHT_PROGBITS
123  - Name: .rela.text
124    Type: SHT_RELA
125    Info: .text
126    Link: .symtab
127    Relocations:
128      - Type:   R_386_PC32
129        Symbol: foo
130        Addend: [[ADDEND]]
131Symbols:
132  - Name: foo
133
134## Case 3: Check we do not allow invalid values.
135# RUN: not yaml2obj %s -D ADDEND=0x1122GGEE 2>&1 | FileCheck %s --check-prefix=ERR
136# RUN: not yaml2obj %s -D ADDEND=-0x1122GGEE 2>&1 | FileCheck %s --check-prefix=ERR
137# RUN: not yaml2obj %s -D ADDEND=1234G5 2>&1 | FileCheck %s --check-prefix=ERR
138# RUN: not yaml2obj %s -D ADDEND=-1234G5 2>&1 | FileCheck %s --check-prefix=ERR
139# RUN: not yaml2obj %s -D ADDEND=foo 2>&1 | FileCheck %s --check-prefix=ERR
140# RUN: not yaml2obj %s -D ADDEND=- 2>&1 | FileCheck %s --check-prefix=ERR
141# RUN: not yaml2obj %s -D ADDEND=--1234 2>&1 | FileCheck %s --check-prefix=ERR
142