Cake: a tool for adaptation of object code

Similar documents
System support for adaptation and composition of applications

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Introduction to Programming Using Java (98-388)

QUIZ. What is wrong with this code that uses default arguments?

6. Pointers, Structs, and Arrays. 1. Juli 2011

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

Stream Computing using Brook+

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

A Fast Review of C Essentials Part I

MPATE-GE 2618: C Programming for Music Technology. Syllabus

Lectures 5-6: Introduction to C

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

C - Basics, Bitwise Operator. Zhaoguo Wang

Instantiation of Template class

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

Lectures 5-6: Introduction to C

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Advanced Systems Programming

Programming in C and C++

Lecture 3. GUI Programming part 1: GTK

Type Checking. Prof. James L. Frankel Harvard University

Inheritance, Polymorphism and the Object Memory Model

Programming in C - Part 2

Lecture 03 Bits, Bytes and Data Types

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

CS Programming In C

Tokens, Expressions and Control Structures

Composing heterogeneous software with style

TMS470 ARM ABI Migration

Exercise: Using Numbers

Open source MySQL Browser for Open Innovation

Advanced Pointer & Data Storage

Automatically generated type-safe GTK+ binding for Dylan

Preliminaries. Part I

Object-Oriented Programming

Introduce C# as Object Oriented programming language. Explain, tokens,

Programming refresher and intro to C programming

slide 1 gaius Game Trees

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Elementary Data Structures: Lists

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Armide Documentation. Release Kyle Mayes

September 10,

A tale of ELFs and DWARFs

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64.

DDMD AND AUTOMATED CONVERSION FROM C++ TO D

The role of semantic analysis in a compiler

One-Slide Summary. Lecture Outline. Language Security

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

In Java we have the keyword null, which is the value of an uninitialized reference type

Chapter 1 Getting Started

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Today s Big Adventure

Today s Big Adventure

C Programming Review CSC 4320/6320

class Polynomial { public: Polynomial(const string& N = "no name", const vector<int>& C = vector<int>());... };

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Creating GNOME Applications with Glade. Part I: Introduction

Programming in C and C++

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

QUIZ. What are 3 differences between C and C++ const variables?

CE221 Programming in C++ Part 1 Introduction

C SCI The X Window System Stewart Weiss

Quiz 0 Review Session. October 13th, 2014

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming

Introduction to C++11 and its use inside Qt

Object-Oriented Programming for Scientific Computing

Announcements. Working on requirements this week Work on design, implementation. Types. Lecture 17 CS 169. Outline. Java Types

Compiling Techniques

Language Reference Manual simplicity

A brief introduction to C programming for Java programmers

Topic 6: A Quick Intro To C

C++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers

G52CPP C++ Programming Lecture 20

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

G52CPP C++ Programming Lecture 9

EMBEDDED SYSTEMS PROGRAMMING More About Languages

Lambdas in unevaluated contexts

Object-Oriented Principles and Practice / C++

CSC 1600 Memory Layout for Unix Processes"

Fast Introduction to Object Oriented Programming and C++

Kakadu and Java. David Taubman, UNSW June 3, 2003

OO for GUI Design (contd.) Questions:

Basic Types, Variables, Literals, Constants

Section 3: File I/O, JSON, Generics. Meghan Cowan

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Transcription:

Cake: a tool for adaptation of object code Stephen Kell Stephen.Kell@cl.cam.ac.uk Computer Laboratory University of Cambridge Cake... p.1/32

Some familiar problems Software is expensive to develop expensive to maintain inflexible Cake... p.2/32

Some common ideas, all entailing mismatch Better programming languages great for new codebases mismatch: inevitably many languages Decentralised development many variant codebases evolving in parallel mismatch: no more interface consensus Unanticipated composition mismatch: no a priori agreement on interfaces Cake... p.3/32

Starting point: Cake s big picture foo.o xyzzy.o bar.o plugh.o Cake... p.4/32

Cake in one slide Cake is a language expressing compositions of software a productive tool for overcoming mismatch operating on binaries designed around practical experience ongoing work In this talk, I ll cover two motivational case-studies the Cake language design some implementation and status Cake... p.5/32

Wanted: a tool for helping with tasks like... Unanticipated composition: port feature P from app X to Y Case study: Konqueror + ROX-Filer Evolution: link client version 1 against library version 2 Case study: gtk-theme-switch Cake... p.6/32

Outline of the rest of this talk Design and first case study Second case study: object exchange The Cake language: core The Cake language: practicalities Status and questions Cake... p.7/32

