Skip to content

Commit 7607ad6

Browse files
committed
Refactor
1 parent eab8217 commit 7607ad6

File tree

1 file changed

+124
-132
lines changed

1 file changed

+124
-132
lines changed

src/arch-x86-64.cc

Lines changed: 124 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -157,134 +157,134 @@ static u32 relax_rex_gotpcrelx(u8 *loc) {
157157
return 0;
158158
}
159159

160-
static u32 relax_gottpoff(u8 *loc) {
161-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
162-
case 0x488b05: return 0x48c7c0; // mov 0(%rip), %rax -> mov $0, %rax
163-
case 0x488b0d: return 0x48c7c1; // mov 0(%rip), %rcx -> mov $0, %rcx
164-
case 0x488b15: return 0x48c7c2; // mov 0(%rip), %rdx -> mov $0, %rdx
165-
case 0x488b1d: return 0x48c7c3; // mov 0(%rip), %rbx -> mov $0, %rbx
166-
case 0x488b25: return 0x48c7c4; // mov 0(%rip), %rsp -> mov $0, %rsp
167-
case 0x488b2d: return 0x48c7c5; // mov 0(%rip), %rbp -> mov $0, %rbp
168-
case 0x488b35: return 0x48c7c6; // mov 0(%rip), %rsi -> mov $0, %rsi
169-
case 0x488b3d: return 0x48c7c7; // mov 0(%rip), %rdi -> mov $0, %rdi
170-
case 0x4c8b05: return 0x49c7c0; // mov 0(%rip), %r8 -> mov $0, %r8
171-
case 0x4c8b0d: return 0x49c7c1; // mov 0(%rip), %r9 -> mov $0, %r9
172-
case 0x4c8b15: return 0x49c7c2; // mov 0(%rip), %r10 -> mov $0, %r10
173-
case 0x4c8b1d: return 0x49c7c3; // mov 0(%rip), %r11 -> mov $0, %r11
174-
case 0x4c8b25: return 0x49c7c4; // mov 0(%rip), %r12 -> mov $0, %r12
175-
case 0x4c8b2d: return 0x49c7c5; // mov 0(%rip), %r13 -> mov $0, %r13
176-
case 0x4c8b35: return 0x49c7c6; // mov 0(%rip), %r14 -> mov $0, %r14
177-
case 0x4c8b3d: return 0x49c7c7; // mov 0(%rip), %r15 -> mov $0, %r15
178-
}
179-
return 0;
180-
}
181-
182-
static u32 relax_rex2_gottpoff(u8 *loc) {
183-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
184-
case 0x488b05: return 0x18c7c0; // mov 0x0(%rip), %r16 -> mov $0, %r16
185-
case 0x488b0d: return 0x18c7c1; // mov 0x0(%rip), %r17 -> mov $0, %r17
186-
case 0x488b15: return 0x18c7c2; // mov 0x0(%rip), %r18 -> mov $0, %r18
187-
case 0x488b1d: return 0x18c7c3; // mov 0x0(%rip), %r19 -> mov $0, %r19
188-
case 0x488b25: return 0x18c7c4; // mov 0x0(%rip), %r20 -> mov $0, %r20
189-
case 0x488b2d: return 0x18c7c5; // mov 0x0(%rip), %r21 -> mov $0, %r21
190-
case 0x488b35: return 0x18c7c6; // mov 0x0(%rip), %r22 -> mov $0, %r22
191-
case 0x488b3d: return 0x18c7c7; // mov 0x0(%rip), %r23 -> mov $0, %r23
192-
case 0x4c8b05: return 0x19c7c0; // mov 0x0(%rip), %r24 -> mov $0, %r24
193-
case 0x4c8b0d: return 0x19c7c1; // mov 0x0(%rip), %r25 -> mov $0, %r25
194-
case 0x4c8b15: return 0x19c7c2; // mov 0x0(%rip), %r26 -> mov $0, %r26
195-
case 0x4c8b1d: return 0x19c7c3; // mov 0x0(%rip), %r27 -> mov $0, %r27
196-
case 0x4c8b25: return 0x19c7c4; // mov 0x0(%rip), %r28 -> mov $0, %r28
197-
case 0x4c8b2d: return 0x19c7c5; // mov 0x0(%rip), %r29 -> mov $0, %r29
198-
case 0x4c8b35: return 0x19c7c6; // mov 0x0(%rip), %r30 -> mov $0, %r30
199-
case 0x4c8b3d: return 0x19c7c7; // mov 0x0(%rip), %r31 -> mov $0, %r31
200-
}
201-
return 0;
202-
}
203-
204-
static u32 relax_tlsdesc_to_ie(u8 *loc) {
205-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
206-
case 0x488d05: return 0x488b05; // lea 0(%rip), %rax -> mov 0(%rip), %rax
207-
case 0x488d0d: return 0x488b0d; // lea 0(%rip), %rcx -> mov 0(%rip), %rcx
208-
case 0x488d15: return 0x488b15; // lea 0(%rip), %rdx -> mov 0(%rip), %rdx
209-
case 0x488d1d: return 0x488b1d; // lea 0(%rip), %rbx -> mov 0(%rip), %rbx
210-
case 0x488d25: return 0x488b25; // lea 0(%rip), %rsp -> mov 0(%rip), %rsp
211-
case 0x488d2d: return 0x488b2d; // lea 0(%rip), %rbp -> mov 0(%rip), %rbp
212-
case 0x488d35: return 0x488b35; // lea 0(%rip), %rsi -> mov 0(%rip), %rsi
213-
case 0x488d3d: return 0x488b3d; // lea 0(%rip), %rdi -> mov 0(%rip), %rdi
214-
case 0x4c8d05: return 0x4c8b05; // lea 0(%rip), %r8 -> mov 0(%rip), %r8
215-
case 0x4c8d0d: return 0x4c8b0d; // lea 0(%rip), %r9 -> mov 0(%rip), %r9
216-
case 0x4c8d15: return 0x4c8b15; // lea 0(%rip), %r10 -> mov 0(%rip), %r10
217-
case 0x4c8d1d: return 0x4c8b1d; // lea 0(%rip), %r11 -> mov 0(%rip), %r11
218-
case 0x4c8d25: return 0x4c8b25; // lea 0(%rip), %r12 -> mov 0(%rip), %r12
219-
case 0x4c8d2d: return 0x4c8b2d; // lea 0(%rip), %r13 -> mov 0(%rip), %r13
220-
case 0x4c8d35: return 0x4c8b35; // lea 0(%rip), %r14 -> mov 0(%rip), %r14
221-
case 0x4c8d3d: return 0x4c8b3d; // lea 0(%rip), %r15 -> mov 0(%rip), %r15
222-
}
223-
return 0;
224-
}
225-
226-
static u32 relax_rex2_tlsdesc_to_ie(u8 *loc) {
227-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
228-
case 0x488d05: return 0x488b05; // lea 0(%rip), %r16 -> mov 0(%rip), %r16
229-
case 0x488d0d: return 0x488b0d; // lea 0(%rip), %r17 -> mov 0(%rip), %r17
230-
case 0x488d15: return 0x488b15; // lea 0(%rip), %r18 -> mov 0(%rip), %r18
231-
case 0x488d1d: return 0x488b1d; // lea 0(%rip), %r19 -> mov 0(%rip), %r19
232-
case 0x488d25: return 0x488b25; // lea 0(%rip), %r20 -> mov 0(%rip), %r20
233-
case 0x488d2d: return 0x488b2d; // lea 0(%rip), %r21 -> mov 0(%rip), %r21
234-
case 0x488d35: return 0x488b35; // lea 0(%rip), %r22 -> mov 0(%rip), %r22
235-
case 0x488d3d: return 0x488b3d; // lea 0(%rip), %r23 -> mov 0(%rip), %r23
236-
case 0x4c8d05: return 0x4c8b05; // lea 0(%rip), %r24 -> mov 0(%rip), %r24
237-
case 0x4c8d0d: return 0x4c8b0d; // lea 0(%rip), %r25 -> mov 0(%rip), %r25
238-
case 0x4c8d15: return 0x4c8b15; // lea 0(%rip), %r26 -> mov 0(%rip), %r26
239-
case 0x4c8d1d: return 0x4c8b1d; // lea 0(%rip), %r27 -> mov 0(%rip), %r27
240-
case 0x4c8d25: return 0x4c8b25; // lea 0(%rip), %r28 -> mov 0(%rip), %r28
241-
case 0x4c8d2d: return 0x4c8b2d; // lea 0(%rip), %r29 -> mov 0(%rip), %r29
242-
case 0x4c8d35: return 0x4c8b35; // lea 0(%rip), %r30 -> mov 0(%rip), %r30
243-
case 0x4c8d3d: return 0x4c8b3d; // lea 0(%rip), %r31 -> mov 0(%rip), %r31
160+
static u32 relax_gottpoff(u8 *loc, u32 r_type) {
161+
if (r_type == R_X86_64_GOTTPOFF) {
162+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
163+
case 0x488b05: return 0x48c7c0; // mov 0(%rip), %rax -> mov $0, %rax
164+
case 0x488b0d: return 0x48c7c1; // mov 0(%rip), %rcx -> mov $0, %rcx
165+
case 0x488b15: return 0x48c7c2; // mov 0(%rip), %rdx -> mov $0, %rdx
166+
case 0x488b1d: return 0x48c7c3; // mov 0(%rip), %rbx -> mov $0, %rbx
167+
case 0x488b25: return 0x48c7c4; // mov 0(%rip), %rsp -> mov $0, %rsp
168+
case 0x488b2d: return 0x48c7c5; // mov 0(%rip), %rbp -> mov $0, %rbp
169+
case 0x488b35: return 0x48c7c6; // mov 0(%rip), %rsi -> mov $0, %rsi
170+
case 0x488b3d: return 0x48c7c7; // mov 0(%rip), %rdi -> mov $0, %rdi
171+
case 0x4c8b05: return 0x49c7c0; // mov 0(%rip), %r8 -> mov $0, %r8
172+
case 0x4c8b0d: return 0x49c7c1; // mov 0(%rip), %r9 -> mov $0, %r9
173+
case 0x4c8b15: return 0x49c7c2; // mov 0(%rip), %r10 -> mov $0, %r10
174+
case 0x4c8b1d: return 0x49c7c3; // mov 0(%rip), %r11 -> mov $0, %r11
175+
case 0x4c8b25: return 0x49c7c4; // mov 0(%rip), %r12 -> mov $0, %r12
176+
case 0x4c8b2d: return 0x49c7c5; // mov 0(%rip), %r13 -> mov $0, %r13
177+
case 0x4c8b35: return 0x49c7c6; // mov 0(%rip), %r14 -> mov $0, %r14
178+
case 0x4c8b3d: return 0x49c7c7; // mov 0(%rip), %r15 -> mov $0, %r15
179+
}
180+
} else {
181+
assert(r_type == R_X86_64_CODE_4_GOTTPOFF);
182+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
183+
case 0x488b05: return 0x18c7c0; // mov 0(%rip), %r16 -> mov $0, %r16
184+
case 0x488b0d: return 0x18c7c1; // mov 0(%rip), %r17 -> mov $0, %r17
185+
case 0x488b15: return 0x18c7c2; // mov 0(%rip), %r18 -> mov $0, %r18
186+
case 0x488b1d: return 0x18c7c3; // mov 0(%rip), %r19 -> mov $0, %r19
187+
case 0x488b25: return 0x18c7c4; // mov 0(%rip), %r20 -> mov $0, %r20
188+
case 0x488b2d: return 0x18c7c5; // mov 0(%rip), %r21 -> mov $0, %r21
189+
case 0x488b35: return 0x18c7c6; // mov 0(%rip), %r22 -> mov $0, %r22
190+
case 0x488b3d: return 0x18c7c7; // mov 0(%rip), %r23 -> mov $0, %r23
191+
case 0x4c8b05: return 0x19c7c0; // mov 0(%rip), %r24 -> mov $0, %r24
192+
case 0x4c8b0d: return 0x19c7c1; // mov 0(%rip), %r25 -> mov $0, %r25
193+
case 0x4c8b15: return 0x19c7c2; // mov 0(%rip), %r26 -> mov $0, %r26
194+
case 0x4c8b1d: return 0x19c7c3; // mov 0(%rip), %r27 -> mov $0, %r27
195+
case 0x4c8b25: return 0x19c7c4; // mov 0(%rip), %r28 -> mov $0, %r28
196+
case 0x4c8b2d: return 0x19c7c5; // mov 0(%rip), %r29 -> mov $0, %r29
197+
case 0x4c8b35: return 0x19c7c6; // mov 0(%rip), %r30 -> mov $0, %r30
198+
case 0x4c8b3d: return 0x19c7c7; // mov 0(%rip), %r31 -> mov $0, %r31
199+
}
244200
}
245201
return 0;
246202
}
247203

