public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
@ 2022-08-30 14:38 Xi Ruoyao
  2022-08-30 18:21 ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Xi Ruoyao @ 2022-08-30 14:38 UTC (permalink / raw)
  To: binutils; +Cc: Pierre Labastie

Building SeaMonkey on i686 results:

    "/usr/bin/ld.gold: internal error in relocate_section, at ../../gold/i386.cc:3683"

i386.cc:3683 is:

    gold_assert(sh_type == elfcpp::SHT_REL);

AFAIK i386 normally use SHT_REL and x86_64 normally use SHT_RELA.  But
we've found that nasm-2.15.05 generates SHT_RELA for i386 as well.

So should SHT_RELA be allowed for i386 at all?  If "yes" we should fix
it for gold, if "no" we should fix it for nasm.
-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-30 14:38 question: i386 ld.gold reports "internal error" linking files with SHT_RELA section Xi Ruoyao
@ 2022-08-30 18:21 ` H.J. Lu
  2022-08-30 18:53   ` Pierre Labastie
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2022-08-30 18:21 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: Binutils, Pierre Labastie

On Tue, Aug 30, 2022 at 7:39 AM Xi Ruoyao via Binutils
<binutils@sourceware.org> wrote:
>
> Building SeaMonkey on i686 results:
>
>     "/usr/bin/ld.gold: internal error in relocate_section, at ../../gold/i386.cc:3683"
>
> i386.cc:3683 is:
>
>     gold_assert(sh_type == elfcpp::SHT_REL);
>
> AFAIK i386 normally use SHT_REL and x86_64 normally use SHT_RELA.  But
> we've found that nasm-2.15.05 generates SHT_RELA for i386 as well.
>
> So should SHT_RELA be allowed for i386 at all?  If "yes" we should fix
> it for gold, if "no" we should fix it for nasm.
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University

 SHT_RELA shouldn't be used for i386.

-- 
H.J.

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-30 18:21 ` H.J. Lu
@ 2022-08-30 18:53   ` Pierre Labastie
  2022-08-30 20:36     ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Pierre Labastie @ 2022-08-30 18:53 UTC (permalink / raw)
  To: H.J. Lu, Xi Ruoyao; +Cc: Binutils

On Tue, 2022-08-30 at 11:21 -0700, H.J. Lu wrote:
> On Tue, Aug 30, 2022 at 7:39 AM Xi Ruoyao via Binutils
> <binutils@sourceware.org> wrote:
> > 
> > Building SeaMonkey on i686 results:
> > 
> >     "/usr/bin/ld.gold: internal error in relocate_section, at
> > ../../gold/i386.cc:3683"
> > 
> > i386.cc:3683 is:
> > 
> >     gold_assert(sh_type == elfcpp::SHT_REL);
> > 
> > AFAIK i386 normally use SHT_REL and x86_64 normally use SHT_RELA.  But
> > we've found that nasm-2.15.05 generates SHT_RELA for i386 as well.
> > 
> > So should SHT_RELA be allowed for i386 at all?  If "yes" we should fix
> > it for gold, if "no" we should fix it for nasm.
> > --
> > Xi Ruoyao <xry111@xry111.site>
> > School of Aerospace Science and Technology, Xidian University
> 
>  SHT_RELA shouldn't be used for i386.
> 

But it is accepted by ld.bfd...

FWIIW, only the dwarf debug sections are generated as SHT_RELA by nasm.

