Message ID | 20240220021106.3345192-1-fanpeng@loongson.cn |
---|---|
State | Accepted |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp148148dyc; Mon, 19 Feb 2024 18:11:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVcM41ZFfPf/tgjw7YHWEIc/O8pJ8BhMxX3kqmMAWj5Pv0pKDemUAtKVbDBXq5YUoQvVCpDl6qkqAvY3yB7udubh+/b0w== X-Google-Smtp-Source: AGHT+IFukx4LdaaCObd4yFWjNaaTM2pEWvisgM4P6/sN770v4tk7QhWZ9fBLeaV0RzA1tjqFhaAN X-Received: by 2002:ad4:5c64:0:b0:68c:ad8c:d291 with SMTP id i4-20020ad45c64000000b0068cad8cd291mr18956257qvh.29.1708395102271; Mon, 19 Feb 2024 18:11:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708395102; cv=pass; d=google.com; s=arc-20160816; b=herXT+082E27n39BpJe2po46dmi3tC5aFlz6f+YLTI6iGkIi/NBYLcX4MyODiZ5Pvw sAnYJYhb6175ozLWfRDEmO1DQV596+gJMeZ2G7P7wbTODFz1XQpnrAt6t3y2qKF1Ty9D 0achTyWgpdOxuKcTBl3sML5cPgcA8gR1jVagtnuFrmx/zy/kArgETyPMsRniXTO+FOOS uP961wmpIK9nE8bKJZ4O1BS9vPpAkv6DsfQd9NWxPkHLdfRR2+o21AMoDEhHhH7augct 9fjmjT2JKyyMcDgHKpC2c1gsu/KPYYrPLUbHN7kO/1kx/uj5V+zBAylt+ZyqqoZbYVUH VrnA== 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=FKWsSvEEFRuYbci5QSf8K0cx+VAD7H/jEYWfaj7cQic=; fh=aiTqVNHVSTiZOxlajUefC1Tp1n0ClTPJ3yQ18lH+9fI=; b=xYsHvdgNelU/V5hUTce0eT9mg5QgPPaWJHzqzWn9iXwZ75BOEw0A0oiEKtGOZ6Ittx Syqu5jgrEyCQL9/CRaETtotxAS+1+cy0iq5fFO4zsxvx/+UGJmCzem4m5iWTZzd0ZbOF LtjbVX4o+v/RdgC4FGgUXOC0HB8VT94fIVcWr3qqQyPRNWC+uHkUMrAhlNadqBK0uyXi vBqehrw2Vl8GhmdXsg7IWmG38E8Q2DinpB0oQd3EzDQvP2lNcpNXhSTFIvXx8sZW7LT7 8fDrr5KFhhP6fzON9Oh5cP2A22ZF5JixZ66B5c6rBwJN/h7TXrCY6JVG6c+6P7fRdWx8 tRvg==; dara=google.com 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 r10-20020a0562140c8a00b0068f740c7530si3010563qvr.538.2024.02.19.18.11.42 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:11:42 -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 EB9313858C50 for <ouuuleilei@gmail.com>; Tue, 20 Feb 2024 02:11:41 +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 DEC173858D20 for <binutils@sourceware.org>; Tue, 20 Feb 2024 02:11:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DEC173858D20 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 DEC173858D20 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=1708395092; cv=none; b=rWyD0GlL6tD+yVWHSgnfKIkYzOwcTNh+XAsIAL2LBBQjmRfx0qpuCrH6gjiQ/IOIEEl9j4fYBqJPUYHJ8HKZE5YYLGSVK6nA+056gZpvudsK2F7ux4d2gwBVWHje9G6E05+SJEWNEMSQybafrr2PW/elOiXhUaUvv3vKhTsxw4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708395092; c=relaxed/simple; bh=OAUATaC+j7E8WgbQ9OTpAkCs3B4LLR+d6ZN1LAkc2qw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Axhoh4o535tYnGy7dO13WYUP48LEvbxFFQ9MWMm9tfFl6xksqgCiUw1vxMeNa8cw4syMeTR9/DHdtiOp9Y6Z3twsHptxwid89UrrD/RNd21GURuQcjmOpJelW1P2/U9Yfgfet87IwnXIjMdEe8AbyUkQ9tqt3mtvuq2NeIdSjgA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8BxefBPCtRlr9sOAA--.40036S3; Tue, 20 Feb 2024 10:11:27 +0800 (CST) Received: from loongson.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxfs08CtRlDWg8AA--.22412S2; Tue, 20 Feb 2024 10:11:25 +0800 (CST) From: ticat-fp <fanpeng@loongson.cn> To: binutils@sourceware.org Cc: mengqinggang@loongson.cn, cailulu@loongson.cn Subject: [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all Date: Tue, 20 Feb 2024 10:11:06 +0800 Message-Id: <20240220021106.3345192-1-fanpeng@loongson.cn> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dxfs08CtRlDWg8AA--.22412S2 X-CM-SenderInfo: xidq1vtqj6z05rqj20fqof0/1tbiAQANEmXTEWMEpQAAs7 X-Coremail-Antispam: 1Uk129KBj93XoW7CryUJrW3uFyfCw18Xw15WrX_yoW8CF1UpF 9xZ34qgrWrJw43W3W2q345urnIkrZrWrsrtrZFqana9FnxZryxXF15JrW29F4Ut348JFZr Zr10y3y5ZFy8AabCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1CPfJUUUUU== X-Spam-Status: No, score=-12.8 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 <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791382103194410578 X-GMAIL-MSGID: 1791382103194410578 |
Series |
LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | success | Github commit url |
Commit Message
ticat_fp
Feb. 20, 2024, 2:11 a.m. UTC
Ignore errors when producing executable files that reference external symbols defined
in other files.
Testcase is:
resolv.c:
int main(int argc, char *argv[]) {
return argc;
}
t.c:
extern const struct my_struct ms1;
static const struct my_struct *ms = &ms1;
t.h:
typedef struct my_struct {
char *str;
int i;
} my_struct;
Compiling and linking command with:
gcc t.c -c ; gcc resolv.c -c
gcc resolv.o t.o -o resolv -Wl,--unresolved-symbols=ignore-all
Got error as:
~/install/usr/bin/ld: t.o:(.data.rel+0x0): undefined reference to `ms1'
collect2: error: ld returned 1 exit status
Signed-off-by: ticat-fp <fanpeng@loongson.cn>
---
bfd/elfnn-loongarch.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On Tue, 2024-02-20 at 10:11 +0800, ticat-fp wrote: > Ignore errors when producing executable files that reference external symbols defined > in other files. > > Testcase is: > resolv.c: > int main(int argc, char *argv[]) { > return argc; > } > > t.c: > > extern const struct my_struct ms1; > static const struct my_struct *ms = &ms1; > > t.h: > typedef struct my_struct { > char *str; > int i; > } my_struct; > > Compiling and linking command with: > gcc t.c -c ; gcc resolv.c -c > gcc resolv.o t.o -o resolv -Wl,--unresolved-symbols=ignore-all > > Got error as: > ~/install/usr/bin/ld: t.o:(.data.rel+0x0): undefined reference to `ms1' > collect2: error: ld returned 1 exit status > > Signed-off-by: ticat-fp <fanpeng@loongson.cn> Signed-off-by may have a legal implication so generally we should use the real name here. Or if this is done during your working time you don't need a Signed-off- by as the change should be covered by Loongson corporate FSF assignment. > --- > bfd/elfnn-loongarch.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > index 1895699af06..6b2d5a7164d 100644 > --- a/bfd/elfnn-loongarch.c > +++ b/bfd/elfnn-loongarch.c > @@ -2662,6 +2662,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > char tls_type; > bfd_vma relocation, off, ie_off, desc_off; > int i, j; > + bool ignored = false; > > howto = loongarch_elf_rtype_to_howto (input_bfd, r_type); > if (howto == NULL || r_type == R_LARCH_GNU_VTINHERIT > @@ -2703,7 +2704,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > } > else > { > - bool warned, ignored; > + bool warned; > > RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, > r_symndx, symtab_hdr, sym_hashes, > @@ -2867,7 +2868,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > { > if (h->dynindx == -1) > { > - if (h->root.type == bfd_link_hash_undefined) > + if (h->root.type == bfd_link_hash_undefined && !ignored) > (*info->callbacks->undefined_symbol) > (info, name, input_bfd, input_section, > rel->r_offset, true);
Got it. I'll resend the v2. Thanks. 2024-02-20 10:31:17 "Xi Ruoyao" <xry111@xry111.site> 写道: > On Tue, 2024-02-20 at 10:11 +0800, ticat-fp wrote: > > Ignore errors when producing executable files that reference external symbols defined > > in other files. > > > > Testcase is: > > resolv.c: > > int main(int argc, char *argv[]) { > > return argc; > > } > > > > t.c: > > > > extern const struct my_struct ms1; > > static const struct my_struct *ms = &ms1; > > > > t.h: > > typedef struct my_struct { > > char *str; > > int i; > > } my_struct; > > > > Compiling and linking command with: > > gcc t.c -c ; gcc resolv.c -c > > gcc resolv.o t.o -o resolv -Wl,--unresolved-symbols=ignore-all > > > > Got error as: > > ~/install/usr/bin/ld: t.o:(.data.rel+0x0): undefined reference to `ms1' > > collect2: error: ld returned 1 exit status > > > > Signed-off-by: ticat-fp <fanpeng@loongson.cn> > > Signed-off-by may have a legal implication so generally we should use > the real name here. > > Or if this is done during your working time you don't need a Signed-off- > by as the change should be covered by Loongson corporate FSF assignment. > > > --- > > bfd/elfnn-loongarch.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > > index 1895699af06..6b2d5a7164d 100644 > > --- a/bfd/elfnn-loongarch.c > > +++ b/bfd/elfnn-loongarch.c > > @@ -2662,6 +2662,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > > char tls_type; > > bfd_vma relocation, off, ie_off, desc_off; > > int i, j; > > + bool ignored = false; > > > > howto = loongarch_elf_rtype_to_howto (input_bfd, r_type); > > if (howto == NULL || r_type == R_LARCH_GNU_VTINHERIT > > @@ -2703,7 +2704,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > > } > > else > > { > > - bool warned, ignored; > > + bool warned; > > > > RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, > > r_symndx, symtab_hdr, sym_hashes, > > @@ -2867,7 +2868,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > > { > > if (h->dynindx == -1) > > { > > - if (h->root.type == bfd_link_hash_undefined) > > + if (h->root.type == bfd_link_hash_undefined && !ignored) > > (*info->callbacks->undefined_symbol) > > (info, name, input_bfd, input_section, > > rel->r_offset, true); > > -- > Xi Ruoyao <xry111@xry111.site> > School of Aerospace Science and Technology, Xidian University 本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。 This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it.
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 1895699af06..6b2d5a7164d 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -2662,6 +2662,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, char tls_type; bfd_vma relocation, off, ie_off, desc_off; int i, j; + bool ignored = false; howto = loongarch_elf_rtype_to_howto (input_bfd, r_type); if (howto == NULL || r_type == R_LARCH_GNU_VTINHERIT @@ -2703,7 +2704,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, } else { - bool warned, ignored; + bool warned; RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, r_symndx, symtab_hdr, sym_hashes, @@ -2867,7 +2868,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, { if (h->dynindx == -1) { - if (h->root.type == bfd_link_hash_undefined) + if (h->root.type == bfd_link_hash_undefined && !ignored) (*info->callbacks->undefined_symbol) (info, name, input_bfd, input_section, rel->r_offset, true);