Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -313,6 +313,7 @@ const SymbolBody &Body, RelExpr Expr) { switch (Expr) { case R_HINT: + case R_NONE: case R_TLSDESC_CALL: llvm_unreachable("cannot relocate hint relocs"); case R_TLSLD: @@ -464,7 +465,10 @@ Addend += Target->getImplicitAddend(BufLoc, Type); SymbolBody &Sym = this->File->getRelocTargetSym(Rel); - if (Target->getRelExpr(Type, Sym) != R_ABS) { + RelExpr Expr = Target->getRelExpr(Type, Sym); + if (Expr == R_NONE) + continue; + if (Expr != R_ABS) { error(this->getLocation(Offset) + ": has non-ABS reloc"); return; } Index: ELF/Relocations.h =================================================================== --- ELF/Relocations.h +++ ELF/Relocations.h @@ -42,6 +42,7 @@ R_MIPS_TLSGD, R_MIPS_TLSLD, R_NEG_TLS, + R_NONE, R_PAGE_PC, R_PC, R_PLT, Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -696,6 +696,11 @@ reportUndefined(Body, C, RI.r_offset); RelExpr Expr = Target->getRelExpr(Type, Body); + + // Ignore "hint" relocations because they are only markers for relaxation. + if (isRelExprOneOf(Expr)) + continue; + bool Preemptible = isPreemptible(Body, Type); Expr = adjustExpr(*File, Body, IsWrite, Expr, Type, Buf + RI.r_offset, C, RI.r_offset); @@ -734,9 +739,7 @@ continue; } - // Ignore "hint" and TLS Descriptor call relocation because they are - // only markers for relaxation. - if (isRelExprOneOf(Expr)) + if (Expr == R_TLSDESC_CALL) continue; if (needsPlt(Expr) || Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -389,7 +389,7 @@ case R_386_TLS_LE_32: return R_NEG_TLS; case R_386_NONE: - return R_HINT; + return R_NONE; default: error(toString(S.File) + ": unknown relocation type: " + toString(Type)); return R_HINT; @@ -684,7 +684,7 @@ case R_X86_64_GOTTPOFF: return R_GOT_PC; case R_X86_64_NONE: - return R_HINT; + return R_NONE; default: error(toString(S.File) + ": unknown relocation type: " + toString(Type)); return R_HINT; @@ -1715,7 +1715,7 @@ case R_ARM_THM_MOVT_PREL: return R_PC; case R_ARM_NONE: - return R_HINT; + return R_NONE; case R_ARM_TLS_LE32: return R_TLS; } Index: test/ELF/Inputs/relocatable-non-alloc.s =================================================================== --- /dev/null +++ test/ELF/Inputs/relocatable-non-alloc.s @@ -0,0 +1,6 @@ +.section .text.foo,"axG",@progbits,foo,comdat,unique,0 +foo: + nop + +.section .debug_info +.long .text.foo Index: test/ELF/relocatable-non-alloc.s =================================================================== --- /dev/null +++ test/ELF/relocatable-non-alloc.s @@ -0,0 +1,10 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/relocatable-non-alloc.s -o %t2.o +# RUN: ld.lld %t2.o %t2.o -r -o %t3.o +# RUN: ld.lld %t1.o %t3.o -o %t.o | FileCheck -allow-empty %s + +# CHECK-NOT: has non-ABS reloc + +.globl _start +_start: