From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 136933858408 for ; Mon, 12 Aug 2024 14:21:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 136933858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 136933858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723472491; cv=none; b=L7h9S9A+NsJIbAxKwGn7QD9Jj57RnOSw5YzcuFPdsDzLdeDS+3GoULOJdAHniuzCHBv54uQpB4wSkHr92ft/h7hEuvUbn4YRSw1WTdMa0Qxe9pTCPmsignf3txflPpZfVNdichyuLhq3OHvxH2qSHc5/7OJ8k+ctckg5RGjvFeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723472491; c=relaxed/simple; bh=B/SLIGOriBScCw6DrkR9in011rBheo7MlO0N/YHg5bA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=bJ+TFylMs+bedmd3RKLjXZksBnwH9qlL/bo0yFm25dqins5OVyRNAh0iVn5AJ5IMAnRTw8N5O2/1zGszhhgdpPfm+Sepm1mWeRtCErVe7XvdzGc1uHMO+8uPhbm9YwSyJBK4sPT5ZtTQx+xwqrGYY/+PHapXpepCB5zDrxd1I9w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723472489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e+aG2CB7qff+G1MjqkDxCcIx+aGd+2XzU8Zfrpk1iwM=; b=gBHZu5ZrmXWJpOOFb3KRVS2TmgcHK6ihlMoSYKb0brcbmlbY5Z07PuKBt9r8Xbkr/XsjT+ POX0hHNdd/Svab/Fd4g1isilaWdxaprHUkp0pnUXQoEUUhIsZnjmYzQezSq9pKcTqaZx4r VCmfhEIMEdgHXqQjJe7YFJfNXr1VS+4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444-zE77PXMSMOyILgTOuHOhNg-1; Mon, 12 Aug 2024 10:21:28 -0400 X-MC-Unique: zE77PXMSMOyILgTOuHOhNg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-427b7a2052bso51945905e9.2 for ; Mon, 12 Aug 2024 07:21:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723472487; x=1724077287; 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=e+aG2CB7qff+G1MjqkDxCcIx+aGd+2XzU8Zfrpk1iwM=; b=KdcZReml8TBKFp1B/SOBYxhPUai6uDZgsFyudZrs0CaYhrufQtWrSX02SMGKlovkS/ G9eyvpHmFFrcKCNa8Cbsa0vnJKsDXHdId24FLGuTWUQnnGoBf3XGNCwXtU2VDaaxJgD5 4jXdxgqFAm1gatRLzJqC7nPZkpVgQIo/OtfxZBl+13AEgxVv92ZQsWi3BIjGLaYFNNjN 7XeQBr86JKO9QsTZBoLEyPunQpgJvLYCVXt/NPFJQDAivW9H255fpkUaXK419H4N7qSF XEMktB5z1zFUEMuD7jl8WqQcNpfzjRs7/evFvURBFX+dn3A+XrrGxGQtl/UbQsKWrTOI HUBA== X-Gm-Message-State: AOJu0YzUwCjh0BUW2BO8j5i1oyO9NSTxLKUZN1IgatPD4cuVmKrG7epV BPPH9HhKano5eHb8G3gp6ZuimJ8YuUbZFmO+KD5Rz1SJG8G3L3AGrUm7/CqWgGHLallnkExyNn3 1vs9mwvtfLgvLJUgaSa3JT7cpalOsVL+Gsg9iEwc0IYqHt7JhC8t+MhNMqaFVE1V98uYRvtCZXo gmKQumy0zE5R7RvegylFISn1ZbSgJwrR79VS78/JQ= X-Received: by 2002:a05:600c:3b8e:b0:426:5e1c:1ac2 with SMTP id 5b1f17b1804b1-429d47f3939mr6255185e9.8.1723472486952; Mon, 12 Aug 2024 07:21:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLiuZ9ohzawChNxkbSX5WMbX/vFX6kphcWO9+ibeK3b+z7bjxpHRkxreJTrukIFd0/AM5HQw== X-Received: by 2002:a05:600c:3b8e:b0:426:5e1c:1ac2 with SMTP id 5b1f17b1804b1-429d47f3939mr6254895e9.8.1723472486368; Mon, 12 Aug 2024 07:21:26 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4c36ba72sm7698025f8f.16.2024.08.12.07.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 07:21:26 -0700 (PDT) From: Andrew Burgess To: binutils@sourceware.org Cc: Andrew Burgess Subject: [PATCH] ld: ensure build-id is placed near ELF headers Date: Mon, 12 Aug 2024 15:21:23 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HEXHASH_WORD,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: After the commit: commit e8e10743f7b207b21a1efb0cc9e42487080db013 Date: Thu Jun 13 15:10:15 2024 +0100 Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments. When an executable is built with the --rosegment option GDB is no longer able to find the build-id of the executable from a core file. The problem is that GDB depends on what I guess was a lucky coincidence; that the build-id was placed close to the ELF headers. When a Linux kernel produces a core file there is specific support in place so that the kernel will emit the first page of any private file mapping that looks like it might contain ELF headers. If the build-id is placed close to the ELF headers then it will be included in this first page and GDB can find it. Using the build-id GDB can then validate that it has the correct executable loaded to debug the core file, or in some cases GDB can use the build-id to find the executable that matches the core file automatically. The Linux kernel support for this feature has existed since 2007, see this (kernel) commit: commit 82df39738ba9e02c057fa99b7461a56117d36119 Date: Tue Oct 16 23:27:02 2007 -0700 Add MMF_DUMP_ELF_HEADERS I ran into this issue while testing on the latest Fedora Rawhide build, currently the linker on this system enables --rosegment by default and as a result GDB is not able to find the build-id for any core file. What's happening is that with --rosegment the linker merges the .note.gnu.build-id sections with all the other data content and places this after the executable content. Without the --rosegment the .note.gnu.build-id section is placed pretty much first before the executable and data sections. As a consequence, without --rosegment the build-id will usually be on the same page as the ELF headers while with --rosegment on the executable content is first and this often fills the rest of the page after the ELF headers. This patch aims to fix this by placing the build-id first. The build-id will then be included within the same LOAD-able segment as the executable content, just as the ELF headers are. With this patch in place GDB is once again able to find the build-id from a core file. --- ld/scripttempl/elf.sc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 54716110b61..17184037753 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -425,7 +425,6 @@ emit_early_ro() { cat <