From patchwork Mon Jul 15 16:39:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 93946 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 C6A8E3864847 for ; Mon, 15 Jul 2024 16:39:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id E74C43858D20 for ; Mon, 15 Jul 2024 16:39:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E74C43858D20 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 E74C43858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721061553; cv=none; b=HYyG2j6dJqqVYH1Ux6qAN5OZKEzdcAuj57BAyE5ocpTFvJ5GU5FaNeJDSVyhxBSg5nM8UTKxX1ZdJb9mJ1+vXb58nhwgUj8/srfzjtNVnY3jEoL4iEwRf9pjNKDNnFagwGNVfVXpH0jpt7zwzVqDUHBqVATRqrxxu9EHyXT4iaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721061553; c=relaxed/simple; bh=zLc3hKZDsfFKJA2mfXTQvdTELpZfQ3Yw2Lh1gXYCfXQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=g4Xth4/x/A+wroObfU6tyeoz09dE272+sjtU6M4sBgZD37muvUM7wsIZQuwY9I6Ia2JgpIS2ggTDRyGbVFcWkx2umLy9DgI9KyVegN5/tqBsRMxj71ZY6o+eZkGkGiiSgOj5cCHmLUGtt9KXjQgDQ92/bRoCvQ8w7Ptoo2La4So= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42726d6eca5so32871605e9.1 for ; Mon, 15 Jul 2024 09:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721061549; x=1721666349; 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=DqBLzc56Gf7UcD2TVAMt11eqd9uUIHZVQlzhWGh8mWU=; b=CEoZUViQh7tW6KsKvuGviG1e+jowdqdP3EEOIpbiBnwkUhgo8jxvnOeAIM/Fd33Fiw eLEfVfWICkriU+qHZ0DV6TWuYcIP3SI5JjYVhyWyUoS6WbNb4N+Qk/1YqErwqvX5Iem2 f150ume/7qR9svvYBWUwCZHpwwhevy0Z4FkhrieK5acCsGU5MdnJ7Ii/tzISqM4A9IwT XyVPJhGC5hz+HWbNLfyZd9SQKh6JPJbiuH501GypEvvh6tuXb9e8q/gldXXbdNrav+IC Hc0k2uvCNpgVNEm2ANcUsEEoQwdqD4geRQw8hnS/dHiZVo/6eGn41RFJBL7Ck76S4qqF OVFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721061549; x=1721666349; 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=DqBLzc56Gf7UcD2TVAMt11eqd9uUIHZVQlzhWGh8mWU=; b=euuZL7TriQ9ATByPZ6cQn/R0xaUn4NZP+tY32E/L0jNLVhkRK/hi+/xuWKIgSsMVaR HadkyJUvx8jPx624ymoE6n6G4hv3OhQehbDh/HgoUNLuS/X++rDqUnTcYhKeGumTqs7Y W4gsCJjEgqI3z+MuIudetzoT3cRWiw9kVz4id1HYE6pjH9QhEKB1SXqNaN+0/DFDnNxI UkVxOAaONdJCm5JE52WeDcqtdxCKwVk2ue760bE2WiN/CvIQBcwH+Hq0pdtjdanCXzsG Z618W068wTutmxagh3WK43NZL36sjT+TP/T73vzgV+ffXQ+ylyfR4gMgEPodKQYzJkYQ IQAg== X-Gm-Message-State: AOJu0Yz3w/FI0QXypU0jqlPvgdtOX9La+glUcBgGIzh3i9246PLTCXko gIYIey+69KfZtob4V7CRdErR+aaTYXyRe/buIlL5racZifU0GbzYbIgkkHI1blhV5lc4V8tlMd3 m X-Google-Smtp-Source: AGHT+IFDLRRPm/K5UHKAjdYN7j8/T+lLtSdp2EsRv9JVrKsVOJExNj0Cpw1Elp3vardIcxK+mFlt/A== X-Received: by 2002:a05:600c:4687:b0:426:593c:935d with SMTP id 5b1f17b1804b1-427b8887babmr1325545e9.5.1721061549005; Mon, 15 Jul 2024 09:39:09 -0700 (PDT) Received: from localhost.localdomain (51-148-40-55.dsl.zen.co.uk. [51.148.40.55]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f239883sm129063415e9.10.2024.07.15.09.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 09:39:08 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Carlos O'Donell , "Andreas K . Huettel" Subject: [PATCH] elf: Fix localplt.awk for DT_RELR-enabled builds Date: Mon, 15 Jul 2024 16:39:06 +0000 Message-Id: <20240715163906.376514-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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~patchwork=sourceware.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. --- scripts/localplt.awk | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/localplt.awk b/scripts/localplt.awk index fe79ca01ab..831ab873c1 100644 --- a/scripts/localplt.awk +++ b/scripts/localplt.awk @@ -10,8 +10,10 @@ 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)"; + print lastfile, jmprel_offset, rela_offset, rel_offset, relr_offset result = 2; } if (pltrelsz > 0 && jmprel_offset == -1) { @@ -22,6 +24,7 @@ FILENAME != lastfile { jmprel_offset = 0; rela_offset = 0; rel_offset = 0; + relr_offset = 0; pltrelsz = -1; delete section_offset_by_address; } @@ -77,6 +80,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 +126,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) }