Skip to content

Commit 9850db7

Browse files
committed
elf_reader: tolerate untyped/local map relocations from llvm 7/9
Symbols for anonymous constants are somewhat irregular on older versions of LLVM. This commit relaxes the constraints on symbols those compilers emit map relocations against. LLVM 7: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT 16 .Lconstinit.1 LLVM 9: 1: 0000000000000000 32 OBJECT LOCAL DEFAULT 22 .Lconstinit.1 LLVM 14 has these symbols correctly sanitized. Signed-off-by: Timo Beckers <[email protected]>
1 parent 1e37e4f commit 9850db7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

elf_reader.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,21 @@ func (ec *elfCode) relocateInstruction(ins *asm.Instruction, rel elf.Symbol) err
468468
offset = uint32(uint64(ins.Constant))
469469

470470
case elf.STT_OBJECT:
471-
if bind != elf.STB_GLOBAL {
471+
// LLVM 9 emits OBJECT-LOCAL symbols for anonymous constants.
472+
if bind != elf.STB_GLOBAL && bind != elf.STB_LOCAL {
472473
return fmt.Errorf("direct load: %s: unsupported object relocation %s", name, bind)
473474
}
474475

475476
offset = uint32(rel.Value)
476477

478+
case elf.STT_NOTYPE:
479+
// LLVM 7 emits NOTYPE-LOCAL symbols for anonymous constants.
480+
if bind != elf.STB_LOCAL {
481+
return fmt.Errorf("direct load: %s: unsupported untyped relocation %s", name, bind)
482+
}
483+
484+
offset = uint32(rel.Value)
485+
477486
default:
478487
return fmt.Errorf("incorrect relocation type %v for direct map load", typ)
479488
}

0 commit comments

Comments
 (0)