From patchwork Sat Jan 6 07:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyang He X-Patchwork-Id: 185614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6651756dyb; Fri, 5 Jan 2024 23:24:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHvOI21sHfmYbfyZ9L4rlqqLKsOrmzrdajIR2Ja5qEOJCri9DnqW8o2jYyS+0588RIjvKG X-Received: by 2002:ac8:7e94:0:b0:429:8493:a7e2 with SMTP id w20-20020ac87e94000000b004298493a7e2mr401013qtj.30.1704525843951; Fri, 05 Jan 2024 23:24:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704525843; cv=pass; d=google.com; s=arc-20160816; b=TT4PhWdWMfB76ctBC4ntz4BH0+aleih5txlFD7kdmYYNp942u7G+7UsaYFwr+NYDUm 9uCU/jKyH1G03UAAB8NxxXUNTl1t+/4EfqWOqMQm3jADZVWupgPrsE3RaUl8LPeg6NEP JXlixlVfiOxey69HoamBbTOoFsUr3+e6hID6V8hyPvaBXgGTt9iXUOFgKgySCtgQwoxQ CASRyW9Z1NuuTCVseQZ8y+mB9VkqIke034TCDx+Pwos6LWuNqkQk8i+XcBv8uVFfeuFc PiC2fXh4KmUaxwGVqIPze0r9bVIxlA5i7ICzrF9ZNFDZJy7HCbiHs+3+RcQxlN/YJiNo aD/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=NNu6oZg6zNTFrW28qNhQOfK7x9SYuOddNgMg0rLTk1k=; fh=ROhve/NKM7P3+DinrOmwzB8ohT55HfHGwph+wd1pQiI=; b=hCZALUno7nCSZDCX5il/6nFQOjhbgU9nXpOlXEAV6xtahL7guI3byGwJ/GCYrs43NZ +Qfq8N4sFIufqaCNc18p/1Vv1LS8jAs3tigsia9rzGB3/plC8Z+3mD210rTROsq/qmMJ 6dEC9Q0i4kMTiqBC2DLbv8IWD7nxiTqwVYapYtUiiLTN8/2/KOq2NFPkrSm5hkBWLm9N XvjN0wIeJH5cX1YjQho1rfAJryeFN2JwA+bCBGWzi3a79CuG9DhSXSYqROOX7Qr5v5xA JvHvMaAwoVQU3wMeCQM5f59PloZNQSo/J6UXMhwtKOjhKwF3aTNHkjsfheyaJVHoc3v5 b/fw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u15-20020a05622a010f00b004297d0709e2si1997338qtw.103.2024.01.05.23.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 23:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BB133858C2D for ; Sat, 6 Jan 2024 07:24:03 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 7302B3858D1E for ; Sat, 6 Jan 2024 07:23:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7302B3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7302B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704525836; cv=none; b=AhSQlJyDvMxmUPkI2l84cIDPo0NjO6FAZnZAHW2cJi2D792kw7SF+9YYrQ5lmpeHUszwYXGY8sfUlb39EHf29/TviCQ93I7oRKKR7LFx4hKFF1Kvd8wz+zKVjBdZN5d+jv9VvT1c2md0iEvoPaK5cvOM/bWLzvebn09vIEehGVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704525836; c=relaxed/simple; bh=bOhHGUs81x/3a/iPFToykD27JpQqXBaLMh3UwxkYUVg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=mFTjKx5GAocStdVSPjb3SIDzxD/wqm38WPGDgo//Phur5rj+/HlFj2IdQWuHOwKdwiuPTttYxpZRCCdJa5HhEA5J8vYPwQ1irNPxVrTXUya/Kvy+FJtJ5IqmvAkEWrheGid8JF/e50Q80OQkFO4verQYQ+ziDvm0sJfpi1Tat1M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8Cx7+sDAJllZpYCAA--.9159S3; Sat, 06 Jan 2024 15:23:47 +0800 (CST) Received: from localhost.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxXNz+_5hlrlcEAA--.11351S2; Sat, 06 Jan 2024 15:23:44 +0800 (CST) From: Jinyang He To: binutils@sourceware.org, mengqinggang@loongson.cn, Lulu Cai , Tiezhu Yang , Xi Ruoyao , WANG Xuerui Cc: Huacai Chen , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Youling Tang , luweining@loongson.cn Subject: [PATCH] LoongArch: Make align symbol be in same section with alignment directive Date: Sat, 6 Jan 2024 15:23:42 +0800 Message-Id: <20240106072342.31696-1-hejinyang@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxXNz+_5hlrlcEAA--.11351S2 X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxWFyDKF4ftw17Gw18uFy8JFc_yoWrtFW7pF y8Ar909FW0kF93Gr45t345Wr1jvws7WFWSvaySk34I9r47XFy8Aa1kJryUWFWDGr45u3W5 Wr1rKa1jvF95A3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j1WlkUUUUU= X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, 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 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+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787324891157671971 X-GMAIL-MSGID: 1787324891157671971 R_LARCH_ALIGN (psABI v2.30) requires a symbol index. The symbol is only created at the first time to handle alignment directive. This means that all other sections may use this symbol. If the section of this symbol is discarded, there may be problems. Search it in its own section. gas/ChangeLog: * config/tc-loongarch.c: (get_align_symbol) New function. * gas/testsuite/gas/loongarch/relax_align2.d: New test. * gas/testsuite/gas/loongarch/relax_align2.s: Likewise. Reported-by: WANG Xuerui Link: https://lore.kernel.org/loongarch/2abbb633-a10e-71cc-a5e1-4d9e39074066@loongson.cn/T/#t --- gas/config/tc-loongarch.c | 53 ++++++++++++++++++++-- gas/testsuite/gas/loongarch/relax_align2.d | 24 ++++++++++ gas/testsuite/gas/loongarch/relax_align2.s | 11 +++++ 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/relax_align2.d create mode 100644 gas/testsuite/gas/loongarch/relax_align2.s diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 5348371fa2c..29e540df429 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -392,6 +392,50 @@ loongarch_target_format () return LARCH_opts.ase_lp64 ? "elf64-loongarch" : "elf32-loongarch"; } +typedef struct +{ + segT sec; + symbolS *s; +} align_sec_sym; + +static htab_t align_hash; + +static hashval_t +align_sec_sym_hash (const void *entry) +{ + const align_sec_sym *e = entry; + return (hashval_t) e->sec; +} + +static int +align_sec_sym_eq (const void *entry1, const void *entry2) +{ + const align_sec_sym *e1 = entry1, *e2 = entry2; + return e1->sec == e2->sec; +} + +static symbolS *get_align_symbol(segT sec) +{ + align_sec_sym search = { sec, NULL }; + align_sec_sym *pentry = htab_find (align_hash, &search); + if (pentry) + return pentry->s; + + /* If we not find the symbol in this section. Create and insert it. */ + symbolS *s = (symbolS *)local_symbol_make (".Lla-relax-align", sec, + &zero_address_frag, 0); + align_sec_sym entry = { sec, s }; + align_sec_sym **slot = + (align_sec_sym **) htab_find_slot (align_hash, &entry, INSERT); + if (slot == NULL) + return NULL; + *slot = (align_sec_sym *) xmalloc (sizeof (align_sec_sym)); + if (*slot == NULL) + return NULL; + **slot = entry; + return entry.s; +} + void md_begin () { @@ -413,6 +457,8 @@ md_begin () it->name, it->format, it->macro); } + align_hash = htab_create (10, align_sec_sym_hash, align_sec_sym_eq, free); + /* FIXME: expressionS use 'offsetT' as constant, * we want this is 64-bit type. */ assert (8 <= sizeof (offsetT)); @@ -1721,10 +1767,9 @@ loongarch_frag_align_code (int n, int max) nops = frag_more (worst_case_bytes); - s = symbol_find (".Lla-relax-align"); - if (s == NULL) - s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg, - &zero_address_frag, 0); + s = get_align_symbol(now_seg); + if (!s) + as_fatal (_("internal error: cannot get align symbol")); ex.X_add_symbol = s; ex.X_op = O_symbol; diff --git a/gas/testsuite/gas/loongarch/relax_align2.d b/gas/testsuite/gas/loongarch/relax_align2.d new file mode 100644 index 00000000000..d647d9b7eef --- /dev/null +++ b/gas/testsuite/gas/loongarch/relax_align2.d @@ -0,0 +1,24 @@ +#as: --no-warn +#readelf: -rsW +#skip: loongarch32-*-* + +Relocation section '\.rela\.text' at offset .* contains 2 entries: +.* +0+04[ ]+0000000500000066[ ]+R_LARCH_ALIGN[ ]+0+[ ]+\.Lla-relax-align \+ 4 +0+14[ ]+0000000500000066[ ]+R_LARCH_ALIGN[ ]+0+[ ]+\.Lla-relax-align \+ 404 + +Relocation section '\.rela\.text2' at offset .* contains 2 entries: +.* +0+04[ ]+0000000600000066[ ]+R_LARCH_ALIGN[ ]+0+[ ]+\.Lla-relax-align \+ 4 +0+14[ ]+0000000600000066[ ]+R_LARCH_ALIGN[ ]+0+[ ]+\.Lla-relax-align \+ 404 + +Symbol table '\.symtab' contains .* entries: +#... +[ ]+.*:[ ]+0+[ ]+0[ ]+SECTION[ ]+LOCAL[ ]+DEFAULT[ ]+1[ ]+\.text +#... +[ ]+.*:[ ]+0+[ ]+0[ ]+SECTION[ ]+LOCAL[ ]+DEFAULT[ ]+5[ ]+\.text2 +#... +[ ]+.*:[ ]+0+[ ]+0[ ]+NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+1[ ]+\.Lla-relax-align +#... +[ ]+.*:[ ]+0+[ ]+0[ ]+NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+5[ ]+\.Lla-relax-align +#pass diff --git a/gas/testsuite/gas/loongarch/relax_align2.s b/gas/testsuite/gas/loongarch/relax_align2.s new file mode 100644 index 00000000000..6cd6bd8731b --- /dev/null +++ b/gas/testsuite/gas/loongarch/relax_align2.s @@ -0,0 +1,11 @@ +.section ".text", "ax" +nop +.align 4 +nop +.align 4, , 4 + +.section ".text2", "ax" +nop +.align 4 +nop +.align 4, , 4