From owner-freebsd-current Tue May 19 02:29:26 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA29814 for freebsd-current-outgoing; Tue, 19 May 1998 02:29:26 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from ren.dtir.qld.gov.au (firewall-user@ns.dtir.qld.gov.au [203.108.138.66]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA29796 for ; Tue, 19 May 1998 02:29:10 -0700 (PDT) (envelope-from syssgm@dtir.qld.gov.au) Received: by ren.dtir.qld.gov.au; id TAA19447; Tue, 19 May 1998 19:29:02 +1000 (EST) Received: from ogre.dtir.qld.gov.au(167.123.8.3) by ren.dtir.qld.gov.au via smap (3.2) id xma019442; Tue, 19 May 98 19:28:55 +1000 Received: from troll.dtir.qld.gov.au (troll-8.dtir.qld.gov.au [167.123.8.1]) by ogre.dtir.qld.gov.au (8.8.7/8.8.7) with ESMTP id TAA01240; Tue, 19 May 1998 19:28:55 +1000 (EST) Received: from localhost (syssgm@localhost) by troll.dtir.qld.gov.au (8.8.5/8.8.5) with SMTP id TAA10958; Tue, 19 May 1998 19:28:50 +1000 (EST) Message-Id: <199805190928.TAA10958@troll.dtir.qld.gov.au> X-Authentication-Warning: troll.dtir.qld.gov.au: syssgm@localhost didn't use HELO protocol To: Terry Lambert cc: freebsd-current@FreeBSD.ORG, syssgm@dtir.qld.gov.au Subject: Re: Fix for undefined "__error" and discussion of shared object versioning References: <199805181843.LAA09263@usr01.primenet.com> In-Reply-To: <199805181843.LAA09263@usr01.primenet.com> from Terry Lambert at "Mon, 18 May 1998 18:43:57 +0000" Date: Tue, 19 May 1998 19:28:50 +1000 From: Stephen McKay Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Monday, 18th May 1998, Terry Lambert wrote: >> I tried a number of variants of this approach and could not make any of >> them work. In all cases (well, all that compiled at all), the local >> hack ___error() was used in preference to the system supplied __error(). >> Otherwise, this would be a good hack, costing only 12 bytes per .o file. > >Use this one instead: > >----------------------------------------------------------------------- >#ifndef __GNUC__ >#ifndef _ERRNO_C_ >static int *___error( void) { extern int errno; return &errno; } >#pragma weak __error = ___error >#endif /* _ERRNO_C_*/ >#endif /* __GNUC__*/ >extern int * __error __P((void)); >#define errno (* __error()) >----------------------------------------------------------------------- > >This works *IF* libc and libc_r are compiled with -D_ERRNO_C_. I still don't think this works. I'm not testing this live, I'm faking up test cases. Assume I changed #ifndef __GNUC__ to #ifdef __GNUC__ already. I've renamed stuff to show the principle not working more easily: === main.c === int fake_errno = 100; main() { int x; x = wibble(); printf("%d\n", x); return 0; } int real_errno = 200; int *real_error() { return &real_errno; } === sub.c === #include #ifdef __GNUC__ #ifndef _ERRNO_C_ static int *fake_error(void) { extern int fake_errno; return &fake_errno; } #pragma weak real_error = fake_error #endif /* _ERRNO_C_*/ #endif /* __GNUC__*/ extern int * real_error __P((void)); #define errno (* real_error()) wibble() { return errno; } ====== This should print 200 if the fix works, but prints 100. Even when I built a mini shared library with real_error() in it, the output was still 100. real_error() was executed as expected when the #pragma was removed, but that doesn't help much. :-) >An ld.so hack is precisely the wrong thing to do; it results in an >infinite recursion on the first error set which happens (which is >usually when Poul's malloc() code calls readlink() for /etc/malloc.conf >and gets an error when it's not a symlink when you link with libc_r). So, it will have to be a better hack and supply __error() internally. >> In my view, the least pleasant option is to bump all major library >> numbers. > >It is, however, the correct one, I've decided, working on getting >this hack to actually work. It would be a big pain though. Could we wait for ELF instead? >The versioning needs major, minor, and subminor. I don't see how your major/minor/subminor is any better than the current major/minor, or how it would avoid the current problem. The current problem is due to replacing a global integer with a function. Replacing one function with another would have been simple. The lesson here is to have no global variables! >There is also a weakness in ld.so; specifically, ld.so, being a shared >object, should also be versioned (Sun does this). This would have let >use "fix" the problem in ld.so by stepping it with libc.so and libc_r.so. Can't we still fix it in ld.so? A new ld.so with the new libc.so should be able to fiddle anything. Stephen. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message