From patchwork Tue Jul 16 10:57:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1960995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ol0vvugK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WNbdm361Pz1xrK for ; Tue, 16 Jul 2024 20:58:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ECC9385E836 for ; Tue, 16 Jul 2024 10:58:18 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 011FB3858424 for ; Tue, 16 Jul 2024 10:58:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 011FB3858424 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 011FB3858424 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721127483; cv=none; b=fwGjJqESNPMMxE4CQUwnTJLLGlpO7tFo9D4JRk5bXpdg3pRMOg7uKz3N0w8+9/EyrAYds2rTWSZL2C6Wi5Ofj1Gig/6jzPGHTBFBAjIW3B/rjkJ2m36xCS0aBgz8Hfn2yhudBuNZsdQmcesxURLhPS+S+oOORbf5KzziuQ/tgDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721127483; c=relaxed/simple; bh=z+sYG2r8HARx95RK9MVz3SvuFU43ynD+4+XOdYJtygY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IgtHQrUZUDfTe86MDTKcnuXnjRCeuAnpLr1TU29qJlHlzgF4y6iDxUbgcJFHwi+SNjyxEp0xsfs9ErhX0/Eveq2IyLU37ko7cRcFQLdoQfqiz/apzxtZUO2XhO3Hf5F9U+0/tPnoA0jxXO4ZwzXCIKxhE1jCF7KHo6HkYe3YW64= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fc2a194750so19176125ad.1 for ; Tue, 16 Jul 2024 03:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721127479; x=1721732279; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MWaSCRsBzijyn2Ym/kWyZ4bxBnGg8upP4Im5DeG+DAA=; b=Ol0vvugKKDeVUTZ3Wo1f4RdyiOcKn6FE7sNxWBzRXh1+MtaWEOiOKBjXK0yQd8tf5b fBo2gLdmG4kOhZCsFVDMPdG1814X+U/fSUdMdXMkiE0EX5hXV4d035yUsdqWgrADjD2J oIh3fMBaAhOgZ9zHjgbaQVX+8lqU+70buUnoNZj4zYvs2LLQLPK1K0fnSYfuv59L7Qoa 3TT/JLOjhLZsNyMUHm5rGDKSjQXlqY8Nzz4UHezkV0n0EOWATDcBtESOBS3BhIP9KGGn qnQhk1eXD79iWOba6KGVwrBirJEqBwSo8fFAyewcYlon0reRoVdp4v6zA1cy2Fh+hzN5 +D8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721127479; x=1721732279; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MWaSCRsBzijyn2Ym/kWyZ4bxBnGg8upP4Im5DeG+DAA=; b=qlWrYfa8MbTII4ls/srIEDVSqKGM8pyqgBXhHCl5Nrsb5e35bmbIU8ZZZinaMRoPlS N/0mzXDxk+cB+glW9CQ2oW3e0oNafOtsgEiXPEfE4K89svZDBAtrQCH8Lwdl7FIRDsG8 L/qUM6l5wbrQVOGGZCIq4kQL3kcqFovBEuoet40PC6/NCfDq2g0rav4qIWs/3JKeOEVW dx7E9I9iHv1fhSq01VUxG2TiUf7OdNATBWSpZX1SW+k1hQIyVXRZZpuLlhwRqe/ns94n 2/vBfAxUJ/txRg7e9ge3hjNyzdi2g+BtbhBNCyTb5r8qH5MGDERVitF4X/11YehbERon IOOg== X-Gm-Message-State: AOJu0Yytf0srzCmjlzZUFLviLXvT89RvjxgVG07WBGwd0hQLEK5eZjMw TQ9f+jvIUc5cAcTKgH/kpTin9PRaujOoJl/5QhEkSntzxDU6NIEVZuzzUVUNNGXXcDJ37NQGR2T 8634= X-Google-Smtp-Source: AGHT+IFcAjtUUvT6Ik8+Z6DZxbDCkw1LeIjh8ghrXQR48uLZ/L03jPrxDeqJTXYR/LhDt+9ia0zBrw== X-Received: by 2002:a17:903:230e:b0:1fb:4f91:6728 with SMTP id d9443c01a7336-1fc3d9d6770mr13977815ad.42.1721127479217; Tue, 16 Jul 2024 03:57:59 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:842a:7fff:2a23:8139:577c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bb6fee9sm55803145ad.37.2024.07.16.03.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 03:57:58 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Carlos O'Donell , "Andreas K . Huettel" Subject: [PATCH v2] elf: Fix localplt.awk for DT_RELR-enabled builds (BZ 31978) Date: Tue, 16 Jul 2024 07:57:45 -0300 Message-ID: <20240716105753.524866-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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.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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org For each input readelf output, localplt.awk parses each 'Relocation section' entry, checks its offset against the dynamic section entry, and saves each DT_JMPREL, DT_RELA, and DT_REL offset value it finds. After all lines are read, the script checks if any segment offset differed from 0, meaning at least one 'Relocation section' was matched. However, if the shared object was built with RELR support and the static linker could place all the relocation on DT_RELR, there would be no DT_JMPREL, DT_RELA, and DT_REL entries; only a DT_RELR. For the current three ABIs that support (aarch64, x86, and powerpc64), the powerpc64 ld.so shows the behavior above. Both x86_64 and aarch64 show extra relocations on '.rela.dyn', which makes the script check to succeed. This patch fixes by handling DT_RELR, where the offset is checked against the dynamic section entries and if the shared object contains an entry it means that there are no extra PLT entries (since all relocations are relative). It fixes the elf/check-localplt failure on powerpc. Checked with a build/check for aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, arm-linux-gnueabihf, s390x-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu, and powerpc64le-linux-gnu. Reviewed-by: Carlos O'Donell --- scripts/localplt.awk | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/localplt.awk b/scripts/localplt.awk index fe79ca01ab..621ae7d8e8 100644 --- a/scripts/localplt.awk +++ b/scripts/localplt.awk @@ -10,7 +10,8 @@ BEGIN { } FILENAME != lastfile { - if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) { + if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0 \ + && relr_offset == 0) { print FILENAME ": *** failed to find expected output (readelf -WSdr)"; result = 2; } @@ -22,6 +23,7 @@ FILENAME != lastfile { jmprel_offset = 0; rela_offset = 0; rel_offset = 0; + relr_offset = 0; pltrelsz = -1; delete section_offset_by_address; } @@ -77,6 +79,8 @@ in_relocs && relocs_offset == rel_offset && NF >= 5 { } } +# No need to handle DT_RELR (all packed relocations are relative). + in_relocs { next } $1 == "Relocation" && $2 == "section" && $5 == "offset" { @@ -121,4 +125,14 @@ $2 == "(REL)" { } next } + +$2 == "(RELR)" { + relr_addr = strtonum($3); + if (relr_addr in section_offset_by_address) { + relr_offset = section_offset_by_address[relr_addr]; + } else { + print FILENAME ": *** DT_RELR does not match any section's address"; + result = 2; + } +} END { exit(result) }