SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
olibc: Another C Library
optimized for embedded Linux



Jim Huang ( 黃敬群 ) <jserv@0xlab.org>
Developer, 0xlab
                    Feb 22, 2013 / Embedded Linux Conference
Rights to copy
                                                                   © Copyright 2013 0xlab
                                                                          http://0xlab.org/
                                                                           contact@0xlab.org
Attribution – ShareAlike 3.0
                                               Corrections, suggestions, contributions and translations
You are free                                                                             are welcome!
   to copy, distribute, display, and perform the work
   to make derivative works                                               Latest update: Feb 22, 2013
   to make commercial use of the work
Under the following conditions
      Attribution. You must give the original author credit.
      Share Alike. If you alter, transform, or build upon this work, you may distribute the
      resulting work only under a license identical to this one.
   For any reuse or distribution, you must make clear to others the license terms of this work.
   Any of these conditions can be waived if you get permission from the copyright holder.
Your fair use and other rights are in no way affected by the above.
License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode
What I will discuss about...

• I learned a bit about the toolchain and system library
  optimizations while developing Android based
  projects.
• It might be a good idea to “reuse” them in ordinary
  embedded Linux projects.
• Therefore, I plan to emphasize on how to leverage
  the engineering efforts originally from Android world.
   – Review C library characteristics
   – Toolchain optimizations
   – Build configurable runtime
   – Performance evaluation
Related talks

• Android Builders Summit 2013
  – LLVMLinux: Compiling Android with LLVM - Behan
    Webster, Converse in Code - Behan Webster

• Embedded Linux Conference 2013
  – Toybox: Writing a new Linux Command Line from
    Scratch - Rob Landley
  – System-wide Memory Management without Swap -
    Howard Cochran
  – Bringing kconfig to EGLIBC - Khem Raj
Agenda   (1) Take from Android
         (2) olibc: configurable
         (3) Optimizations
         (4) Action Items
Take from Android
bionic libc, dynamic linker, debugging facilities
We know, Android is not Linux, but...




                  ≠
       We're __taking__ someting useful
          back to embedded Linux.
from Rob Landley's talk
       • “Dalvik is the new ROM basic"
       • …
       • “why not extend toolbox/bionic instead of replace?
          – just enough to run dalvik. (The new ROM BASIC.)"




  Our "something useful" is the base to launch Dalvik Virtual Machine
                and the above Android Framework




Source: http://www.landley.net/talks/celf-2013.txt
Source: http://www.landley.net/talks/celf-2013.txt
Why build bionic-derived libc?

       • License
           – glibc (LGPL), uClibc (LGPL), dietlibc (GPL), musl (MIT)

       • Optimized for major (consumer) targets
           – ARMv7 + MIPS + Intel Atom optimizations
           – glibc (good arm/mips/atom), uClibc (simpler
             arm/mips/x86), dietlbc (N/A), musl (simple x86)

       • API coverage is getting more complete by versions.
       • Catch up with latest SoC technologies
           – Contributors: Google, Intel, Qualcomm, Texas
             Instruments, NVIDIA, ST-Ericsson, Linaro, MIPS, etc.
       • The problem is, Android is not a community project.

“Copyleft is dying.
 GPLv2 was category killer, synonymous with copyleft." – Rob Landley
Goals of olibc

• Create small, fast, free, and standard-compliant
  implementation for C Library.
• Offer configurable levels of functionality and should
  scale from tiny embedded Linux up to general
  purpose environments such as Android-powered
  smart devices.
• Provide system utilities around C library
   – benchmarking, validation, prelinker, ...

• Introduce steady security, performance, and
  comformance fixes.
Programming Model
                        loading
                                                                      SoC
#include <stdio.h>                Memory
int main() {
                                                     Execute
    printf(“Hello Wolrdn”);                                              Write
    return 0;                                                             back
}                                 “Stack” Section

    hello.c                                                              Memory
                                                                Reg
    (Source)                       “BSS” Section
                                                                         access
              arm-gcc
              (Compiler)                                                 execute
                                   “Data” Section

                                                                         decode


                                   “Text” Section                PC       fetch

     hello                                                     runtime
     (ELF)




    Let's review the programming model...
Programming Model (multi-threaded)
  Bare-metal            Multi-Thread

                     Stack       Stack        Stack
   “Stack” Section

                     ………………………………
   ………
                                  BSS

   “BSS” Section

                             “Data” Section
   “Data” Section


                     Text        Text         Text
   “Text” Section

                              scheduler
Programming Model (multi-process)
       Multi-Process        [Linux]                 Multi-Process           [Android]




                                              application     application      application

application   application     application


                                                            Framework & VM




                                                            middleware & Library
              Library



                                  scheduler                                        scheduler

              kernel                                            kernel
bionic libc

• Small C Library implementation
    – mixture of NetBSD (libc) and FreeBSD (libm)

•   BSD license
•   Partially POSIX compatible; not compatible with glibc
•   No SysV IPC support (due to Binder IPC)
•   Support for ARM (w/ Thumb), x86, MIPS
•   Fast pthread implementation (based on futexes)
•   Small footprint
    glibc 2.11    : /lib/libc.so            → 1,208,224 bytes
    uClibc 0.9.30 : /lib/libuClibc.so       →   424,235 bytes
    bionic 2.1    : /system/lib/libc.so     →   243,948 bytes
Not in bionic libc

