Index: lld/ELF/Arch/SPARCV9.cpp =================================================================== --- lld/ELF/Arch/SPARCV9.cpp +++ lld/ELF/Arch/SPARCV9.cpp @@ -114,11 +114,15 @@ break; case R_SPARC_GOT22: case R_SPARC_PC22: - case R_SPARC_HI22: case R_SPARC_LM22: // T-imm22 write32be(loc, (read32be(loc) & ~0x003fffff) | ((val >> 10) & 0x003fffff)); break; + case R_SPARC_HI22: + // V-imm22 + checkUInt(loc, val >> 10, 22, rel); + write32be(loc, (read32be(loc) & ~0x003fffff) | ((val >> 10) & 0x003fffff)); + break; case R_SPARC_WDISP19: // V-disp19 checkInt(loc, val, 21, rel); @@ -126,10 +130,13 @@ break; case R_SPARC_GOT10: case R_SPARC_PC10: - case R_SPARC_LO10: // T-simm10 write32be(loc, (read32be(loc) & ~0x000003ff) | (val & 0x000003ff)); break; + case R_SPARC_LO10: + // T-simm13 + write32be(loc, (read32be(loc) & ~0x00001fff) | (val & 0x000003ff)); + break; case R_SPARC_64: case R_SPARC_UA64: // V-xword64 @@ -137,6 +144,7 @@ break; case R_SPARC_HH22: // V-imm22 + checkUInt(loc, val >> 42, 22, rel); write32be(loc, (read32be(loc) & ~0x003fffff) | ((val >> 42) & 0x003fffff)); break; case R_SPARC_HM10: @@ -145,6 +153,7 @@ break; case R_SPARC_H44: // V-imm22 + checkUInt(loc, val >> 22, 22, rel); write32be(loc, (read32be(loc) & ~0x003fffff) | ((val >> 22) & 0x003fffff)); break; case R_SPARC_M44: @@ -153,7 +162,7 @@ break; case R_SPARC_L44: // T-imm13 - write32be(loc, (read32be(loc) & ~0x00000fff) | (val & 0x00000fff)); + write32be(loc, (read32be(loc) & ~0x00001fff) | (val & 0x00000fff)); break; case R_SPARC_TLS_LE_HIX22: // T-imm22 Index: lld/test/ELF/sparcv9-reloc.s =================================================================== --- /dev/null +++ lld/test/ELF/sparcv9-reloc.s @@ -0,0 +1,39 @@ +# REQUIRES: sparc +# RUN: llvm-mc -filetype=obj -triple=sparcv9 %s -o %t.o +# RUN: ld.lld %t.o --defsym=a=0x0123456789ABCDEF --defsym=b=0x0123456789A --defsym=c=0x01234567 -o %t +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s +# RUN: llvm-objdump -s --no-show-raw-insn %t | FileCheck --check-prefix=HEX %s + +# R_SPARC_HH22, R_SPARC_HM10 +.section .ABS_64,"ax",@progbits + sethi %hh(a), %o0 + or %o0, %hm(a), %o0 +# CHECK-LABEL: section .ABS_64: +# CHECK: sethi 18641, %o0 +# CHECK-NEXT: or %o0, 359, %o0 + +# R_SPARC_H44, R_SPARC_M44, R_SPARC_L44 +.section .ABS_44,"ax",@progbits + sethi %h44(b), %o0 + or %o0, %m44(b), %o0 + sllx %o0, 12, %o0 + or %o0, %l44(b), %o0 +# CHECK-LABEL: section .ABS_44: +# CHECK: sethi 18641, %o0 +# CHECK: or %o0, 359, %o0 +# CHECK: or %o0, 2202, %o0 + +# R_SPARC_HI22, R_SPARC_LO10 +.section .ABS_32,"ax",@progbits + sethi %hi(c), %o0 + or %o0, %lo(c), %o0 +# CHECK-LABEL: section .ABS_32: +# CHECK: sethi 18641, %o0 +# CHECK-NEXT: or %o0, 359, %o0 + +# R_SPARC_64, R_SPARC_32 +.section .ABS,"ax",@progbits + .quad a + .long c +# HEX-LABEL: section .ABS: +# HEX-NEXT: 01234567 89abcdef 01234567 Index: lld/test/ELF/sparcv9-tls-le.s =================================================================== --- /dev/null +++ lld/test/ELF/sparcv9-tls-le.s @@ -0,0 +1,15 @@ +# REQUIRES: sparc +# RUN: llvm-mc -filetype=obj -triple=sparcv9 %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s + +sethi %tle_hix22(a), %o0 +xor %o0, %tle_lox10(a), %o0 +# LE: sethi 1, %o0 +# LE-NEXT: xor %o0, -2, %o0 + +.section .tbss +.globl a +a: +.zero 1024+2 +b: