NetWinder C Library Notes <author>Scott Bambrough, <tt>scottb@netwinder.org</tt> <date>$Revision: 1.1.1.1 $, $Date: 1999/11/02 15:25:12 $ <abstract> This document describes the C library used on the NetWinder. </abstract> <toc> <sect>The GNU C Library<p> The latest version of GLIBC is based on the official GNU 2.1 release. The changes made by Rebel.com and Phil Blundell are fully integrated into the main source tree. It is possible to get the source from the GLIBC CVS archive and build it for the NetWinder without patches. The next disk image release (build 15) uses this latest version of GLIBC.<p> Note that the GLIBC used on the NetWinder has versioning disabled. When we first started shipping the NetWinder, versioning was broken in GLIBC on the ARM. This causes problems for us as GLIBC is backwards compatible with LIBC 2.0, but not backwards compatible with a non-versioned build of 2.1. As a consequence, the upgrading to a versioned libc is a big job. All the executables have to be upgraded as well.<p> The Titan, Debian and Redhat distributions currently being worked upon are all using versioned GLIBC libraries. Eventually Rebel.com will as well.<p> <sect1>Fixed bugs<p> The tftphdr structure in /usr/include/arpa/tftp.h had problems due to the alignment on the ARM. The structure as it comes across the network is 5 bytes of packed data, while the struct on the arm has padding after the initial short, the union, and is padded to an even number of words in length. Adding __attribute__ ((packed)) to the struct as shown below fixes the problem.<p> <verb> struct { short th_opcode; union { unsigned short tu_block; short tu_code; char tu_stuff[1]; } __attribute__ ((packed)) th_u char th_data[1] __attribute__ ((packed)); } __attribute__ ((packed)) tftphdr; </verb> This bug is known to break the tftp client, tftpd daemon, and the NetWinder firmware. It is fixed in the current GLIBC.<p> The ether_header and ether_addr structures in /usr/include/net/ethernet.h had problems due to the alignment on the ARM. Both structures have padding problems at the end of the structure making them a different length than the data that is received across the wire. Adding __attribute__ ((packed)) to the structures as shown below fixes the problem.<p> <verb> struct ether_addr { u_int8_t ether_addr_octet[ETH_ALEN]; } __attribute__ ((packed)); struct ether_header { u_int8_t ether_dhost[ETH_ALEN]; u_int8_t ether_shost[ETH_ALEN]; u_int16_t ether_type; } __attribute__ ((packed)); </verb> This bug is known to break tcpdump. Actually tcpdump defines it's own version of these structures, but the principle is the same. I have sent a bug report to the tcpdump maintainers. This bug is fixed in the current GLIBC sources.<p> I found a nasty bug in the ARM socket call code. We had a bug with ping. It was always printing the error `Socket operation on non-socket.`. At least on my machine. On others a different error would occur.<p> strace showed the recvfrom call in ping was failing on restart after the SIGALRM signal was handled. Its parameters on restart were garbage. This is because the socket call never modified sp; it moved sp into ip and used ip to push the args, so it never had to clean up the stack.<p> This is nice as it saves one instruction, however the syscall is not an atomic operation. It can be interrupted if a signal occurs. If the signal handler used any stack it trashed the socket call args, because according to it the next available stack slot is pointed at by sp.<p> Now for the really bad news. mmap() suffers from the same bug. All of these bugs have been fixed and integrated into the CVS source tree. The current GLIBC RPM on netwinder.org also contains these fixes.<p> <sect>Miscellaneous<p> <sect1>Author<p> The author and maintainer of the NetWinder C Library Notes is Scott Bambrough (scottb@netwinder.org). Please send any comments, additions, or corrections so they can be included in the next release. The latest version of this document may be obtained from <url url="http://www.netwinder.org/~scottb/notes/Glibc-Notes.html">.<p> <sect1>History<p> The first public release of this document was as an html web page.<p> October 21, 1999 (version 1.0): Converted web page to SGML, and updated the content.<p> <sect1>Copyright Notice<p> This document is copyright (c) Scott Bambrough, 1999.<p> Permission is granted to make and distribute verbatim copies of this document. The copyright notice and this permission notice must be preserved on all copies.<p> </article>