248-
static u32 relax_tlsdesc_to_le(u8 *loc) {
249-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
250-
case 0x488d05: return 0x48c7c0; // lea 0(%rip), %rax -> mov $0, %rax
251-
case 0x488d0d: return 0x48c7c1; // lea 0(%rip), %rcx -> mov $0, %rcx
252-
case 0x488d15: return 0x48c7c2; // lea 0(%rip), %rdx -> mov $0, %rdx
253-
case 0x488d1d: return 0x48c7c3; // lea 0(%rip), %rbx -> mov $0, %rbx
254-
case 0x488d25: return 0x48c7c4; // lea 0(%rip), %rsp -> mov $0, %rsp
255-
case 0x488d2d: return 0x48c7c5; // lea 0(%rip), %rbp -> mov $0, %rbp
256-
case 0x488d35: return 0x48c7c6; // lea 0(%rip), %rsi -> mov $0, %rsi
257-
case 0x488d3d: return 0x48c7c7; // lea 0(%rip), %rdi -> mov $0, %rdi
258-
case 0x4c8d05: return 0x49c7c0; // lea 0(%rip), %r8 -> mov $0, %r8
259-
case 0x4c8d0d: return 0x49c7c1; // lea 0(%rip), %r9 -> mov $0, %r9
260-
case 0x4c8d15: return 0x49c7c2; // lea 0(%rip), %r10 -> mov $0, %r10
261-
case 0x4c8d1d: return 0x49c7c3; // lea 0(%rip), %r11 -> mov $0, %r11
262-
case 0x4c8d25: return 0x49c7c4; // lea 0(%rip), %r12 -> mov $0, %r12
263-
case 0x4c8d2d: return 0x49c7c5; // lea 0(%rip), %r13 -> mov $0, %r13
264-
case 0x4c8d35: return 0x49c7c6; // lea 0(%rip), %r14 -> mov $0, %r14
265-
case 0x4c8d3d: return 0x49c7c7; // lea 0(%rip), %r15 -> mov $0, %r15
204+
static u32 relax_tlsdesc_to_ie(u8 *loc, u32 r_type) {
205+
if (r_type == R_X86_64_GOTPC32_TLSDESC) {
206+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
207+
case 0x488d05: return 0x488b05; // lea 0(%rip), %rax -> mov 0(%rip), %rax
208+
case 0x488d0d: return 0x488b0d; // lea 0(%rip), %rcx -> mov 0(%rip), %rcx
209+
case 0x488d15: return 0x488b15; // lea 0(%rip), %rdx -> mov 0(%rip), %rdx
210+
case 0x488d1d: return 0x488b1d; // lea 0(%rip), %rbx -> mov 0(%rip), %rbx
211+
case 0x488d25: return 0x488b25; // lea 0(%rip), %rsp -> mov 0(%rip), %rsp
212+
case 0x488d2d: return 0x488b2d; // lea 0(%rip), %rbp -> mov 0(%rip), %rbp
213+
case 0x488d35: return 0x488b35; // lea 0(%rip), %rsi -> mov 0(%rip), %rsi
214+
case 0x488d3d: return 0x488b3d; // lea 0(%rip), %rdi -> mov 0(%rip), %rdi
215+
case 0x4c8d05: return 0x4c8b05; // lea 0(%rip), %r8 -> mov 0(%rip), %r8
216+
case 0x4c8d0d: return 0x4c8b0d; // lea 0(%rip), %r9 -> mov 0(%rip), %r9
217+
case 0x4c8d15: return 0x4c8b15; // lea 0(%rip), %r10 -> mov 0(%rip), %r10
218+
case 0x4c8d1d: return 0x4c8b1d; // lea 0(%rip), %r11 -> mov 0(%rip), %r11
219+
case 0x4c8d25: return 0x4c8b25; // lea 0(%rip), %r12 -> mov 0(%rip), %r12
220+
case 0x4c8d2d: return 0x4c8b2d; // lea 0(%rip), %r13 -> mov 0(%rip), %r13
221+
case 0x4c8d35: return 0x4c8b35; // lea 0(%rip), %r14 -> mov 0(%rip), %r14
222+
case 0x4c8d3d: return 0x4c8b3d; // lea 0(%rip), %r15 -> mov 0(%rip), %r15
223+
}
224+
} else {
225+
assert(r_type == R_X86_64_CODE_4_GOTPC32_TLSDESC);
226+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
227+
case 0x488d05: return 0x488b05; // lea 0(%rip), %r16 -> mov 0(%rip), %r16
228+
case 0x488d0d: return 0x488b0d; // lea 0(%rip), %r17 -> mov 0(%rip), %r17
229+
case 0x488d15: return 0x488b15; // lea 0(%rip), %r18 -> mov 0(%rip), %r18
230+
case 0x488d1d: return 0x488b1d; // lea 0(%rip), %r19 -> mov 0(%rip), %r19
231+
case 0x488d25: return 0x488b25; // lea 0(%rip), %r20 -> mov 0(%rip), %r20
232+
case 0x488d2d: return 0x488b2d; // lea 0(%rip), %r21 -> mov 0(%rip), %r21
233+
case 0x488d35: return 0x488b35; // lea 0(%rip), %r22 -> mov 0(%rip), %r22
234+
case 0x488d3d: return 0x488b3d; // lea 0(%rip), %r23 -> mov 0(%rip), %r23
235+
case 0x4c8d05: return 0x4c8b05; // lea 0(%rip), %r24 -> mov 0(%rip), %r24
236+
case 0x4c8d0d: return 0x4c8b0d; // lea 0(%rip), %r25 -> mov 0(%rip), %r25
237+
case 0x4c8d15: return 0x4c8b15; // lea 0(%rip), %r26 -> mov 0(%rip), %r26
238+
case 0x4c8d1d: return 0x4c8b1d; // lea 0(%rip), %r27 -> mov 0(%rip), %r27
239+
case 0x4c8d25: return 0x4c8b25; // lea 0(%rip), %r28 -> mov 0(%rip), %r28
240+
case 0x4c8d2d: return 0x4c8b2d; // lea 0(%rip), %r29 -> mov 0(%rip), %r29
241+
case 0x4c8d35: return 0x4c8b35; // lea 0(%rip), %r30 -> mov 0(%rip), %r30
242+
case 0x4c8d3d: return 0x4c8b3d; // lea 0(%rip), %r31 -> mov 0(%rip), %r31
243+
}
266244
}
267245
return 0;
268246
}
269247

