From patchwork Wed Aug 30 17:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 74987 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 4FE943858C39 for ; Wed, 30 Aug 2023 17:32:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FE943858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693416748; bh=m4SeF/4oQ0HI7KG+pnIKtdNbHeRP1xYL5KuwhSUs20c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=J4T9sbuDfb1UMrLph7lk3f86xy5Kp+NHWq51enIWwwMv9KNW0nTMgJPTYPt3HLUp4 BHmKYUxgn9GF2eaFYUCZe6x1eT8/7Hg3oSURjAPr1MnWVQCtkdkfYt0qE/+CqfTogI Vkvn9TwHvffH6D/xU59bUG6a1wGKwWrICOP3k0u0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id DBCC43857B9B for ; Wed, 30 Aug 2023 17:31:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBCC43857B9B Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68bed2c786eso4114666b3a.0 for ; Wed, 30 Aug 2023 10:31:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693416712; x=1694021512; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m4SeF/4oQ0HI7KG+pnIKtdNbHeRP1xYL5KuwhSUs20c=; b=lzkKRXQX4hzuXO8IB8qsXCLAdhPVUz9V80s/t+6lX+YQdyVnclF0vSmpILRSAf4nd1 iNw3sEgBNr1TIdMhiqdKCsDzg9fpJFGF1rsSMY+k9buCCfwGGiI8FInHB8EMFbThB5JP WhBZmaag1URR/k8FoxDK9yuHdTE+PFXeIkUOvkGVgDYIOzatUjRLuYYSm04P7RgE3yFd 1rXdFYjdHTKu9outTyGXFJp4zkCfKiZoW3G9p2VMJ4mOcpSrwKWkJuNGkncWZ3tw5UEA JA8SJOwPMSRYizihBV436ZLLE3dcbjX5BWj0htnKl0CrOwfdAZo2PNmywxGFtOn6nJWU Z4Qw== X-Gm-Message-State: AOJu0YyBEDiSrj5YleimeNuRJfYI8Rw0XvEbOcgGQCMhUalTGiHEqbPd XFvZcjE29BFPXV7EAgvTlUCY3tpY+os= X-Google-Smtp-Source: AGHT+IGS+2NbhBNB1Cqi5cF3EsETcwz+ICn0HLAdR3Fdx5CYsKgYXM460Sw1ggEHH5+DtUjcvwldlA== X-Received: by 2002:a05:6a21:71cb:b0:14c:d5c7:381b with SMTP id ay11-20020a056a2171cb00b0014cd5c7381bmr3235209pzc.36.1693416711577; Wed, 30 Aug 2023 10:31:51 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.161.42]) by smtp.gmail.com with ESMTPSA id p9-20020a63b809000000b0055b61cd99a1sm10852444pge.81.2023.08.30.10.31.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 10:31:51 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id DC6CF7401C1 for ; Wed, 30 Aug 2023 10:31:49 -0700 (PDT) To: binutils@sourceware.org Subject: [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER Date: Wed, 30 Aug 2023 10:31:49 -0700 Message-ID: <20230830173149.757103-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.1 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: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org Sender: "Binutils" For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output sections of their linked to sections are different. * ldelf.c (elf_orphan_compatible): Don't merge sections with different SHF_LINK_ORDER. * testsuite/ld-elf/pr30791a.d: New file. * testsuite/ld-elf/pr30791a.s: Likewise. * testsuite/ld-elf/pr30791b.d: Likewise. * testsuite/ld-elf/pr30791b.s: Likewise. * testsuite/ld-elf/pr30791c.s: Likewise. * testsuite/ld-elf/pr30791d.s: Likewise. --- ld/ldelf.c | 7 ++++++- ld/testsuite/ld-elf/pr30791a.d | 16 ++++++++++++++++ ld/testsuite/ld-elf/pr30791a.s | 20 ++++++++++++++++++++ ld/testsuite/ld-elf/pr30791b.d | 11 +++++++++++ ld/testsuite/ld-elf/pr30791b.s | 20 ++++++++++++++++++++ ld/testsuite/ld-elf/pr30791c.s | 20 ++++++++++++++++++++ ld/testsuite/ld-elf/pr30791d.s | 20 ++++++++++++++++++++ 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-elf/pr30791a.d create mode 100644 ld/testsuite/ld-elf/pr30791a.s create mode 100644 ld/testsuite/ld-elf/pr30791b.d create mode 100644 ld/testsuite/ld-elf/pr30791b.s create mode 100644 ld/testsuite/ld-elf/pr30791c.s create mode 100644 ld/testsuite/ld-elf/pr30791d.s diff --git a/ld/ldelf.c b/ld/ldelf.c index 4212075a0e2..d74354a9622 100644 --- a/ld/ldelf.c +++ b/ld/ldelf.c @@ -2080,9 +2080,14 @@ elf_orphan_compatible (asection *in, asection *out) return false; /* We can't merge with a member of an output section group or merge two sections with differing SHF_EXCLUDE or other processor and OS - specific flags when doing a relocatable link. */ + specific flags or with different SHF_LINK_ORDER when doing a + relocatable link. */ if (bfd_link_relocatable (&link_info) && (elf_next_in_group (out) != NULL + || ((elf_section_flags (in) & SHF_LINK_ORDER) != 0 + && (elf_section_flags (out) & SHF_LINK_ORDER) != 0 + && (elf_linked_to_section (in)->output_section + != elf_linked_to_section (out)->output_section)) || ((elf_section_flags (out) ^ elf_section_flags (in)) & (SHF_MASKPROC | SHF_MASKOS)) != 0)) return false; diff --git a/ld/testsuite/ld-elf/pr30791a.d b/ld/testsuite/ld-elf/pr30791a.d new file mode 100644 index 00000000000..2446b525fa9 --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791a.d @@ -0,0 +1,16 @@ +#source: pr30791a.s +#source: pr30791b.s +#ld: -r +#readelf: -S --wide + +#... +Section Headers: +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#pass diff --git a/ld/testsuite/ld-elf/pr30791a.s b/ld/testsuite/ld-elf/pr30791a.s new file mode 100644 index 00000000000..44b75db87d8 --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791a.s @@ -0,0 +1,20 @@ + .section .text.a,"ax",%progbits + .globl a + .type a, %function +a: +.LFB0: + .section __patchable_function_entries,"awo",%progbits,.LPFE0 + .dc.a .LPFE0 + .section .text.a +.LPFE0: + .byte 0 + .section .text.b,"ax",%progbits + .globl b + .type b, %function +b: +.LFB1: + .section __patchable_function_entries,"awo",%progbits,.LPFE1 + .dc.a .LPFE1 + .section .text.b +.LPFE1: + .byte 0 diff --git a/ld/testsuite/ld-elf/pr30791b.d b/ld/testsuite/ld-elf/pr30791b.d new file mode 100644 index 00000000000..5013c240f8a --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791b.d @@ -0,0 +1,11 @@ +#source: pr30791c.s +#source: pr30791d.s +#ld: -r +#readelf: -S --wide + +#failif +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#... + \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.* +#... diff --git a/ld/testsuite/ld-elf/pr30791b.s b/ld/testsuite/ld-elf/pr30791b.s new file mode 100644 index 00000000000..3f97f6c979f --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791b.s @@ -0,0 +1,20 @@ + .section .text.c,"ax",%progbits + .globl c + .type c, %function +c: +.LFB0: + .section __patchable_function_entries,"awo",%progbits,.LPFE0 + .dc.a .LPFE0 + .section .text.c +.LPFE0: + .byte 0 + .section .text.d,"ax",%progbits + .globl d + .type d, %function +d: +.LFB1: + .section __patchable_function_entries,"awo",%progbits,.LPFE1 + .dc.a .LPFE1 + .section .text.d +.LPFE1: + .byte 0 diff --git a/ld/testsuite/ld-elf/pr30791c.s b/ld/testsuite/ld-elf/pr30791c.s new file mode 100644 index 00000000000..71ef77bf5e9 --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791c.s @@ -0,0 +1,20 @@ + .text + .globl a + .type a, %function +a: +.LFB0: + .section __patchable_function_entries,"awo",%progbits,.LPFE0 + .dc.a .LPFE0 + .text +.LPFE0: + .byte 0 + .text + .globl b + .type b, %function +b: +.LFB1: + .section __patchable_function_entries,"awo",%progbits,.LPFE1 + .dc.a .LPFE1 + .text +.LPFE1: + .byte 0 diff --git a/ld/testsuite/ld-elf/pr30791d.s b/ld/testsuite/ld-elf/pr30791d.s new file mode 100644 index 00000000000..5ca1c60bdb9 --- /dev/null +++ b/ld/testsuite/ld-elf/pr30791d.s @@ -0,0 +1,20 @@ + .text + .globl c + .type c, %function +c: +.LFB0: + .section __patchable_function_entries,"awo",%progbits,.LPFE0 + .dc.a .LPFE0 + .text +.LPFE0: + .byte 0 + .text + .globl d + .type d, %function +d: +.LFB1: + .section __patchable_function_entries,"awo",%progbits,.LPFE1 + .dc.a .LPFE1 + .text +.LPFE1: + .byte 0