From patchwork Fri Sep 20 21:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 97779 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 3C753385842D for ; Fri, 20 Sep 2024 21:27:18 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by sourceware.org (Postfix) with ESMTPS id 97D513858406 for ; Fri, 20 Sep 2024 21:26:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97D513858406 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97D513858406 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726867587; cv=none; b=lLclHzTF2DqiRqdFveSoeuIlW8yDuYtD30aB6vOpqRxrCZuRV5gefZvoEAp56eENchQBCtPppAT9LDzxiZ/3EGBCR+GsFODP8GsS4QoK+3szG/fSrgaLrJ55hX28TyxTcIGb8vsRK60SvWUE1qjOiyNLCmzoyPFY+RkxuBkbwgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726867587; c=relaxed/simple; bh=KyDDZL3aqDvXNGdcGRIyCOlosLf2yXND5IhIduCOQs8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=AtxfXPELxCRxNfX2ITJuBASMEckDBxCySQikDEGLrFpnCtpjOwJyKZ7gmwCGiJcN1TVzj82k9JsjG1SgTv3z6W3rAZ3mpGsExLU5PoIoYC2Ib7levi4bPcSQZuIpEtGOS4WOYwokqDSRH179wb9J+/oN+YOvi0ZkFNig/+8zXdM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-e1d4368ad91so2874610276.0 for ; Fri, 20 Sep 2024 14:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726867584; x=1727472384; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=2XsEkIZSAcXXO6xn3MIOXQ4i2KNesuLSwP8pS7EIOZY=; b=iq9uJdrt5U9/CC03UmBALNo4vcrLbkCFs5WFwFTe9xSKyLoy3oGTqfwNdCycCBAdQw YSVqcXuXyyYgBxYJGXviu4AjalNGSx+MTjAbaBaUuEbfOKeyeAv3nCjQM6dDbWWMve2B IJB+JSbMboevALZuMSMFeRjcr3jPPVh42wHfpOR6T9jeD1nSn29qfGpJ1aFjuZM26m6n kKDTD07M7duPUWeRT4hXxbkcMdZ4mTiY7LayNF/177RXCnuhnJ4kT9n6lQ/7Q/QYzOge wUt4m490wwrXywyF03xvx/A0lGpqQ/mi8UYhBQv5FlCr6KXSLjApG/3x1P9KAtFtVILM QDiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726867584; x=1727472384; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2XsEkIZSAcXXO6xn3MIOXQ4i2KNesuLSwP8pS7EIOZY=; b=KYcYToi3fvF6111HS6mHBo9I3eSFR0TQmpQnMEflxPbUhg7LC1iYwxZRdzEHS5ws5+ 2uvh0GzK+7Cs14rlDLm7j8DgPubjHVDnuICZCSEKG7fWs/I9kDKWrjO0OEE9d6cL8YAA 4Z5mMfXlo6Zg4kIkiT5QFfLGrnbtcz8R1MaQ0EFI5hAhR7OzWi83RjpHRZ0o1iVVPDFM ATB4JG0gvzcShRDgizovfB4BRihtLDl/DinP4RgONA0Ihaw4183w4rzOV7SG59c55cqy EPHFzdjhsYVEdia10NA9jb8reO7XvATHNbbNOiC5Z1Kaxae/zBbg6ryNUYS7rzAYQgFe q4JQ== X-Gm-Message-State: AOJu0YxL9el6CbwAdktrmqnCJvMp57rxIF/YthDGyiKw4MMNR1JRGVMs ldB7TC6v85g/jCZ50MifpLElvekcF37H/C4L6tL/MlDlCABG/n5VdzXJyZ73WYZPdWhxygSttDv 9UfgYD7NVa2X4GmPTc74S3ya88ERSZ9icaIaOe/XU X-Google-Smtp-Source: AGHT+IES0a85y2x3G5yaSVWaMIN+fAgDBi2HyXA4pJwmuS45I3QRss7kFu5KHAnvMkKd0LN/J5ETckHUutNejKzzNlI= X-Received: by 2002:a05:690c:698f:b0:6d4:72b7:177e with SMTP id 00721157ae682-6de09783891mr64460707b3.5.1726867583815; Fri, 20 Sep 2024 14:26:23 -0700 (PDT) MIME-Version: 1.0 From: "H.J. Lu" Date: Sat, 21 Sep 2024 05:25:47 +0800 Message-ID: Subject: [PATCH] ld: Ignore .note.gnu.build-id when placing orphaned notes To: Binutils , Nick Clifton , Alan Modra X-Spam-Status: No, score=-3017.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The commits: e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments. bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map place .note.gnu.build-id before text sections when --rosegment is used. Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and -z separate-code are used together to avoid putting any note sections between .note.gnu.build-id and text sections in the same PT_LOAD segment. PR ld/32191 * ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when placing orphaned notes. * testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld. * testsuite/ld-elf/pr23658-1c.d: Likewise. * testsuite/ld-i386/i386.exp: Run PR ld/32191 test. * testsuite/ld-i386/pr32191.d: New file. * testsuite/ld-x86-64/lam-u48.rd: Updated. * testsuite/ld-x86-64/lam-u57.rd: Likewise. * testsuite/ld-x86-64/pr32191-x32.d: New file. * testsuite/ld-x86-64/pr32191.d: Likewise. * testsuite/ld-x86-64/pr32191.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests. From 07ffe0601da8ef38cbf64acccaee0dd143d7d5da Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 20 Sep 2024 11:32:26 +0800 Subject: [PATCH] ld: Ignore .note.gnu.build-id when placing orphaned notes The commits: e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments. bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map place .note.gnu.build-id before text sections when --rosegment is used. Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and -z separate-code are used together to avoid putting any note sections between .note.gnu.build-id and text sections in the same PT_LOAD segment. PR ld/32191 * ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when placing orphaned notes. * testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld. * testsuite/ld-elf/pr23658-1c.d: Likewise. * testsuite/ld-i386/i386.exp: Run PR ld/32191 test. * testsuite/ld-i386/pr32191.d: New file. * testsuite/ld-x86-64/lam-u48.rd: Updated. * testsuite/ld-x86-64/lam-u57.rd: Likewise. * testsuite/ld-x86-64/pr32191-x32.d: New file. * testsuite/ld-x86-64/pr32191.d: Likewise. * testsuite/ld-x86-64/pr32191.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests. Signed-off-by: H.J. Lu --- ld/ldlang.c | 14 +++++++++++++- ld/testsuite/ld-elf/pr23658-1a.d | 2 +- ld/testsuite/ld-elf/pr23658-1c.d | 2 +- ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-i386/pr32191.d | 9 +++++++++ ld/testsuite/ld-x86-64/lam-u48.rd | 1 + ld/testsuite/ld-x86-64/lam-u57.rd | 1 + ld/testsuite/ld-x86-64/pr32191-x32.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr32191.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr32191.s | 5 +++++ ld/testsuite/ld-x86-64/x86-64.exp | 2 ++ 11 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-i386/pr32191.d create mode 100644 ld/testsuite/ld-x86-64/pr32191-x32.d create mode 100644 ld/testsuite/ld-x86-64/pr32191.d create mode 100644 ld/testsuite/ld-x86-64/pr32191.s diff --git a/ld/ldlang.c b/ld/ldlang.c index 9e8cc224f4d..95d64fd05e2 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2047,13 +2047,25 @@ lang_insert_orphan (asection *s, place orphan note section after non-note sections. */ first_orphan_note = NULL; + + /* NB: When --rosegment is used, the .note.gnu.build-id + section is placed before text sections. Ignore the + .note.gnu.build-id section if -z separate-code and + --rosegment are used together to avoid putting any + note sections between the .note.gnu.build-id section + and text sections in the same PT_LOAD segment. */ + bool ignore_build_id = (link_info.separate_code + && link_info.one_rosegment); + for (sec = link_info.output_bfd->sections; (sec != NULL && !bfd_is_abs_section (sec)); sec = sec->next) if (sec != snew && elf_section_type (sec) == SHT_NOTE - && (sec->flags & SEC_LOAD) != 0) + && (sec->flags & SEC_LOAD) != 0 + && (!ignore_build_id + || strcmp (sec->name, ".note.gnu.build-id") != 0)) { if (!first_orphan_note) first_orphan_note = sec; diff --git a/ld/testsuite/ld-elf/pr23658-1a.d b/ld/testsuite/ld-elf/pr23658-1a.d index 10c6ef3973b..388f7a42fa7 100644 --- a/ld/testsuite/ld-elf/pr23658-1a.d +++ b/ld/testsuite/ld-elf/pr23658-1a.d @@ -3,7 +3,7 @@ #source: pr23658-1c.s #source: pr23658-1d.s #source: start.s -#ld: --build-id +#ld: --build-id --no-rosegment #readelf: -l --wide # Since generic linker targets don't place SHT_NOTE sections as orphan, # SHT_NOTE sections aren't grouped nor sorted. diff --git a/ld/testsuite/ld-elf/pr23658-1c.d b/ld/testsuite/ld-elf/pr23658-1c.d index 87acecaabe1..6ab72dc60b3 100644 --- a/ld/testsuite/ld-elf/pr23658-1c.d +++ b/ld/testsuite/ld-elf/pr23658-1c.d @@ -3,7 +3,7 @@ #source: pr23658-1c.s #source: pr23658-1d.s #source: start.s -#ld: --build-id -shared +#ld: --build-id --no-rosegment -shared #readelf: -l --wide #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi #xfail: ![check_shared_lib_support] diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index a66d67a3244..90293226954 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -514,6 +514,7 @@ run_dump_test "pr28870" run_dump_test "pr28894" run_dump_test "pr30787" run_dump_test "pr31047" +run_dump_test "pr32191" if { !([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"] diff --git a/ld/testsuite/ld-i386/pr32191.d b/ld/testsuite/ld-i386/pr32191.d new file mode 100644 index 00000000000..8d7838a1311 --- /dev/null +++ b/ld/testsuite/ld-i386/pr32191.d @@ -0,0 +1,9 @@ +#source: ../ld-x86-64/pr32191.s +#as: --32 -mx86-used-note=yes +#ld: -shared -m elf_i386 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-x86-64/lam-u48.rd b/ld/testsuite/ld-x86-64/lam-u48.rd index ad312627059..8fac904c064 100644 --- a/ld/testsuite/ld-x86-64/lam-u48.rd +++ b/ld/testsuite/ld-x86-64/lam-u48.rd @@ -1,3 +1,4 @@ +#... Displaying notes found in: .note.gnu.property [ ]+Owner[ ]+Data size[ ]+Description GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 diff --git a/ld/testsuite/ld-x86-64/lam-u57.rd b/ld/testsuite/ld-x86-64/lam-u57.rd index 8b77e6311c0..dd8d1dafbeb 100644 --- a/ld/testsuite/ld-x86-64/lam-u57.rd +++ b/ld/testsuite/ld-x86-64/lam-u57.rd @@ -1,3 +1,4 @@ +#... Displaying notes found in: .note.gnu.property [ ]+Owner[ ]+Data size[ ]+Description GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 diff --git a/ld/testsuite/ld-x86-64/pr32191-x32.d b/ld/testsuite/ld-x86-64/pr32191-x32.d new file mode 100644 index 00000000000..19e06a26c11 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191-x32.d @@ -0,0 +1,9 @@ +#source: pr32191.s +#as: --x32 -mx86-used-note=yes +#ld: -shared -m elf32_x86_64 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-x86-64/pr32191.d b/ld/testsuite/ld-x86-64/pr32191.d new file mode 100644 index 00000000000..9038ccd9b35 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191.d @@ -0,0 +1,9 @@ +#source: pr32191.s +#as: --64 -mx86-used-note=yes +#ld: -shared -m elf_x86_64 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-x86-64/pr32191.s b/ld/testsuite/ld-x86-64/pr32191.s new file mode 100644 index 00000000000..953f0de670f --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191.s @@ -0,0 +1,5 @@ + .text + .global foo +foo: + .nops 4 + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index cf78fffe29f..e9b50b6cf8c 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -541,6 +541,8 @@ run_dump_test "tlsie5" run_dump_test "tlsdesc3" run_dump_test "tlsdesc4" run_dump_test "tlsdesc5" +run_dump_test "pr32191" +run_dump_test "pr32191-x32" if { ![skip_sframe_tests] } { run_dump_test "sframe-simple-1" -- 2.46.1