dwarfdump: Added macro support to llvm-dwarfdump tool.
[oota-llvm.git] / test / MC / Mips / sort-relocation-table.s
1 # RUN: llvm-mc -filetype=obj -arch mipsel %s | llvm-readobj -r | FileCheck %s
2
3 # Test the order of records in the relocation table.
4 # *HI16 and local *GOT16 relocations should be immediately followed by the
5 # corresponding *LO16 relocation against the same symbol.
6 #
7 # We try to implement the same semantics as gas, ie. to order the relocation
8 # table the same way as gas.
9 #
10 # gnu as command line:
11 # mips-linux-gnu-as -EL sort-relocation-table.s -o sort-relocation-table.o
12 #
13 # TODO: Add mips16 and micromips tests.
14 # Note: offsets are part of expected output, so it's simpler to add new test
15 #       cases at the bottom of the file.
16
17 # CHECK:       Relocations [
18 # CHECK-NEXT:  {
19
20 # Put HI before LO.
21 addiu $2,$2,%lo(sym1)
22 lui $2,%hi(sym1)
23
24 # CHECK-NEXT:    0x4 R_MIPS_HI16 sym1
25 # CHECK-NEXT:    0x0 R_MIPS_LO16 sym1
26
27 # When searching for a matching LO, ignore LOs against a different symbol.
28 addiu $2,$2,%lo(sym2)
29 lui $2,%hi(sym2)
30 addiu $2,$2,%lo(sym2_d)
31
32 # CHECK-NEXT:    0xC R_MIPS_HI16 sym2
33 # CHECK-NEXT:    0x8 R_MIPS_LO16 sym2
34 # CHECK-NEXT:    0x10 R_MIPS_LO16 sym2_d
35
36 # Match HI with 2nd LO because it has higher offset (than the 1st LO).
37 addiu $2,$2,%lo(sym3)
38 addiu $2,$2,%lo(sym3)
39 lui $2,%hi(sym3)
40
41 # CHECK-NEXT:    0x14 R_MIPS_LO16 sym3
42 # CHECK-NEXT:    0x1C R_MIPS_HI16 sym3
43 # CHECK-NEXT:    0x18 R_MIPS_LO16 sym3
44
45 # HI is already followed by a matching LO, so don't look further, ie. ignore the
46 # "free" LO with higher offset.
47 lui $2,%hi(sym4)
48 addiu $2,$2,%lo(sym4)
49 addiu $2,$2,%lo(sym4)
50
51 # CHECK-NEXT:    0x20 R_MIPS_HI16 sym4
52 # CHECK-NEXT:    0x24 R_MIPS_LO16 sym4
53 # CHECK-NEXT:    0x28 R_MIPS_LO16 sym4
54
55 # Match 2nd HI with 2nd LO, since it's the one with highest offset among the
56 # "free" ones.
57 addiu $2,$2,%lo(sym5)
58 addiu $2,$2,%lo(sym5)
59 lui $2,%hi(sym5)
60 addiu $2,$2,%lo(sym5)
61 lui $2,%hi(sym5)
62
63 # CHECK-NEXT:    0x2C R_MIPS_LO16 sym5
64 # CHECK-NEXT:    0x3C R_MIPS_HI16 sym5
65 # CHECK-NEXT:    0x30 R_MIPS_LO16 sym5
66 # CHECK-NEXT:    0x34 R_MIPS_HI16 sym5
67 # CHECK-NEXT:    0x38 R_MIPS_LO16 sym5
68
69 # When more HIs are matched with one LO, sort them in descending order of
70 # offset.
71 addiu $2,$2,%lo(sym6)
72 lui $2,%hi(sym6)
73 lui $2,%hi(sym6)
74
75 # CHECK-NEXT:    0x48 R_MIPS_HI16 sym6
76 # CHECK-NEXT:    0x44 R_MIPS_HI16 sym6
77 # CHECK-NEXT:    0x40 R_MIPS_LO16 sym6
78
79 #  sym7 is a local symbol, so GOT relocation against it needs a matching LO.
80 sym7:
81 addiu $2,$2,%lo(sym7)
82 lui $2,%got(sym7)
83
84 # CHECK-NEXT:    0x50 R_MIPS_GOT16 sym7
85 # CHECK-NEXT:    0x4C R_MIPS_LO16 sym7
86
87 # sym8 is not a local symbol, don't look for a matching LO for GOT.
88 .global sym8
89 addiu $2,$2,%lo(sym8)
90 lui $2,%got(sym8)
91
92 # CHECK-NEXT:    0x54 R_MIPS_LO16 sym8
93 # CHECK-NEXT:    0x58 R_MIPS_GOT16 sym8
94
95 # A small combination of previous checks.
96 symc1:
97 addiu $2,$2,%lo(symc1)
98 addiu $2,$2,%lo(symc1)
99 addiu $2,$2,%lo(symc1)
100 lui $2,%hi(symc1)
101 lui $2,%got(symc1)
102 addiu $2,$2,%lo(symc2)
103 lui $2,%hi(symc1)
104 lui $2,%hi(symc1)
105 lui $2,%got(symc2)
106 lui $2,%hi(symc1)
107 addiu $2,$2,%lo(symc1)
108 addiu $2,$2,%lo(symc2)
109 lui $2,%hi(symc1)
110 lui $2,%hi(symc1)
111
112 # CHECK-NEXT:    0x78 R_MIPS_HI16 symc1
113 # CHECK-NEXT:    0x74 R_MIPS_HI16 symc1
114 # CHECK-NEXT:    0x6C R_MIPS_GOT16 symc1
115 # CHECK-NEXT:    0x68 R_MIPS_HI16 symc1
116 # CHECK-NEXT:    0x5C R_MIPS_LO16 symc1
117 # CHECK-NEXT:    0x8C R_MIPS_HI16 symc1
118 # CHECK-NEXT:    0x60 R_MIPS_LO16 symc1
119 # CHECK-NEXT:    0x90 R_MIPS_HI16 symc1
120 # CHECK-NEXT:    0x64 R_MIPS_LO16 symc1
121 # CHECK-NEXT:    0x70 R_MIPS_LO16 symc2
122 # CHECK-NEXT:    0x7C R_MIPS_GOT16 symc2
123 # CHECK-NEXT:    0x80 R_MIPS_HI16 symc1
124 # CHECK-NEXT:    0x84 R_MIPS_LO16 symc1
125 # CHECK-NEXT:    0x88 R_MIPS_LO16 symc2