Slicing Unconditional Jumps with Unnecessary Control Dependencies - - PowerPoint PPT Presentation

slicing unconditional jumps with unnecessary control
SMART_READER_LITE
LIVE PREVIEW

Slicing Unconditional Jumps with Unnecessary Control Dependencies - - PowerPoint PPT Presentation

Slicing Unconditional Jumps with Unnecessary Control Dependencies Carlos Galindo Sergio P erez Josep Silva VRAIN Universitat Polit` ecnica de Val` encia, Spain 30th International Symposium on Logic-Based Program Synthesis and


slide-1
SLIDE 1

Slicing Unconditional Jumps with Unnecessary Control Dependencies

Carlos Galindo Sergio P´ erez Josep Silva

VRAIN Universitat Polit` ecnica de Val` encia, Spain

30th International Symposium on Logic-Based Program Synthesis and Transformation September 9th, 2020

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 1 / 14

slide-2
SLIDE 2

Program slicing

Program slicing

A software analysis technique to extract the statements of a program that affect a given slicing criterion.

1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum);

11

log(prod );

12 } 1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum );

11

log(prod );

12 }

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 2 / 14

slide-3
SLIDE 3

Program slicing

Program slicing

A software analysis technique to extract the statements of a program that affect a given slicing criterion.

1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum);

11

log(prod );

12 } 1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum );

11

log(prod );

12 }

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 2 / 14

slide-4
SLIDE 4

Program slicing

Program slicing

A software analysis technique to extract the statements of a program that affect a given slicing criterion.

1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum);

11

log(prod );

12 } 1 void

main(int n) {

2

int sum = 0;

3

int prod = 0;

4

int i = 0;

5

while (i < 10) {

6

sum += 1;

7

prod += n;

8

i++;

9

}

10

log(sum );

11

log(prod );

12 }

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 2 / 14

slide-5
SLIDE 5

Program slicing

Example

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(a) Original program

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(b) SDG slice

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(c) Minimal slice

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 3 / 14

slide-6
SLIDE 6

Program slicing

Example

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(a) Original program

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(b) SDG slice

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(c) Minimal slice

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 3 / 14

slide-7
SLIDE 7

Program slicing

Example

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(a) Original program

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(b) SDG slice

1 public

void f() {

2

while (X) {

3

if (Y) {

4

if (Z) {

5

A;

6

break;

7

}

8

B;

9

break;

10

}

11

C;

12

}

13

D;

14 }

(c) Minimal slice

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 3 / 14

slide-8
SLIDE 8

Program slicing

The System Dependence Graph

CFG CDG DDG PDG SDG Slice Figure: Sequence of graphs generated to produce a slice.

1 void h() { 2

while (x < 10) {

3

print(x);

4

x++;

5

}

6 }

Enter h() while (x < 10) print(x) Exit h() x++

CFG

Enter h() while (x < 10) print(x) x++

PDG

Black: CDG, Red: DDG

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 4 / 14

slide-9
SLIDE 9

Program slicing

The System Dependence Graph

CFG CDG DDG PDG SDG Slice Figure: Sequence of graphs generated to produce a slice.

1 void h() { 2

while (x < 10) {

3

print(x);

4

x++;

5

}

6 }

Enter h() while (x < 10) print(x) Exit h() x++

CFG

Enter h() while (x < 10) print(x) x++

PDG

Black: CDG, Red: DDG

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 4 / 14

slide-10
SLIDE 10

Program slicing

The System Dependence Graph

CFG CDG DDG PDG SDG Slice Figure: Sequence of graphs generated to produce a slice.

1 void h() { 2

while (x < 10) {

3

print(x);

4

x++;

5

}

6 }

Enter h() while (x < 10) print(x) Exit h() x++

CFG

Enter h() while (x < 10) x++ print(x)

PDG

Black: CDG, Red: DDG

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 4 / 14

slide-11
SLIDE 11

Program slicing

The System Dependence Graph

CFG CDG DDG PDG SDG Slice Figure: Sequence of graphs generated to produce a slice.

1 void h() { 2

while (x < 10) {

3

print(x);

4

x++;

5

}

6 }

Enter h() while (x < 10) print(x) Exit h() x++

CFG

Enter h() while (x < 10) x++ print(x)

PDG

Black: CDG, Red: DDG

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 4 / 14

slide-12
SLIDE 12

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-13
SLIDE 13

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

CFG: Jumps as arcs

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-14
SLIDE 14

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10)

CFG: Jumps as arcs

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-15
SLIDE 15

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10)

CFG: Jumps as arcs

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-16
SLIDE 16

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

CFG: Jumps as nodes

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-17
SLIDE 17

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10) break

CFG: Jumps as nodes

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-18
SLIDE 18

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10) break

CFG: Jumps as nodes

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-19
SLIDE 19

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

ACFG: Adds non-exec. arcs to create control deps.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-20
SLIDE 20

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10) break

ACFG: Adds non-exec. arcs to create control deps.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-21
SLIDE 21

Program slicing

Unconditional jumps (break, return, goto) in the CFG

1

void main () {

2

x = 0;

3

while (true) {

4

x++;

5

if (x > 10)

6

break;

7

}

8

print(x);

9

}

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