•   Complete wide chars
•   C++ exceptions (limited since NDKr5)
•   Full C++ STL
•   Full POSIX Thread
Memory Map                   [Android pre-4.x]

0x00000000
0x00008000
                app_process

0x40000000
               Java apps and          No memory with execution attribute
               resource data
                                             File mapping direction
             *.apk,*.jar,*.ttf etc.



                                      Some memory are of execution attribute
              Shared lib; libc,
               libwecore etc.                File mapping direction
              various .so files
0xB0000000
             /system/bin/linker

                    Stack
0xBEFFFFFF
Memory related changes

• ASLR (Address space layout randomization) since
  Android 4.0
  – help protect system and third party applications from
    exploits due to memory-management issues
  – PIE (Position Independent Executable) is added since
    Android 4.1
  – original ELF prelinker was removed

• AddressSanitizer since 4.1
AddressSanitizer vs. Valgrind

                       Valgrin           AddressSanitizer
Heap out-of-bounds     Yes               Yes
Stack out-of-bounds    No                Yes
Global out-of-bounds   No                Yes
Use-after-free         Yes               Yes
Use-after-return       No                Sometimes/Yes
Uninitialized reads    Yes               No
Overhead               10x-30x           1.5x-3x
Host platform          Linux, Mac OS X   where (latest)
                                         GCC/LLVM runs
AddressSanitizer
=================================================================
==7161== ERROR: AddressSanitizer global-buffer-overflow on address 0x2a002194 at
pc 0x2a00051b bp 0xbeeafb0c sp 0xbeeafb08
READ of size 4 at 0x2a002194 thread T0
    #0 0x40022a4b (/system/lib/libasan_preload.so+0x8a4b)
    #1 0x40023e77 (/system/lib/libasan_preload.so+0x9e77)
    #2 0x4001c98f (/system/lib/libasan_preload.so+0x298f)
    #3 0x2a000519 (/system/bin/global-out-of-bounds+0x519)
    #4 0x4114371d (/system/lib/libc.so+0x1271d)
0x2a002194 is located 4 bytes to the right of global variable 'global_array
(external/test/global-out-of-bounds.cpp)' (0x2a002000) of size 400
Shadow byte and word:
  0x05400432: f9
  0x05400430: 00 00 f9 f9     int global_array[100] = {-1};
More shadow bytes:
  0x05400420: 00 00 00 00     int main(int argc, char **argv) {
  0x05400424: 00 00 00 00
  0x05400428: 00 00 00 00
                                 return global_array[argc + 100]; /* BOOM */
  0x0540042c: 00 00 00 00     }
=>0x05400430: 00 00 f9 f9
  0x05400434: f9 f9 f9 f9
  0x05400438: 00 00 00 00
  0x0540043c: 00 00 00 00
  0x05400440: 00 00 00 00
Stats: 0M malloced (0M for red zones) by 35 calls
Stats: 0M realloced by 0 calls
Shared library issues

• Older Android dynamic linker has an arbitrary low
  (for larger applications such as GStreamer,
  LibreOffice) limit on number of shared libs: 128
  – Until Sep 12, 2012, dynamically allocating soinfo-structs
    in linker is implemented.

• Mozilla: Use a hacked-up copy of the bionic linker
  in our own code, in addition to the system one.
  – two run-time linkers not aware of each others ended up a
    failure
C++ Integrations
              C++ Exception   C++ RTTI   Standard Library

system        No              No         No

gabi++        No              Yes        No

stlport       No              Yes        Yes

gnustl        Yes             Yes        Yes


• olibc provides stlport, which depends on wchar
  support in libc.
Debuggerd

• Nice embedded-specific crash handler
  – used on all Android devices
• Crash report data placed in log/tombstone
• Debuggerd also facilitates connecting debugger to
  dying process
  – Can halt and wait for gdb to attach to the process

• Apache license
How Debuggerd works
• Debuggerd acts as a crash-handling daemon
• Adds default signal handler to each process, which handles
  any signals that generate core
   – included in bionic, thus every application gets it
• Signal handler captures deadly signal and contacts
  debuggerd
• Debuggerd records information using ptrace (registers,
  stack, memory areas), and /proc
• Has builtin ARM stack unwinder for generating a backtrace
• Automatically rotates a fixed number of crash reports
• Reference:
  https://wiki.linaro.org/WorkingGroups/ToolChain/Outputs/LibunwindDebuggerd
unwinding

• Unwinding = processing stack and memory image
  to create a backtrace
• Backtrace is very compact - summarizes stack
  information nicely
• Local variables usually not available
• Different methods available, depending on
  compilation flags
Crash Handler

• New crash handler written by Tim Bird of Sony
  – Based on debuggerd from Android
• Implemented as a core file handler
• Writes crash report to a “tombstone_0x” file in
  /tmp/tombstones
• Writes information from /proc, ptrace, and kernel
  log buffer
• Also writes some information to the kernel log
• Information: http://elinux.org/Crash_handler
License Issue
• THE BIONIC LIBRARY: DID GOOGLE WORK AROUND
  THE GPL? brownrudnick, Mar 2011
• Bionic Revisited: What the Summary Judgment Ruling in
  Oracle v. Google Means for Android and the GPL,
  brownrudnick, Nov 2011
   – Google tries to “clean” Linux kernel headers to avoid the
     GPL
olibc: configurable
     Kernel


Kernel headers


C Library

  Applications
Major problem: broken toolchain
How Toolchain works
External Toolchain Issues