Experiment 1: a simple exercise in glue I like program X, but it lacks feature P found in program Y. let X = ROX-Filer, P = history and Y = Konqueror static GList history = NULL; / Most recent first / static GList history tail = NULL; / Oldest item / void bookmarks add history(const gchar path ); GtkWidget build history menu (FilerWindow filer window ); class LIBKONQ EXPORT KonqHistoryManager : public KParts::HistoryProvider, public KonqHistoryComm { //... void addtohistory( bool pending, const KURL& url, const QString& typedurl = QString::null, const QString& title = QString :: null ); virtual QStringList allurls() const; /... / }; Cake... p.8/32

Decision: black-box approach Why not hack source? must understand source language must understand code internals poor compositionality poor maintainability time sink? Instead choose black-box approach; but possibly less powerful? performance?... Cake... p.9/32

Decision: work with binaries Why binaries? unify many source languages convenience no source code? debugging analogue: use DWARF metadata But oblivious to cross-module macro expansion cross-module inlining template metaprogramming,... (... at compile time. First two are bad ideas anyway.) Cake... p.10/32

Konqueror + ROX case-study: findings Easy: converting and transferring data interposing on control flow Hard: extricating the history feature from libkonq altering embedded policy bypassing language quirks (protected) manual set-up of infrastructure state understanding infrastructure (binding convention,... ) Interesting: difficulties were infrastructure, not application Cake... p.11/32

Outline of the rest of this talk Design and first case study Second case study: object exchange The Cake language: core The Cake language: practicalities Status and questions Cake... p.12/32

A second case study: evolution gtk-theme-switch one version for Gtk+ 1.2, another for Gtk+ 2.0 forked codebase (maintenance)... diff (-U3) is 500 lines can one binary work with both libraries? Main challenge: exchange of mismatched objects. Cake... p.13/32

Object exchange in action Cake... p.14/32

Outline of the rest of this talk Design and first case study Second case study: object exchange The Cake language: core The Cake language: practicalities Status and questions Cake... p.15/32

Introducing the Cake language Cake is a configuration language i.e. expresses inter-component relationships specifically: mismatch resolutions Cake complements existing languages: accommodates heterogeneity accommodates plug-incompatibility Cake... p.16/32

Cake language: basics Two main kinds of statement: exists describes existing binaries derive derives new ones A simple Cake module: exists elf reloc ( switch2.o ) switch2; exists elf external sharedlib ( gtk-x11-2.0 ) gtk-x11-2.0; exists elf external sharedlib ( gdk-x11-2.0 ) gdk-x11-2.0; //... more follow derive elf executable ( switch2 ) switch-exec = make exec( link [switch2, gtk-x11-2.0, gdk-x11-2.0, /... / ] ); Cake... p.17/32

A simple mismatch, using C++ struct foo { int a; float b; }; int manipulate foo ( struct foo f ); struct foo { float b; int a; char pad ignored [42]; }; int manipulate foo ( struct foo f ); In C++, you might write int wrap manipulate foo ( first :: foo f) { second :: foo obj ; obj.a = f >a; obj.b = f >b; int retval = second :: manipulate foo(&obj); f >a = obj.a; f >b = obj.b; return retval ; } Cake... p.18/32

A simple mismatch, in Cake In Cake, you d write...... nothing! (Assuming sufficient debug information... ) Cake... p.19/32

Function correspondences (1) Consider these two mismatched functions. guint gtk signal connect (GtkObject o, const gchar name, GtkSignalFunc f, gpointer f data ); gulong g signal connect data ( gpointer inst, const gchar detail, GCallback c h, gpointer data, GClosureNotify destroy data, GConnectFlags flags ); How would you manually code around this mismatch? Cake... p.20/32

Function correspondences (2) In Cake: derive /... / switch exec = link [switch12, libgtk20 ] { //... switch12 libgtk20 { gtk signal connect ( i, d, c h, data ) g signal connect data ( i, d, c h, data, null, {}); // more correspondences... } // more pairwise blocks... }; pattern-matching + dual scoping primitive values (e.g. guint guint) for free Cake... p.21/32

Value correspondences Name-matching gets so far. Further: value correspondences. struct GtkWindow { GtkBin bin; gchar title ; //... GtkWindowType type; guint window has focus:1; }; struct GtkWindow { GtkBin bin; gchar title ; //... gchar wm role; guint type :4; / GtkWindowType / guint has focus :1; }; Cake... p.22/32

Value correspondences Name-matching gets so far. Further: value correspondences. struct GtkWindow { GtkBin bin; gchar title ; //... GtkWindowType type; guint window has focus:1; }; struct GtkWindow { GtkBin bin; gchar title ; //... gchar wm role; guint type :4; / GtkWindowType / guint has focus :1; }; switch12 libgtk20 { values GtkWindow GtkWindow { Cake... p.22/32

Value correspondences Name-matching gets so far. Further: value correspondences. struct GtkWindow { GtkBin bin; gchar title ; //... GtkWindowType type; guint window has focus:1; }; struct GtkWindow { GtkBin bin; gchar title ; //... gchar wm role; guint type :4; / GtkWindowType / guint has focus :1; }; switch12 libgtk20 { values GtkWindow GtkWindow { void wm role; Cake... p.22/32

Value correspondences Name-matching gets so far. Further: value correspondences. struct GtkWindow { GtkBin bin; gchar title ; //... GtkWindowType type; guint window has focus:1; }; struct GtkWindow { GtkBin bin; gchar title ; //... gchar wm role; guint type :4; / GtkWindowType / guint has focus :1; }; switch12 libgtk20 { values GtkWindow GtkWindow { void wm role; type as.gtkwindowtype < > type as.gtkwindowtype; Cake... p.22/32

Value correspondences Name-matching gets so far. Further: value correspondences. struct GtkWindow { GtkBin bin; gchar title ; //... GtkWindowType type; guint window has focus:1; }; struct GtkWindow { GtkBin bin; gchar title ; //... gchar wm role; guint type :4; / GtkWindowType / guint has focus :1; }; switch12 libgtk20 { values GtkWindow GtkWindow { } } void wm role; type as.gtkwindowtype < > type as.gtkwindowtype; window has focus has focus ; Cake... p.22/32

More complex correspondence patterns Function patterns may be predicated on call content: // rule matched when using a particular argument value gtk type check object cast (0, ) ( true ); Simple stub language for defining sequences (on RHS): gtk window set policy (win, shrink, grow, ) ( if shrink then gtk window set size request (win, 0, 0) else void; if grow then gtk window set resizable (win, TRUE) else void ); future: context-predicated patterns (stack; sequence... ) Cake... p.23/32

Future: interpretations of object files In the first case study was a notion of component style. dcop( // hide DCOP internals and enable introspection kde-3.x( konqueror, // KDE initialisation and self-binding qt-4.x( // import Qt initialisation constraints gcc-c++-4.x( // apply name-mangling rules etc. elf reloc( // basic interpretation konq historymgr.o ) //... Future work needed to work all this out: define these stackable interpretations code generation Cake... p.24/32

Outline of the rest of this talk Design and first case study Second case study: object exchange The Cake language: core The Cake language: practicalities Status and questions Cake... p.25/32

How Cake understands object files Cake gets quite far using debugging info. But can also use: annotations in exists blocks to supplement debugging info to enable optimisations static analysis (none yet... ) Cake... p.26/32

Annotations enabling optimisations exists elf reloc ( switch.o ) switch12 { declare { gtk dialog new : object { // function returning a vbox: opaque ptr; // pointer to an object, where : ignored; // vbox is opaque to switch12, } ptr // and other fields are ignored } / more annotations... / } opaque and ignored used during object exchange...... to limit depth of deep copy Cake... p.27/32

Choose your own adventurousness Annotations can be made with varying strength. if check, annotation must be verifiable from metadata or static analysis if declare, annotations must not contradict metadata if override, contradiction is allowed Composition tasks naturally cover the spectrum... exists elf reloc ( switch.o ) switch12 { } override { gtk dialog new : GtkDialog ptr; } / static type in source code is imprecise (GtkWidget) / Cake... p.28/32

Treatment of values Cake describes treatment of values, not types there is no type system in Cake (but could be added) But the Cake compiler consumes static metadata! necessary: can t assume RTTI, e.g. in C need stronger assumptions e.g. than C imprecise static types cause problems Primitive data types (i.e. value forms) are defined by a pair DWARF encoding (e.g. unsigned, float, fixed,... ) length in bytes From these, get pointers, enums, structures,... Cake... p.29/32

Summary: what Cake gives the programmer Cake relates heterogeneous, mismatched components. zero-effort handling of simple binary incompatibilities expressive pattern-matching allow conservative or relaxed coding convenient pairwise correspondences ( dual scope ) flexible treatment of data encoding and identifiers (in future) abstraction over component styles Cake... p.30/32

Outline of the rest of this talk Design and first case study Second case study: object exchange The Cake language: core The Cake language: practicalities Status and questions Cake... p.31/32

Status Case-studies implemented as hand-written glue code... but Gtk case study is partially automated stubs and conversion functions are generated by scripts Cake compiler is ongoing right now parses, reads DWARF, merges annotations, complains more soon Runtime library rep man is most developed piece used in the Gtk case study completely generic Thanks for your attention. Any questions? Cake... p.32/32