Typo
[linux_from_scratch_hints.git] / OLD / nptl.txt
blobdb32ba679bf180a40ba6b757a2ca81187062b2f0
1 AUTHOR:         Teemu Tervo <teemu.tervo@gmx.net>
2 DATE:           2003-12-19
3 LICENSE:        The MIT License
4 SYNOPSIS:       Building an LFS system with the NPTL library
5 DESCRIPTION:    Using the new libpthread implementation NPTL (Native POSIX
6                 Threading Library) instead of linuxthreads.
7 PREREQUISITES:  LFS version 5.0+
9 HINT:
11 Contents
12 ========
13 1. Introduction
14 2. Software requirements
15 3. Inline installation
16 4. Drawbacks
17 5. Feedback
20 Introduction
21 ============
23 The Native POSIX Threading Library is a relatively new threading library
24 designed to replace the linuxthreads package in Glibc. It has many
25 advantages over the linuxthreads package, one of which is the focus on
26 standards-compliance. NPTL never sacrifices standards-compliance under
27 any circumstances, no matter the gains. Despite this, NPTL has
28 world-class performance, with thread-spawning speeds as much as 500x the
29 speed of traditional thread libs.
31 Despite all these changes, it maintains near-complete
32 backwards-compatibility with linuxthreads, and generally works perfectly
33 as a drop-in replacement where the proper compiler infrastructure is
34 already present.
37 Software requirements (as of December 18th 2003)
38 ================================================
40 1. A kernel with proper support for thread-local storage. This means
41    you must use a fairly recent 2.6 kernel. RedHat has managed to
42    backport this functionality into 2.4, but the patch is rather messy
43    and many parts of it will fail to apply on a vanilla kernel. If
44    you're going to use 2.4, you're on your own.
46    If you have no experience with 2.6, I suggest you have a look at
47    the post-halloween document, which summarizes the changes since 2.4.
49      http://www.linux.org.uk/~davej/docs/post-halloween-2.6.txt
51    I won't go into further detail on using the 2.6.x kernels, since
52    it is fairly straight-forward, but be sure to replace modutils with
53    the new module handling package called module-init-tools.
55      ftp://ftp.kernel.org/pub/linux/kernel/people/rusty/modules/
57    For those minimalists who like to disable everything in the kernel config
58    it should be noted that CONFIG_FUTEX shouldn't be set to no, futexes are
59    required for NPTL to function. Also note that you'll need to run
60    2.6 on both the host and the target system and that you should use
61    gcc-3.x (3.2.3 is a safe bet) to compile it.
63 2. A CVS tarball of Glibc. NPTL is no longer distributed in a separate
64    tarball as it has now been been added to the glibc source tree.
66      cvs -d :pserver:anoncvs@sources.redhat.com:/cvs/glibc -z3 co libc     
67      mv libc glibc-2.3-`date +%Y%m%d`
68      tar cjf glibc-2.3-`date +%Y%m%d`.tar.bz2 glibc-2.3-`date +%Y%m%d`
69      rm -rf glibc-2.3-`date +%Y%m%d`
71 5. H J Lu's Binutils version 2.14.90.0.5 or newer
73    Or more precisely, a binutils release with .cfi_rel_offset support. Right
74    now, this leaves us with either FSF CVS or the HJL branch. As usual,
75    when using the HJL release, you'll also need to install m4, bison and
76    flex in chapter 5.
78      ftp://ftp.kernel.org/pub/linux/devel/binutils/ (HJL)
79      ftp://sources.redhat.com/pub/binutils/releases (FSF)
81 6. Sanitized kernel headers
83    It is agreed that user space shouldn't use kernel headers, but a
84    set of sanitized headers such as distributions use instead. In
85    addition to it not being kosher, stock kernel headers in /usr/include
86    will break a lot of packages due to changes in 2.6 kernels. Get the
87    latest Fedora headers from:
89      http://download.fedora.redhat.com/pub/fedora/linux/core/development/SRPMS/
91    The package name is glibc-kernheaders-*. You can use rpm2cpio to first
92    convert and extract it. All you'll need is glibc-kernheaders.tar.bz2.
93    I've also made the tarball available in http://ttervo.vectorstar.net/nptl,
94    but don't expect it to be the latest one available. In the same directory,
95    you'll also find POSIX compliancy patches for several packages (see notes
96    after chapter 5 Glibc instructions).
98 7. Couple of essential patches
100    You'll need a couple of patches as well. If not otherwise mentioned, they
101    are expected to be used during both chapters 5 and 6. All are available in
103      http://ttervo.vectorstar.net/nptl
105    Binutils testsuite will fail one test due to changes introduced in
106    glibc cvs. The patch is named binutils-VERSION-fix-static-linking.patch.
108    Util-linux won't compile against 2.6 kernel headers, so we patch it in
109    chapter 5. We don't install sanitized headers there, since it's easier to
110    just make this one package work along with the 2.6 headers.
112    If you're going to use GCC-3.3.1, you need a patch to fix an issue
113    with static compilation of some programs, caused the same changes that
114    make binutils tests fail. For 3.3.2 and later this isn't needed. The patch
115    has been named gcc-3.3.1-fix-static-linking.patch.
118    This hint was tested using glibc-20031218, binutils-2.14.90.0.7 and
119    gcc-3.3.2 with both the host and the target systems using linux-2.6.0.
121 Inline installation
122 ===================
124 Chapter 5 -- Installing 2.6 kernel headers
125 ------------------------------------------
127 When installing the headers, you must use the "make include/asm" command
128 in place of "make symlinks". The latter no longer works in 2.6 kernels.
131 Chapter 5 -- Installing Glibc
132 -----------------------------
134 You won't need to apply the sscanf patch, this has been fixed.
136 Configure Glibc with the following command:
138           ../glibc-2.3*/configure --prefix=/tools --disable-profile \
139               --with-headers=/tools/include --with-binutils=/tools/bin \
140               --enable-add-ons=nptl --enable-kernel=current --without-gd \
141               --without-cvs --with-tls
143 During make check, you can expect some failures.
146 About POSIX conformance
147 -----------------------
149 Packages such as coreutils use the _POSIX2_VERSION variable defined in 
150 unistd.h to see which POSIX version to conform to. CVS Glibc has this variable
151 set to a newer version and this causes problems with many packages and scripts
152 which use obsoleted syntax like tail -1 instead of tail -n 1. To get around
153 this, export _POSIX2_VERSION=199209, and make sure it's set at all times.
155 There are also few other methods, which means this will eventually be a nice
156 flamewar subject on lfs-dev when the next Glibc version is released. You
157 could:
158   1) Patch each package using illegal syntax, like I do.
159   2) Edit the _POSIX2_VERSION variable directly in unistd.h.
160   3) Patch coreutils to also require POSIXLY_CORRECT variable set, before
161      spouting out "You can't do this anymore." This is what RH does.
163 The nice thing about standards is there are so many ways to avoid them.
166 Chapter 6 -- Mounting /dev/shm
167 ------------------------------
169 NPTL's semaphore code and its testsuite uses /dev/shm, hence it's
170 recommended to mount it not only in chapter 6 but also after booting to the
171 final system.
173 Chapter 6 -- Installing 2.6 kernel headers
174 ------------------------------------------
176 It is agreed that user space shouldn't use kernel headers, but use a
177 set of sanitized headers such as distributions use instead. Glibc is an
178 exception to this rule, and it needs to be built against the most
179 recent headers to make use of new kernel features. So we'll install
180 them to a prefix other than /usr/include and instruct Glibc to look
181 for them there.
183           make mrproper &&
184           make include/linux/version.h &&
185           make include/asm &&
186           mkdir /usr/src/glibcheaders &&
187           cp -HR include/asm /usr/src/glibcheaders &&
188           cp -R include/asm-generic /usr/src/glibcheaders &&
189           cp -R include/linux /usr/src/glibcheaders &&
190           touch /usr/src/glibcheaders/linux/autoconf.h
193 Chapter 6 -- Installing Glibc
194 -----------------------------
196 If you try running /tools/lib/libc.so.6, you'll see it won't work due to
197 some assertions failing. http://ttervo.vectorstar.net/nptl contains a patch,
198 which fixes this problem. This is merely a cosmetic issue, and is optional.
200 Use the following command to configure Glibc:
202           ../glibc-2.3*/configure --prefix=/usr --libexecdir=/usr/bin \
203               --disable-profile --with-headers=/usr/src/glibcheaders \
204               --enable-add-ons=nptl --enable-kernel=current --without-cvs \
205               --with-tls
207 As of this writing, the testsuite should pass without any failures. After make
208 install, you can remove /usr/src/glibcheaders.
211 Chapter 6 -- Installing sanitized kernel headers
212 ------------------------------------------------
214 Right after installing Glibc, untar the glibc-kernheaders tarball
215 and cd to the extracted usr/include directory.
217           cp -R asm-i386 /usr/include/asm    
218           cp -R linux /usr/include
221 Chapter 6 -- Installing modutils
222 --------------------------------
224 Feel free to skip this package and install module-init-tools in its
225 place. Modutils is useful only if you want to use binary modules
226 built for 2.4.
229 Drawbacks
230 =========
232 I've been running NPTL on my system for a few months now, and in that period
233 the only unsolvable problem I've come across is that the beautiful debugger
234 called Valgrind won't work. As an alternative though, GDB-6.0+ will. In
235 addition, all binaries linked against linuxthreads' libpthread will fail
236 to function.
238 Feedback
239 ========
241 If you have an idea for something I should add, want to report a bug,
242 point out typos and/or bad grammar, tell me if the hint sucks or wish
243 to offer me penis enlargement products, drop me a line at teemu.tervo@gmx.net.
245 ACKNOWLEDGEMENTS:
247 Thanks to Zack Winkles for the original hint, as well as to Ryan and Greg
248 for all their help, suggestions and corrections.
250 CHANGELOG:
252 [2003-04-11]
253 * Initial release of rewrite.
254 [2003-04-18]
255 * Added patch for 2.4.20 futex support.
256 [2003-04-21]
257 * Backed out futex patch. General cleanups.
258 [2003-04-21]
259 * Added note about module-init-tools (Thanks DJ Lucas)
260 * Added warning about NVIDIA.
261 [2003-04-23]
262 * Moved to GCC 3.3.
263 [2003-04-24]
264 * NVIDIA_GLX works now.
265 [2003-04-26]
266 * Devfs notes.
267 * Patch to make 2.4.20 work w/ NPTL (Thanks YuX).
268 [2003-05-05]
269 * Added fix to allow building against old hosts.
270 * Added patch to fix detection of eh_frame using coreutils.
271 * Added note about rml's procps.
272 [2003-05-06]
273 * Oops. Forgot to put up the location of the GCC patch.
274 [2003-05-12]
275 * Another rewrite
276 * LFS has moved to PLFS
277 * Don't disable fixincl as it breaks GCC on old hosts
278 * Removed 2.4 patch.
279 * Removed any remants of NVIDIA.
280 [2003-05-15]
281 * Futexes have been made optional in the latest kernel,
282           make sure the user enables it.
283 * Update text for GCC 3.3.
284 [2003-05-19]
285 * Clarify warning about futexes.
286 [2003-09-22]
287 * Adopted by Teemu
288 * Edited hint to new format
289 * Install sanitized kernel headers
290 * Added note about Drepper's release notes
291 * Clarified binutils requirement
292 * Changed linux-2.5 > 2.6, added note about post-halloween doc
293 * Added note about _POSIX2_VERSION and the Glibc version string
294 * Added patch that removes a couple of asserts in glibc, thanks to NeoCool
295 * Removed reference to sysklogd patch, it's not needed
296 [2003-10-12]
297 * Removed references to the nptl tarball, as it no longer exists
298 * Revised glibc cvs checkout commands
299 * Added the drawbacks section
300 * Added a nicer assertion patch for glibc
301 * Added --without-cvs to glibc configure commands
302 * Added note about /dev/shm
303 * Added POSIX conformance section, describing the issue a bit more thoroughly
304 [2003-10-15]
305 * Install lowlevellock.h in chapter6 glibc
306 * Revised /dev/shm note
307 * Added GCC patch to fix static linking
308 * Added a patch for util-linux to compile with 2.6 headers in chapter 5
309 [2003-11-04]
310 * Added binutils patch related to the issue with static linking
311 * Added glibc makefile patch to fix testsuite
312 * Fixed the RH kernel headers URL
313 * Fix for static linking no longer needed with GCC-3.3.2
314 * Removed lowlevellock.h, nothing needing it works even with it installed
315 [2003-11-15]
316 * Changed sanitized headers dl location, they're now over at fedora's site
317 * Revised the part about futexes in the kernel, it was misleading
318 [2003-12-13]
319 * Dropped editing of glibc's version.h, it's unnecessary, outdate and
320   removing it will prevent me from ever updating it
321 * Updated post-halloween doc location
322 [2003-12-19]
323 * Dropped glibc-DATE-nptl-testsuite.patch, it is no longer needed
324 * 2.6 kernels are not in test phase anymore