Skip to content

Commit 88a3f09

Browse files
committed
Binary: Only emit an external ref instruction when the call is external.
1 parent 9f228f5 commit 88a3f09

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

binary/ql/lib/semmle/code/binary/ast/internal/CilInstructions.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class CilMethod extends @method {
6868
result.getIndex() = i
6969
}
7070

71+
string getFullyQualifiedName() {
72+
result = this.getDeclaringType().getFullName() + "." + this.getName()
73+
}
74+
7175
CilParameter getParameter(int i) {
7276
result.getMethod() = this and
7377
result.getIndex() = i
@@ -363,7 +367,7 @@ abstract class CilCall extends CilInstruction {
363367

364368
final predicate hasReturnValue() { il_call_has_return_value(this) }
365369

366-
string getExternalName() { il_call_target_unresolved(this, result) }
370+
CilMethod getTarget() { result.getFullyQualifiedName() = this.getExternalName() }
367371
}
368372

369373
class CilIl_jmp extends @il_il_jmp, CilCall { }

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/TranslatedInstruction.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@ class TranslatedCilCall extends TranslatedCilInstruction, TTranslatedCilCall {
21322132
then v.asSome() = this.getTempVariable(CallReturnValueTag())
21332133
else v.isNone()
21342134
or
2135+
not exists(instr.getTarget()) and
21352136
opcode instanceof Opcode::ExternalRef and
21362137
tag = CilCallTargetTag() and
21372138
v.asSome() = this.getTempVariable(CilCallTargetVarTag())
@@ -2141,6 +2142,7 @@ class TranslatedCilCall extends TranslatedCilInstruction, TTranslatedCilCall {
21412142
instr.hasReturnValue() and
21422143
tag = CallReturnValueTag()
21432144
or
2145+
not exists(instr.getTarget()) and
21442146
tag = CilCallTargetVarTag()
21452147
}
21462148

@@ -2154,19 +2156,23 @@ class TranslatedCilCall extends TranslatedCilInstruction, TTranslatedCilCall {
21542156
getTranslatedCilInstruction(instr.getABackwardPredecessor()).getStackElement(index) = result
21552157
)
21562158
or
2159+
not exists(instr.getTarget()) and
21572160
operandTag instanceof CallTargetTag and
21582161
result = this.getInstruction(CilCallTargetTag()).getResultVariable()
21592162
)
21602163
}
21612164

21622165
override string getExternalName(InstructionTag tag) {
2166+
// TODO: Only when external
2167+
not exists(instr.getTarget()) and
21632168
tag = CilCallTargetTag() and
21642169
result = instr.getExternalName()
21652170
}
21662171

21672172
override Instruction getChildSuccessor(TranslatedElement child, SuccessorType succType) { none() }
21682173

21692174
override Instruction getSuccessor(InstructionTag tag, SuccessorType succType) {
2175+
not exists(instr.getTarget()) and
21702176
tag = CilCallTargetTag() and
21712177
succType instanceof DirectSuccessor and
21722178
result = this.getInstruction(CilCallTag())
@@ -2176,13 +2182,21 @@ class TranslatedCilCall extends TranslatedCilInstruction, TTranslatedCilCall {
21762182
result = getTranslatedInstruction(instr.getASuccessor()).getEntry()
21772183
}
21782184

2179-
override Instruction getEntry() { result = this.getInstruction(CilCallTargetTag()) }
2185+
override Instruction getEntry() {
2186+
not exists(instr.getTarget()) and
2187+
result = this.getInstruction(CilCallTargetTag())
2188+
}
21802189

21812190
override Variable getResultVariable() {
21822191
instr.hasReturnValue() and
21832192
result = this.getTempVariable(CallReturnValueTag())
21842193
}
21852194

2195+
override TranslatedFunction getStaticCallTarget(InstructionTag tag) {
2196+
tag = CilCallTag() and
2197+
result = getTranslatedFunction(instr.getTarget())
2198+
}
2199+
21862200
final override Variable getStackElement(int i) {
21872201
if instr.hasReturnValue()
21882202
then

0 commit comments

Comments
 (0)