[llvm] f997370 - [AMDGPU][MC] Corrected branch relocation handling to detect undefined labels
Dmitry Preobrazhensky via llvm-commits
llvm-commits at lists.llvm.org
Mon May 18 04:07:30 PDT 2020
Author: Dmitry Preobrazhensky
Date: 2020-05-18T14:04:58+03:00
New Revision: f997370d9c8f4a67e495312078ca7b6dc2e94fa4
URL: https://github.com/llvm/llvm-project/commit/f997370d9c8f4a67e495312078ca7b6dc2e94fa4
DIFF: https://github.com/llvm/llvm-project/commit/f997370d9c8f4a67e495312078ca7b6dc2e94fa4.diff
LOG: [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
Added:
llvm/test/MC/AMDGPU/labels-branch-err.s
Modified:
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
index d352219a7a98..619fde74e88d 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
@@ -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");
}
diff --git a/llvm/test/MC/AMDGPU/labels-branch-err.s b/llvm/test/MC/AMDGPU/labels-branch-err.s
new file mode 100644
index 000000000000..e7e8bd114a93
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/labels-branch-err.s
@@ -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
More information about the llvm-commits
mailing list