From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15173 invoked by alias); 22 Apr 2008 09:06:14 -0000 Received: (qmail 15156 invoked by uid 22791); 22 Apr 2008 09:06:14 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 22 Apr 2008 09:05:47 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id m3M9G86x012908; Tue, 22 Apr 2008 11:16:08 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id m3M9G8pw012907; Tue, 22 Apr 2008 11:16:08 +0200 Date: Tue, 22 Apr 2008 09:06:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Better ld -pie bug workaround for nscd Message-ID: <20080422091608.GI3726@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2008-04/txt/msg00003.txt.bz2 Hi! Using -fpic is too heavy hammer for the workaround, all accesses will then be function calls, which isn't needed. Using initial-exec tls model works around the bug too, and the code is far more efficient (and eventually when ld is fixed, ld -pie can transition that to local-exec to make it even more efficient). The unrelated change to make dbs hidden (note, can't use attribute_hidden, as connections.o isn't -DSHARED) seems to turn of a bunch relocations against dbs into relative relocations. 2008-04-22 Jakub Jelinek * nscd/Makefile (nscd-cflags): Set back to -fpie. * nscd/nscd.h (mem_in_flight): Add attribute_tls_model_ie. * nscd/connections.c (mem_in_flight): Likewise. * nscd/nscd.h (dbs): Make hidden. --- libc/nscd/Makefile.jj 2008-04-22 09:08:33.000000000 +0200 +++ libc/nscd/Makefile 2008-04-22 10:41:10.000000000 +0200 @@ -90,8 +90,7 @@ CFLAGS-nscd_initgroups.c = -fexceptions nscd-cflags = -DIS_IN_nscd=1 -D_FORTIFY_SOURCE=2 ifeq (yesyes,$(have-fpie)$(build-shared)) -#nscd-cflags += -fpie -nscd-cflags += -fpic +nscd-cflags += -fpie endif ifeq (yes,$(have-ssp)) nscd-cflags += -fstack-protector --- libc/nscd/nscd.h.jj 2008-04-22 09:08:33.000000000 +0200 +++ libc/nscd/nscd.h 2008-04-22 10:50:54.000000000 +0200 @@ -130,7 +130,7 @@ struct database_dyn /* Global variables. */ -extern struct database_dyn dbs[lastdb]; +extern struct database_dyn dbs[lastdb] __attribute__ ((visibility ("hidden"))); extern const char *const dbnames[lastdb]; extern const char *const serv2str[LASTREQ]; @@ -201,7 +201,7 @@ extern __thread struct mem_in_flight } block[IDX_last]; struct mem_in_flight *next; -} mem_in_flight; +} mem_in_flight attribute_tls_model_ie; /* Global list of the mem_in_flight variables of all the threads. */ extern struct mem_in_flight *mem_in_flight_list; --- libc/nscd/connections.c.jj 2008-04-22 10:51:00.000000000 +0200 +++ libc/nscd/connections.c 2008-04-22 10:51:51.000000000 +0200 @@ -226,7 +226,7 @@ static int sock; unsigned long int client_queued; /* Data structure for recording in-flight memory allocation. */ -__thread struct mem_in_flight mem_in_flight; +__thread struct mem_in_flight mem_in_flight attribute_tls_model_ie; /* Global list of the mem_in_flight variables of all the threads. */ struct mem_in_flight *mem_in_flight_list; Jakub