From patchwork Mon Nov 1 12:50:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46902 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BB06385801D for ; Mon, 1 Nov 2021 12:52:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB06385801D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635771154; bh=6gccksuSNAo9Jox4h4E2iftmGCqbSm0PQ1jYfmojqEw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=feNltPFXqULh9JuC15HWtUn12i8IgUzhAiZMGeXcgUEl4Twokv2x6jynk9NJfRcjp MKOjBg2Bj9fPOX+biWsZrD4on6ZjiHAZrdU9RfX5FbxeNrDJ+h07zBjvvqWbQ/mcZY pVPNZsYMao3mSVfatJ/jaNhOAcwNuBO9cV78dD9E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id A3E093858020 for ; Mon, 1 Nov 2021 12:50:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A3E093858020 Received: by mail-qt1-x836.google.com with SMTP id h16so11232885qtk.0 for ; Mon, 01 Nov 2021 05:50:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6gccksuSNAo9Jox4h4E2iftmGCqbSm0PQ1jYfmojqEw=; b=3nXvrnp0uVhnPPoFv7GJFL+kKA1bMn7LxPu4ORhFTbl8azd6mYDyFfPCVFBl3skln5 +MU1PUbF3m+5Wqaa2BF9Vcig323J+GXBh/IFblTMrr7jkAUUd246LcASOEsjVx4G7z5A geAk1U9xsCqRXLJVIFvYdttQMo2twSMxZXz3oyzHWpsSeSrnhdb9OAh6jmGur4Bd7qhz N9/sbdTPrPhh33iifnQhLb7YIKz38YIHY/NqWIzTsSvtrgHDZvPghGkh2K84qs3Yg+/S x5YQN3+MAmAl+258t9MgdbGQ0oyNa+C9mH3Ww9vGcxnZHOp4xWko+P3iQetQnwPpSDL1 Ox8Q== X-Gm-Message-State: AOAM530JJ5ibX0fGjrZSIttp9pBjPXsMTmrDiiQC5krgbUF2vn4jBwU1 BhlQVplNviPNs/jY9jgvgzA/idxQCMwUDQ== X-Google-Smtp-Source: ABdhPJwNgClv/EAN3HHa1l9tIugEXHDy08auXIP/WQA/GyfWwCde4WRqTc8nIOGfB1OmvNtX8oPtsA== X-Received: by 2002:ac8:5a49:: with SMTP id o9mr29360631qta.416.1635771010139; Mon, 01 Nov 2021 05:50:10 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id g1sm4958193qtb.7.2021.11.01.05.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 05:50:09 -0700 (PDT) To: libc-alpha@sourceware.org, =?utf-8?b?RsSBbmctcnXDrCBTw7JuZw==?= Subject: [PATCH 3/3] elf: Assume disjointed .rela.dyn and .rela.plt for loader Date: Mon, 1 Nov 2021 09:50:03 -0300 Message-Id: <20211101125003.500945-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101125003.500945-1-adhemerval.zanella@linaro.org> References: <20211101125003.500945-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The linker might add another section between the two relocation section for the loader as well. For instance on arm, lld does: [ 7] .rel.dyn REL 000007f0 0007f0 000088 08 A 1 0 4 [ 8] .ARM.exidx ARM_EXIDX 00000878 000878 0000b0 00 AL1 2 0 4 [ 9] .rel.plt REL 00000928 000928 000028 08 AI 1 17 4 This patch removes the ELF_DURING_STARTUP optimization and assume both section might no be linear. Checked on x86_64, i686, aarch64, armhf, powerpc64le, powerpc64, and powerpc (to check if this breaks on different architectures). --- elf/dynamic-link.h | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index ac4cc70dea..f619615e5c 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -65,12 +65,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], #ifdef RESOLVE_MAP -# if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP -# define ELF_DURING_STARTUP (1) -# else -# define ELF_DURING_STARTUP (0) -# endif - /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'. These functions are almost identical, so we use cpp magic to avoid duplicating their code. It cannot be done in a more general function @@ -106,9 +100,8 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], \ if (ranges[0].start + ranges[0].size == (start + size)) \ ranges[0].size -= size; \ - if (ELF_DURING_STARTUP \ - || (!(do_lazy) \ - && (ranges[0].start + ranges[0].size) == start)) \ + if (!(do_lazy) \ + && (ranges[0].start + ranges[0].size) == start) \ { \ /* Combine processing the sections. */ \ ranges[0].size += size; \ @@ -121,20 +114,13 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], } \ } \ \ - if (ELF_DURING_STARTUP) \ - elf_dynamic_do_##reloc ((map), scope, ranges[0].start, ranges[0].size, \ - ranges[0].nrelative, 0, skip_ifunc); \ - else \ - { \ - int ranges_index; \ - for (ranges_index = 0; ranges_index < 2; ++ranges_index) \ - elf_dynamic_do_##reloc ((map), scope, \ - ranges[ranges_index].start, \ - ranges[ranges_index].size, \ - ranges[ranges_index].nrelative, \ - ranges[ranges_index].lazy, \ - skip_ifunc); \ - } \ + for (int ranges_index = 0; ranges_index < 2; ++ranges_index) \ + elf_dynamic_do_##reloc ((map), scope, \ + ranges[ranges_index].start, \ + ranges[ranges_index].size, \ + ranges[ranges_index].nrelative, \ + ranges[ranges_index].lazy, \ + skip_ifunc); \ } while (0) # if ELF_MACHINE_NO_REL || ELF_MACHINE_NO_RELA