Files
oldlinux-files/docs/bin-format/Linux Frontiers.htm
2024-02-19 00:23:35 -05:00

311 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0048)http://www.stllinux.org/meeting_notes/1995/0817/ -->
<?xml version="1.0" encoding="UTF-8"?><HTML lang=en xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>STLLUG 08/17/1995 - Linux Frontiers</TITLE>
<META content="text/html; charset=ISO-8859-1" http-equiv=Content-Type><!-- #(@) $Id: index.html,v 1.3 2002/01/14 02:09:24 mike808 Exp $ --><!-- Copyright 2001 by stllinux.org, --><!-- St. Louis, Missouri, U.S.A. --><!-- All rights reserved. Licensed for use on www.stllinux.org. --><!-- All brands and product names are trademarks or registered trademarks of --><!-- their respective companies. -->
<META content="MSHTML 5.00.3502.5390" name=GENERATOR></HEAD>
<BODY aLink=#ff0000 bgColor=#ffffff link=#cc0000 text=#000000 vLink=#000099><!-- BEGIN BODY TEXT --><FONT size=+2>STLLUG - St. Louis Linux
User Group</FONT><BR>08/17/1995 : Linux Frontiers<BR><FONT size=1>Presenter: <A
href="http://www.feldt.com/">Matthew Feldt</A></FONT>
<HR>
<H1><I>Linux Frontiers</I></H1>
<P><FONT size=5><I>Matt Welsh<BR>O'Reilly and Associates, Inc.</I></FONT> </P>
<HR>
<H3>What is Linux?</H3>
<UL>
<LI>Free 32-bit UNIX system for the x86
<LI>Developed by volunteers on Internet
<LI>Distributed via FTP and CD-ROM by many vendors
<LI>Supports full preemptive multitasking, TCP/IP networking, and much more
<LI>Large hardware support base
<LI>Thousands of free applications available: X11R6, Emacs, TeX, gcc, you name
it
<LI>Commercial apps emerging including WordPerfect and Mathematica
<LI>Being ported to Alpha, m68k, SPARC, MIPS, and others </LI></UL>
<HR>
<H3>More Information about Linux</H3>
<UL>
<LI>Running Linux, O'Reilly and Associates 1995
<LI><A href="http://sunsite.unc.edu/mdw/linux.html">WWW:
http://sunsite.unc.edu/mdw/linux.html</A>
<LI><A href="ftp://sunsite.unc.edu:/pub/Linux/docs">FTP:
sunsite.unc.edu:/pub/Linux/docs</A>
<LI>comp.os.linux.* USENET newsgroups </LI></UL>
<HR>
<H3>Overview</H3>
<DL>
<DT><B>ELF Support</B>
<DD>Executable and Linkable Format: AT&amp;T Binary Spec for Linux
<DT><B>iBCS2 Emulation</B>
<DD>The standard for x86 UNIX binaries
<DT><B>WINE: The Windows Emulator</B>
<DD>Run MS-Windows applications under Linux/X11R6
<DT><B>Loadable Kernel Modules</B>
<DD>Load and unload kernel drivers dynamically </DD></DL>
<HR>
<H3>ELF</H3>
<DL>
<DT><B>Executable and Linkable Format</B>
<DD>Defines binary format for executables, object files, and libraries.
<DT><B>a.out and COFF</B>
<DD>Two other binary formats: a.out originated at BSD, and used initially by
Linux.
<DT><B>Advantages of ELF</B>
<UL>
<LI>More flexible and powerful than a.out, simplifies compilers and linkers.
Also more complex, and more processing overhead is required in some cases.
<LI>Makes it very easy to build and use shared libraries.
<LI>More interoperable with other systems and tools. </LI></UL></DT></DL>
<HR>
<H3>ELF vs. a.out format</H3>
<CENTER><IMG alt="ELF vs. a.out file format" border=0 height=307
src="Linux Frontiers.files/elfvsaout.gif" width=402></CENTER>
<HR>
<H3>Building ELF Shared Libraries</H3>
<OL>
<LI>Build objects as PIC (position-independent) code:<BR><CODE>gcc -fPIC -O -c
foo.c -o foo.o</CODE>
<LI>Link objects into shared object:<BR><CODE>gcc -shared -o libfoo.so foo.o
bar.o ...</CODE>
<LI>To use shared libs, just link as normal:<BR><CODE>gcc -O -o baz baz.o
-lfoo</CODE><BR>Uses libfoo.so shared lib automatically. </LI></OL>
<HR>
<H3>Dynamic Linking and Loading</H3>
<DL>
<DT><B>ld.so</B>
<DD>performs dynamic linking for executables at load time
<DT><B>libdl.a</B>
<DD>allows you to do dynamic linking within a program<BR>* dlopen() opens
shared object, returns handle<BR>* dlsym() looks up symbol from shared object,
returns pointer<BR>Can then use pointer (function or object) as usual </DD></DL>
<HR>
<H3>Dynamic Linking Example</H3><PRE> /* Open shared obj libfoo.so
* RTLD_LAZY: Only relocate as necessary
*/
handle = dlopen( "libfoo.so", RTLD_LAZY );
/* Look up symbol for thefunction() */
funcptr = ( funcptr_t )dlsym( handle, "thefunction" );
/* Call function from shared object */
( *fptr )();
</PRE>Dynamic linking with ELF is easy and fun!
<HR>
<H3>Upgrading to ELF</H3>
<P>All tools at <A
href="ftp://sunsite.unc.edu:/pub/Linux/GCC">ftp://sunsite.unc.edu:/pub/Linux/GCC</A>
</P><B>You will need:</B>
<UL>
<LI>Post-1.1.52 kernel
<LI>ld.so-1.7.3.tar.gz -- new runtime linker
<LI>libc-5.0.9 -- new ELF-based C library
<LI>gcc-2.7.0 -- gcc with ELF support
<LI>binutils-2.6.2.l17 -- ld, gas, etc. for ELF
<LI>The Linux ELF-HOWTO -- a must! </LI></UL>
<HR>
<H3>iBCS2 Support</H3><B>Intel Binary Compatibility Spec, v.2</B>
<UL>
<LI>Standard for user/kernel interface for x86 UNIX systems, including SVR3,
SVR4, BSD, Xenix, etc.
<LI>Defines system call interface, signal behavior, network layer interface,
etc.
<LI>Nothings perfect: Many vendor-specific extensions </LI></UL><B>iBCS2 for
Linux</B>
<UL>
<LI>Allows binaries from other x86 UNIX systems to run under Linux
<LI>This includes commercial applications! </LI></UL>
<HR>
<H3>iBCS2 Features</H3><B>Kernel emulator</B>
<UL>
<LI>Loads binaries of appropriate format (ELF, COFF, etc.)
<LI>Provides LCALL7 trap for system calls </LI></UL><B>Personalities</B>
<UL>
<LI>Each process has a "personality" chosen from binary format at load time
<LI>Maps system calls, error codes, and signal numbers between application and
kernel
<LI>Also used to choose system-call behavior on per-process basis (e.g.,
select timeout) </LI></UL>
<HR>
<H3>iBCS2 Shared libraries</H3>
<UL>
<LI>Dynamically-linked binaries need an iBCS2-compliant libc.so
<LI>iBCS2 team has modified libc sources for this
<LI>Statically-linked binaries (e.g., WordPerfect) have no problem
<LI>XFree86 shared libraries can be used for X apps
<LI>libsocket, libnsl used by some systems has limited support
<LI>You may be able to use native shared libs under Linux (with ELF support)
if license permits </LI></UL>
<HR>
<H3>Supported Systems</H3><B>Binary formats</B>
<UL>
<LI>a.out, ELF, COFF, or x.out </LI></UL><B>O/S emulations</B>
<UL>
<LI>i386 BSD (386BSD, FreeBSD, NetBSD, BSDI/386), very alpha.
<LI>SVR4 (Interactive, Unixware, USL, Dell etc.)
<LI>SVR3 generic
<LI>SCO (SVR3 with extensions for symlinks and long filenames)
<LI>Wyse V/386 (SVR3 with extensions for symlinks)
<LI>Xenix V/386 (386 small model binaries only)
<LI>Xenix 286 </LI></UL>
<HR>
<H3>Getting the Emulator</H3>
<P>Files at <A
href="ftp://tsx-11.mit.edu/pub/linux/BETA/ibcs2">tsx-11.mit.edu/pub/linux/BETA/ibcs2</A>
</P>
<DL>
<DT><B>ibcs-1.2-yymmdd.tar.gz</B>
<DD>The kernel emulator
<DT><B>sco-libs-yymmdd.tar.gz</B>
<DD>SCO shared libs
<DT><B>svr4-shlib-yymmdd.tar.gz</B>
<DD>SVR4 shared libs
<DT><B>libc_s-yymmdd.tar.gz</B>
<DD>iBCS2 libc source </DD></DL>
<P>Mail <I><A
href="mailto:majordomo@vger.rutgers.edu">majordomo@vger.rutgers.edu</A></I> for
info on the linux-ibcs2 mailing list </P>
<HR>
<H3>WINE: The Windows Emulator</H3><B>What is it?</B>
<UL>
<LI>An MS-Windows emulator for x86-based UNIX and X11
<LI>Loads MS-Windows executables into 32-bit UNIX process
<LI>Emulates Windows API by catching calls and translating to X11 equivalents
</LI></UL><B>How well does it work?</B>
<UL>
<LI>Most applets installed with Windows run to some extent
<LI>Solitaire works!
<LI>A number of PD/shareware MSW games run
<LI>No reports of major apps yet---except occasionally Quicken </LI></UL>
<HR>
<H3>Where can I get WINE?</H3>
<UL>
<LI><A
href="ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine">/pub/Linux/ALPHA/wine</A> on
sunsite.unc.edu
<LI>Most recent is Wine-yymmdd.tar.gz
<LI>First get the Wine.FAQ and related docs
<LI>See comp.emulators.ms-windows.wine </LI></UL>
<HR>
<H3>WINE Program Loader</H3>
<UL>
<LI>Loads MS-Windows .EXE file into 32-bit process address space
<LI>All WINE code itself is 32-bit, but this is fine
<LI>No need for machine-level emulation
<LI>Loads executable and each WINE module, performing relocation for API entry
points
<LI>Creates x86 selector for each module segment
<LI>Adds selectors to process LDT with new system call: modify_ldt
<LI>Kernel creates new LDT for process, copies it, and adds new selectors
</LI></UL>
<HR>
<H3>WINE Windows API Emulator</H3>
<UL>
<LI>Loader provides 16-bit entry points for all API functions
<LI>Stack frame is copied on API call and control transfered to 32-bit WINE
function
<LI>WINE code produces X11 calls when appropriate, and captures X events
</LI></UL>
<HR>
<H3>Loadable Kernel Modules</H3><B>Dynamically loaded kernel code</B>
<UL>
<LI>Allows device drivers, file systems, or other routines to be contained in
a module
<LI>Modules can be loaded and unloaded on a running system
<LI>Saves memory and kernel image size; only load those modules you need
<LI>Allows portions of kernel to be maintained and released independently
</LI></UL>
<HR>
<H3>What is a module?</H3>
<UL>
<LI>Simply an object file containing routines and/or data to load into a
running kernel
<LI>If multiple source files are used, prelink into one .o file with ld -r
<LI>Must provide two routines (init_module and cleanup_module) called at
module load/unload </LI></UL><B>Required Tools</B>
<UL>
<LI>A recent 1.2.x or 1.3.x kernel
<LI>Module utilities insmod, lsmod, and rmmod (found with kernel source)
</LI></UL>
<HR>
<H3>Loading a Module</H3>
<OL>
<LI><B>Prepare module in user space</B>
<UL>
<LI>insmod reads object file from disk, resolve any external symbols
<LI>These symbols provided by kernel or other loaded modules using
get_kernel_syms
<LI>This is similar to linking an object against other objects </LI></UL>
<LI><B>Allocate kernel memory</B>
<UL>
<LI>create_module() tells kernel to alloc memory for new module
<LI>Takes two args: name of module and total size </LI></UL>
<LI><B>Load module into kernel memory</B>
<UL>
<LI>init_module() called to copy module into kernel space
<LI>insmod must also pass in module name, size, pointers to init/cleanup,
etc. </LI></UL>
<LI><B>Add exported module symbols to kernel</B>
<UL>
<LI>Symbol table passed in by init_module added to kernel's list
<LI>Module symbols can now be used by other modules --- "stacking"
<LI>Modules can shadow each other's symbols </LI></UL>
<LI><B>Call init_module routine</B>
<UL>
<LI>Module now part of kernel proper; just fire it up </LI></UL></LI></OL>
<HR>
<H3>Module Dependencies and Deletion</H3><B>Deleting a module</B>
<UL>
<LI>Kernel keeps list of module dependencies
<LI>Can't delete a module if any other module uses routines from it
<LI>If ref count is 0, cleanup_module called, and kernel memory freed
</LI></UL><B>Dependencies</B>
<UL>
<LI>Modules can only be loaded into kernel they were compiled under
<LI>This prevents data structures, function interfaces, etc. from differing
<LI>Can cause serious and subtle problems if this is not adhered to!
<LI>New features allow modules to keep track of struct "versions"
<LI>Checksum computed for each data structure used in kernel and module
</LI></UL>
<HR>
<P><I><FONT size=-1>These are slides for the "Linux Frontiers" talk given for
the O'Reilly and Associates "Running Linux '95" tour. For more information
please contact Matt Welsh at <A
href="mailto:mdw@cs.cornell.edu">mdw@cs.cornell.edu</A>. </FONT></I></P>
<P>This file and associated slides are Copyright (c)1995 by Matt Welsh. You are
free to copy and distribute this file (or slides produced thereof) VERBATIM in
any medium, physical or electronic. This copyright notice should be entact on
all copies and attribution to the author retained. </P>
<P>Update: mdw 21 August 1995</P>
<HR>
<P><I><FONT size=-1>Links and conversion from Postscript to HTML done by Matthew
Feldt. </FONT></I></P>
<HR SIZE=4>
<P>Last Modified: 5 September 1995<BR><I>St. Louis Unix Users Group - Linux
SIG</I> </P><!-- END BODY TEXT --></BODY></HTML>