Skip to content

Commit 8f482d5

Browse files
authored
Revert "[sancov][LoongArch] Resolve pcaddu18i+jirl in evaluateBranch and teach sancov" (llvm#155879)
Reverts llvm#155371 Breaks ubsan bots.
1 parent d77cf57 commit 8f482d5

File tree

3 files changed

+4
-87
lines changed

3 files changed

+4
-87
lines changed

lld/test/ELF/loongarch-call36.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
## hi20 = target - pc + (1 << 17) >> 18 = 0x60020 - 0x20010 + 0x20000 >> 18 = 1
99
## lo18 = target - pc & (1 << 18) - 1 = 0x60020 - 0x20010 & 0x3ffff = 16
1010
# EXE1: 20010: pcaddu18i $t0, 1
11-
# EXE1-NEXT: 20014: jirl $zero, $t0, 16 <foo>
11+
# EXE1-NEXT: 20014: jirl $zero, $t0, 16
1212

1313
# RUN: ld.lld %t/a.o --section-start=.text=0x20010 --section-start=.sec.foo=0x40020 -o %t/exe2
1414
# RUN: llvm-objdump --no-show-raw-insn -d %t/exe2 | FileCheck --match-full-lines %s --check-prefix=EXE2
1515
## hi20 = target - pc + (1 << 17) >> 18 = 0x40020 - 0x20010 + 0x20000 >> 18 = 1
1616
## lo18 = target - pc & (1 << 18) - 1 = 0x40020 - 0x20010 & 0x3ffff = -131056
1717
# EXE2: 20010: pcaddu18i $t0, 1
18-
# EXE2-NEXT: 20014: jirl $zero, $t0, -131056 <foo>
18+
# EXE2-NEXT: 20014: jirl $zero, $t0, -131056
1919

2020
# RUN: ld.lld %t/a.o -shared -T %t/a.t -o %t/a.so
2121
# RUN: llvm-readelf -x .got.plt %t/a.so | FileCheck --check-prefix=GOTPLT %s
@@ -34,7 +34,7 @@
3434
## hi20 = foo@plt - pc + (1 << 17) >> 18 = 0x1234520 - 0x1274670 + 0x20000 >> 18 = -1
3535
## lo18 = foo@plt - pc & (1 << 18) - 1 = 0x1234520 - 0x1274670 & 0x3ffff = -336
3636
# SO-NEXT: pcaddu18i $t0, -1{{$}}
37-
# SO-NEXT: jirl $zero, $t0, -336 <.plt+0x20>{{$}}
37+
# SO-NEXT: jirl $zero, $t0, -336{{$}}
3838

3939
# GOTPLT: section '.got.plt':
4040
# GOTPLT-NEXT: 0x01274730 00000000 00000000 00000000 00000000

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/MC/MCSubtargetInfo.h"
2727
#include "llvm/MC/TargetRegistry.h"
2828
#include "llvm/Support/Compiler.h"
29-
#include <bitset>
3029

3130
#define GET_INSTRINFO_MC_DESC
3231
#define ENABLE_INSTR_PREDICATE_VERIFIER
@@ -96,79 +95,10 @@ createLoongArchAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS,
9695
namespace {
9796

9897
class LoongArchMCInstrAnalysis : public MCInstrAnalysis {
99-
int64_t GPRState[31] = {};
100-
std::bitset<31> GPRValidMask;
101-
102-
static bool isGPR(MCRegister Reg) {
103-
return Reg >= LoongArch::R0 && Reg <= LoongArch::R31;
104-
}
105-
106-
static unsigned getRegIndex(MCRegister Reg) {
107-
assert(isGPR(Reg) && Reg != LoongArch::R0 && "Invalid GPR reg");
108-
return Reg - LoongArch::R1;
109-
}
110-
111-
void setGPRState(MCRegister Reg, std::optional<int64_t> Value) {
112-
if (Reg == LoongArch::R0)
113-
return;
114-
115-
auto Index = getRegIndex(Reg);
116-
117-
if (Value) {
118-
GPRState[Index] = *Value;
119-
GPRValidMask.set(Index);
120-
} else {
121-
GPRValidMask.reset(Index);
122-
}
123-
}
124-
125-
std::optional<int64_t> getGPRState(MCRegister Reg) const {
126-
if (Reg == LoongArch::R0)
127-
return 0;
128-
129-
auto Index = getRegIndex(Reg);
130-
131-
if (GPRValidMask.test(Index))
132-
return GPRState[Index];
133-
return std::nullopt;
134-
}
135-
13698
public:
13799
explicit LoongArchMCInstrAnalysis(const MCInstrInfo *Info)
138100
: MCInstrAnalysis(Info) {}
139101

140-
void resetState() override { GPRValidMask.reset(); }
141-
142-
void updateState(const MCInst &Inst, uint64_t Addr) override {
143-
// Terminators mark the end of a basic block which means the sequentially
144-
// next instruction will be the first of another basic block and the current
145-
// state will typically not be valid anymore. For calls, we assume all
146-
// registers may be clobbered by the callee (TODO: should we take the
147-
// calling convention into account?).
148-
if (isTerminator(Inst) || isCall(Inst)) {
149-
resetState();
150-
return;
151-
}
152-
153-
switch (Inst.getOpcode()) {
154-
default: {
155-
// Clear the state of all defined registers for instructions that we don't
156-
// explicitly support.
157-
auto NumDefs = Info->get(Inst.getOpcode()).getNumDefs();
158-
for (unsigned I = 0; I < NumDefs; ++I) {
159-
auto DefReg = Inst.getOperand(I).getReg();
160-
if (isGPR(DefReg))
161-
setGPRState(DefReg, std::nullopt);
162-
}
163-
break;
164-
}
165-
case LoongArch::PCADDU18I:
166-
setGPRState(Inst.getOperand(0).getReg(),
167-
Addr + SignExtend64<32>(Inst.getOperand(1).getImm() << 18));
168-
break;
169-
}
170-
}
171-
172102
bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
173103
uint64_t &Target) const override {
174104
unsigned NumOps = Inst.getNumOperands();
@@ -178,14 +108,6 @@ class LoongArchMCInstrAnalysis : public MCInstrAnalysis {
178108
return true;
179109
}
180110

181-
if (Inst.getOpcode() == LoongArch::JIRL) {
182-
if (auto TargetRegState = getGPRState(Inst.getOperand(1).getReg())) {
183-
Target = *TargetRegState + Inst.getOperand(2).getImm();
184-
return true;
185-
}
186-
return false;
187-
}
188-
189111
return false;
190112
}
191113

llvm/tools/sancov/sancov.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
730730
std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
731731
failIfEmpty(MII, "no instruction info for target " + TripleName);
732732

733-
std::unique_ptr<MCInstrAnalysis> MIA(
733+
std::unique_ptr<const MCInstrAnalysis> MIA(
734734
TheTarget->createMCInstrAnalysis(MII.get()));
735735
failIfEmpty(MIA, "no instruction analysis info for target " + TripleName);
736736

@@ -750,9 +750,6 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
750750
failIfError(BytesStr);
751751
ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(*BytesStr);
752752

753-
if (MIA)
754-
MIA->resetState();
755-
756753
for (uint64_t Index = 0, Size = 0; Index < Section.getSize();
757754
Index += Size) {
758755
MCInst Inst;
@@ -763,7 +760,6 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
763760
Size = std::min<uint64_t>(
764761
ThisBytes.size(),
765762
DisAsm->suggestBytesToSkip(ThisBytes, ThisAddr));
766-
MIA->resetState();
767763
continue;
768764
}
769765
uint64_t Addr = Index + SectionAddr;
@@ -774,7 +770,6 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
774770
MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target) &&
775771
SanCovAddrs.find(Target) != SanCovAddrs.end())
776772
Addrs->insert(CovPoint);
777-
MIA->updateState(Inst, Addr);
778773
}
779774
}
780775
}

0 commit comments

Comments
 (0)