From patchwork Thu Jun 16 08:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 1644191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=jemOgdCi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LNvtW3HyCz9sG0 for ; Thu, 16 Jun 2022 18:08:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 651793857C48 for ; Thu, 16 Jun 2022 08:08:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 651793857C48 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655366880; bh=70XOkFQMUO3dx50o7HOPW6O8kZPKy/h4Lek5RIn/jOc=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jemOgdCipNSV4L+ARtS0MiSCKUp6zCPbGXbRe8ds6EXZG01ABrD4JGP/49032axlT 2N80WzE/h1hG8dJLaA6iDiAy1wCe4b4j/BrXzk1Sgw/JLCo/ZB2WJsLp31OEYjtVjd ICXLQLqO7ySKiXOEKoyV86biP58saOETwJOjni7o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 528D83858C56 for ; Thu, 16 Jun 2022 08:07:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 528D83858C56 Received: by mail-yb1-xb49.google.com with SMTP id m11-20020a25710b000000b0065d4a4abca1so452494ybc.18 for ; Thu, 16 Jun 2022 01:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=70XOkFQMUO3dx50o7HOPW6O8kZPKy/h4Lek5RIn/jOc=; b=GU4s6Np/47tMNY4DC+iaiHxnUY3nVQEBKF+8kmeojH2CVQqiejFo9lLh3kJkpQ1lvr 2AfiYUTQ2McB/5UfjYo2IOfCK7TA9hfbm1+Fb9Af5YkRnVwHRWeESReK5o7jSPLdrdTF sECX0LFJl5SsuWkNebvBUh+euiDYLQyKgSo58XSV1G+BJCHoxlWtnEDOSOotkMhRaRCR wIje/K3CUDguO1f6wSLjvC1VAXTIVqFqqiSKcGvr5x5hvnnWmzrmJUZpR7of7lXSWnpv dy7unTMC+M/ooPaBb+v9LLcVWC5AQVp4rJCT0nEx1N6OTC5o91DxwwIEy6WJJtxsF5sP Z9ug== X-Gm-Message-State: AJIora/rAd9HpS8fGAeg8iSqzU/aMn8i6+ux8/UcD3zGHa52v0GV6fvM jRZpcIVUWXPhc18dolod9sKApj1lPYRZjxjwBydX7JB9aj8RERRynGx2+XIw2EFtDRnY7A2o8+v +hvkFxJOmYVr4gAekrFGEaxlEP9q6y2iFf8RkzT8h0kzVmjrildpQOD+7zYE0MbHT9sSV X-Google-Smtp-Source: AGRyM1t/pburbThON7UP9uzSq00LdBKBOrsvWMdq6eSQD/byucJ8zqE3UqlLCCMSnwePp+okLJ4oo5UgE+dA X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:2ddc:f0bd:cda:3946]) (user=maskray job=sendgmr) by 2002:a81:10d5:0:b0:317:4d00:9b3b with SMTP id 204-20020a8110d5000000b003174d009b3bmr4265208ywq.248.1655366864658; Thu, 16 Jun 2022 01:07:44 -0700 (PDT) Date: Thu, 16 Jun 2022 01:07:39 -0700 Message-Id: <20220616080739.3736718-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] x86-64: Handle fewer relocation types for RTLD_BOOTSTRAP To: libc-alpha@sourceware.org, "H.J. Lu" X-Spam-Status: No, score=-20.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Fangrui Song via Libc-alpha From: Fangrui Song Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The RTLD_BOOTSTRAP branch is used to relocate ld.so itself. It only needs to handle RELATIVE, GLOB_DAT, and JUMP_SLOT. RELATIVE has been handled (by _ELF_DYNAMIC_DO_RELOC due to DT_RELACOUNT, or RELR), so the switch statement only needs to handle GLOB_DAT and JUMP_SLOT. We can drop these `#if[n]def RTLD_BOOTSTRAP` and add a large `# ifndef RTLD_BOOTSTRAP` instead. --- sysdeps/x86_64/dl-machine.h | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 06c9a932b0..34766325ae 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -298,6 +298,11 @@ and creates an unsatisfiable circular dependency.\n", switch (r_type) { + case R_X86_64_GLOB_DAT: + case R_X86_64_JUMP_SLOT: + *reloc_addr = value; + break; + # ifndef RTLD_BOOTSTRAP # ifdef __ILP32__ case R_X86_64_SIZE64: @@ -314,29 +319,14 @@ and creates an unsatisfiable circular dependency.\n", value = sym->st_size; *reloc_addr = value + reloc->r_addend; break; -# endif - - case R_X86_64_GLOB_DAT: - case R_X86_64_JUMP_SLOT: - *reloc_addr = value; - break; case R_X86_64_DTPMOD64: -# ifdef RTLD_BOOTSTRAP - /* During startup the dynamic linker is always the module - with index 1. - XXX If this relocation is necessary move before RESOLVE - call. */ - *reloc_addr = 1; -# else /* Get the information from the link map returned by the resolve function. */ if (sym_map != NULL) *reloc_addr = sym_map->l_tls_modid; -# endif break; case R_X86_64_DTPOFF64: -# ifndef RTLD_BOOTSTRAP /* During relocation all TLS symbols are defined and used. Therefore the offset is already correct. */ if (sym != NULL) @@ -353,23 +343,19 @@ and creates an unsatisfiable circular dependency.\n", *reloc_addr = value; # endif } -# endif break; case R_X86_64_TLSDESC: { struct tlsdesc volatile *td = (struct tlsdesc volatile *)reloc_addr; -# ifndef RTLD_BOOTSTRAP if (! sym) { td->arg = (void*)reloc->r_addend; td->entry = _dl_tlsdesc_undefweak; } else -# endif { -# ifndef RTLD_BOOTSTRAP # ifndef SHARED CHECK_STATIC_TLS (map, sym_map); # else @@ -381,7 +367,6 @@ and creates an unsatisfiable circular dependency.\n", } else # endif -# endif { td->arg = (void*)(sym->st_value - sym_map->l_tls_offset + reloc->r_addend); @@ -392,13 +377,9 @@ and creates an unsatisfiable circular dependency.\n", } case R_X86_64_TPOFF64: /* The offset is negative, forward from the thread pointer. */ -# ifndef RTLD_BOOTSTRAP if (sym != NULL) -# endif { -# ifndef RTLD_BOOTSTRAP CHECK_STATIC_TLS (map, sym_map); -# endif /* We know the offset of the object the symbol is contained in. It is a negative value which will be added to the thread pointer. */ @@ -416,7 +397,6 @@ and creates an unsatisfiable circular dependency.\n", } break; -# ifndef RTLD_BOOTSTRAP case R_X86_64_64: /* value + r_addend may be > 0xffffffff and R_X86_64_64 relocation updates the whole 64-bit entry. */ @@ -481,7 +461,7 @@ and creates an unsatisfiable circular dependency.\n", default: _dl_reloc_bad_type (map, r_type, 0); break; -# endif +# endif /* !RTLD_BOOTSTRAP */ } } }