Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 May 1998 17:47:10 +1000
From:      Stephen McKay <syssgm@dtir.qld.gov.au>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        freebsd-current@FreeBSD.ORG, syssgm@dtir.qld.gov.au
Subject:   Re: Fix for undefined "__error" and discussion of shared object versioning 
Message-ID:  <199805200747.RAA09525@troll.dtir.qld.gov.au>
In-Reply-To: <199805200312.UAA26227@usr04.primenet.com> from Terry Lambert at "Wed, 20 May 1998 03:12:25 %2B0000"
References:  <199805200312.UAA26227@usr04.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday, 20th May 1998, Terry Lambert wrote:

>hermes% gcc -v
>gcc version 2.7.2.1

Ditto.

Tweaking your code slightly:

-- errno.h -------------------------------------------------------------------
#ifndef KERNEL
#include <sys/cdefs.h>
__BEGIN_DECLS
int *   __error __P((void));
extern int fake_used;
static int *___error(void) { extern int errno; fake_used++; return &errno; }
#pragma weak __error = ___error
#warning "using a fake errno.h"
__END_DECLS
#define errno           (* __error()) 
#endif 
-- terry.c -------------------------------------------------------------------
#include "errno.h"      /* use hacked errno.h because of paranoia*/
#include <stdio.h>

int fake_used;

main()
{
	printf("default errno is %d\n", errno);
	printf("fake_used is %d\n", fake_used);
}
------------------------------------------------------------------------------
My non-libc_r linkage does:
------------------------------------------------------------------------------
$ cc -o terry terry.c
In file included from terry.c:1:
errno.h:8: warning: #warning "using a fake errno.h"
$ ./terry
default errno is 0
fake_used is 1
------------------------------------------------------------------------------
My libc_r linkage does:
------------------------------------------------------------------------------
$ cc -o terry terry.c -lc_r
In file included from terry.c:1:
errno.h:8: warning: #warning "using a fake errno.h"
$ ./terry                  
default errno is 2
fake_used is 2
------------------------------------------------------------------------------

>The difference in the output is because PHK's malloc always fails a
>``readlink("/etc/malloc.conf");'' and sets errno = ENOENT (2).

This explains the errno of 2.  fake_used should be 0.  I explain the
count of 2 by assuming that one is for the assignment to errno, and
the other for the read of errno.  Our ___error() should not have been
called at all in this example.  So, it's not working properly after all.

I am keen to make this work, but don't know how.  Why don't weak symbols
work for this?

>> 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.
>
>It would avoid the problem by letting us bump the minor but not the
>subminor when the errno.h change went in.  So long as you did not
>foolishly replace an existing library of the same major/minor that
>you had built on your own, the executable would continue to prefer
>the old library to the new library you had built.

What you are saying is that we would bump the minor numbers on all
libraries with your system, as opposed to bumping the major numbers
on all libraries with the current system.  This gains nothing as far
as I can see.

>> The lesson here is to have no global variables!
>
>Tell POSIX/ANSI about it.  Call me if they actually listen to you, since
>I want some things fixed.  8-).

It's all happening with the Open Group now, isn't it?  Aren't they about
to release Unix 98 to match Windoze 98?  Misfeature for misfeature I
expect. :-)

Stephen.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805200747.RAA09525>