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 Netto X-Patchwork-Id: 812767 Delivered-To: patch@linaro.org Received: by 2002:a5d:42c4:0:b0:367:895a:4699 with SMTP id t4csp239472wrr; Tue, 16 Jul 2024 03:58:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPyGxbY4Ny1muyiCPovnLJRCVT5LQfU1xND92bXAw8KQeiL2bENfu7HARFdiRD9WxIbv4y0Lkhxlv3e9JdJtME X-Google-Smtp-Source: AGHT+IE7k3YXV/YBwYqPtA2UCsSd0rMhkPb+cnt4mkkwJjVkq7xJibFi46k6FDP1hKJyM7Q3XdqM X-Received: by 2002:a05:620a:3916:b0:79e:fc9c:4bcb with SMTP id af79cd13be357-7a17b69c736mr188261185a.11.1721127494119; Tue, 16 Jul 2024 03:58:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1721127494; cv=pass; d=google.com; s=arc-20160816; b=dTl/cxyDVs4B3X9bqAJKuVN++7GlV9juiOrrks5KyDlrVZdXd1BFx1NLTf4IW2PIyk ENZnzLM1Gu/x1XFxw7bVdhpvHrG9GU+OCuWF+73ve0V569u26PAlSLLh/95HqNv85cV0 o8cJonbdJtOA+uq3rM1c9Yg5r5FPInGx5W/tmY5yzN/3ZlGl5NofV6fkHZjVlvI332DG 0Jn2JFM/w2g5EDxFwcbjT49YGzsrPSPHoE10xKM549bm27tAHHFix2PG++VSwNWxtqvI jWyRQwtdfixicbR0ghQETBXou8XEMuFoImODOl5UcO4u0nbxB+FTPbx1N+EYzpfZshMO WLGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=MWaSCRsBzijyn2Ym/kWyZ4bxBnGg8upP4Im5DeG+DAA=; fh=vxC34zm98lKhINU6ektHstch2+KwK1mjDXdJpo1/Y9M=; b=mjHFdHqeeHNtUqtMhXHuUO6EZQ3ipY1iRdFHh8TFSNZmwg13B2duqXt0suQ8aTaB9F 6MsCpQ8xaphCLsB1+KqzOk70Vv8iiNIn0Z+BwPDDCzDT0HqFQyxKTHHJKW7k2B14MWGx qbhjGS6Jedi1W3/Nh43RYuFh4fcC3lZtw6OaVaIZfd4Uo3bjz8FUuVG3uNmjovZrqXBr jHEEhsZGv4uMWKCJh01y5NmqzUYoYsb5VY79WYEeTfugmWmTooEP+VfHJcB7o9nfIA10 gMxqRE9ImpBAj6MhNWpZy5LvSCKiAc5O2XxDIpK8fW4+ZdOi0QyQ0QjD4mSIJySIpbOz KTzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ol0vvugK; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id af79cd13be357-7a160b7c660si719870785a.49.2024.07.16.03.58.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 03:58:14 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ol0vvugK; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BABA93861808 for ; Tue, 16 Jul 2024 10:58:13 +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-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~patch=linaro.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) }