Index: lld/ELF/Arch/SPARCV9.cpp =================================================================== --- lld/ELF/Arch/SPARCV9.cpp +++ lld/ELF/Arch/SPARCV9.cpp @@ -55,6 +55,14 @@ case R_SPARC_UA32: case R_SPARC_64: case R_SPARC_UA64: + case R_SPARC_H44: + case R_SPARC_M44: + case R_SPARC_L44: + case R_SPARC_HH22: + case R_SPARC_HM10: + case R_SPARC_LM22: + case R_SPARC_HI22: + case R_SPARC_LO10: return R_ABS; case R_SPARC_PC10: case R_SPARC_PC22: @@ -69,6 +77,9 @@ return R_PLT_PC; case R_SPARC_NONE: return R_NONE; + case R_SPARC_TLS_LE_HIX22: + case R_SPARC_TLS_LE_LOX10: + return R_TLS; default: error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + ") against symbol " + toString(s)); @@ -103,9 +114,15 @@ break; case R_SPARC_GOT22: case R_SPARC_PC22: + 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); @@ -116,11 +133,45 @@ // 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 write64be(loc, val); 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: + // T-simm13 + write32be(loc, (read32be(loc) & ~0x00001fff) | ((val >> 32) & 0x000003ff)); + 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: + // T-imm10 + write32be(loc, (read32be(loc) & ~0x000003ff) | ((val >> 12) & 0x000003ff)); + break; + case R_SPARC_L44: + // T-imm13 + write32be(loc, (read32be(loc) & ~0x00001fff) | (val & 0x00000fff)); + break; + case R_SPARC_TLS_LE_HIX22: + // T-imm22 + write32be(loc, (read32be(loc) & ~0x003fffff) | ((~val >> 10) & 0x003fffff)); + break; + case R_SPARC_TLS_LE_LOX10: + // T-simm13 + write32be(loc, (read32be(loc) & ~0x00001fff) | (val & 0x000003ff) | 0x1C00); + break; default: llvm_unreachable("unknown relocation"); } Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -148,6 +148,7 @@ .Cases("elf_amd64", "elf_x86_64", {ELF64LEKind, EM_X86_64}) .Case("elf_i386", {ELF32LEKind, EM_386}) .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU}) + .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9}) .Default({ELFNoneKind, EM_NONE}); if (ret.first == ELFNoneKind) Index: lld/ELF/InputSection.cpp =================================================================== --- lld/ELF/InputSection.cpp +++ lld/ELF/InputSection.cpp @@ -650,6 +650,7 @@ // Variant 2. case EM_HEXAGON: + case EM_SPARCV9: case EM_386: case EM_X86_64: return s.getVA(0) - tls->p_memsz - 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_DATA,"ax",@progbits + .quad a + .long c +# HEX-LABEL: section .ABS_DATA: +# 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,17 @@ +# 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 + +## %hix(@tpoff(a)) = ~(st_value(a) - 1026) >> 10 = 1 +## %lo(@tpoff(a)) = (st_value(a) - 1026) & 0x3ff | 0x1c00 = -2 (0x1ffe) +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: