Skip to content

Commit

Permalink
Fixes handling logic for i386/ELF GOTPC relocation
Browse files Browse the repository at this point in the history
The i386/ELF JITLink backend was not correctly handling the GOTPC relocation
by skipping the in-built addend, which was manifesting itself in the form of
a segmentation fault in the `LF_external_to_absolute_conversion.s` test. This
CR has fixed that issue.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D141746
  • Loading branch information
jkshtj committed Jan 14, 2023
1 parent 347028a commit a3e975d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
//===----------------------------------------------------------------------===//

#include "llvm/ExecutionEngine/JITLink/ELF_i386.h"
#include "DefineExternalSectionStartAndEndSymbols.h"
#include "ELFLinkGraphBuilder.h"
#include "JITLinkGeneric.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/ExecutionEngine/JITLink/i386.h"
#include "llvm/Object/ELFObjectFile.h"

#include "DefineExternalSectionStartAndEndSymbols.h"

#define DEBUG_TYPE "jitlink"

using namespace llvm;
Expand Down Expand Up @@ -180,9 +179,18 @@ class ELFLinkGraphBuilder_i386 : public ELFLinkGraphBuilder<ELFT> {
if (!Kind)
return Kind.takeError();

auto FixupAddress = orc::ExecutorAddr(FixupSection.sh_addr) + Rel.r_offset;
int64_t Addend = 0;

auto FixupAddress = orc::ExecutorAddr(FixupSection.sh_addr) + Rel.r_offset;
switch (*Kind) {
case i386::EdgeKind_i386::Delta32: {
const char *FixupContent = BlockToFix.getContent().data() +
(FixupAddress - BlockToFix.getAddress());
Addend = *(const support::ulittle32_t *)FixupContent;
break;
}
}

Edge::OffsetT Offset = FixupAddress - BlockToFix.getAddress();
Edge GE(*Kind, Offset, *GraphSymbol, Addend);
LLVM_DEBUG({
Expand Down

0 comments on commit a3e975d

Please sign in to comment.