summaryrefslogtreecommitdiff
path: root/docs/busybox.net
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-05-01 05:26:01 +0000
committerRob Landley <rob@landley.net>2006-05-01 05:26:01 +0000
commitc488f87953ff2c4d4fc005c52ec30c5cb6885f72 (patch)
tree7a7b8178ce6bd038661eada1e25f5d9d327d0956 /docs/busybox.net
parent73f54702bc5dba06c8cc736be13ea686195fe4e9 (diff)
downloadbusybox-w32-c488f87953ff2c4d4fc005c52ec30c5cb6885f72.tar.gz
busybox-w32-c488f87953ff2c4d4fc005c52ec30c5cb6885f72.tar.bz2
busybox-w32-c488f87953ff2c4d4fc005c52ec30c5cb6885f72.zip
Notes on portability, and on when #include <linux/blah> is appropriate.
Diffstat (limited to 'docs/busybox.net')
-rw-r--r--docs/busybox.net/programming.html114
1 files changed, 114 insertions, 0 deletions
diff --git a/docs/busybox.net/programming.html b/docs/busybox.net/programming.html
index 61777afb1..b73e6ef95 100644
--- a/docs/busybox.net/programming.html
+++ b/docs/busybox.net/programming.html
@@ -12,12 +12,14 @@
12 </ul> 12 </ul>
13 <li><a href="#adding">Adding an applet to busybox</a></li> 13 <li><a href="#adding">Adding an applet to busybox</a></li>
14 <li><a href="#standards">What standards does busybox adhere to?</a></li> 14 <li><a href="#standards">What standards does busybox adhere to?</a></li>
15 <li><a href="#portability">Portability.</a></li>
15 <li><a href="#tips">Tips and tricks.</a></li> 16 <li><a href="#tips">Tips and tricks.</a></li>
16 <ul> 17 <ul>
17 <li><a href="#tips_encrypted_passwords">Encrypted Passwords</a></li> 18 <li><a href="#tips_encrypted_passwords">Encrypted Passwords</a></li>
18 <li><a href="#tips_vfork">Fork and vfork</a></li> 19 <li><a href="#tips_vfork">Fork and vfork</a></li>
19 <li><a href="#tips_short_read">Short reads and writes</a></li> 20 <li><a href="#tips_short_read">Short reads and writes</a></li>
20 <li><a href="#tips_memory">Memory used by relocatable code, PIC, and static linking.</a></li> 21 <li><a href="#tips_memory">Memory used by relocatable code, PIC, and static linking.</a></li>
22 <li><a href="#tips_kernel_headers">Including Linux kernel headers.</a></li>
21 </ul> 23 </ul>
22 <li><a href="#who">Who are the BusyBox developers?</a></li> 24 <li><a href="#who">Who are the BusyBox developers?</a></li>
23</ul> 25</ul>
@@ -180,6 +182,82 @@ applet is otherwise finished. When polishing and testing a busybox applet,
180we ensure we have at least the option of full standards compliance, or else 182we ensure we have at least the option of full standards compliance, or else
181document where we (intentionally) fall short.</p> 183document where we (intentionally) fall short.</p>
182 184
185<h2><a name="portability">Portability.</a></h2>
186
187<p>Busybox is a Linux project, but that doesn't mean we don't have to worry
188about portability. First of all, there are different hardware platforms,
189different C library implementations, different versions of the kernel and
190build toolchain... The file "include/platform.h" exists to centralize and
191encapsulate various platform-specific things in one place, so most busybox
192code doesn't have to care where it's running.</p>
193
194<p>To start with, Linux runs on dozens of hardware platforms. We try to test
195each release on x86, x86-64, arm, power pc, and mips. (Since qemu can handle
196all of these, this isn't that hard.) This means we have to care about a number
197of portability issues like endianness, word size, and alignment, all of which
198belong in platform.h. That header handles conditional #includes and gives
199us macros we can use in the rest of our code. At some point in the future
200we might grow a platform.c, possibly even a platform subdirectory. As long
201as the applets themselves don't have to care.</p>
202
203<p>On a related note, we made the "default signedness of char varies" problem
204go away by feeding the compiler -funsigned-char. This gives us consistent
205behavior on all platforms, and defaults to 8-bit clean text processing (which
206gets us halfway to UTF-8 support). NOMMU support is less easily separated
207(see the tips section later in this document), but we're working on it.</p>
208
209<p>Another type of portability is build environments: we unapologetically use
210a number of gcc and glibc extensions (as does the Linux kernel), but these have
211been picked up by packages like uClibc, TCC, and Intel's C Compiler. As for
212gcc, we take advantage of newer compiler optimizations to get the smallest
213possible size, but we also regression test against an older build environment
214using the Red Hat 9 image at "http://busybox.net/downloads/qemu". This has a
2152.4 kernel, gcc 3.2, make 3.79.1, and glibc 2.3, and is the oldest
216build/deployment environment we still put any effort into maintaining. (If
217anyone takes an interest in older kernels you're welcome to submit patches,
218but the effort would probably be better spent
219<a href="http://www.selenic.com/linux-tiny/">trimming
220down the 2.6 kernel</a>.) Older gcc versions than that are uninteresting since
221we now use c99 features, although
222<a href="http://fabrice.bellard.free.fr/tcc/">tcc</a> might be worth a
223look.</p>
224
225<p>We also test busybox against the current release of uClibc. Older versions
226of uClibc aren't very interesting (they were buggy, and uClibc wasn't really
227usable as a general-purpose C library before version 0.9.26 anyway).</p>
228
229<p>Other unix implementations are mostly uninteresting, since Linux binaries
230have become the new standard for portable Unix programs. Specifically,
231the ubiquity of Linux was cited as the main reason the Intel Binary
232Compatability Standard 2 died, by the standards group organized to name a
233successor to ibcs2: <a href="http://www.telly.org/86open/">the 86open
234project</a>. That project disbanded in 1999 with the endorsement of an
235existing standard: Linux ELF binaries. Since then, the major players at the
236time (such as <a
237href=http://www-03.ibm.com/servers/aix/products/aixos/linux/index.html>AIX</a>, <a
238href=http://www.sun.com/software/solaris/ds/linux_interop.jsp#3>Solaris</a>, and
239<a href=http://www.onlamp.com/pub/a/bsd/2000/03/17/linuxapps.html>FreeBSD</a>)
240have all either grown Linux support or folded.</p>
241
242<p>The major exceptions are newcomer MacOS X, some embedded environments
243(such as newlib+libgloss) which provide a posix environment but not a full
244Linux environment, and environments like Cygwin that provide only partial Linux
245emulation. Also, some embedded Linux systems run a Linux kernel but amputate
246things like the /proc directory to save space.</p>
247
248<p>Supporting these systems is largely a question of providing a clean subset
249of BusyBox's functionality -- whichever applets can easily be made to
250work in that environment. Annotating the configuration system to
251indicate which applets require which prerequisites (such as procfs) is
252also welcome. Other efforts to support these systems (swapping #include
253files to build in different environments, adding adapter code to platform.h,
254adding more extensive special-case supporting infrastructure such as mount's
255legacy mtab support) are handled on a case-by-case basis. Support that can be
256cleanly hidden in platform.h is reasonably attractive, and failing that
257support that can be cleanly separated into a separate conditionally compiled
258file is at least worth a look. Special-case code in the body of an applet is
259something we're trying to avoid.</p>
260
183<h2><a name="tips" />Programming tips and tricks.</a></h2> 261<h2><a name="tips" />Programming tips and tricks.</a></h2>
184 262
185<p>Various things busybox uses that aren't particularly well documented 263<p>Various things busybox uses that aren't particularly well documented
@@ -411,6 +489,42 @@ above factors seem to mostly account for it (but some were difficult
411to measure).</p> 489to measure).</p>
412</blockquote> 490</blockquote>
413 491
492<h2><a name="tips_kernel_headers"></a>Including kernel headers</h2>
493
494<p>The "linux" or "asm" directories of /usr/include contain Linux kernel
495headers, so that the C library can talk directly to the Linux kernel. In
496a perfect world, applications shouldn't include these headers directly, but
497we don't live in a perfect world.</p>
498
499<p>For example, Busybox's losetup code wants linux/loop.c because nothing else
500#defines the structures to call the kernel's loopback device setup ioctls.
501Attempts to cut and paste the information into a local busybox header file
502proved incredibly painful, because portions of the loop_info structure vary by
503architecture, namely the type __kernel_dev_t has different sizes on alpha,
504arm, x86, and so on. Meaning we either #include <linux/posix_types.h> or
505we hardwire #ifdefs to check what platform we're building on and define this
506type appropriately for every single hardware architecture supported by
507Linux, which is simply unworkable.</p>
508
509<p>This is aside from the fact that the relevant type defined in
510posix_types.h was renamed to __kernel_old_dev_t during the 2.5 series, so
511to cut and paste the structure into our header we have to #include
512<linux/version.h> to figure out which name to use. (What we actually do is
513check if we're building on 2.6, and if so just use the new 64 bit structure
514instead to avoid the rename entirely.) But we still need the version
515check, since 2.4 didn't have the 64 bit structure.</p>
516
517<p>The BusyBox developers spent <u>two years</u> _two years_ trying to figure
518out a clean way to do all this.  There isn't one. The losetup in the
519util-linux package from kernel.org isn't doing it cleanly either, they just
520hide the ugliness by nesting #include files. Their mount/loop.h
521#includes "my_dev_t.h", which #includes <linux/posix_types.h> and
522<linux/version.h> just like we do. There simply is no alternative.</p>
523
524<p>We should never directly include kernel headers when there's a better
525way to do it, but block copying information out of the kernel headers is not
526a better way.</p>
527
414<h2><a name="who">Who are the BusyBox developers?</a></h2> 528<h2><a name="who">Who are the BusyBox developers?</a></h2>
415 529
416<p>The following login accounts currently exist on busybox.net. (I.E. these 530<p>The following login accounts currently exist on busybox.net. (I.E. these