From patchwork Tue Oct 22 09:38: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: 99313 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 3EF633857C5F for ; Tue, 22 Oct 2024 09:38:52 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [207.46.229.174]) by sourceware.org (Postfix) with ESMTP id D5FA83858CD1 for ; Tue, 22 Oct 2024 09:38:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5FA83858CD1 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 D5FA83858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.46.229.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729589907; cv=none; b=DlLwFK/6X/46K8UhKv2iudlE24cuHBYowyRW3UL/nEDkvtcBLuXZx0o+0hcQClXdd3X1C5XBFPbvh8ZbL8bKoZeyRzNkKCEpcbsadEeVnYpb+GHlaLMmE3lGAoqZl+7TVqOTSAvtkL1VRK/MEtrr1V4JxvxS+QnbxAs1oiKBgFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729589907; c=relaxed/simple; bh=SAu2Rq7So7hei1OTQzuJAHPD2rKhhTk+dzrSh226khs=; h=From:To:Subject:Date:Message-Id; b=ENQBRt1NRGoMcfxrgnxX4WAlieG+SQV2BbxffQPI808RxLhLkf0eR3kyjoXGBzSUcwSmQh35qf5j2dzjXAMjWtc0g19FuwPJ5orNEPem/zOtfK/J4uqHd0dMlai+gFVdYhEI7LjV3md09G1pZqk4UF2W63D3H9lUmQzvxxXFqog= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.38]) by app1 (Coremail) with SMTP id TAJkCgDnFuWMchdn7L0PAA--.9634S4; Tue, 22 Oct 2024 17:38:21 +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] GAS: Keep symbols in their own section [PR27566] Date: Tue, 22 Oct 2024 17:38:18 +0800 Message-Id: <20241022093818.58251-1-zengxiao@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: TAJkCgDnFuWMchdn7L0PAA--.9634S4 X-Coremail-Antispam: 1UD129KBjvJXoWxAF48Xw1xJr4xZr1ktrWxCrg_yoW5Zw1kpF y8AFWIgrWrXFnrtrsrtr1UCayxJws2gFya9ryfZay2vr1xXr92q3WktrWagF47JrWUu3Wr Za9xZrWFvwn8A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkF14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK 82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUdHUDUUUUU= X-CM-SenderInfo: p2hqw5xldrqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 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 001208 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)