Skip to content

Commit

Permalink
elf_reader: tolerate untyped/local map relocations from llvm 7/9
Browse files Browse the repository at this point in the history
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 <timo@isovalent.com>
  • Loading branch information
ti-mo committed May 23, 2022
1 parent 1e37e4f commit 9850db7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion elf_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,21 @@ func (ec *elfCode) relocateInstruction(ins *asm.Instruction, rel elf.Symbol) err
offset = uint32(uint64(ins.Constant))

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

offset = uint32(rel.Value)

case elf.STT_NOTYPE:
// LLVM 7 emits NOTYPE-LOCAL symbols for anonymous constants.
if bind != elf.STB_LOCAL {
return fmt.Errorf("direct load: %s: unsupported untyped relocation %s", name, bind)
}

offset = uint32(rel.Value)

default:
return fmt.Errorf("incorrect relocation type %v for direct map load", typ)
}
Expand Down

0 comments on commit 9850db7

Please sign in to comment.