Pierre Labastie

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-30 18:53   ` Pierre Labastie
@ 2022-08-30 20:36     ` H.J. Lu
  2022-08-31  4:43       ` Xi Ruoyao
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2022-08-30 20:36 UTC (permalink / raw)
  To: Pierre Labastie; +Cc: Xi Ruoyao, Binutils

On Tue, Aug 30, 2022 at 11:53 AM Pierre Labastie
<pierre.labastie@neuf.fr> wrote:
>
> On Tue, 2022-08-30 at 11:21 -0700, H.J. Lu wrote:
> > On Tue, Aug 30, 2022 at 7:39 AM Xi Ruoyao via Binutils
> > <binutils@sourceware.org> wrote:
> > >
> > > Building SeaMonkey on i686 results:
> > >
> > >     "/usr/bin/ld.gold: internal error in relocate_section, at
> > > ../../gold/i386.cc:3683"
> > >
> > > i386.cc:3683 is:
> > >
> > >     gold_assert(sh_type == elfcpp::SHT_REL);
> > >
> > > AFAIK i386 normally use SHT_REL and x86_64 normally use SHT_RELA.  But
> > > we've found that nasm-2.15.05 generates SHT_RELA for i386 as well.
> > >
> > > So should SHT_RELA be allowed for i386 at all?  If "yes" we should fix
> > > it for gold, if "no" we should fix it for nasm.
> > > --
> > > Xi Ruoyao <xry111@xry111.site>
> > > School of Aerospace Science and Technology, Xidian University
> >
> >  SHT_RELA shouldn't be used for i386.
> >
>
> But it is accepted by ld.bfd...

Do you have .o files for ld.bfd I can take a look at?

> FWIIW, only the dwarf debug sections are generated as SHT_RELA by nasm.
>
> Pierre Labastie



-- 
H.J.

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-30 20:36     ` H.J. Lu
@ 2022-08-31  4:43       ` Xi Ruoyao
  2022-08-31 19:20         ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Xi Ruoyao @ 2022-08-31  4:43 UTC (permalink / raw)
  To: H.J. Lu, Pierre Labastie; +Cc: Binutils

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

On Tue, 2022-08-30 at 13:36 -0700, H.J. Lu wrote:

> > >  SHT_RELA shouldn't be used for i386.
> > 
> > But it is accepted by ld.bfd...
> 
> Do you have .o files for ld.bfd I can take a look at?
> 
> > FWIIW, only the dwarf debug sections are generated as SHT_RELA by
> > nasm.

Hi,

$ cat t.asm
section .text
extern printf
global main
main:
  push ebp
  mov ebp, esp
  push msg
  call printf
  add esp, 4
  leave
  ret

section .data
  msg db 'Hello, world!', 13, 10, 0

section .note.GNU-stack noalloc noexec nowrite progbits
$ nasm t.asm -f elf32 -F dwarf
$ cc t.o && ./a.out 
Hello, world!
$ cc -fuse-ld=gold t.o 
/usr/bin/ld.gold: internal error in relocate_section, at ../../gold/i386.cc:3683
collect2: error: ld returned 1 exit status

I'll attach "t.asm' and "t.o.gz".

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

[-- Attachment #2: t.o.gz --]
[-- Type: application/gzip, Size: 586 bytes --]

[-- Attachment #3: t.asm --]
[-- Type: text/plain, Size: 232 bytes --]

section .text
extern printf
global main
main:
  push ebp
  mov ebp, esp
  push msg
  call printf
  add esp, 4
  leave
  ret

section .data
  msg db 'Hello, world!', 13, 10, 0

section .note.GNU-stack noalloc noexec nowrite progbits

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-31  4:43       ` Xi Ruoyao
@ 2022-08-31 19:20         ` H.J. Lu
  2022-09-01  0:47           ` Xi Ruoyao
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2022-08-31 19:20 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: Pierre Labastie, Binutils

On Tue, Aug 30, 2022 at 9:43 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Tue, 2022-08-30 at 13:36 -0700, H.J. Lu wrote:
>
> > > >  SHT_RELA shouldn't be used for i386.
> > >
> > > But it is accepted by ld.bfd...
> >
> > Do you have .o files for ld.bfd I can take a look at?
> >
> > > FWIIW, only the dwarf debug sections are generated as SHT_RELA by
> > > nasm.
>
> Hi,
>
> $ cat t.asm
> section .text
> extern printf
> global main
> main:
>   push ebp
>   mov ebp, esp
>   push msg
>   call printf
>   add esp, 4
>   leave
>   ret
>
> section .data
>   msg db 'Hello, world!', 13, 10, 0
>
> section .note.GNU-stack noalloc noexec nowrite progbits
> $ nasm t.asm -f elf32 -F dwarf
> $ cc t.o && ./a.out
> Hello, world!
> $ cc -fuse-ld=gold t.o
> /usr/bin/ld.gold: internal error in relocate_section, at ../../gold/i386.cc:3683
> collect2: error: ld returned 1 exit status
>
> I'll attach "t.asm' and "t.o.gz".
>
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University

