Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9a5c333

Browse files
committed
Merging r308978:
------------------------------------------------------------------------ r308978 | fedor.sergeev | 2017-07-25 08:28:28 -0700 (Tue, 25 Jul 2017) | 16 lines [Sparc] invalid adjustments in TLS_LE/TLS_LDO relocations removed Summary: Some SPARC TLS relocations were applying nontrivial adjustments to zero value, leading to unexpected non-zero values in ELF and then Solaris linker failures. Getting rid of these adjustments. Fixes PR33825. Reviewers: rafael, asb, jyknight Subscribers: joerg, jyknight, llvm-commits Differential Revision: https://reviews.llvm.org/D35567 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@309187 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent de90d74 commit 9a5c333

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
6161
case Sparc::fixup_sparc_lo10:
6262
return Value & 0x3ff;
6363

64-
case Sparc::fixup_sparc_tls_ldo_hix22:
65-
case Sparc::fixup_sparc_tls_le_hix22:
66-
return (~Value >> 10) & 0x3fffff;
67-
68-
case Sparc::fixup_sparc_tls_ldo_lox10:
69-
case Sparc::fixup_sparc_tls_le_lox10:
70-
return (~(~Value & 0x3ff)) & 0x1fff;
71-
7264
case Sparc::fixup_sparc_h44:
7365
return (Value >> 22) & 0x3fffff;
7466

@@ -84,6 +76,13 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
8476
case Sparc::fixup_sparc_hm:
8577
return (Value >> 32) & 0x3ff;
8678

79+
case Sparc::fixup_sparc_tls_ldo_hix22:
80+
case Sparc::fixup_sparc_tls_le_hix22:
81+
case Sparc::fixup_sparc_tls_ldo_lox10:
82+
case Sparc::fixup_sparc_tls_le_lox10:
83+
assert(Value == 0 && "Sparc TLS relocs expect zero Value");
84+
return 0;
85+
8786
case Sparc::fixup_sparc_tls_gd_add:
8887
case Sparc::fixup_sparc_tls_gd_call:
8988
case Sparc::fixup_sparc_tls_ldm_add:

test/MC/Sparc/sparc-tls-relocations.s

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
! Testing Sparc TLS relocations emission
2+
! (for now a couple local ones).
3+
!
4+
! RUN: llvm-mc %s -arch=sparc -show-encoding | FileCheck %s --check-prefix=ASM
5+
! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s --check-prefix=ASM
6+
! RUN: llvm-mc %s -arch=sparc -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=REL
7+
! RUN: llvm-mc %s -arch=sparcv9 -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=REL
8+
! RUN: llvm-mc %s -arch=sparc -filetype=obj | llvm-objdump -r -d - | FileCheck %s --check-prefix=OBJDUMP
9+
! RUN: llvm-mc %s -arch=sparcv9 -filetype=obj | llvm-objdump -r -d - | FileCheck %s --check-prefix=OBJDUMP
10+
11+
! REL: Arch: sparc
12+
! REL: Relocations [
13+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LE_HIX22 Head 0x0
14+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LE_LOX10 Head 0x0
15+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LDO_HIX22 Head 0x0
16+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LDM_HI22 Head 0x0
17+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LDM_LO10 Head 0x0
18+
! REL: 0x{{[0-9,A-F]+}} R_SPARC_TLS_LDO_LOX10 Head 0x0
19+
! REL: ]
20+
21+
22+
! OBJDUMP: foo:
23+
foo:
24+
! Here we use two different sequences to get the address of a static TLS variable 'Head'
25+
! (note - there is no intent to have valid assembler function here,
26+
! we just check how TLS relocations are emitted)
27+
!
28+
! First sequence uses LE_HIX22/LE_LOX10
29+
30+
! OBJDUMP: {{[0-9,a-f]+}}: 31 00 00 00 sethi 0, %i0
31+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_HIX22 Unknown
32+
! ASM: sethi %tle_hix22(Head), %i0 ! encoding: [0x31,0x00,0x00,0x00]
33+
! ASM: ! fixup A - offset: 0, value: %tle_hix22(Head), kind: fixup_sparc_tls_le_hix22
34+
sethi %tle_hix22(Head), %i0
35+
36+
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 20 00 xor %i0, 0, %i0
37+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_LOX10 Unknown
38+
! ASM: xor %i0, %tle_lox10(Head), %i0 ! encoding: [0xb0,0x1e,0x20,0x00]
39+
! ASM: ! fixup A - offset: 0, value: %tle_lox10(Head), kind: fixup_sparc_tls_le_lox10
40+
xor %i0, %tle_lox10(Head), %i0
41+
42+
43+
! Second sequence is for PIC, so it is more complicated.
44+
! It uses LDO_HIX22/LDO_LOX10/LDO_ADD/LDM_HI22/LDM_LO10/LDM_ADD/LDM_CALL
45+
46+
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
47+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_HIX22 Unknown
48+
! ASM: sethi %tldo_hix22(Head), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
49+
! ASM: ! fixup A - offset: 0, value: %tldo_hix22(Head), kind: fixup_sparc_tls_ldo_hix22
50+
sethi %tldo_hix22(Head), %i1
51+
52+
! OBJDUMP: {{[0-9,a-f]+}}: 35 00 00 00 sethi 0, %i2
53+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_HI22 Unknown
54+
! ASM: sethi %tldm_hi22(Head), %i2 ! encoding: [0x35,0b00AAAAAA,A,A]
55+
! ASM: ! fixup A - offset: 0, value: %tldm_hi22(Head), kind: fixup_sparc_tls_ldm_hi22
56+
sethi %tldm_hi22(Head), %i2
57+
58+
! OBJDUMP: {{[0-9,a-f]+}}: b4 06 a0 00 add %i2, 0, %i2
59+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_LO10 Unknown
60+
! ASM: add %i2, %tldm_lo10(Head), %i2 ! encoding: [0xb4,0x06,0b101000AA,A]
61+
! ASM: ! fixup A - offset: 0, value: %tldm_lo10(Head), kind: fixup_sparc_tls_ldm_lo10
62+
add %i2, %tldm_lo10(Head), %i2
63+
64+
! ???error from llvm-mc on the next asm line???
65+
! add %i0, %i2, %o0, %tldm_add(Head)
66+
67+
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 60 00 xor %i1, 0, %i0
68+
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_LOX10 Unknown
69+
! ASM: xor %i1, %tldo_lox10(Head), %i0 ! encoding: [0xb0,0x1e,0b011000AA,A]
70+
! ASM: ! fixup A - offset: 0, value: %tldo_lox10(Head), kind: fixup_sparc_tls_ldo_lox10
71+
xor %i1, %tldo_lox10(Head), %i0
72+
73+
! ???error from llvm-mc on the next asm line???
74+
! call __tls_get_addr, %tldm_call(Head)
75+
! nop
76+
! ???error from llvm-mc on the next asm line???
77+
! add %o0, %i0, %i0, %tldo_add(Head)
78+
79+
.type Head,@object
80+
.section .tbss,#alloc,#write,#tls
81+
Head:
82+
.word 0
83+
.size Head, 4

0 commit comments

Comments
 (0)