Skip to content

Commit

Permalink
[ELF] Remove R_X86_64_{TLSLD,TPOFF32,TPOFF64} error checks
Browse files Browse the repository at this point in the history
Compiler should not emit these types of relocations unless it knows
they will never refer imported symbols. However, it looks like GCC 7
emits these relocations against global symbols with STB_GNU_UNIQUE
attribute, which can be resolved to a symbol in other ELF module at
runtime. It looks like the bug only exists in GCC 7 and fixed in
recent versions of GCC.

mold verifies the above conditions and reports an error if the
condition is violated. On the other hand, GNU ld and LLVM lld don't
verify and simply create a shared library that is not always
guaranteed to work.

Give this situation, I decided to simply remove the verification code
from mold. This is what other linkers do, and it make mold "compatible"
with GCC 7.

Fixes #145
  • Loading branch information
rui314 committed Dec 24, 2021
1 parent 13245fd commit d9606d6
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions elf/arch-x86-64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,19 +619,12 @@ void InputSection<X86_64>::scan_relocations(Context<X86_64> &ctx) {
if (i + 1 == rels.size())
Fatal(ctx) << *this
<< ": TLSGD reloc must be followed by PLT32 or GOTPCREL";
if (sym.is_imported)
Fatal(ctx) << *this << ": TLSLD reloc refers external symbol: " << sym;

if (ctx.arg.relax && !ctx.arg.shared)
i++;
else
sym.flags |= NEEDS_TLSLD;
break;
case R_X86_64_DTPOFF32:
case R_X86_64_DTPOFF64:
if (sym.is_imported)
Fatal(ctx) << *this << ": DTPOFF reloc refers external symbol: " << sym;
break;
case R_X86_64_GOTTPOFF: {
ctx.has_gottp_rel = true;

Expand All @@ -651,6 +644,8 @@ void InputSection<X86_64>::scan_relocations(Context<X86_64> &ctx) {
sym.flags |= NEEDS_TLSDESC;
break;
}
case R_X86_64_DTPOFF32:
case R_X86_64_DTPOFF64:
case R_X86_64_TPOFF32:
case R_X86_64_TPOFF64:
case R_X86_64_SIZE32:
Expand Down

0 comments on commit d9606d6

Please sign in to comment.