I. Compiler & Debugger

A. LLVM Compiler

LLVM (llvm.org) builds compiler as a set of libraries. This enables rapid innovation and attack problem like never before.

  • In Xcode, LLVM uses Clang front end to parse source code into interim format.
  • LLVM code generation layer (back-end) turns this interim format to final machine code.
  • This front-end/ back-end approach is very powerful. Front-end can also be LLVM GCC (also included in Xcode).

Link-time optimisation, static analysis .. are now available due to LLVM.

B. LLDB Debugger

II. Linkers

In iOS there are 2 types of linking, the (static) linking is done in Compilation, and the Dynamic Linking (or Late Linking) is done at runtime.

A. Static Linker

B. Dynamic Linker

Dynamic Linker is part of Operating System which copies the shared libraries needed by executed code to RAM, then fill jump table and relocate pointers (in other words, load code to a running process & link/bind code to the running process).

  • In Windows, DLL (dynamic linked library) is the shared library – loaded at runtime.
  • In UNIX, Dynamic Linker (ld) can be configured with environment variables such as LD_PRELOAD , or LD_LIBRARY_PATH
  • On iOS and OSX (built upon Apple Darwin OS) the Dynamic Linker (ld) machine code is executed as part of the exec or posix_spawn call.

Exec is the OS functionality to run an executable file in context of a running process, replacing the previous executable file. As process is reused, Pid stays the same, but machine code, data, heap & stack of process is replaced by those of new program.

Spawn is a metaphor for laying egg – creating offspring; fork and spawn both create offspring process but fork does a crude copy (faster) while spawn reliably construct process parameters (slower).

POSIX is the IEEE standard for Unix-like OS: Posix defines standard programs like awk, echo, ed. ed is line-editor, not being used due to vi or Emacs, but if something is wrong, ed is the only available editor.

III. Libraries Based on the types of linking, there are 2 types of libraries – static libraries and dynamic libraries.

A. Static Library

B. Dynamic Library Dynamic libraries allow the app to load the code into it’s address space when it’s actually needed (either at launch time or runtime). Dynamic libraries are not part of executable file – their linking to the program is dynamic (linked later on demand).

Advertisements