[AMDGPU][MC] Corrected branch relocation handling to detect undefined labels

Fixed ELF object writer to die gracefully when an undefined label is encountered in a branch instruction.
See https://bugs.llvm.org/show_bug.cgi?id=41914.

Reviewers: arsenm, rampitec

Differential Revision: https://reviews.llvm.org/D79943
This commit is contained in:
Dmitry Preobrazhensky
2020-05-18 14:04:58 +03:00
parent 968d293063
commit f997370d9c
2 changed files with 15 additions and 0 deletions
@@ -6,8 +6,10 @@
//
//===----------------------------------------------------------------------===//
#include "AMDGPUFixupKinds.h"
#include "AMDGPUMCTargetDesc.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixup.h"
@@ -80,6 +82,15 @@ unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_AMDGPU_ABS64;
}
if (Fixup.getTargetKind() == AMDGPU::fixup_si_sopp_br) {
const auto *SymA = Target.getSymA();
assert(SymA);
Ctx.reportError(Fixup.getLoc(),
Twine("undefined label '") + SymA->getSymbol().getName() + "'");
return ELF::R_AMDGPU_NONE;
}
llvm_unreachable("unhandled relocation type");
}
+4
View File
@@ -0,0 +1,4 @@
// RUN: not llvm-mc -arch=amdgcn -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=ERROR %s
// ERROR: error: undefined label 'undef_label'
s_branch undef_label