• CodeSourcery Toolchain doesn't use gold linker,
  and Android's original build flags are a bit
  aggressive.
  – e.g. ICF (Identical Code Folding), which is gold only
    redundancy elimination
  – Option: --icf (known to bring 5% size reduction)

• Default link script doesn't take olibc into
  consideration.
• Sometimes, toolchains have optimization bugs
Build Android compatible toolchain

• Barebone-style building:
  – Inside Android tree
  – Specify all system and bionic header file paths, shared
    library, paths, libgcc.a, crtbegin_*.o, crtend_*.o, etc.

• Standalone-style building:
  – Convenient for native developers:
    arm-xxx-eabi-gcc -mandroid --sysroot=<path-to-sysroot > hello.c -o hello
     (<path to sysroot> is a pre-compiled copy of Bionic)
olibc: Configurable and Optimized

• Configured using the Kconfig language pioneered by
  the Linux kernel
   – Extensions, Library settings, crash handler, ...
• Encapulate the Android build system to become
  simpler and dedicated one.
• Allow full optimization techniques originally applied by
  Android including implementation and toolchain
   – SoC enhancements
• Use repo to manage source tree
   – repo init -u https://github.com/olibc/manifest.git
   – repo sync
Optimizations
Build Tweaks: Symbol Visibility
1
                                 Linux-arm.mk
-fvisibi-lity=hidden
                                  Android.mk              1. Goal: Visibility of a function should match the
                                                              API spec in programmer’s design.
2
                                                          2. Solution:
               __attribute__((visibility(“public”)))
    *.h
               function decl
                                                          First, systematically applying the 5 steps.
                                                          Fundamentally, need to go through the
                                                          APIs of each library:
3                                                               Consciously decide what should be
    $ make        -j5                                          “public” and what shouldn’t.

                                                          3. Result: ~500 KB savings for opencore libs
4
          /tmp/GoOgLe.o: In function foo
                                                          4. Key: The whole hidden functions can be
          src.c: undefined reference to “z”
                                                          garbage collected if unused locally:
                                       Until no failure
5                                                         5. Toolchain’s options:
    __attribute__((visibility(“public”)))
                                                              -ffunction-sections,
    Int z;
                                                              -Wl,--gcsections,
Build Tweaks: code size
                                                                                             (unit: byte)
 • Android default inline options:                  GCC-4.2.1       GCC-4.4.3     GCC-4.4.3
                                                                                  (tuned inline options)
 -finline-functions
 -fno-inline-functions-called-once        Native                                    22,087,436
                                          system
                                          image
                                                    23,839,29       23,027,032
                                                    1

Use genetic algorithm to find best-fit:
-finline
-fno-inline-functions
-finline-functions-called-once
--param max-inline-insns-auto=62
--param inline-unit-growth=0
--param large-unit-insns=0
--param inline-call-cost=4
                                                   GCC-4.2.1          GCC-4.4.3      GCC-4.4.3(tuned)
                                                               Native system image size




Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
Instrumentation-based FDO                          (Feedback-Directed
                                                                  Optimization)
   1. Build twice.
   2. Find representative input
   3. Instrumentation run: 2~3X slower but this perturbation is OK, because
  threading in Android is not that time sensitive
   4. 1 profile per file, dumped at application exit.

                                   arm-xxx-eabi-gcc           3          Optimized
                                                                        Optimized
  arm-xxx-eabi-gcc
 arm-xxx-eabi-gcc          1      arm-xxx-eabi-gcc                        Binary
                                                                         Binary
 –fprofile-generate=./profile      –fprofile-use=./profile.zip
                                  –fprofile-use=./profile.zip
–fprofile-generate=./profile                                             with FDO
                                                                        with FDO


          Instrumented
         Instrumented
              Binary
             Binary


  2    Run the instrumented
      Run the instrumented
               binary
              binary                    Profile.zip
                                       Profile.zip


         Representative
        Representative
           Input Data
          Input Data
FDO Performance
       • Global hotness for ARM (HOT_BB_COUNT_FRACTION, Branch
         prediction routine for the GNU compiler, gcc-4.4.x/gcc/predict.c)
          – 1% improvement on Android's skia library as belows.
           – smaller effects on smaller Android benchmarks.
                                                              (unit: bytes)
     Content      Work       default       fdo-default     fdo-modified

     Size of libskia         7,879,646        7,396,032        7,319,668

     Size reduction             0.00%             6.14%             7.11%

     Stdev (over 100 runs)        0.28             0.63              0.26

     Speedup                           1           0.98              0.97




Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
Dynamic Linker Optimizations

• Why?
  – The major reason to optimize dynamic linker is to speed
    up application startup time.

• How?
  – Implement GNU style hash support for bionic linker
  – Prelinker improvements: incremental global prelinking
(normalized) Dynamic Link time

 1
0.9
0.8
0.7
0.6
0.5                          lp
0.4                          gp
                             re.gp
0.3
                             re.pe.gp
0.2                          re.pe.pgp.gp
0.1                          re.pe.pgp.gp.are
 0
(normalized) Symbol Lookup number

 1
0.9
0.8
0.7
0.6
0.5                             elf.lp
0.4                             elf.gp
                                elf.re.gp
0.3                             elf.re.pe.gp
0.2                             elf.re.pe.pgp.gp
0.1                             elf.re.pe.pgp.gp.are

 0
