GNU ld bug

Marvin Wolfthal maw@dvlp.cgiusa.com
Tue Mar 19 11:22:00 GMT 2002


Hi,

The premise to this is that I know nothing about gnu ld internals, so take it
for what its worth and pardon me if I'm wasting your time.

Pursuing a segmentation error in ld 2.11.2 I loaded the core file into
ddd and saw that the crash was in
elf32_sparc_relocate_section()
...
...
 relocation = (h->root.u.def.value
                              + sec->output_section->vma
                              + sec->output_offset);

I noticed that sec->output_section was NULL.

Looking at the source I saw the
comment
 /* In these cases, we don't need the relocation
                     value.  We check specially because in some
                     obscure cases sec->output_section will be NULL.  */

and noticed there was no explicit check for a NULL, which I added.
 ld crashed again, this time at line 1182, so I added another check
(see diff below).

The link now completes but I get several warnings:
/opt/gnu/bin/ld: bfd assertion fail elflink.h:5225
The program runs to a certain point and crashes.

Here is the diff:

*** elf32-sparc.c       Mon Jun 11 06:04:13 2001
--- /opt/gnu/src/binutils-2.11.2/bfd/elf32-sparc.c      Tue Mar 19 12:48:18 2002
***************
*** 1179,1187 ****
--- 1179,1194 ----
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
+        if (sec->output_section == NULL )
+          {
+            relocation = 0;
+          }
+          else
+          {
          relocation = (sec->output_section->vma
                        + sec->output_offset
                        + sym->st_value);
+          }
        }
        else
        {
***************
*** 1193,1199 ****
              || h->root.type == bfd_link_hash_defweak)
            {
              sec = h->root.u.def.section;
!             if ((r_type == R_SPARC_WPLT30
                   && h->plt.offset != (bfd_vma) -1)
                  || ((r_type == R_SPARC_GOT10
                       || r_type == R_SPARC_GOT13
--- 1200,1208 ----
              || h->root.type == bfd_link_hash_defweak)
            {
              sec = h->root.u.def.section;
!             if ( (sec->output_section == NULL )
!                  ||
!                   (r_type == R_SPARC_WPLT30
                   && h->plt.offset != (bfd_vma) -1)
                  || ((r_type == R_SPARC_GOT10
                       || r_type == R_SPARC_GOT13



I hope this information may be useful.

Regards,
Marvin Wolfthal
---------------------------------------------------------
Marvin Wolfthal maw@dvlp.cgiusa.com
Executive Consultant
CGI


---------------------------------------------------------
Marvin Wolfthal maw@dvlp.cgiusa.com
Executive Consultant
CGI



More information about the Binutils mailing list