-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[BPF] Remove unused weak symbol __bpf_trap #166003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,16 @@ bool BPFAsmPrinter::doFinalization(Module &M) { | |
| } | ||
| } | ||
|
|
||
| for (GlobalObject &GO : M.global_objects()) { | ||
| if (!GO.hasExternalWeakLinkage()) | ||
| continue; | ||
|
|
||
| if (!SawTrapCall && GO.getName() == BPF_TRAP) { | ||
| GO.eraseFromParent(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return AsmPrinter::doFinalization(M); | ||
| } | ||
|
|
||
|
|
@@ -160,6 +170,20 @@ bool BPFAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, | |
| } | ||
|
|
||
| void BPFAsmPrinter::emitInstruction(const MachineInstr *MI) { | ||
| if (MI->isCall()) { | ||
| for (const MachineOperand &Op : MI->operands()) { | ||
| if (Op.isGlobal()) { | ||
| if (const GlobalValue *GV = Op.getGlobal()) | ||
| if (GV->getName() == BPF_TRAP) | ||
| SawTrapCall = true; | ||
| } else if (Op.isSymbol()) { | ||
| if (const MCSymbol *Sym = Op.getMCSymbol()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will always fire an assertion: MCSymbol *getMCSymbol() const {
assert(isMCSymbol() && "Wrong MachineOperand accessor");
return Contents.Sym;
}But What's the right fix?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used Op.isSymbol() as a possible target but running bpf selftest, the branch with Op.isSymbol() never to be true, at least when running linux kernel bpf selftests. Let me double check whether this branch isSymbol() is really necessary or not. |
||
| if (Sym->getName() == BPF_TRAP) | ||
| SawTrapCall = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| BPF_MC::verifyInstructionPredicates(MI->getOpcode(), | ||
| getSubtargetInfo().getFeatureBits()); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ; RUN: llc < %s | FileCheck %s | ||
| ; | ||
| target triple = "bpf" | ||
|
|
||
| define i32 @test(i8 %x) { | ||
| entry: | ||
| %0 = and i8 %x, 3 | ||
| switch i8 %0, label %default.unreachable4 [ | ||
| i8 0, label %return | ||
| i8 1, label %sw.bb1 | ||
| i8 2, label %sw.bb2 | ||
| i8 3, label %sw.bb3 | ||
| ] | ||
|
|
||
| sw.bb1: ; preds = %entry | ||
| br label %return | ||
|
|
||
| sw.bb2: ; preds = %entry | ||
| br label %return | ||
|
|
||
| sw.bb3: ; preds = %entry | ||
| br label %return | ||
|
|
||
| default.unreachable4: ; preds = %entry | ||
| unreachable | ||
|
|
||
| return: ; preds = %entry, %sw.bb3, %sw.bb2, %sw.bb1 | ||
| %retval.0 = phi i32 [ 12, %sw.bb1 ], [ 43, %sw.bb2 ], [ 54, %sw.bb3 ], [ 32, %entry ] | ||
| ret i32 %retval.0 | ||
| } | ||
|
|
||
| ; CHECK-NOT: __bpf_trap |
Uh oh!
There was an error while loading. Please reload this page.