Enter main() x = 0 while (true) print(x) x++ if (x > 10) break

ACFG: Adds non-exec. arcs to create control deps.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 5 / 14

slide-22
SLIDE 22

Program slicing

Node classification in the CFG

CFG: Statement Predicate ACFG: Pseudo-predicate

Enter main() x = 0 while (true) x++ print(x) if (x > 10) break Exit main()

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 6 / 14

slide-23
SLIDE 23

Program slicing

The unconditional jump problem: graphs

start while (X) if (Z) if (Y) B C D end break A break start while (X) B break A break D if (Y) if (Z) C T T T T T F F F F F

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 7 / 14

slide-24
SLIDE 24

Program slicing

Kumar and Horwitz’s solution

A new definition of control dependence

Node b is control-dependent on node a iff b post-dominates, in the CFG,

  • ne but not all of a’s ACFG successors.

A modified slicing algorithm

Do not traverse control-dependence arcs whose target is a pseudo-predicate and not the slicing criterion.

CFG CDG DDG PDG SDG Slice

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 8 / 14

slide-25
SLIDE 25

Program slicing

Kumar and Horwitz’s solution

A new definition of control dependence

Node b is control-dependent on node a iff b post-dominates, in the CFG,

  • ne but not all of a’s ACFG successors.

A modified slicing algorithm

Do not traverse control-dependence arcs whose target is a pseudo-predicate and not the slicing criterion.

CFG CDG DDG PDG SDG Slice

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 8 / 14

slide-26
SLIDE 26

Program slicing

Kumar and Horwitz’s solution

Enter f() while (X) D if (Y) if (Z) C A break1 B break2

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 9 / 14

slide-27
SLIDE 27

Program slicing

Kumar and Horwitz’s solution

Enter f() while (X) D if (Y) if (Z) C A B break1 break2

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 9 / 14

slide-28
SLIDE 28

A simpler solution

Goal

Modify fewer steps in the slice creation. Try to maintain the original slicing algorithm.

Slicing criterion

Let P be a program. A slicing criterion C of P is a tuple s, v where s is a statement in P and v is a set of variables that are used or defined in s.

Key ideas

(1) Unconditional jumps that have no variables cannot be selected as criterion. (2) Convert the conditional traversal in arc removal.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 10 / 14

slide-29
SLIDE 29

A simpler solution

Goal

Modify fewer steps in the slice creation. Try to maintain the original slicing algorithm.

Slicing criterion

Let P be a program. A slicing criterion C of P is a tuple s, v where s is a statement in P and v is a set of variables that are used or defined in s.

Key ideas

(1) Unconditional jumps that have no variables cannot be selected as criterion. (2) Convert the conditional traversal in arc removal.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 10 / 14

slide-30
SLIDE 30

A simpler solution

Goal

Modify fewer steps in the slice creation. Try to maintain the original slicing algorithm.

Slicing criterion

Let P be a program. A slicing criterion C of P is a tuple s, v where s is a statement in P and v is a set of variables that are used or defined in s.

Key ideas

(1) Unconditional jumps that have no variables cannot be selected as criterion. (2) Convert the conditional traversal in arc removal.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 10 / 14

slide-31
SLIDE 31

A simpler solution

Example (manual removal of unnecessary control arcs)

public void f() { while (X) { if (Y) { if (Z) { A; break; // 1 } B; break; // 2 } C; } D; }

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 11 / 14

slide-32
SLIDE 32

A simpler solution

Example (manual removal of unnecessary control arcs)

public void f() { while (X) { if (Y) { if (Z) { A; break; // 1 } B; break; // 2 } C; } D; }

Enter f() while (X) D if (Y) if (Z) C A break1 B break2

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 11 / 14

slide-33
SLIDE 33

A simpler solution

Example (manual removal of unnecessary control arcs)

public void f() { while (X) { if (Y) { if (Z) { A; break; // 1 } B; break; // 2 } C; } D; }

Enter f() while (X) D if (Y) if (Z) C A break1 B break2

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 11 / 14

slide-34
SLIDE 34

A simpler solution

The algorithm

Input: An ACFG G = (N, A). Output: A CDG G ′ = (N′, Ac).

1: Ac = genControlArcs(G) 2: for all (ns, ne) ∈ Ac do 3:

if (ns, ne ∈ unjumps ∧ jumpDest(ns) == jumpDest(ne)) then

4:

Ac = Ac \ (x, ne) ∀ x ∈ N

5:

end if

6: end for 7: N′ = N \ {End} 8: G ′ = (N′, Ac)

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 12 / 14

slide-35
SLIDE 35

A simpler solution

Comparison to Kumar and Horwitz

Fewer arcs in the dependence graphs. No modification to the slicing algorithm. Not all nodes may be selected as criterion.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 13 / 14

slide-36
SLIDE 36

Conclusions

An analysis of unconditional jumps and their handling in control flow and dependence graphs. Two solutions available: Kumar and Horwitz’s and our proposal. Theoretical proof of correctness.

  • C. Galindo et al. (UPV)

Slicing Unconditional Jumps LOPSTR 2020 - September 9th 14 / 14