https://sourceware.org/bugzilla/show_bug.cgi?id=22920

            Bug ID: 22920
           Summary: Segfault in ld with RISC-V binary target
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: geoffrey at allott dot email
  Target Milestone: ---

When using the latest release (2.30) and master (2.30.51.20180303), configured
on an x86_64-linux-gnu host with --target=riscv32-unknown-elf, the following
sequence of steps will segfault:

    cat <<EOF > main.s
    la t0, addr
    EOF

    cat <<EOF > link.ld
    OUTPUT_FORMAT(binary);

    SECTIONS {
        main : { main.o }
        addr = ABSOLUTE(42);
    }
    EOF

    riscv32-unknown-elf-as main.s -o main.o
    riscv32-unknown-elf-ld -T link.ld

The backtrace at the time of the segfault is as follows:

(gdb) bt
#0  0x00005555555b42c7 in _bfd_riscv_relax_section (abfd=0x5555558e00b0,
sec=<optimized out>, info=0x5555558a4fa0 <link_info>, 
    again=0x7fffffffe460) at ./elfnn-riscv.c:3444
#1  0x0000555555583226 in lang_size_sections_1 (prev=0x5555558c9da0, 
    output_section_statement=output_section_statement@entry=0x5555558ca3b0,
fill=fill@entry=0x0, dot=<optimized out>, 
    relax=relax@entry=0x7fffffffe604, check_regions=check_regions@entry=0) at
ldlang.c:5436
#2  0x0000555555583318 in lang_size_sections_1 (prev=<optimized out>,
prev@entry=0x5555558ca3c0, 
    output_section_statement=output_section_statement@entry=0x5555558ca3b0,
fill=0x0, dot=<optimized out>, 
    relax=relax@entry=0x7fffffffe604, check_regions=check_regions@entry=0) at
ldlang.c:5531
#3  0x00005555555837ef in lang_size_sections_1 (prev=<optimized out>,
prev@entry=0x5555558a0310 <statement_list>, 
    output_section_statement=0x5555558ca300, fill=fill@entry=0x0,
dot=<optimized out>, dot@entry=0, 
    relax=relax@entry=0x7fffffffe604, check_regions=check_regions@entry=0) at
ldlang.c:5177
#4  0x0000555555585ab4 in one_lang_size_sections_pass
(relax=relax@entry=0x7fffffffe604, check_regions=check_regions@entry=0)
    at ldlang.c:5604
#5  0x0000555555587326 in lang_size_sections (relax=0x7fffffffe604,
check_regions=0) at ldlang.c:5716
#6  0x00005555555875a0 in lang_relax_sections (need_layout=<optimized out>) at
ldlang.c:6967
#7  0x0000555555598673 in gldelf32lriscv_map_segments (need_layout=<optimized
out>) at eelf32lriscv.c:66
#8  gldelf32lriscv_after_allocation () at eelf32lriscv.c:143
#9  0x0000555555589c39 in lang_process () at ldlang.c:7405
#10 0x0000555555577844 in main (argc=<optimized out>, argv=<optimized out>) at
./ldmain.c:439

It appears that the variable htab is null here

(gdb) l
3439              while (h->root.type == bfd_link_hash_indirect
3440                     || h->root.type == bfd_link_hash_warning)
3441                h = (struct elf_link_hash_entry *) h->root.u.i.link;
3442    
3443              if (h->plt.offset != MINUS_ONE)
3444                symval = sec_addr (htab->elf.splt) + h->plt.offset;
3445              else if (h->root.u.def.section->output_section == NULL
3446                       || (h->root.type != bfd_link_hash_defined
3447                           && h->root.type != bfd_link_hash_defweak))
3448                continue;
(gdb) p htab
$1 = (struct riscv_elf_link_hash_table *) 0x0

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to