From owner-freebsd-bugs@FreeBSD.ORG Thu May 29 22:00:10 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 96300106567C for ; Thu, 29 May 2008 22:00:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6CA828FC14 for ; Thu, 29 May 2008 22:00:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m4TM0A16052818 for ; Thu, 29 May 2008 22:00:10 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m4TM0Abv052817; Thu, 29 May 2008 22:00:10 GMT (envelope-from gnats) Resent-Date: Thu, 29 May 2008 22:00:10 GMT Resent-Message-Id: <200805292200.m4TM0Abv052817@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Martin Simmons Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C891210656AD for ; Thu, 29 May 2008 21:50:58 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 92FE48FC27 for ; Thu, 29 May 2008 21:50:58 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m4TLnHGJ020294 for ; Thu, 29 May 2008 21:49:17 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m4TLnHlZ020293; Thu, 29 May 2008 21:49:17 GMT (envelope-from nobody) Message-Id: <200805292149.m4TLnHlZ020293@www.freebsd.org> Date: Thu, 29 May 2008 21:49:17 GMT From: Martin Simmons To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/124114: 7.0 shared libs cannot read errno when loaded into a 6.0 pthreaded program X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2008 22:00:10 -0000 >Number: 124114 >Category: misc >Synopsis: 7.0 shared libs cannot read errno when loaded into a 6.0 pthreaded program >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu May 29 22:00:10 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Martin Simmons >Release: 7.0-RELEASE >Organization: LispWorks Ltd >Environment: FreeBSD heapbsd7.cam.lispworks.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC 2008 root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: There is something wrong with the way that errno is resolved when running 6.0 programs on 7.0-RELEASE with the compat6x-i386-6.3.602114.200711 pkg. If a 7.0 shared library that uses errno is loaded into a 6.0 program that uses pthreads, then the value of errno in the library code will be incorrect. In particular, it will access the global errno value instead of the thread-specific one. I've included two test cases. The X11 one is pretty much how the problem was discovered. The libc one is doing the same thing as the libX11 function _XRead, where the problem occurs in the X11 example. It also fails when compiled on FreeBSD 5.4 and run on FreeBSD 7.0 with compat5x. This kind of code worked without any problems when built and run on FreeBSD 5 and also when run on FreeBSD 6 with compat5x. >How-To-Repeat: Test case 1: X11 ---------------- a. Make the file below available on a 6.0 machine. $ cat xerror.c #include #include #include void *do_x11(void *arg) { Display *disp; Atom primary; Window root; Atom actual_type; int actual_format; unsigned long nitems; unsigned long bytesafter; unsigned char *prop; int i; printf("Opening display\n"); disp = XOpenDisplay(NULL); primary = XInternAtom(disp, "PRIMARY", 0); root = XRootWindow(disp, DefaultScreen(disp)); printf("Atom is %d\nRoot is %d\n", (int)primary, (int)root); fflush(stdout); for (i = 0; i < 10000; i++) { XGetWindowProperty(disp, root, primary, 0, 0, False, primary, &actual_type, &actual_format, &nitems, &bytesafter, &prop); } printf("Closing display\n"); fflush(stdout); XCloseDisplay(disp); return NULL; } int main() { pthread_t pt; pthread_create(&pt, NULL, do_x11, NULL); pthread_join(pt, NULL); return 0; } b. Compile it on a 6.0 machine to make a.out: $ cc -pthread -I/usr/X11R6/include xerror.c -L/usr/X11R6/lib -lX11 c. Copy a.out to a 7.0 machine and run it with compat6x installed. $ ./a.out Opening display Atom is 1 Root is 91 XIO: fatal IO error 0 (Unknown error: 0) on X server "heap:0.0" after 8 requests (7 known processed) with 0 events remaining. d. It should return without printing any X errors Test case 2: libc ----------------- a. Make the two files below available on a 6.0 machine. $ cat lib.c #include #include int readerror() { char buf[1]; read(-1, buf, 1); return errno; } $ cat user.c #include #include extern int readerror(void); void *do_error(void *arg) { printf("errno = %d\n", readerror()); } int main() { pthread_t pt; pthread_create(&pt, NULL, do_error, NULL); pthread_join(pt, NULL); return 0; } b. Compile them on a 6.0 machine to make lib.so and a.out: $ cc -shared -o lib.so lib.c $ cc -pthread user.c lib.so c. Copy a.out and lib.c to a 7.0 machine and compile lib.c again: $ cc -shared -o lib.so lib.c d. Run the 6.0 a.out on the 7.0 machine with compat6x installed: $ env LD_LIBRARY_PATH=`pwd` ./a.out errno = 0 e. It should print errno = 9 (i.e. EBADF). >Fix: >Release-Note: >Audit-Trail: >Unformatted: