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 Netto X-Patchwork-Id: 812625 Delivered-To: patch@linaro.org Received: by 2002:adf:fac3:0:b0:367:895a:4699 with SMTP id a3csp1887432wrs; Mon, 15 Jul 2024 09:39:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6gNp6VXB1K5ecWnmAwMmbQExLrtrYS7Cw8TuDXHnCwYhliob8I3KeLVhL2dyE29y4iSR3s11dX67SRXNifX3r X-Google-Smtp-Source: AGHT+IEfneGB0rEUl+SfDH/Wuj3xz3QpknMsZt8q6orRChzwdImaaSH1ivAJRHCHO2yD7Zc9Nb3D X-Received: by 2002:a05:6122:1ad6:b0:4eb:5cb9:f219 with SMTP id 71dfb90a1353d-4f4cd10badcmr728791e0c.0.1721061564755; Mon, 15 Jul 2024 09:39:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1721061564; cv=pass; d=google.com; s=arc-20160816; b=IOVkr/byBHvPtsrjvpWOsNzrnlCgX0cIlvqUoaevJR1qVn0UKMUd7Vt0bYvnBzAr0u aazKuwztdDodnl+fJNa9NGd4YhZjRyywbQGM1mqiIFrlSXPxOwx+Lqc6BH0/VaUdh/Ms FCeJEkZB6QbI802q5CdSZmK+EgDxs500cnSTCyDyQAGpWER2yJrPBmLHAPcAMTiI/uaa xG0S2+AUluKjgRowll3hU4vvDD117TpWxMpoyi7g4CNJTZ1Jv01GJTg2qTtt/wTwJEQX p3F5crC4jRhX3kpGhRKIw1CJwuSi+VmgeT57KGZtRFWkaRzezemxHA0UOVRhDewHXVI+ XdkQ== 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=DqBLzc56Gf7UcD2TVAMt11eqd9uUIHZVQlzhWGh8mWU=; fh=vxC34zm98lKhINU6ektHstch2+KwK1mjDXdJpo1/Y9M=; b=a3fJgdHeG5W7cd+FpjL8s3HaRdUd2sntnN6ZHGUeP0efwy5KU4A297PBTzjzDrZvGG 4U+7RNZIVygBEbtl+cP8Y+e4FV1LX06motBt9T32+9EO+eejPQs0S4Dxm/upV8jGcslx y0W52fLQAnEiHGZeVkUdSoQUTRXZSrYIdf8WQVerfKcI/JnRVW8d8GtD7iTEPTaUPiux T/L5VQr+I5dPxtcUhM+ysxqe414hADk6zSh14NOx0mNNC3eWoeN4UiHveue2PwhZbfnj PZz/08FHaYDuKpxVRMPzFFnvgswRN6qznhXriRz7zGQvZl2/IWsnO2Bam3NXHbdqjPOD ZKwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CEoZUViQ; 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 d75a77b69052e-44f5b81f19dsi54985661cf.612.2024.07.15.09.39.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 09:39:24 -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=CEoZUViQ; 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 636433858435 for ; Mon, 15 Jul 2024 16:39:24 +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-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~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. --- 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) }