Building a Portable LSB Application - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Building a Portable LSB Application

Description:

The Free Standards Group offers a certification program at http://www.freestandards.org ... add a getpassword routine and call it it seemed the cheapest hack ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 34
Provided by: linux8
Category:

less

Transcript and Presenter's Notes

Title: Building a Portable LSB Application


1
Linux Standard Base
  • Building a Portable LSB Application
  • Notes for a tutorial presented at the Ottawa
    Linux Symposium July 25 2003
  • Mats Wichmann, Intel
  • LSB Workgroup
  • mats.d.wichmann_at_intel.com

2
Binary Compatibility
  • The LSB describes a stable runtime environment
    for apps core functionality
  • Required shared libraries
  • A description of the behaviour of public
    interfaces
  • Symbol versioning as needed
  • An LSB dynamic linker
  • Commands needed for installation, startup
  • Includes the FHS where things go

3
LSB Components
  • The LSB Project Produces
  • LSB Written Specification (ABI)
  • One base spec, many processor supplements
  • Runtime Test Suite
  • Development Environment
  • Sample Implementation
  • Mini-distro, used as example and testbed
  • Application Battery

4
LSB Compliance
  • For a distribution, the LSB describes a Runtime
    Environment for applications
  • Means ready to run a compliant application
  • Not that ordinary commands are compiled as LSB
  • Supply a runtime linker, compliant libraries
    commands, ...
  • Prove by running the tests, example applications
  • Can be implemented on a non-Linux system

5
LSB Certified Distros
  • The Free Standards Group offers a certification
    program at http//www.freestandards.org
  • Pay a fee, submit test results, use the LSB
    Certified logo
  • All major Linux distributions are LSB Certified
  • Red Hat, SuSE, Mandrake, Turbo, Connectiva, etc.
  • many others (22 certifications as of 7/2003
    including for LSB 1.3 and non-ia32 architectures)

6
LSB Application Compliance
  • Use only LSB interfaces and libraries
  • Link against LSB runtime linker LSB DSOs (only)
  • Statically link with non-LSB specified libs, or
    bundle non-LSB shared libs with the app
  • Pass LSB Application Checker
  • Pass FHS checklist
  • Pass application's FVT on LSB SI and two LSB
    systems
  • Package in LSB-described rpm format

7
Building
  • How to make sure the rules are followed?
  • The spec is lengthy
  • By reference, it includes many shelf-feet of
    additional specs (!)
  • The LSB doesnt describe a development
    environment
  • The answer tools
  • lsbappchk examine a binary (statically)
  • clean stub libraries and headers
  • Toolkits to control compile and link
  • two available

8
Build Toolkits
  • chroot environment
  • Isolated environment
  • Explicitly imports non-LSB commands, libraries
    through bind mounts
  • Better for self-contained builds
  • compiler wrapper (lsbcc and lsbc)
  • Restricted build in standard environment
  • Better for builds that need non-LSB features
  • In particular, for GNU-style configure scripts

9
A Trivial Program
  • Lets see the tools in action
  • hello.c (with a twist)
  • cat hello.cinclude include
    main() printf("hello world d\n",
    getpid())
  • gcc hello.o o hello-1 ./hello-1hello world
    14250

10
A Trivial Program
  • /opt/lsbappchk/bin/lsbappchk hello-1lsbappchk
    for LSB Specification 1.3.3Checking binary
    hello-1Incorrect program interpreter
    /lib/ld-linux.so.2Header 1 PT_INTERP
    FailedFound wrong intepreter in .interp section
    /lib/ld-linux.so.2 instead of /lib/ld-lsb.so.1
  • Thats not an LSB binary

11
The chroot Environment
  • A chroot that imports
  • gcc toolchain (binutils)
  • LSB stub libraries and header files
  • A copy of RPM for packaging
  • Start and stop scripts
  • Editable customization files
  • An ssh setup to enter the chroot

12
lsbdev-chroot Install
  • lsbdev-chroot requires
  • lsbdev-base, lsbdev-chroot, lsb-rpm
  • Available as rpm or deb packages
  • Find the latest kits at
  • http//www.linuxbase.org/download.html

13
Configure lsbdev-chroot
  • Package configuration
  • view /opt/lsbdev-base/doc/README
  • Edit /etc/lsbdev-chroot/lsbdev-chroot.conf
  • change BUILDUSERS for your users
  • Import extra directories
  • /etc/lsbdev-chroot/extra_mount_dirs.conf
  • Import individual extra files
  • /etc/lsbdev-chroot/extra_mount_files.conf