What happened are

1. nasm generates RELA relocation for debug sections.  But addend
in RELA relocation is 0:

Relocation section '.rela.debug_info' at offset 0x3a0 contains 5 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name + Addend
00000006  00000501 R_386_32               00000000   .debug_abbrev + 0
0000000c  00000201 R_386_32               00000000   .text + 0
00000010  00000201 R_386_32               00000000   .text + 0
00000014  00000601 R_386_32               00000000   .debug_line + 0
0000002c  00000201 R_386_32               00000000   .text + 0

and addend is stored at the relocation offset like REL relocation:

Hex dump of section '.debug_info':
  0x00000000 31000000 02000000 00000401 00000000 1...............
  0x00000010 12000000 00000000 782e7300 4e41534d ........x.s.NASM
  0x00000020 20322e31 352e3035 00018002 00000000  2.15.05........
  0x00000030 00000000 00

2. ld.bfd treats RELA relocation like REL relocation.  It uses addend at
the relocation offset, not in RELA relocation.

It just works with ld.bfd by accident.  A linker, like gold, can disallow RELA
relocation.  A linker, like lld, can use addend in RELA relocation and addend
at the relocation offset is ignored.


-- 
H.J.

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-08-31 19:20         ` H.J. Lu
@ 2022-09-01  0:47           ` Xi Ruoyao
  2022-09-01 16:34             ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Xi Ruoyao @ 2022-09-01  0:47 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Pierre Labastie, Binutils

On Wed, 2022-08-31 at 12:20 -0700, H.J. Lu wrote:

> It just works with ld.bfd by accident.  A linker, like gold, can disallow RELA
> relocation.  A linker, like lld, can use addend in RELA relocation and addend
> at the relocation offset is ignored.

Thanks, we've reported the issue to NASM:
https://bugzilla.nasm.us/show_bug.cgi?id=3392807

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: question: i386 ld.gold reports "internal error" linking files with SHT_RELA section
  2022-09-01  0:47           ` Xi Ruoyao
@ 2022-09-01 16:34             ` H.J. Lu
  0 siblings, 0 replies; 8+ messages in thread
From: H.J. Lu @ 2022-09-01 16:34 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: Pierre Labastie, Binutils

On Wed, Aug 31, 2022 at 5:47 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Wed, 2022-08-31 at 12:20 -0700, H.J. Lu wrote:
>
> > It just works with ld.bfd by accident.  A linker, like gold, can disallow RELA
> > relocation.  A linker, like lld, can use addend in RELA relocation and addend
> > at the relocation offset is ignored.
>
> Thanks, we've reported the issue to NASM:
> https://bugzilla.nasm.us/show_bug.cgi?id=3392807
>

I created a pull request:

https://github.com/netwide-assembler/nasm/pull/37

to fix this issue.

-- 
H.J.

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

end of thread, other threads:[~2022-09-01 16:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 14:38 question: i386 ld.gold reports "internal error" linking files with SHT_RELA section Xi Ruoyao
2022-08-30 18:21 ` H.J. Lu
2022-08-30 18:53   ` Pierre Labastie
2022-08-30 20:36     ` H.J. Lu
2022-08-31  4:43       ` Xi Ruoyao
2022-08-31 19:20         ` H.J. Lu
2022-09-01  0:47           ` Xi Ruoyao
2022-09-01 16:34             ` H.J. Lu

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