15
Coccinelle Program matching and transformation tool for C (System) code. Gilles Muller, Julia Lawall EPI REGAL, INRIA/LIP6

Owf 2013 rii coccinelle muller speaker 1

Embed Size (px)

Citation preview

Page 1: Owf 2013 rii coccinelle muller speaker 1

Coccinelle

Program matching and transformation tool for C (System) code.

Gilles Muller, Julia Lawall EPI REGAL, INRIA/LIP6

Page 2: Owf 2013 rii coccinelle muller speaker 1

The problem: Dealing with Systems Code

It’s huge

It’s configuration polymorph

It’s often written in C

It evolves continuously

It’s (unfortunately) buggy

Page 3: Owf 2013 rii coccinelle muller speaker 1

A “simple” Bug in Linux

The “!&” bug

if (!state->card-> ac97_status & CENTER_LFE_ON) val &= ~DSP_BIND_CENTER_LFE; In sound/oss/ali5455.c until Linux 2.6.18

Page 4: Owf 2013 rii coccinelle muller speaker 1

A “simple” Bug in Linux

The “!&” bug if (!state->card-> ac97_status & CENTER_LFE_ON) val &= ~DSP_BIND_CENTER_LFE; Boolean Integer

Page 5: Owf 2013 rii coccinelle muller speaker 1

A “simple” Bug in Linux

The “!&” bug if (!state->card-> ac97_status & CENTER_LFE_ON) val &= ~DSP_BIND_CENTER_LFE; Boolean Integer

Page 6: Owf 2013 rii coccinelle muller speaker 1

Bug fix

if (!(state->card-> ac97_status & CENTER_LFE_ON)) val &= ~DSP_BIND_CENTER_LFE; Boolean Integer

Page 7: Owf 2013 rii coccinelle muller speaker 1

The Coccinelle tool

Program matching and transformation for unpreprocessed C code.

Fits with the existing habits of Systems (Linux) programmers.

Semantic Patch Language (SmPL): Based on the syntax of patches, Declarative approach to transformation High level search that abstracts away from

irrelevant details A single small semantic patch can modify hundreds

of files, at thousands of code sites

Page 8: Owf 2013 rii coccinelle muller speaker 1

A Simple SmPL Sample

@@ expression E; constant C; @@ !E & C

Page 9: Owf 2013 rii coccinelle muller speaker 1

A Simple SmPL Sample

@@ expression E; constant C; @@ - !E & C

Page 10: Owf 2013 rii coccinelle muller speaker 1

A Simple SmPL Sample

@@ expression E; constant C; @@ - !E & C + !(E & C)

Page 11: Owf 2013 rii coccinelle muller speaker 1

A Simple SmPL Sample

@@ expression E; constant C; @@ - !E & C + !(E & C)

96 instances in Linux from 2.6.13 (August 2005) to v2.6.28 (December 2008)

Warning, this is not always a bug !!!

Page 12: Owf 2013 rii coccinelle muller speaker 1

Bugs in Linux 2.6 [ASPLOS 2010]

Page 13: Owf 2013 rii coccinelle muller speaker 1

Coccinelle Impact

1000 patches accepted in the Linux kernel

40 SP in kernel sources

Many users… but we don’t know all of them

Page 14: Owf 2013 rii coccinelle muller speaker 1

Questions?

CocciCheck your code, it’s free…. http://coccinelle.lip6.fr Why Coccinelle ?

A Coccinelle (ladybug) is a bug that eats smaller bugs

Page 15: Owf 2013 rii coccinelle muller speaker 1