Skip to content

Commit f997370

Browse files
committed
[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
1 parent 968d293 commit f997370

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "AMDGPUFixupKinds.h"
910
#include "AMDGPUMCTargetDesc.h"
1011
#include "llvm/BinaryFormat/ELF.h"
12+
#include "llvm/MC/MCContext.h"
1113
#include "llvm/MC/MCELFObjectWriter.h"
1214
#include "llvm/MC/MCExpr.h"
1315
#include "llvm/MC/MCFixup.h"
@@ -80,6 +82,15 @@ unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
8082
return ELF::R_AMDGPU_ABS64;
8183
}
8284

85+
if (Fixup.getTargetKind() == AMDGPU::fixup_si_sopp_br) {
86+
const auto *SymA = Target.getSymA();
87+
assert(SymA);
88+
89+
Ctx.reportError(Fixup.getLoc(),
90+
Twine("undefined label '") + SymA->getSymbol().getName() + "'");
91+
return ELF::R_AMDGPU_NONE;
92+
}
93+
8394
llvm_unreachable("unhandled relocation type");
8495
}
8596

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not llvm-mc -arch=amdgcn -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=ERROR %s
2+
// ERROR: error: undefined label 'undef_label'
3+
4+
s_branch undef_label

0 commit comments

Comments
 (0)