14
Running lsbdev-chroot
  • Startup
  • /etc/init.d/lsbdev-chroot start
  • initializes a chrootable environment
  • mounts system files in the chroot
  • starts SSHD on port 5436 in the chroot
  • can slogin to this port
  • Shutdown
  • /etc/init.d/lsbdev-chroot stop
  • stops SSHD
  • unmounts the system files

15
Example using chroot
  • Build, check, test
  • slogin p 5436 localhost gcc hello.c -o
    hello-2 ./hello-2hello world 14250
    /opt/lsbappchk/bin/lsbappchk hello-2lsbappchk
    for LSB Specification 1.3.3Checking binary
    hello-2
  • If it doesnt run, the distros LSB package is
    probsably not installed!
  • On ia32, check for /lib/ld-lsb.so.1

16
The lsbcc wrapper
  • lsbcc / lsbc wrappers are invoked as if they
    were the compiler
  • Fiddle with arguments, then invoke real compiler
  • Alternate names/locations for compiler supported
  • Make sure stub libraries are linked against
  • Make sure all other libraries are linked
    statically
  • Use LSB headers
  • Install
  • lsbdev-base, lsbdev-cc, lsbdev-c (if needed)

17
Example using lsbcc
  • lsbcc hello.c -o hello-3 ./hello-3hello
    world 14986 /opt/lsbappchk/bin/lsbappchk
    hello-3lsbappchk for LSB Specification
    1.3.3Checking binary hello-3

18
The lsbsi test environment
  • The lsb-si (Sample Implementation) is a
    mini-distro
  • Designed to include only whats required by the
    LSB specification
  • Built using the Linux-from-scratch (LFS) model
  • Useful for catching non-LSB stuff the lsbsi
    probably doesnt have it!
  • The easiest way to use the lsbsi is the user mode
    Linux (uml) form lsb-umlsi (ia32 only)
  • A configuration script prompts for setup on first
    run

19
Example testing in umlsi
  • After installing the umlsi,
  • /opt/lsb-umlsi/bin/umlsi
  • Wait for it to boot, log in
  • lsbsi/root mount...none on /mnt/disk type
    hostfs (rw)lsbsi/root cd /mnt/disk/home/mats/OL
    S/srclsbsi/mnt/disk/home/mats/OLS/src
    ./hello-2hello world 88lsbsi/mnt/disk/home/mat
    s/OLS/src ./hello-3hello world
    89lsbsi/mnt/disk/home/mats/OLS/src
    ./hello-1-bash ./hello-1 No such file or
    directoryhome/mats/OLS/src
  • Notice the lsbsi wont run the non-LSB binary!

Hosts filesystem is mounted here
20
Compiling bad code
  • What if we break the source?
  • readelf s /lib/libc.so.6 grep
    getpid000bb160 g DF .text 00000032 GLIBC_2.0
    __getpid000bb160 w DF .text 00000032 GLIBC_2.0
    getpid
  • Change the code to use the internal __getpid in
    hello2.c
  • cc hello2.c ./a.outhello world 11185
  • Thats still a working program natively, but
    should have an additional LSB conformance problem

21
bad code
  • lsbappchk a.outlsbappchk for LSB Specification
    1.3.3Checking binary a.outIncorrect program
    interpreter /lib/ld-linux.so.2Header 1
    PT_INTERP FailedFound wrong intepreter in
    .interp section /lib/ld-linux.so.2 instead of
    /lib/ld-lsb.so.1Symbol __getpid used, but not
    part of LSB lsbcc hello2.c/tmp/ccqrdLCg.o In
    function main'/tmp/ccqrdLCg.o(.text0x17)
    undefined reference to __getpidcollect2 ld
    returned 1 exit status
  • The stub libraries prevent linking it

oops!
22
LSB Packaging Issues
  • LSB packages need to install into FHS-conforming
    locations
  • Generally, /opt/package, /etc/opt/package and
    /var/opt/package
  • Follow the FHS checklist
  • Initscripts are installed through a required
    installer (install_initd), not directly
  • Packages should be in rpm format
  • Doesnt mean the rpm command is required
  • LSB specifies the RPM package format, and
    provides a tool to check a package is okay

23
More Packaging
  • RPM is used for packaging, not for building
  • In practice, most versions of RPM will package
    okay
  • But distros rpm is unlikely to have LSB building
    rules
  • LSB packages may not use triggers
  • Packages should depend on lsb and nothing else
    except other known LSB conforming packages
  • Dont depend on distros packages!
  • Names should start with lsb-, and be registered
    with LANANA to keep a clean package namespace

