This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Fix _res (was Re: _res_init/_res and libpthread)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Ulrich Drepper <drepper at redhat dot com>, Roland McGrath <roland at redhat dot com>, Thorsten Kukuk <kukuk at suse dot de>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Fri, 7 Feb 2003 17:27:31 +0100
- Subject: [PATCH] Fix _res (was Re: _res_init/_res and libpthread)
- References: <20030207143302.GA29017@suse.de>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Feb 07, 2003 at 03:33:03PM +0100, Thorsten Kukuk wrote:
>
> Hi,
>
> With current glibc (compiled without TLS support and without nptl),
> the following test program does not work if I link it against
> libpthread. If I don't link it against libpthread, it works fine:
>
> kukuk@E113:~/tmp> gcc res_init.c -o res_init
> kukuk@E113:~/tmp> ./res_init
> count 3
> kukuk@E113:~/tmp> gcc res_init.c -o res_init -lpthread
> kukuk@E113:~/tmp> ./res_init
> count 0
>
> Any ideas why _res does not work any longer?
>
> #include <netinet/in.h>
> #include <arpa/nameser.h>
> #include <resolv.h>
>
> #include <stdio.h>
>
> main(){
> res_init();
>
> printf("count %i\n", _res.nscount );
>
> }
Making aliases of common symbols is a bad thing...
So we ended up with two different 512B objects:
_res (which libc.so used) and _res@GLIBC_2.0 (which everyone else used).
2003-02-07 Jakub Jelinek <jakub@redhat.com>
* resolv/res_libc.c (_res): Ensure _res is not common symbol,
so that it can have aliases.
* inet/herrno.c (h_errno): Put it into .bss not .data section.
--- libc/resolv/res_libc.c.jj 2003-01-03 17:31:47.000000000 -0500
+++ libc/resolv/res_libc.c 2003-02-07 11:13:33.000000000 -0500
@@ -77,8 +77,11 @@ extern __thread struct __res_state __lib
attribute_hidden;
# define _res __libc_res
#else
-/* The resolver state for use by single-threaded programs. */
-struct __res_state _res;
+/* The resolver state for use by single-threaded programs.
+ This differs from plain `struct __res_state _res;' in that it doesn't
+ create a common definition, but a plain symbol that resides in .bss,
+ which can have an alias. */
+struct __res_state _res __attribute__((section (".bss")));
/* We declare this with compat_symbol so that it's not
visible at link time. Programs must use the accessor functions. */
--- libc/inet/herrno.c.jj 2002-12-28 05:08:10.000000000 -0500
+++ libc/inet/herrno.c 2003-02-07 11:12:30.000000000 -0500
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,97,98,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996,97,98,2002,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -31,7 +31,10 @@ extern __thread int __libc_h_errno __att
attribute_hidden;
# define h_errno __libc_h_errno
#else
-int h_errno = 0;
+/* This differs from plain `int h_errno;' in that it doesn't create
+ a common definition, but a plain symbol that resides in .bss,
+ which can have an alias. */
+int h_errno __attribute__((section (".bss")));
weak_alias (h_errno, _h_errno)
/* We declare these with compat_symbol so that they are not
Jakub