Linux Porting and Migration Strategies

Darren R. Davis

Senior Software Engineer

Novell, Inc.

Presentation Overview

This session is targeted at software developers who have applications they want to move to Linux.

The goal of this session is to discuss and highlight the issues in porting applications from Windows or Unix to Linux, and also discuss what issues there are in having Linux applications support multiple Linux distributions.

It will cover Tools, Languages, and Programming APIs used in Applications on Windows and Unix and what their counter part is on Linux.

Application portability between processor architectures will also be covered.

More informative than technical, but NO business. Meaning I assume you know why your porting to Linux.

Presenter Overview

Senior Software Engineer working in Novell's Strategic Partner Engineering group helping ISVs to port their applications to SUSE Linux.

Masters degree in Computer Science from Utah State University.

I have worked in the UNIX and Linux industry since 1987 in roles of development, management, technology strategy and technology evangelism for several companies.

I have been involved in the Open Source Community since 1993. Started by helping move open source software to Novell UnixWare. Using since 1987.

Darren R. Davis (mailto://ddavis@novell.com)

Presentation Outline

Tools

GUI and CLI

Languages

C/C++

C# (Mono and .Net)

Java

Scripting (Python, PERL, PHP)

BASIC

Application Programming Interfaces (API)

C Library

etc.

Presentation Outline (cont.)

Porting and Migration

Windows to Linux

UNIX to Linux

Linux to Linux (compatibility)

Applications

CLI or Server Daemons (no user interface)

GUI (Qt, GTK, Motif)

LSB – Linux Standard Base

Linux “shrink wrapped” software

Architectures

IA32, IA64, AMD64/EM64T, PPC, IBM S/390, IBM zSeries

Tools, Languages, and APIs

Tools (Languages)

C and C++

GCC - GNU Compiler Collection

http://gcc.gnu.org/

ISO C

Also Objective C, Fortran, Java, Ada

Make

GNU Make

C# and .Net programmers

Mono - http://www.mono-project.com/

DotGNU - http://www.dotgnu.org/

Java (J2SE and J2EE)

Sun JVM - http://java.sun.com/

BEA JRockit - http://www.beasys.com/

IBM JVM - http://www.ibm.com/developerworks/java/

Tools (Scripting Languages)

Python

HTTP://www.python.org/

General purpose scripting language

Also good for prototyping projects

PERL

HTTP://www.perl.com/

General purpose scripting that is used extensively

PHP

HTTP://www.php.net/

Web scripting language

Linux, Apache, MySQL, PHP (LAMP)

Tools (Other Languages)

BASIC

REALbasic

Fortran 77

GCC

commercial compilers to meet the latest standards

COBOL

commercial compilers to meet standards

Pascal

GPC – GNU Pascal Compiler works with GCC

Borland Kylix

Delphi and C++

Tools (GUI)

Eclipse

HTTP://www.eclipse.org/

Support for C, C++, Java

Extensible to support new languages

Kdevelop

HTTP://www.kdevelop.org/

Support for C, C++

NetBeans

HTTP://www.netbeans.org/

Java Development Environment

Editors for CLI experts

Usual Emacs, Vi, etc. (just search the web)

Eclipse

KDevelop

Tools (Misc)

Source Code Control

CVS – Concurrent Version System

HTTP://www.gnu.org/software/cvs/

System Management

WBEM – Web Based Enterprise Management

DMTF standard ( http://www.dmtf.org/ )

OpenWBEM

HTTP://www.openwbem.org/

SUSE YaST moving to use OpenWBEM

Enable your application by writing an OpenWBEM provider

Many Third Party Libraries and Tools Available

Search the Internet (Links available from Novell)

Porting

Porting Overview

Business Case (Though don't want to talk about it here)

Compiler and Language Dialect

Platform Dependent Issues (Architecture, OS, etc)

Platform Run-time services

Platform Build-time dependencies (tools)

Middle-ware dependencies (DB, libraries, etc)

User Interface dependencies (libraries, portability)

Platform Testing environment (test resources)

Platform Support Issues (another business issue)

Porting Overview

Current application running on existing system.

Source Available

Install GNU tools on existing platform

Recreate Build Environment

Convert Makefiles

Compile and Debug

Identify Compiler Differences from Code Issues

Consult compiler documentation

Build and Test application

Move to Linux and Recreate

Finish with Test Certification (LSB, Open Group)

Porting from Windows

WINE

Windows Compatibility Layer (running existing *.exe)

Can also be used as a library for building on Linux

http://www.winehq.com/

CodeWeavers

CrossOver Office (WINE repackaged)

http://www.codeweavers.com/

Mono

For moving .Net Applications

Visual Basic

Excellent option with REALbasic

http://www.realsoftware.com/

Porting from Windows

It may be possible to use GNU tools directly

Install GNU tools on Windows

CYGWIN – Linux like environment for Windows

HTTP://www.cygwin.com/

This may get you part of the way to Linux

Porting from Windows

Trolltech – Tools for Cross Platform Development

http://www.trolltech.com/

Creators of Qt Library

C++ Application Framework

Class Libraries

Multi-platform

Linux

Mac OS X

Windows

Also the library used by KDE

Help you to create Cross Platform Applications

Porting from UNIX

What is UNIX?

May sound funny, but many developers porting applications are not fully aware.

UNIX is a registered trademark of the Open Group

http://www.unix.org/ and http://www.opengroup.org/

It is a set of specifications for defining operating system interfaces.

Single UNIX Specification

IEEE POSIX

ISO C

Products are certified by the Open Group to meet the UNIX specification

So UNIX was a product, but now it is a specification.

UNIX

Porting from Solaris to Linux

General Steps:

GCC on Linux versus SPARCworks on Solaris

So get a GCC for Solaris to factor out the compiler

http://www.sunfreeware.com/

Understand the compiler differences

Google “Solaris to Linux porting guide” for resources

Optionally, Build on a Linux for SPARC

Not really necessary, but don't have to immediately deal with architectures issues (bit size, endianness)

Build on target Linux

Works for other Languages as well

Java is VERY straightforward

Solaris

Porting from Solaris to Linux

Runtime and Library Issues

Focus on LSB compliant Libraries

Only standard C++ libraries are provided in GCC

X Window libs, but probably Motif and possibly CDE

Motif use Open Motif or LessTif

CDE is available for Linux

Port to KDE or GNOME

Threaded Applications need consideration

Solaris specific threads

port to POSIX threads

POSIX threads

use NPTL on Linux – Native POSIX Threads Library

Solaris

Porting from Solaris to Linux

Runtime and Library Issues

Signal Handler

Linux supports MOST of the Signals of SVR4 and BSD

Differences outlined in several documents

LSB Book

Process Management or /proc

differences between Unix and Linux

LSB states to avoid /proc on Linux

Solaris

Linux Application Portability

Building Portable Linux Applications

API – Application Programming Interface

Source level interface

With APIs you must make sure you target standard library interfaces as much as possible.

Watch out for issues related to library version updates

Avoid new and changing APIs

Issues related to running on older and newer Linux Distributions.

Well defined for C

POSIX, Single UNIX Specification

Follow the LSB!

Linux Application Portability

Building Portable Linux Applications

ABI - Application Binary Interface

Binary level interface needed for single binary

C++ has posed ABI issues in the past

Static linking if necessary to avoid library issues

Tools

Issues related to compiler versions

A Distribution shipping GCC 2.96

http://gcc.gnu.org/gcc-2.96.html

- Use the latest release of GCC if possible

Common Issues with porting C

Library Issues with GNU C library

Primary components

libc.* the C run-time library

libm.* the math library

libpthread.* the threads library

( replaced by NPTL )

librt.* the real-time extensions library

libnss.* the name resolution library

Mostly a non-issue with newer Linux Distributions

Issues are related to compatibility between older and newer Linux Distributions for a binary.

Watch out for building applications on newer libraries and wanting to run the binary on older distributions.

C

Common Issues with porting C

Missing Libraries between Distributions

Shared libraries the differ or don't exist between the build-time distribution and the run-time distribution.

Guard against this by using only LSB libraries

Is an issue related to libelf (binutils versus elfutils)

Incorrectly built binaries and libraries

errno and h_errno were integer variables pre-threading

Threaded libraries handle errno differently

So use errno.h and netdb.h

Dynamic loader issues can be worked around by using LD_ASSUME_KERNEL

Best to rebuild the application if possible

Common Issues with porting C++

LSB 2.0 just starting to standardize the ABI for C++

Compiler specific libraries for C++

libstdc++.*

libgcc_s.*

Can be resolved by statically linking if possible

Often, ISVs ship their own version of these libraries

C++

Linux Standard Base

Linux Standard Base

“We strive to develop and promote a set of standards that will increase compatibility among Linux distributions and enable software applications to run on any compliant system. In addition, the LSB will help coordinate efforts to recruit software vendors to port and write products for Linux.”

Also described as “Shrink-Wrapped Applications”

HTTP://www.linuxbase.org/

Linux Standard Base

IBM Press:

Building Applications with the Linux Standard Base

(ISBN 0-13-145695-4)

http://lsbbook.gforge.freestandards.org/lsb-book.html

Free on the Internet

Linux Standard Base

What is it?

First, a developer specification

defining libraries (APIs)

defining the ABI which applications must follow

Versions for various architectures

POSIX 1003.1, Single UNIX Specificaiton, ISO C

Process to update the specification

Packages available on the LSB Website

To create an LSB build environment

To help certify LSB compliant applications

Process to certify LSB compliant Applications

Linux Standard Base (APIs and Libs)

libc – Standard C Library

libdl – Dynamic Loader Library

libm – Math Library

libutil – Utility Functions Library

libcrypt – Cryptology Library

libz – Compression Library

libpthread – POSIX (Linux) Threads Library

(Use the new NPTL – Native POSIX Thread Library)

LSB

Linux Standard Base (APIs and Libs)

libncurses – Text/Terminal User Interface Library

libX11 – X Windows System Interface Library

libXext – X Windows Extensions Library

libXt – X Toolkit Intrinsics Library

libICE – X Inter-Client Exchange Library

libSM – X Session Management Library

libGL – OpenGL Graphics Library

LSB

Linux Standard Base (Packages)

lsb-build-chroot

The LSB Build environment is a tool to make it easier to generate LSB compliant binaries.

lsb-build-base

The LSB Build environment base package provides stub libraries and header files. These can be used to build LSB compliant applications. Note that the version number of the package refers to the version of the specification that the stub libraries and header files have been generated for.

LSB

Linux Standard Base (Packages)

lsb-build-c++

This package provides interim C++ building support for the lsb-build packages. It adds C++ headers and LSB-conforming builds of the static C++ libraries to the files installed by lsb-build-base.

lsb-build-cc

This package provides lsbcc, which is one of the approaches that can be used to build LSB conforming applications.

LSB

Linux Standard Base (Packages)

lsbdev-base

The LSB Build environment base package provides stub libraries and header files. These can be used to build LSB compliant applications. Note that the version number of the package refers to the version of the specification that the stub libraries and header files have been generated for.

lsbdev-c++

This package provides interim C++ building support for the lsbdev packages. It adds C++ headers and LSB-conforming builds of the static C++ libraries to the files installed by lsbdev-base.

LSB

Linux Standard Base (Packages)

lsbdev-cc

This package provides lsbcc, which is one of the approaches that can be used to build LSB conforming applications.

lsbdev-chroot

The LSB Build environment is a tool to make it easier to generate LSB compliant binaries.

LSB

Linux Standard Base (Using)

Commands

/opt/lsb/bin/lsbappchk

/opt/lsb/bin/lsblibchk

/opt/lsb/bin/libchk

/opt/lsb/bin/lsbcc

/opt/lsb/bin/lsbc++

/opt/lsb/bin/dummy_link

Libraries and Headers

/opt/lsb

Linux Standard Base (Using)

#include <stdio.h>

#include <unistd.h>

main()

{

printf(“Hello world: %d\n”, getpid());

}

Example “Hello World”

Linux Standard Base (Using)

$ lsbcc -o hw_good helloworld.c

$ lsbappchk hw_good

lsbappchk for LSB Specification 2.0

Checking binary hw_good

$

Checking for LSB Compliance

Linux Standard Base (Using)

#include <stdio.h>

#include <unistd.h>

main()

{

printf(“Hello world: %d\n”, _getpid());

}

Example Bad “Hello World”

Linux Standard Base (Using)

$ lsbcc -o hw_bad helloworld.c

/tmp/cc5CITzio.o: In function 'main':

/tmp/cc5CITzio.o(.text_0xd): undefined ref..

collect2: ld returned 1 exit status

$

Command lsbcc fails

Linux Standard Base (Packaging)

LSB Defines a standard package format

RPM

HTTP://www.rpm.org

RPM Checking

$ lsbpkgchk lsb-mypkg

LSB Defines a standard location for application files

File installation location standard

Filesystem Hierarchy Standard (FHS)

HTTP://www.pathname.com/fhs/

LANANA – Linux Assigned Names and Numbers Authority

HTTP://www.lanana.org/

Machine Architecture Issues

Architecture Issues

ENDIAN

Byte ordering or Network ordering

BIT SIZE

Size of INT, LONG, FLOAT, DOUBLE, PTR, etc.

31 bit

32 bit

64 bit

An issue whenever an application is processing byte ordered data such as reading and writing data files.

C unions and some structures, bit field operators, etc.

It is an advantage to write applications that are portable!

Architecture Review “endian”

Big Endian

32 bit word

0

4

8

12

0

4

8

12

0

5

9

13

2

6

10

14

3

7

11

15

Little Endian

32 bit word

0

4

8

12

3

7

11

15

2

6

10

14

1

5

9

13

0

4

8

12

CPU Architectures (SUSE support)

IA32 – Intel Pentium, AMD Athalon

32 bit, “little endian”

AMD x86-64 – AMD Athalon 64, Opteron

EM64T – Intel Pentium 4 EM64T, Xeon

64 bit, “little endian”

IA64 – Intel Itanium, Itanium 2

64 bit, “little endian”

PPC, PPC32 – IBM Power PC

32 bit, “big endian”

PPC64 – IBM Power PC, POWER 4, 5

64 bit, “big endian”

CPU Architectures (SUSE support)

IBM zSeries

64 bit, “big endian”

IBM S/390

31 bit, “big endian”

There are others as well supported by other Linux OSs

MIPS

Alpha

ARM

etc.

Architecture Issues (Summary)

Byte Ordering

endian

Byte Size

32bit versus 64bit

Absolute Addresses

Applications that use mmap()

Padding

Structures or Aggregate Data Types

Novell wants to help!

Novell Developers

HTTP://developer.novell.com/

Novell Linux Migration

HTTP://developer.novell.com/linux/migration.html

Question and Answer

Legal

Java is a trademark of Sun Microsystems, Inc.

Linux is a registered trademark of Linux Torvalds

LSB is trademark of The Free Standards Group

SUSE is a registered trademark of SUSE GmbH, a Novell Business

UNIX and UnixWare are registered trademarks of The Open Group

Windows is a trademark of Microsoft Corporation

Other company, product, or service names mentioned herein may be trademarks or service marks of others.

License

Copyright(c) 2005 Novell, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 with no Invariant Sections.

2003-12-08T12:43:39