From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73214 invoked by alias); 18 Mar 2018 02:07:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 71978 invoked by uid 89); 18 Mar 2018 02:07:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=dim, H*r:sk:static-, Hx-spam-relays-external:sk:static-, H*RU:sk:static- X-HELO: hera.aquilenet.fr Date: Sun, 18 Mar 2018 02:07:00 -0000 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: Re: [PATCH] hurd: Fix early rtld access to errno Message-ID: <20180318020712.mks5ijnqzkugxgec@var.youpi.perso.aquilenet.fr> References: <20180318015332.9759-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180318015332.9759-1-samuel.thibault@ens-lyon.org> User-Agent: NeoMutt/20170113 (1.7.2) X-SW-Source: 2018-03/txt/msg00431.txt.bz2 Samuel Thibault, on dim. 18 mars 2018 02:53:32 +0100, wrote: > * sysdeps/generic/dl-sysdep.h (RTLD_EXTERN_ERRNO): Define macro to 0. > * sysdeps/mach/hurd/i386/dl-sysdep.h: Include . > [IS_IN(rtld)] (RTLD_EXTERN_ERRNO): Define macro to 1. > [!IS_IN(rtld)] (RTLD_EXTERN_ERRNO): Define macro to 0. > * include/errno.h [IS_IN(rtld) && !defined RTLD_EXTERN_ERRNO]: Error > out. > [!IS_IN(rtld)] (RTLD_EXTERN_ERRNO): Define to 0. > [RTLD_EXTERN_ERRNO]: Do not use TLS access to errno. All that being said, I'm surprised: AIUI this problem would be the same on all platforms as soon as one would set RTLD_PRIVATE_ERRNO to 0. Trying to set RTLD_PRIVATE_ERRNO to 0 on Linux x86_64 for instance, ld.so crashes in assert (info[DT_FLAGS] == NULL || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0); since __thread access produces DF_STATIC_TLS. Ignoring that check just pushes the crash to open_verify()'s __set_errno call, on fs:(%eax) or fs:0 access (depending whether initial-exec TLS model is enabled or not). I guess that at that point Linux x86_64 hasn't initialized %fs yet. I tried to just disable the use of __thread access to errno in rtld with > @@ -20,7 +24,7 @@ > # define errno rtld_errno > extern int rtld_errno attribute_hidden; > > -# elif IS_IN_LIB > +# elif IS_IN_LIB && !IS_IN(rtld) > > # include > But that's only pushing the issue to the __errno_location() function. In sysdeps/mach/hurd/errno-loc.c I made the rtld version of __errno_location() a weak function which avoids accessing TLS by using a static variable, that function being overriden by libc as soon as it gets loaded. I'm actually wondering why not all archs would need this when RTLD_PRIVATE_ERRNO is 0. Samuel