public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all
@ 2024-02-20  2:11 ticat-fp
  2024-02-20  2:31 ` Xi Ruoyao
  0 siblings, 1 reply; 3+ messages in thread
From: ticat-fp @ 2024-02-20  2:11 UTC (permalink / raw)
  To: binutils; +Cc: mengqinggang, cailulu

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(-)

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);
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all
  2024-02-20  2:11 [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all ticat-fp
@ 2024-02-20  2:31 ` Xi Ruoyao
  2024-02-20  2:56   ` 樊鹏
  0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2024-02-20  2:31 UTC (permalink / raw)
  To: ticat-fp, binutils; +Cc: mengqinggang, cailulu

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all
  2024-02-20  2:31 ` Xi Ruoyao
@ 2024-02-20  2:56   ` 樊鹏
  0 siblings, 0 replies; 3+ messages in thread
From: 樊鹏 @ 2024-02-20  2:56 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: binutils, mengqinggang, cailulu

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. 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-20  2:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20  2:11 [PATCH] LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all ticat-fp
2024-02-20  2:31 ` Xi Ruoyao
2024-02-20  2:56   ` 樊鹏

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).