From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by sourceware.org (Postfix) with ESMTPS id 3BCAF3950C6F for ; Fri, 18 Sep 2020 13:55:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3BCAF3950C6F Received: by mail-io1-xd41.google.com with SMTP id r9so6904840ioa.2 for ; Fri, 18 Sep 2020 06:55:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=27kKe3nQ278qZlmlONFzbl3pKhvWUcUeGAr7DYwucdI=; b=A5YN5zNrA+iQijlHkJ7AtD88xjetSG6OFo55TGe0zCp/0WukMftS8+yIziqbbIQW6m ijg4CkJH5F71jLpg/8xA9uKzAUul/5/1TEb7AUavWEczQZdPtw1GLNnayQY/MPoDKgzw ZpDK1EUKA9jVuNxdzD1w8nH2Ij6KOXwwtnqQ+1IvYupXFNw17RIxb4kyeBVztO9cGWvf aHTdMRXD+YfOtpnyfTK6JZt+xEfB2D3QTUrNk+tKiFxyeqKZeXzxXyBMJrxLCwU7gpMO fIrF37p7K2UTOOV802YYtnytTVZcpJ1nHiFX8YPON1ufL81ujuAlXLZxSOhUWt7/loMH OzHw== X-Gm-Message-State: AOAM5325+kLvMOQfBCwY6+UHcjR70wJf6OojB9lN1qb54nwohYQpoMnG VKLD/mwXdZsYE73TpwI08n3rAmBfBSjHao8wwoY= X-Google-Smtp-Source: ABdhPJymUDhxgHTICHIBwXEQsaI9eF9kN0gt39pxcc7Wa2YhBr4PmBr+APIx9rErsSWbYNAXzO57608Zu3y4jZm7Vz0= X-Received: by 2002:a5e:881a:: with SMTP id l26mr26678186ioj.51.1600437355679; Fri, 18 Sep 2020 06:55:55 -0700 (PDT) MIME-Version: 1.0 References: <20200912134441.2407884-1-hjl.tools@gmail.com> <20200912134441.2407884-2-hjl.tools@gmail.com> <874knva4r6.fsf@oldenburg2.str.redhat.com> In-Reply-To: <874knva4r6.fsf@oldenburg2.str.redhat.com> From: "H.J. Lu" Date: Fri, 18 Sep 2020 06:55:19 -0700 Message-ID: Subject: Re: [PATCH 1/3] x86: Initialize CPU info via IFUNC relocation [BZ 26203] To: Florian Weimer Cc: "H.J. Lu via Libc-alpha" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Sep 2020 13:55:57 -0000 On Fri, Sep 18, 2020 at 1:06 AM Florian Weimer wrote: > > * H. J. Lu via Libc-alpha: > > > X86 CPU features in ld.so are initialized by init_cpu_features, which is > > invoked by DL_PLATFORM_INIT from _dl_sysdep_start. But when ld.so is > > loaded by static executable, DL_PLATFORM_INIT is never called. > > I don't think that's accurate. It's called from elf/dl-support.c in the > static case. But I agree that it's too late in this case. I was referring to the ld.so case. elf/dl-support.c isn't used for ld.so. > > Also x86 cache info in libc.o and libc.a is initialized by a > > constructor which may be called too late. Instead, we should > > initialize x86 CPU features and cache info by initializing dummy > > function pointers via IFUNC relocation. > > Why would ld put this special IRELATIVE relocation first? I'm sorry, > but this looks very brittle. This is for ld.so. ld.so doesn't assume that IFUNC is usable before everything is setted up properly. This IRELATIVE relocation is not different from other dynamic relocations, IRELATIVE or not. The key here is that we want to call init_cacheinfo as early as possible. Calling from _dl_relocate_object is as early as we can get. > I think there's an existing mechanism for this corner case, > ARCH_SETUP_IREL. Could you use that? > ARCH_SETUP_IREL is for static executable, not ld.so. -- H.J.