@@ -12,30 +12,37 @@ RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.so | FileCheck %s --ch
1212## Test the TLSDESC to LE optimization. Also check --emit-relocs.
1313RUN: %link %linkopts -z now --no-align-segments --section-start .text=0x11000 %t.a.o %t.c.o -o %t.a.le --emit-relocs
1414RUN: %readelf --dyn-relocations %t.a.le | FileCheck %s --match-full-lines --allow-empty --check-prefix=LE-REL
15- RUN: %objdump --no-show-raw-insn -M no-aliases -hdr %t.a.le | FileCheck %s --check-prefix=LE --check-prefix=LER
15+ RUN: %objdump --no-show-raw-insn -M no-aliases -hdr %t.a.le | FileCheck %s --check-prefix=LE --check-prefix=LER --check-prefix=LE-RELAX --check-prefix=LER-RELAX
1616
1717RUN: %link %linkopts -z now --no-align-segments --section-start .text=0x11000 %t.aa.o %t.c.o -o %t.aa.le
1818RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.aa.le | FileCheck %s --check-prefix=LEA
1919
2020## Test the TLSDESC to IE optimization.
2121RUN: %link %linkopts -z now --no-align-segments --section-start .text=0x11000 --section-start .got=0x120e0 %t.a.o %t.c.so -o %t.a.ie
2222RUN: %readelf --dyn-relocations %t.a.ie | FileCheck %s --match-full-lines --check-prefix=IE-REL%xlen
23- RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.ie | FileCheck %s --check-prefix=IE --check-prefix=IE%xlen
23+ RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.ie | FileCheck %s --check-prefix=IE --check-prefix=IE%xlen --check-prefix=IE-RELAX --check-prefix=IE%xlen-RELAX
24+
25+ ## Same as above but with --no-relax-tlsdesc, only check assembly output.
26+ RUN: %link %linkopts -z now --no-relax-tlsdesc --no-align-segments --section-start .text=0x11000 %t.a.o %t.c.o -o %t.a.norelax.le --emit-relocs
27+ RUN: %objdump --no-show-raw-insn -M no-aliases -hdr %t.a.norelax.le | FileCheck %s --check-prefix=LE --check-prefix=LER --check-prefix=LE-NORELAX --check-prefix=LER-NORELAX
28+
29+ RUN: %link %linkopts -z now --no-relax-tlsdesc --no-align-segments --section-start .text=0x11000 --section-start .got=0x120e0 %t.a.o %t.c.so -o %t.a.norelax.ie
30+ RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.norelax.ie | FileCheck %s --check-prefix=IE --check-prefix=IE%xlen --check-prefix=IE-NORELAX --check-prefix=IE%xlen-NORELAX
2431
2532## The same tests for executables are repeated with -pie, except for output static relocation checks as --emit-relocs does not work with -pie.
2633
2734## Test the TLSDESC to LE optimization. Also check --emit-relocs.
2835RUN: %link %linkopts -pie -z now --keep-labels --no-align-segments --section-start .text=0x11000 %t.a.o %t.c.o -o %t.a.pie.le --emit-relocs
2936RUN: %readelf --dyn-relocations %t.a.pie.le | FileCheck %s --match-full-lines --allow-empty --check-prefix=LE-REL
30- RUN: %objdump --no-show-raw-insn -M no-aliases -hdr %t.a.pie.le | FileCheck %s --check-prefix=LE
37+ RUN: %objdump --no-show-raw-insn -M no-aliases -hdr %t.a.pie.le | FileCheck %s --check-prefix=LE --check-prefix=LE-RELAX
3138
3239RUN: %link %linkopts -pie -z now --keep-labels --no-align-segments --section-start .text=0x11000 %t.aa.o %t.c.o -o %t.aa.pie.le
3340RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.aa.pie.le | FileCheck %s --check-prefix=LEA
3441
3542## Test the TLSDESC to IE optimization.
3643RUN: %link %linkopts -pie -z now --keep-labels --no-align-segments --section-start .text=0x11000 --section-start .got=0x120e0 %t.a.o %t.c.so -o %t.a.pie.ie
3744RUN: %readelf --dyn-relocations %t.a.pie.ie | FileCheck %s --match-full-lines --check-prefix=IE-REL%xlen
38- RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.pie.ie | FileCheck %s --check-prefix=IE --check-prefix=IE%xlen
45+ RUN: %objdump --no-show-raw-insn -M no-aliases -h -d %t.a.pie.ie | FileCheck %s --check-prefix=IE --check-prefix=IE%xlen --check-prefix=IE-RELAX --check-prefix=IE%xlen-RELAX
3946
4047## .got has 3 additional header slots before the TLS slot.
4148
@@ -92,50 +99,64 @@ GD-NEXT: c.add a0, tp
9299LE-REL-NOT: R_RISCV
93100
94101LE-LABEL: <foo>:
102+ LE-NORELAX-NEXT: addi zero, zero, 0x0
103+ LER-NORELAX-NEXT: R_RISCV_NONE b
104+ LER-NORELAX-NEXT: R_RISCV_RELAX *ABS*
95105LE-NEXT: c.add a7, a7
96106LE-NEXT-LLD: R_RISCV_TLSDESC_HI20 b
107+ LE-NORELAX-NEXT: addi zero, zero, 0x0
97108LER-NEXT: R_RISCV_NONE b
98109LER-NEXT: R_RISCV_RELAX *ABS*
99110LE-NEXT: c.add a7, a7
100111LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi0
112+ LE-NORELAX-NEXT: addi zero, zero, 0x0
101113LER-NEXT: R_RISCV_NONE b
102114LER-NEXT: R_RISCV_RELAX *ABS*
103- LE-NEXT: 11008: c.add a7, a7
104- LE-NEXT-LLD: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi0
105- LER-NEXT: R_RISCV_NONE b
106- LER-NEXT: R_RISCV_RELAX *ABS*
115+ LE-NORELAX-NEXT: 11014: c.add a7, a7
116+ LE-RELAX-NEXT: 11008: c.add a7, a7
117+ LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi0
118+ LER-RELAX-NEXT: R_RISCV_NONE b
119+ LER-RELAX-NEXT: R_RISCV_RELAX *ABS*
120+
107121LE-NEXT: addi a0, zero, 0x7ff
108122LE-NEXT-LLD: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi0
109123LER-NEXT: R_RISCV_LO12_I b
110124LER-NEXT: R_RISCV_RELAX *ABS*
111125LE-NEXT: c.add a0, tp
112126
113127LE-LABEL: <.Ltlsdesc_hi1>:
128+ LE-NORELAX-NEXT: addi zero, zero, 0x0
129+ LER-NORELAX-NEXT: R_RISCV_NONE b
130+ LER-NORELAX-NEXT: R_RISCV_RELAX *ABS*
131+ LE-NORELAX-NEXT: addi zero, zero, 0x0
132+ LER-NORELAX-NEXT: R_RISCV_NONE b
133+ LE-NORELAX-NEXT: addi zero, zero, 0x0
134+ LER-NORELAX-NEXT: R_RISCV_NONE b
114135LE-NEXT: addi a0, zero, 0x7ff
115- LE-NEXT-LLD: R_RISCV_TLSDESC_HI20 b
116- LER-NEXT: R_RISCV_NONE b
117- LER-NEXT: R_RISCV_RELAX *ABS*
118- LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi1
119- LE-NEXT-LLD: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi1
120- LER-NEXT: R_RISCV_NONE b
121- LER-NEXT: R_RISCV_NONE b
122- LE-NEXT-LLD: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi1
136+ LE-NEXT-LLD: R_RISCV_TLSDESC_HI20 b
137+ LER-RELAX- NEXT: R_RISCV_NONE b
138+ LER-RELAX- NEXT: R_RISCV_RELAX *ABS*
139+ LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi1
140+ LE-NEXT-LLD: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi1
141+ LER-RELAX- NEXT: R_RISCV_NONE b
142+ LER-RELAX- NEXT: R_RISCV_NONE b
143+ LE-NEXT-LLD: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi1
123144LER-NEXT: R_RISCV_LO12_I b
124145LE-NEXT: c.add a0, tp
125146LE-LABEL: <.Ltlsdesc_hi2>:
126147LE-NEXT: addi zero, zero, 0x0
127- LER-NEXT-LLD: R_RISCV_TLSDESC_HI20 b
148+ LER-NEXT-LLD: R_RISCV_TLSDESC_HI20 b
128149LER-NEXT: R_RISCV_NONE b
129150LE-NEXT: addi zero, zero, 0x0
130- LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi2
151+ LE-NEXT-LLD: R_RISCV_TLSDESC_LOAD_LO12 .Ltlsdesc_hi2
131152LER-NEXT: R_RISCV_NONE b
132153LER-NEXT: R_RISCV_RELAX *ABS*
133154LE-NEXT: addi zero, zero, 0x0
134- LE-NEXT-LLD: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi2
155+ LE-NEXT-LLD: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi2
135156LER-NEXT: R_RISCV_NONE b
136157LER-NEXT: R_RISCV_RELAX *ABS*
137158LE-NEXT: addi a0, zero, 0x7ff
138- LE-NEXT-LLD: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi2
159+ LE-NEXT-LLD: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi2
139160LER-NEXT: R_RISCV_LO12_I b
140161LE-NEXT: c.add a0, tp
141162
@@ -165,29 +186,42 @@ IE-REL4: {{0*}}120e4 {{0*}}010a R_RISCV_TLS_TPREL32 {{0+}} b + 0
165186IE-REL8: {{0*}}120e8 {{0*}}010000000b R_RISCV_TLS_TPREL64 {{0+}} b + 0
166187
167188IE-LABEL: <foo>:
189+ IE-NORELAX-NEXT: addi zero, zero, 0x0
168190IE-NEXT: c.add a7, a7
191+ IE-NORELAX-NEXT: addi zero, zero, 0x0
169192IE-NEXT: c.add a7, a7
170- ## &.got[c]-. = 0x120e4 - 0x11008 = 0x10dc
171- ## &.got[c]-. = 0x120e8 - 0x11008 = 0x10e0
172- IE-NEXT: 11008: auipc a0, 0x1
193+ ## &.got[c]-. = 0x120e4 - 0x11008 = 0x10dc (8 bytes less if previous nops are not relaxed)
194+ ## &.got[c]-. = 0x120e8 - 0x11008 = 0x10e0 (8 bytes less if previous nops are not relaxed)
195+ IE-NORELAX-NEXT: 11010: auipc a0, 0x1
196+ IE-RELAX-NEXT: 11008: auipc a0, 0x1
173197IE-NEXT: c.add a7, a7
174- IE4-NEXT: lw a0, 0xdc(a0)
175- IE8-NEXT: ld a0, 0xe0(a0)
198+ IE4-NORELAX-NEXT: lw a0, 0xd4(a0)
199+ IE4-RELAX-NEXT: lw a0, 0xdc(a0)
200+ IE8-NORELAX-NEXT: ld a0, 0xd8(a0)
201+ IE8-RELAX-NEXT: ld a0, 0xe0(a0)
176202IE-NEXT: c.add a0, tp
177203
178204IE-LABEL: <.Ltlsdesc_hi1>:
179- ## &.got[c]-. = 0x120e4 - 0x11018 = 0x10cc
180- ## &.got[c]-. = 0x120e8 - 0x11018 = 0x10d0
181- IE-NEXT: 11018: auipc a0, 0x1
182- IE4-NEXT: lw a0, 0xcc(a0)
183- IE8-NEXT: ld a0, 0xd0(a0)
205+ ## &.got[c]-. = 0x120e4 - 0x11018 = 0x10cc (16 bytes less if previous nops are not relaxed)
206+ ## &.got[c]-. = 0x120e8 - 0x11018 = 0x10d0 (16 bytes less if previous nops are not relaxed)
207+ IE-NORELAX-NEXT: addi zero, zero, 0x0
208+ IE-NORELAX-NEXT: addi zero, zero, 0x0
209+ IE-NORELAX-NEXT: 11028: auipc a0, 0x1
210+ IE-RELAX-NEXT: 11018: auipc a0, 0x1
211+ IE4-NORELAX-NEXT: lw a0, 0xbc(a0)
212+ IE4-RELAX-NEXT: lw a0, 0xcc(a0)
213+ IE8-NORELAX-NEXT: ld a0, 0xc0(a0)
214+ IE8-RELAX-NEXT: ld a0, 0xd0(a0)
184215IE-NEXT: c.add a0, tp
185- ## &.got[c]-. = 0x120e4 - 0x1102a = 0x10ba
186- ## &.got[c]-. = 0x120e8 - 0x1102a = 0x10be
216+ ## &.got[c]-. = 0x120e4 - 0x1102a = 0x10ba (16 bytes less if previous nops are not relaxed)
217+ ## &.got[c]-. = 0x120e8 - 0x1102a = 0x10be (16 bytes less if previous nops are not relaxed)
187218IE-LABEL: <.Ltlsdesc_hi2>:
188219IE-NEXT: addi zero, zero, 0x0
189220IE-NEXT: addi zero, zero, 0x0
190- IE-NEXT: 1102a: auipc a0, 0x1
191- IE4-NEXT: lw a0, 0xba(a0)
192- IE8-NEXT: ld a0, 0xbe(a0)
221+ IE-NORELAX-NEXT: 1103a: auipc a0, 0x1
222+ IE-RELAX-NEXT: 1102a: auipc a0, 0x1
223+ IE4-NORELAX-NEXT: lw a0, 0xaa(a0)
224+ IE4-RELAX-NEXT: lw a0, 0xba(a0)
225+ IE8-NORELAX-NEXT: ld a0, 0xae(a0)
226+ IE8-RELAX-NEXT: ld a0, 0xbe(a0)
193227IE-NEXT: c.add a0, tp
0 commit comments