From patchwork Tue Oct 22 09:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Zeng X-Patchwork-Id: 99314 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 517223857341 for ; Tue, 22 Oct 2024 09:43:52 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from eswincomputing.com (mail.eswincomputing.com [123.124.195.78]) by sourceware.org (Postfix) with ESMTP id 397AE3858CD1 for ; Tue, 22 Oct 2024 09:43:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 397AE3858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 397AE3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=123.124.195.78 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729590209; cv=none; b=FI6VPjRMZSZdZcs9bq6QlOPt/odAVsai3PFnVxgVIX46uXjkV+lK+tXoyN1nCZEpDELuJU0XqY20dUIhPbJvErY10LGU4hLvZXI/puAoAYE04ZO7tYcj7Ei2fsNd4EjJWmcUKcFpXj6zOiARnwK+Hxkq2wjhJLfw2i8Ab6USnlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729590209; c=relaxed/simple; bh=MhPOCp1CBOJc4Up+Q95wNpjB5QpswoYL8rQTUyEHN/0=; h=From:To:Subject:Date:Message-Id; b=Jd01ne9gxcqXdkilrWMTco7bn6DOkVMGchN4NNuyZl7bOnugEBmvFjC8CeCCUOSNIgiAuArr/sqnnddG3/FWe/sp738dITWfFkDhfiqweY4dSehHgCbh3vuoopQWW/e3Kh0kSZKETVaqdu7VwZhgo6ylIpHdQta53A/dCKc9nFU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.38]) by app1 (Coremail) with SMTP id TAJkCgBXh+W3cxdnI74PAA--.9955S4; Tue, 22 Oct 2024 17:43:20 +0800 (CST) From: Xiao Zeng To: binutils@sourceware.org Cc: jbeulich@suse.com, amodra@gmail.com, hjl.tools@gmail.com, zhengyu@eswincomputing.com, jiawei@iscas.ac.cn, Xiao Zeng Subject: [PATCH v1] GAS: Keep symbols in their own section [PR27566] Date: Tue, 22 Oct 2024 17:43:18 +0800 Message-Id: <20241022094318.58444-1-zengxiao@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: TAJkCgBXh+W3cxdnI74PAA--.9955S4 X-Coremail-Antispam: 1UD129KBjvJXoWxAF48Xw1xJr4xZr1ktrWxCrg_yoW5Zw1kpF y8AFWIgrWrXFnrtrsrtr1UCayxJws29Fya9ryfZay2vr1xXr92q3WDtrWagF47JrWUu3Wr Za9xZrWFvwn8A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUva14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWU AVWUtwCY02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv 67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyT uYvjfUr2-eDUUUU X-CM-SenderInfo: p2hqw5xldrqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, 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 PR27566 is categorized under ld: but the root cause of this issue is in gas. The following assembly example is provided: .section .rodata .globl Sym .type Sym, @object .set Sym, . + 0x1200 .size Sym, 8 readelf reads ELF information: Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 4] .rodata PROGBITS 0000000000000000 000040 000000 00 A 0 0 1 Symbol table '.symtab' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name 6: 0000000000001200 8 OBJECT GLOBAL DEFAULT 4 Sym The Sym belongs to the .rodata section, but the size of .rodata is 0. PR gas/27566 * write.c (size_seg): Update section size. * testsuite/gas/elf/elf.exp: New test. * testsuite/gas/elf/pr27566.d: New file. * testsuite/gas/elf/pr27566.s: Likewise. Signed-off-by: Xiao Zeng --- gas/testsuite/gas/elf/elf.exp | 1 + gas/testsuite/gas/elf/pr27566.d | 11 +++++++++++ gas/testsuite/gas/elf/pr27566.s | 5 +++++ gas/write.c | 7 +++++++ 4 files changed, 24 insertions(+) create mode 100644 gas/testsuite/gas/elf/pr27566.d create mode 100644 gas/testsuite/gas/elf/pr27566.s diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp index c828c3af25c..6a69acbc109 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -387,4 +387,5 @@ if { [is_elf_format] } then { run_dump_test "bignums" $dump_opts run_dump_test "section-symbol-redef" run_dump_test "pr27228" + run_dump_test "pr27566" } diff --git a/gas/testsuite/gas/elf/pr27566.d b/gas/testsuite/gas/elf/pr27566.d new file mode 100644 index 00000000000..75268cefb20 --- /dev/null +++ b/gas/testsuite/gas/elf/pr27566.d @@ -0,0 +1,11 @@ +#as: +#name: Keep symbols in their own section (PR 27566) +#readelf: -S --wide + +There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+: + +Section Headers: + +\[Nr\] Name +Type +Addr(ess|) +Off +Size +ES +Flg +Lk +Inf +Al +#... + *\[ [1-9]\] *\.rodata +PROGBITS +0*0 +0[0-9a-f]* +0*1208 .* +#pass diff --git a/gas/testsuite/gas/elf/pr27566.s b/gas/testsuite/gas/elf/pr27566.s new file mode 100644 index 00000000000..4232df21494 --- /dev/null +++ b/gas/testsuite/gas/elf/pr27566.s @@ -0,0 +1,5 @@ + .section .rodata + .globl Sym + .type Sym, @object + .set Sym, . + 0x1200 + .size Sym, 8 diff --git a/gas/write.c b/gas/write.c index 18cf18fc830..7f69d7aad44 100644 --- a/gas/write.c +++ b/gas/write.c @@ -559,6 +559,7 @@ size_seg (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *xxx ATTRIBUTE_UNUSED) segment_info_type *seginfo; int x; valueT size, newsize; + symbolS *symp; subseg_change (sec, 0); @@ -577,6 +578,12 @@ size_seg (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *xxx ATTRIBUTE_UNUSED) else size = 0; + /* Keep symbols in their own section. */ + for (symp = symbol_rootP; symp; symp = symbol_next (symp)) + if (S_GET_SEGMENT (symp) == sec + && size < (S_GET_VALUE (symp) + S_GET_SIZE (symp))) + size = S_GET_VALUE (symp) + S_GET_SIZE (symp); + flags = bfd_section_flags (sec); if (size == 0 && bfd_section_size (sec) != 0 && (flags & SEC_HAS_CONTENTS) != 0)