270-
static u32 relax_rex2_tlsdesc_to_le(u8 *loc) {
271-
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
272-
case 0x488d05: return 0x18c7c0; // lea 0(%rip), %r16 -> mov $0, %r16
273-
case 0x488d0d: return 0x18c7c1; // lea 0(%rip), %r17 -> mov $0, %r17
274-
case 0x488d15: return 0x18c7c2; // lea 0(%rip), %r18 -> mov $0, %r18
275-
case 0x488d1d: return 0x18c7c3; // lea 0(%rip), %r19 -> mov $0, %r19
276-
case 0x488d25: return 0x18c7c4; // lea 0(%rip), %r20 -> mov $0, %r20
277-
case 0x488d2d: return 0x18c7c5; // lea 0(%rip), %r21 -> mov $0, %r21
278-
case 0x488d35: return 0x18c7c6; // lea 0(%rip), %r22 -> mov $0, %r22
279-
case 0x488d3d: return 0x18c7c7; // lea 0(%rip), %r23 -> mov $0, %r23
280-
case 0x4c8d05: return 0x19c7c0; // lea 0(%rip), %r24 -> mov $0, %r24
281-
case 0x4c8d0d: return 0x19c7c1; // lea 0(%rip), %r25 -> mov $0, %r25
282-
case 0x4c8d15: return 0x19c7c2; // lea 0(%rip), %r26 -> mov $0, %r26
283-
case 0x4c8d1d: return 0x19c7c3; // lea 0(%rip), %r27 -> mov $0, %r27
284-
case 0x4c8d25: return 0x19c7c4; // lea 0(%rip), %r28 -> mov $0, %r28
285-
case 0x4c8d2d: return 0x19c7c5; // lea 0(%rip), %r29 -> mov $0, %r29
286-
case 0x4c8d35: return 0x19c7c6; // lea 0(%rip), %r30 -> mov $0, %r30
287-
case 0x4c8d3d: return 0x19c7c7; // lea 0(%rip), %r31 -> mov $0, %r31
248+
static u32 relax_tlsdesc_to_le(u8 *loc, u32 r_type) {
249+
if (r_type == R_X86_64_GOTPC32_TLSDESC) {
250+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
251+
case 0x488d05: return 0x48c7c0; // lea 0(%rip), %rax -> mov $0, %rax
252+
case 0x488d0d: return 0x48c7c1; // lea 0(%rip), %rcx -> mov $0, %rcx
253+
case 0x488d15: return 0x48c7c2; // lea 0(%rip), %rdx -> mov $0, %rdx
254+
case 0x488d1d: return 0x48c7c3; // lea 0(%rip), %rbx -> mov $0, %rbx
255+
case 0x488d25: return 0x48c7c4; // lea 0(%rip), %rsp -> mov $0, %rsp
256+
case 0x488d2d: return 0x48c7c5; // lea 0(%rip), %rbp -> mov $0, %rbp
257+
case 0x488d35: return 0x48c7c6; // lea 0(%rip), %rsi -> mov $0, %rsi
258+
case 0x488d3d: return 0x48c7c7; // lea 0(%rip), %rdi -> mov $0, %rdi
259+
case 0x4c8d05: return 0x49c7c0; // lea 0(%rip), %r8 -> mov $0, %r8
260+
case 0x4c8d0d: return 0x49c7c1; // lea 0(%rip), %r9 -> mov $0, %r9
261+
case 0x4c8d15: return 0x49c7c2; // lea 0(%rip), %r10 -> mov $0, %r10
262+
case 0x4c8d1d: return 0x49c7c3; // lea 0(%rip), %r11 -> mov $0, %r11
263+
case 0x4c8d25: return 0x49c7c4; // lea 0(%rip), %r12 -> mov $0, %r12
264+
case 0x4c8d2d: return 0x49c7c5; // lea 0(%rip), %r13 -> mov $0, %r13
265+
case 0x4c8d35: return 0x49c7c6; // lea 0(%rip), %r14 -> mov $0, %r14
266+
case 0x4c8d3d: return 0x49c7c7; // lea 0(%rip), %r15 -> mov $0, %r15
267+
}
268+
} else {
269+
assert(r_type == R_X86_64_CODE_4_GOTPC32_TLSDESC);
270+
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
271+
case 0x488d05: return 0x18c7c0; // lea 0(%rip), %r16 -> mov $0, %r16
272+
case 0x488d0d: return 0x18c7c1; // lea 0(%rip), %r17 -> mov $0, %r17
273+
case 0x488d15: return 0x18c7c2; // lea 0(%rip), %r18 -> mov $0, %r18
274+
case 0x488d1d: return 0x18c7c3; // lea 0(%rip), %r19 -> mov $0, %r19
275+
case 0x488d25: return 0x18c7c4; // lea 0(%rip), %r20 -> mov $0, %r20
276+
case 0x488d2d: return 0x18c7c5; // lea 0(%rip), %r21 -> mov $0, %r21
277+
case 0x488d35: return 0x18c7c6; // lea 0(%rip), %r22 -> mov $0, %r22
278+
case 0x488d3d: return 0x18c7c7; // lea 0(%rip), %r23 -> mov $0, %r23
279+
case 0x4c8d05: return 0x19c7c0; // lea 0(%rip), %r24 -> mov $0, %r24
280+
case 0x4c8d0d: return 0x19c7c1; // lea 0(%rip), %r25 -> mov $0, %r25
281+
case 0x4c8d15: return 0x19c7c2; // lea 0(%rip), %r26 -> mov $0, %r26
282+
case 0x4c8d1d: return 0x19c7c3; // lea 0(%rip), %r27 -> mov $0, %r27
283+
case 0x4c8d25: return 0x19c7c4; // lea 0(%rip), %r28 -> mov $0, %r28
284+
case 0x4c8d2d: return 0x19c7c5; // lea 0(%rip), %r29 -> mov $0, %r29
285+
case 0x4c8d35: return 0x19c7c6; // lea 0(%rip), %r30 -> mov $0, %r30
286+
case 0x4c8d3d: return 0x19c7c7; // lea 0(%rip), %r31 -> mov $0, %r31
287+
}
288288
}
289289
return 0;
290290
}
@@ -580,8 +580,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
580580
if (sym.has_gottp(ctx)) {
581581
write32s(sym.get_gottp_addr(ctx) + A - P);
582582
} else {
583-
u32 insn = (rel.r_type == R_X86_64_GOTTPOFF) ?
584-
relax_gottpoff(loc - 3) : relax_rex2_gottpoff(loc - 3);
583+
u32 insn = relax_gottpoff(loc - 3, rel.r_type);
585584
loc[-3] = insn >> 16;
586585
loc[-2] = insn >> 8;
587586
loc[-1] = insn;
@@ -624,17 +623,15 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
624623
if (sym.has_tlsdesc(ctx)) {
625624
write32s(sym.get_tlsdesc_addr(ctx) + A - P);
626625
} else if (sym.has_gottp(ctx)) {
627-
u32 insn = (rel.r_type == R_X86_64_GOTPC32_TLSDESC) ?
628-
relax_tlsdesc_to_ie(loc - 3) : relax_rex2_tlsdesc_to_ie(loc - 3);
626+
u32 insn = relax_tlsdesc_to_ie(loc - 3, rel.r_type);
629627
if (!insn)
630628
Fatal(ctx) << *this << ": illegal instruction sequence for TLSDESC";
631629
loc[-3] = insn >> 16;
632630
loc[-2] = insn >> 8;
633631
loc[-1] = insn;
634632
write32s(sym.get_gottp_addr(ctx) + A - P);
635633
} else {
636-
u32 insn = (rel.r_type == R_X86_64_GOTPC32_TLSDESC) ?
637-
relax_tlsdesc_to_le(loc - 3) : relax_rex2_tlsdesc_to_le(loc - 3);
634+
u32 insn = relax_tlsdesc_to_le(loc - 3, rel.r_type);
638635
if (!insn)
639636
Fatal(ctx) << *this << ": illegal instruction sequence for TLSDESC";
640637
loc[-3] = insn >> 16;
@@ -853,17 +850,12 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
853850
ctx.needs_tlsld = true;
854851
break;
855852
case R_X86_64_GOTTPOFF:
856-
if (!ctx.arg.relax || !sym.is_tprel_linktime_const(ctx) ||
857-
!relax_gottpoff(loc - 3))
858-
sym.flags |= NEEDS_GOTTP;
859-
break;
860853
case R_X86_64_CODE_4_GOTTPOFF:
861854
if (!ctx.arg.relax || !sym.is_tprel_linktime_const(ctx) ||
862-
!relax_rex2_gottpoff(loc - 3))
855+
!relax_gottpoff(loc - 3, rel.r_type))
863856
sym.flags |= NEEDS_GOTTP;
864857
break;
865858
case R_X86_64_CODE_6_GOTTPOFF:
866-
// Relaxation of this relocation type is not suported yet
867859
sym.flags |= NEEDS_GOTTP;
868860
break;
869861
case R_X86_64_TLSDESC_CALL:

0 commit comments

Comments
 (0)