DT_GNU_HASH: visible dynamic linking improvement =
     Better hash function (few collisions)
     + Drop unnecessary entry from hash
     + Bloom filter

                      void foo (){
     libc.so            printf(“fooooo”);
      printf            bar();
                      }


    libfoo.so
       foo
       bar


                         libfoo.so
           DT_GNU_HASH               DT_HASH
           foo                       foo
           bar                       bar
                                     printf
GNU-style Hash


      SysV ELF hash

 name    2sym collision #        3sym collision #       3+sym collision #
 sysv            1749                   5
 libiberty       42
 dcache          37                    GNU-style hash
 djb2            29
 sdbm            39
 djb3            31
 rot             337                    39                         61
 sax             34
 fnv             40
 oat             30




Experiment by Jakub Jelinek
http://cygwin.com/ml/libc-alpha/2006-06/msg00098.html
Symbol lookup      fail#     gnu         filtered by bloom
                 s      #                     hash
                 in ELF
     gnu.gp        3758     23702     19950     23310               18234(78%)

     gnu.gp.re     3758     20544     16792     19604               14752(75%)

     gnu.lp       61750   460996 399252        450074             345032(76%)

     gnu.lp.re    61750   481626 419882        448492             342378(76%)


                                            H = {x, y, z} = hash functions
                                            Hash function may collision
                                              → Bloom filter may got false positives
Bit array




NOTE: Android 4.0 removes the support of prelinker,
but gnu style hash is still useful.
Action Items
TODO

• Use eglibc-like Option Group
  – based on POSIX.1-2001 specifications
• Comply with relevant standards
• Resolve external toolchain issues
    – Allow arm-none-eabi- and arm-none-linux-gnueabi-
    – Don't depend on prebuilt toolchain anymore

•   Collaboration: crosstool-ng, buildroot, yocto, ...
•   Validation: improve unit-test, bench, ABI test
•   More SoC enhancements
•   Extensions
    – BioMP: Migrating OpenMP into Bionic
       http://code.google.com/p/biomp/
Reference

• olibc hosted at GitHub: http://olibc.github.com/
• Optimizing Android Performance with GCC Compiler, Geunsik
  Lim
• Embedded-Appropriate Crash Handling in Linux, Tim Bird
• Smaller and Faster Android, Shih-wei Liao, Google Inc.
http://0xlab.org

Mais conteúdo relacionado

Mais procurados

Develop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsDevelop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsNational Cheng Kung University
 
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsF9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsNational Cheng Kung University
 
Microkernel-based operating system development
Microkernel-based operating system developmentMicrokernel-based operating system development
Microkernel-based operating system developmentSenko Rašić
 
Introduction to Microkernels
Introduction to MicrokernelsIntroduction to Microkernels
Introduction to MicrokernelsVasily Sartakov
 
Plan9: Bad Movie, Good Operating System
Plan9: Bad Movie, Good Operating SystemPlan9: Bad Movie, Good Operating System
Plan9: Bad Movie, Good Operating SystemQuentin Fennessy
 
A tour of F9 microkernel and BitSec hypervisor
A tour of F9 microkernel and BitSec hypervisorA tour of F9 microkernel and BitSec hypervisor
A tour of F9 microkernel and BitSec hypervisorLouie Lu
 
DTrace in the Non-global Zone
DTrace in the Non-global ZoneDTrace in the Non-global Zone
DTrace in the Non-global Zonebcantrill
 

Mais procurados (20)

Implement Runtime Environments for HSA using LLVM
Implement Runtime Environments for HSA using LLVMImplement Runtime Environments for HSA using LLVM
Implement Runtime Environments for HSA using LLVM
 
Embedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile DevicesEmbedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile Devices
 
Embedded Virtualization for Mobile Devices
Embedded Virtualization for Mobile DevicesEmbedded Virtualization for Mobile Devices
Embedded Virtualization for Mobile Devices
 
μ-Kernel Evolution
μ-Kernel Evolutionμ-Kernel Evolution
μ-Kernel Evolution
 
Develop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsDevelop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM Boards
 
Android Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and OrganizationAndroid Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and Organization
 
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsF9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
 
L4 Microkernel :: Design Overview
L4 Microkernel :: Design OverviewL4 Microkernel :: Design Overview
L4 Microkernel :: Design Overview
 
Construct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoTConstruct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoT
 
Microkernel-based operating system development
Microkernel-based operating system developmentMicrokernel-based operating system development
Microkernel-based operating system development
 
Introduction to Microkernels
Introduction to MicrokernelsIntroduction to Microkernels
Introduction to Microkernels
 
Plan9: Bad Movie, Good Operating System
Plan9: Bad Movie, Good Operating SystemPlan9: Bad Movie, Good Operating System
Plan9: Bad Movie, Good Operating System
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Xvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisorXvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisor
 
Priority Inversion on Mars
Priority Inversion on MarsPriority Inversion on Mars
Priority Inversion on Mars
 
A tour of F9 microkernel and BitSec hypervisor
A tour of F9 microkernel and BitSec hypervisorA tour of F9 microkernel and BitSec hypervisor
A tour of F9 microkernel and BitSec hypervisor
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
Microkernel design
Microkernel designMicrokernel design
Microkernel design
 
DTraceCloud2012
DTraceCloud2012DTraceCloud2012
DTraceCloud2012
 
DTrace in the Non-global Zone
DTrace in the Non-global ZoneDTrace in the Non-global Zone
DTrace in the Non-global Zone
 

Destaque

Lecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationLecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationNational Cheng Kung University
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例National Cheng Kung University
 
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明National Cheng Kung University
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明National Cheng Kung University
 
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明National Cheng Kung University
 
icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介Kito Cheng
 

Destaque (17)

Lecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationLecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and Implementation
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明
進階嵌入式系統開發與實作 (2013 秋季班 ) 課程說明
 
Open Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to EcosystemOpen Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to Ecosystem
 
Develop Your Own Operating System
Develop Your Own Operating SystemDevelop Your Own Operating System
Develop Your Own Operating System
 
2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明
 
How A Compiler Works: GNU Toolchain
How A Compiler Works: GNU ToolchainHow A Compiler Works: GNU Toolchain
How A Compiler Works: GNU Toolchain
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
從線上售票看作業系統設計議題
從線上售票看作業系統設計議題從線上售票看作業系統設計議題
從線上售票看作業系統設計議題
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介
 

Semelhante a Here are the key points about AddressSanitizer:- It detects heap buffer overflows, stack overflows, use-after-free and use-after-return bugs.- It provides better detection than Valgrind for these types of bugs. - The runtime overhead is lower than Valgrind, around 1.5-3x slower execution.- It works by instrumenting the code at compile time (via GCC/LLVM) to add shadow memory and runtime checks.- When a bug is detected, it prints a stack trace and debug information about the invalid memory access.- It has been included in Android since version 4.1 to help find memory bugs in the system and third

Cross-compilation native sous android
Cross-compilation native sous androidCross-compilation native sous android
Cross-compilation native sous androidThierry Gayet
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetesKrishna-Kumar
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker IntroductionHao Fan
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded LinuxTushar B Kute
 
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...Takaya Saeki
 
Unikernels - Bristech June 2016
Unikernels - Bristech June 2016 Unikernels - Bristech June 2016
Unikernels - Bristech June 2016 Daniel Drozdzewski
 
A Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeA Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeAll Things Open
 
Making clouds: turning opennebula into a product
Making clouds: turning opennebula into a productMaking clouds: turning opennebula into a product
Making clouds: turning opennebula into a productCarlo Daffara
 
Making Clouds: Turning OpenNebula into a Product
Making Clouds: Turning OpenNebula into a ProductMaking Clouds: Turning OpenNebula into a Product
Making Clouds: Turning OpenNebula into a ProductNETWAYS
 
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...OpenNebula Project
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlabNational Cheng Kung University
 
Linux on System z Update: Current & Future Linux on System z Technology
Linux on System z Update: Current & Future Linux on System z TechnologyLinux on System z Update: Current & Future Linux on System z Technology
Linux on System z Update: Current & Future Linux on System z TechnologyIBM India Smarter Computing
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMSherif Mousa
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
UniK - a unikernel compiler and runtime
UniK - a unikernel compiler and runtimeUniK - a unikernel compiler and runtime
UniK - a unikernel compiler and runtimeLee Calcote
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in LinuxSadegh Dorri N.
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackJackson F. de A. Mafra
 

Semelhante a Here are the key points about AddressSanitizer:- It detects heap buffer overflows, stack overflows, use-after-free and use-after-return bugs.- It provides better detection than Valgrind for these types of bugs. - The runtime overhead is lower than Valgrind, around 1.5-3x slower execution.- It works by instrumenting the code at compile time (via GCC/LLVM) to add shadow memory and runtime checks.- When a bug is detected, it prints a stack trace and debug information about the invalid memory access.- It has been included in Android since version 4.1 to help find memory bugs in the system and third (20)

Cross-compilation native sous android
Cross-compilation native sous androidCross-compilation native sous android
Cross-compilation native sous android
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetes
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded Linux
 
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
 
Unikernels - Bristech June 2016
Unikernels - Bristech June 2016 Unikernels - Bristech June 2016
Unikernels - Bristech June 2016
 
A Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeA Tour of Open Source on the Mainframe
A Tour of Open Source on the Mainframe
 
Making clouds: turning opennebula into a product
Making clouds: turning opennebula into a productMaking clouds: turning opennebula into a product
Making clouds: turning opennebula into a product
 
Making Clouds: Turning OpenNebula into a Product
Making Clouds: Turning OpenNebula into a ProductMaking Clouds: Turning OpenNebula into a Product
Making Clouds: Turning OpenNebula into a Product
 
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...
OpenNebulaConf 2013 - Making Clouds: Turning OpenNebula into a Product by Car...
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab
 
Linux on System z Update: Current & Future Linux on System z Technology
Linux on System z Update: Current & Future Linux on System z TechnologyLinux on System z Update: Current & Future Linux on System z Technology
Linux on System z Update: Current & Future Linux on System z Technology
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
UniK - a unikernel compiler and runtime
UniK - a unikernel compiler and runtimeUniK - a unikernel compiler and runtime
UniK - a unikernel compiler and runtime
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in Linux
 
Cont0519
Cont0519Cont0519
Cont0519
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - Stack
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 