24
More complex example
  • Lets examine the rsync program
  • lsbappchk /usr/bin/rsynclsbappchk for LSB
    Specification 1.3.3 Checking binary
    /usr/bin/rsyncIncorrect program interpreter
    /lib/ld-linux.so.2Header 1 PT_INTERP
    FailedFound wrong intepreter in .interp section
    /lib/ld-linux.so.2 instead of /lib/ld-lsb.so.1DT
    _NEEDED libpopt.so.0 is used, but not part of
    the LSBDT_NEEDED libresolv.so.2 is used, but
    not part of the LSBSymbol poptGetContext used,
    but not part of LSB. . . Symbol getpass used,
    but not part of LSBSymbol mallinfo used, but not
    part of LSBSymbol glob64 has version GLIBC_2.2
    expecting GLIBC_2.1

25
complex
  • How many of these are problems?
  • Saw two non-LSB libraries
  • Several non-LSB interfaces, some from one of the
    non-LSB libs, but not all
  • One symbol version issue
  • The libraries may be eliminated by running
    configure the right way
  • The non-LSB symbols may go away

26
complex
  • Symbol version issue
  • readelf -s /lib/libc.so.6 grep glob64 405
    000a0f30 3378 FUNC GLOBAL DEFAULT 11
    glob64_at_GLIBC_2.1 2084 0009f9c0 3378 FUNC
    GLOBAL DEFAULT 11 glob64_at__at_GLIBC_2.2 readelf
    -s /opt/lsbdev-base/lib/libc.so grep glob64
    837 00007798 5 FUNC GLOBAL DEFAULT 6
    glob64_at__at_GLIBC_2.1 842 00007798 5 FUNC
    GLOBAL DEFAULT 6 glob64
  • Version 2.1 will be linked from the stub libc,
    and is found in the system libc, so this will be
    okay

27
complex
  • Given some uncertainty, lets just try it
  • CClsbcc ./configureconfigure Configuring
    rsync 2.5.5...checking for gcc...
    lsbcc...checking for inet_ntop in -lresolv...
    yes...checking for mallinfo... no...checking
    for poptGetContext in -lpopt... yes
  • This looks fairly okay
  • lsbcc has turned libresolv and libpopt into
    static links

28
complex
  • On build, some problems appear, however . . .
  • lsbcc -I. -I. -g -O2 -DHAVE_CONFIG_H -Wall -W -c
    clientname.c -o clientname.oclientname.c In
    function client_sockaddr'clientname.c120
    warning implicit declaration of function
    IN6_IS_ADDR_V4MAPPEDclientname.c120
    dereferencing pointer to incomplete
    typeclientname.c127 storage size of sin6'
    isn't knownclientname.c127 warning unused
    variable sin6clientname.c In function
    compare_addrinfo_sockaddr'clientname.c213
    dereferencing pointer to incomplete type
  • The LSB headers dont support IPV6 yet (coming in
    2.0), but digging shows we can disable this via
    configure

29
complex
  • Once thats fixed, a rebuild shows getpass is not
    found
  • This is not an LSB interface, and was not checked
    for or worked around by configure
  • We wrote a patch to add a getpassword routine and
    call it it seemed the cheapest hack
  • After some study of FHS issues, rsync is
    configured like this
  • CClsbcc ./configure -disable-ipv6
    \-prefix/opt/lsb-rsync

30
complex
  • It also needs one FHS patch that cant be set via
    configure
  • --- rsync.h.orig rsync.h_at__at_ -26,7 26,7 _at__at_
    define RSYNC_RSH_ENV "RSYNC_RSH define
    RSYNC_NAME "rsync-define RSYNCD_CONF
    "/etc/rsyncd.confdefine RSYNCD_CONF
    "/etc/opt/lsb-rsync/rsyncd.conf define
    DEFAULT_LOCK_FILE "/var/run/rsyncd.lock define
    URL_PREFIX "rsync//"

Change to FHS path
31
Thoughts
  • Static linking
  • Sometimes non-LSB code is unavoidable
  • Document the package the static archive comes
    from for build reproducibility (on rpm-based
    systems, often a devel or static-devel!)
  • Static linking LGPL libs is okay for open source
    programs, but requires shipping relinkable
    objects if the source is not available to
    preserve users freedom to modify the library

32
Whats it good for?
  • When people cant, or dont want to ship from
    source
  • Not just closed source programs
  • Consider installing on a huge cluster
  • it may be easier to push a binary package
  • better if the binary package doesnt depend so
    heavily on the system it was built on (i.e.
    distroversion)
  • May help identify less-standard interfaces in the
    sources more portable source code

33
Resources
  • lsbdev packages
  • http//www.linuxbase.org/download.html
  • Lsb sample implementation
  • http//www.linuxbase.org/download.html
  • FHS checklist
  • http//www.linuxbase.org/test/fhschecklist.html
  • Certification
  • http//www.freestandards.org/certification
Write a Comment
User Comments (0)
About PowerShow.com