Último

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Here are the key points about AddressSanitizer:- It detects heap buffer overflows, stack overflows, use-after-free and use-after-return bugs.- It provides better detection than Valgrind for these types of bugs. - The runtime overhead is lower than Valgrind, around 1.5-3x slower execution.- It works by instrumenting the code at compile time (via GCC/LLVM) to add shadow memory and runtime checks.- When a bug is detected, it prints a stack trace and debug information about the invalid memory access.- It has been included in Android since version 4.1 to help find memory bugs in the system and third

  • 1. olibc: Another C Library optimized for embedded Linux Jim Huang ( 黃敬群 ) <jserv@0xlab.org> Developer, 0xlab Feb 22, 2013 / Embedded Linux Conference
  • 2. Rights to copy © Copyright 2013 0xlab http://0xlab.org/ contact@0xlab.org Attribution – ShareAlike 3.0 Corrections, suggestions, contributions and translations You are free are welcome! to copy, distribute, display, and perform the work to make derivative works Latest update: Feb 22, 2013 to make commercial use of the work Under the following conditions Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode
  • 3. What I will discuss about... • I learned a bit about the toolchain and system library optimizations while developing Android based projects. • It might be a good idea to “reuse” them in ordinary embedded Linux projects. • Therefore, I plan to emphasize on how to leverage the engineering efforts originally from Android world. – Review C library characteristics – Toolchain optimizations – Build configurable runtime – Performance evaluation
  • 4. Related talks • Android Builders Summit 2013 – LLVMLinux: Compiling Android with LLVM - Behan Webster, Converse in Code - Behan Webster • Embedded Linux Conference 2013 – Toybox: Writing a new Linux Command Line from Scratch - Rob Landley – System-wide Memory Management without Swap - Howard Cochran – Bringing kconfig to EGLIBC - Khem Raj
  • 5. Agenda (1) Take from Android (2) olibc: configurable (3) Optimizations (4) Action Items
  • 6. Take from Android bionic libc, dynamic linker, debugging facilities
  • 7. We know, Android is not Linux, but... ≠ We're __taking__ someting useful back to embedded Linux.
  • 8. from Rob Landley's talk • “Dalvik is the new ROM basic" • … • “why not extend toolbox/bionic instead of replace? – just enough to run dalvik. (The new ROM BASIC.)" Our "something useful" is the base to launch Dalvik Virtual Machine and the above Android Framework Source: http://www.landley.net/talks/celf-2013.txt Source: http://www.landley.net/talks/celf-2013.txt
  • 9. Why build bionic-derived libc? • License – glibc (LGPL), uClibc (LGPL), dietlibc (GPL), musl (MIT) • Optimized for major (consumer) targets – ARMv7 + MIPS + Intel Atom optimizations – glibc (good arm/mips/atom), uClibc (simpler arm/mips/x86), dietlbc (N/A), musl (simple x86) • API coverage is getting more complete by versions. • Catch up with latest SoC technologies – Contributors: Google, Intel, Qualcomm, Texas Instruments, NVIDIA, ST-Ericsson, Linaro, MIPS, etc. • The problem is, Android is not a community project. “Copyleft is dying. GPLv2 was category killer, synonymous with copyleft." – Rob Landley
  • 10. Goals of olibc • Create small, fast, free, and standard-compliant implementation for C Library. • Offer configurable levels of functionality and should scale from tiny embedded Linux up to general purpose environments such as Android-powered smart devices. • Provide system utilities around C library – benchmarking, validation, prelinker, ... • Introduce steady security, performance, and comformance fixes.
  • 11. Programming Model loading SoC #include <stdio.h> Memory int main() { Execute printf(“Hello Wolrdn”); Write return 0; back } “Stack” Section hello.c Memory Reg (Source) “BSS” Section access arm-gcc (Compiler) execute “Data” Section decode “Text” Section PC fetch hello runtime (ELF) Let's review the programming model...
  • 12. Programming Model (multi-threaded) Bare-metal Multi-Thread Stack Stack Stack “Stack” Section ……………………………… ……… BSS “BSS” Section “Data” Section “Data” Section Text Text Text “Text” Section scheduler
  • 13. Programming Model (multi-process) Multi-Process [Linux] Multi-Process [Android] application application application application application application Framework & VM middleware & Library Library scheduler scheduler kernel kernel
  • 14. bionic libc • Small C Library implementation – mixture of NetBSD (libc) and FreeBSD (libm) • BSD license • Partially POSIX compatible; not compatible with glibc • No SysV IPC support (due to Binder IPC) • Support for ARM (w/ Thumb), x86, MIPS • Fast pthread implementation (based on futexes) • Small footprint glibc 2.11 : /lib/libc.so → 1,208,224 bytes uClibc 0.9.30 : /lib/libuClibc.so → 424,235 bytes bionic 2.1 : /system/lib/libc.so → 243,948 bytes
  • 15. Not in bionic libc • Complete wide chars • C++ exceptions (limited since NDKr5) • Full C++ STL • Full POSIX Thread
  • 16. Memory Map [Android pre-4.x] 0x00000000 0x00008000 app_process 0x40000000 Java apps and No memory with execution attribute resource data File mapping direction *.apk,*.jar,*.ttf etc. Some memory are of execution attribute Shared lib; libc, libwecore etc. File mapping direction various .so files 0xB0000000 /system/bin/linker Stack 0xBEFFFFFF
  • 17. Memory related changes • ASLR (Address space layout randomization) since Android 4.0 – help protect system and third party applications from exploits due to memory-management issues – PIE (Position Independent Executable) is added since Android 4.1 – original ELF prelinker was removed • AddressSanitizer since 4.1
  • 18. AddressSanitizer vs. Valgrind Valgrin AddressSanitizer Heap out-of-bounds Yes Yes Stack out-of-bounds No Yes Global out-of-bounds No Yes Use-after-free Yes Yes Use-after-return No Sometimes/Yes Uninitialized reads Yes No Overhead 10x-30x 1.5x-3x Host platform Linux, Mac OS X where (latest) GCC/LLVM runs
  • 19. AddressSanitizer ================================================================= ==7161== ERROR: AddressSanitizer global-buffer-overflow on address 0x2a002194 at pc 0x2a00051b bp 0xbeeafb0c sp 0xbeeafb08 READ of size 4 at 0x2a002194 thread T0 #0 0x40022a4b (/system/lib/libasan_preload.so+0x8a4b) #1 0x40023e77 (/system/lib/libasan_preload.so+0x9e77) #2 0x4001c98f (/system/lib/libasan_preload.so+0x298f) #3 0x2a000519 (/system/bin/global-out-of-bounds+0x519) #4 0x4114371d (/system/lib/libc.so+0x1271d) 0x2a002194 is located 4 bytes to the right of global variable 'global_array (external/test/global-out-of-bounds.cpp)' (0x2a002000) of size 400 Shadow byte and word: 0x05400432: f9 0x05400430: 00 00 f9 f9 int global_array[100] = {-1}; More shadow bytes: 0x05400420: 00 00 00 00 int main(int argc, char **argv) { 0x05400424: 00 00 00 00 0x05400428: 00 00 00 00 return global_array[argc + 100]; /* BOOM */ 0x0540042c: 00 00 00 00 } =>0x05400430: 00 00 f9 f9 0x05400434: f9 f9 f9 f9 0x05400438: 00 00 00 00 0x0540043c: 00 00 00 00 0x05400440: 00 00 00 00 Stats: 0M malloced (0M for red zones) by 35 calls Stats: 0M realloced by 0 calls
  • 20. Shared library issues • Older Android dynamic linker has an arbitrary low (for larger applications such as GStreamer, LibreOffice) limit on number of shared libs: 128 – Until Sep 12, 2012, dynamically allocating soinfo-structs in linker is implemented. • Mozilla: Use a hacked-up copy of the bionic linker in our own code, in addition to the system one. – two run-time linkers not aware of each others ended up a failure
  • 21. C++ Integrations C++ Exception C++ RTTI Standard Library system No No No gabi++ No Yes No stlport No Yes Yes gnustl Yes Yes Yes • olibc provides stlport, which depends on wchar support in libc.
  • 22. Debuggerd • Nice embedded-specific crash handler – used on all Android devices • Crash report data placed in log/tombstone • Debuggerd also facilitates connecting debugger to dying process – Can halt and wait for gdb to attach to the process • Apache license
  • 23. How Debuggerd works • Debuggerd acts as a crash-handling daemon • Adds default signal handler to each process, which handles any signals that generate core – included in bionic, thus every application gets it • Signal handler captures deadly signal and contacts debuggerd • Debuggerd records information using ptrace (registers, stack, memory areas), and /proc • Has builtin ARM stack unwinder for generating a backtrace • Automatically rotates a fixed number of crash reports • Reference: https://wiki.linaro.org/WorkingGroups/ToolChain/Outputs/LibunwindDebuggerd
  • 24. unwinding • Unwinding = processing stack and memory image to create a backtrace • Backtrace is very compact - summarizes stack information nicely • Local variables usually not available • Different methods available, depending on compilation flags
  • 25. Crash Handler • New crash handler written by Tim Bird of Sony – Based on debuggerd from Android • Implemented as a core file handler • Writes crash report to a “tombstone_0x” file in /tmp/tombstones • Writes information from /proc, ptrace, and kernel log buffer • Also writes some information to the kernel log • Information: http://elinux.org/Crash_handler
  • 26. License Issue • THE BIONIC LIBRARY: DID GOOGLE WORK AROUND THE GPL? brownrudnick, Mar 2011 • Bionic Revisited: What the Summary Judgment Ruling in Oracle v. Google Means for Android and the GPL, brownrudnick, Nov 2011 – Google tries to “clean” Linux kernel headers to avoid the GPL
  • 27. olibc: configurable Kernel Kernel headers C Library Applications
  • 30. External Toolchain Issues • CodeSourcery Toolchain doesn't use gold linker, and Android's original build flags are a bit aggressive. – e.g. ICF (Identical Code Folding), which is gold only redundancy elimination – Option: --icf (known to bring 5% size reduction) • Default link script doesn't take olibc into consideration. • Sometimes, toolchains have optimization bugs
  • 31. Build Android compatible toolchain • Barebone-style building: – Inside Android tree – Specify all system and bionic header file paths, shared library, paths, libgcc.a, crtbegin_*.o, crtend_*.o, etc. • Standalone-style building: – Convenient for native developers: arm-xxx-eabi-gcc -mandroid --sysroot=<path-to-sysroot > hello.c -o hello (<path to sysroot> is a pre-compiled copy of Bionic)
  • 32. olibc: Configurable and Optimized • Configured using the Kconfig language pioneered by the Linux kernel – Extensions, Library settings, crash handler, ... • Encapulate the Android build system to become simpler and dedicated one. • Allow full optimization techniques originally applied by Android including implementation and toolchain – SoC enhancements • Use repo to manage source tree – repo init -u https://github.com/olibc/manifest.git – repo sync
  • 33.
  • 35. Build Tweaks: Symbol Visibility 1 Linux-arm.mk -fvisibi-lity=hidden Android.mk 1. Goal: Visibility of a function should match the API spec in programmer’s design. 2 2. Solution: __attribute__((visibility(“public”))) *.h function decl First, systematically applying the 5 steps. Fundamentally, need to go through the APIs of each library: 3  Consciously decide what should be $ make -j5 “public” and what shouldn’t. 3. Result: ~500 KB savings for opencore libs 4 /tmp/GoOgLe.o: In function foo 4. Key: The whole hidden functions can be src.c: undefined reference to “z” garbage collected if unused locally: Until no failure 5 5. Toolchain’s options: __attribute__((visibility(“public”))) -ffunction-sections, Int z; -Wl,--gcsections,
  • 36. Build Tweaks: code size (unit: byte) • Android default inline options: GCC-4.2.1 GCC-4.4.3 GCC-4.4.3 (tuned inline options) -finline-functions -fno-inline-functions-called-once Native 22,087,436 system image 23,839,29 23,027,032 1 Use genetic algorithm to find best-fit: -finline -fno-inline-functions -finline-functions-called-once --param max-inline-insns-auto=62 --param inline-unit-growth=0 --param large-unit-insns=0 --param inline-call-cost=4 GCC-4.2.1 GCC-4.4.3 GCC-4.4.3(tuned) Native system image size Source: Smaller and Faster Android, Shih-wei Liao, Google Inc. Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
  • 37. Instrumentation-based FDO (Feedback-Directed Optimization) 1. Build twice. 2. Find representative input 3. Instrumentation run: 2~3X slower but this perturbation is OK, because threading in Android is not that time sensitive 4. 1 profile per file, dumped at application exit. arm-xxx-eabi-gcc 3 Optimized Optimized arm-xxx-eabi-gcc arm-xxx-eabi-gcc 1 arm-xxx-eabi-gcc Binary Binary –fprofile-generate=./profile –fprofile-use=./profile.zip –fprofile-use=./profile.zip –fprofile-generate=./profile with FDO with FDO Instrumented Instrumented Binary Binary 2 Run the instrumented Run the instrumented binary binary Profile.zip Profile.zip Representative Representative Input Data Input Data
  • 38. FDO Performance • Global hotness for ARM (HOT_BB_COUNT_FRACTION, Branch prediction routine for the GNU compiler, gcc-4.4.x/gcc/predict.c) – 1% improvement on Android's skia library as belows. – smaller effects on smaller Android benchmarks. (unit: bytes) Content Work default fdo-default fdo-modified Size of libskia 7,879,646 7,396,032 7,319,668 Size reduction 0.00% 6.14% 7.11% Stdev (over 100 runs) 0.28 0.63 0.26 Speedup 1 0.98 0.97 Source: Smaller and Faster Android, Shih-wei Liao, Google Inc. Source: Smaller and Faster Android, Shih-wei Liao, Google Inc.
  • 39. Dynamic Linker Optimizations • Why? – The major reason to optimize dynamic linker is to speed up application startup time. • How? – Implement GNU style hash support for bionic linker – Prelinker improvements: incremental global prelinking
  • 40. (normalized) Dynamic Link time 1 0.9 0.8 0.7 0.6 0.5 lp 0.4 gp re.gp 0.3 re.pe.gp 0.2 re.pe.pgp.gp 0.1 re.pe.pgp.gp.are 0
  • 41. (normalized) Symbol Lookup number 1 0.9 0.8 0.7 0.6 0.5 elf.lp 0.4 elf.gp elf.re.gp 0.3 elf.re.pe.gp 0.2 elf.re.pe.pgp.gp 0.1 elf.re.pe.pgp.gp.are 0
  • 42. DT_GNU_HASH: visible dynamic linking improvement = Better hash function (few collisions) + Drop unnecessary entry from hash + Bloom filter void foo (){ libc.so printf(“fooooo”); printf bar(); } libfoo.so foo bar libfoo.so DT_GNU_HASH DT_HASH foo foo bar bar printf
  • 43. GNU-style Hash SysV ELF hash name 2sym collision # 3sym collision # 3+sym collision # sysv 1749 5 libiberty 42 dcache 37 GNU-style hash djb2 29 sdbm 39 djb3 31 rot 337 39 61 sax 34 fnv 40 oat 30 Experiment by Jakub Jelinek http://cygwin.com/ml/libc-alpha/2006-06/msg00098.html
  • 44. Symbol lookup fail# gnu filtered by bloom s # hash in ELF gnu.gp 3758 23702 19950 23310 18234(78%) gnu.gp.re 3758 20544 16792 19604 14752(75%) gnu.lp 61750 460996 399252 450074 345032(76%) gnu.lp.re 61750 481626 419882 448492 342378(76%) H = {x, y, z} = hash functions Hash function may collision → Bloom filter may got false positives Bit array NOTE: Android 4.0 removes the support of prelinker, but gnu style hash is still useful.
  • 46. TODO • Use eglibc-like Option Group – based on POSIX.1-2001 specifications • Comply with relevant standards • Resolve external toolchain issues – Allow arm-none-eabi- and arm-none-linux-gnueabi- – Don't depend on prebuilt toolchain anymore • Collaboration: crosstool-ng, buildroot, yocto, ... • Validation: improve unit-test, bench, ABI test • More SoC enhancements • Extensions – BioMP: Migrating OpenMP into Bionic http://code.google.com/p/biomp/
  • 47. Reference • olibc hosted at GitHub: http://olibc.github.com/ • Optimizing Android Performance with GCC Compiler, Geunsik Lim • Embedded-Appropriate Crash Handling in Linux, Tim Bird • Smaller and Faster Android, Shih-wei Liao, Google Inc.