Menu

#525 elfcopy --rename-section produces object files that SIGSEGV GNU ld

RELEASE_1_0
closed
Kai Wang
elfcopy (3)
elfcopy
r3400M
2016-04-16
2016-04-15
Roger
No

Hello,

While compiling the Xen kernel on FreeBSD I've realized that (at least on FreeBSD) using elfcopy --rename-section produces output object files that SIGSEGV GNU ld (tried versions 2.17.50 and 2.25.1). The issue is quite simple to reproduce, here are the steps:

$ cat main.c

int main(int argc, char *argv[])
{
    return 0;
}

$ clang -g -c main.c
$ elfcopy --rename-section .comment=.init.comment main.o main.init.o
$ ld -melf_x86_64_fbsd -r -o main.ld.o main.init.o
Segmentation fault (core dumped)

If GNU objcopy is used instead of elfcopy everything works, and ld doesn't SIGSEGV. I also have a trace of the SIGSEGV in ld, in case it's helpful:

Starting program: /usr/bin/ld -melf_x86_64_fbsd -r -o main.ld.o main.init.o
warning: shared library handler failed to enable breakpoint

Program received signal SIGSEGV, Segmentation fault.
0x000000000042d0f4 in _bfd_elf_rela_local_sym ()
(gdb) bt
#0  0x000000000042d0f4 in _bfd_elf_rela_local_sym ()
#1  0x0000000000460d70 in elf64_x86_64_relocate_section ()
#2  0x00000000004396be in bfd_elf_final_link ()
#3  0x000000000041a3be in ldwrite ()
    at /root/freebsd-dis/gnu/usr.bin/binutils/ld/../../../../contrib/binutils/ld/ldwrite.c:557
#4  0x00000000004179b8 in main (argc=<value optimized out>, argv=<value optimized out>)
    at /root/freebsd-dis/gnu/usr.bin/binutils/ld/../../../../contrib/binutils/ld/ldmain.c:468
#5  0x000000000040031f in _start ()
#6  0x0000000000000000 in ?? ()
(gdb)

I'm happy to help in anyway I can.

Thanks, Roger.

Discussion

  • Roger

    Roger - 2016-04-15

    Attaching my main.o object file, since this issue also seems to be related to the usage of clang 3.8.0.

     
  • Ed Maste

    Ed Maste - 2016-04-15

    Confirmed, I tested on stable/10 (with clang 3.4.1) and it did not trigger the ld segfault.

     
  • Kai Wang

    Kai Wang - 2016-04-15
    • status: new --> accepted
    • assigned_to: Kai Wang
     
  • Kai Wang

    Kai Wang - 2016-04-15

    Thanks for reporting this issue. I'll handle it.

     
  • Ed Maste

    Ed Maste - 2016-04-15

    Simpler reproduction:

    elfcopy main.o foo.o
    ld -r -o bar.o foo.o
    
     
  • Kai Wang

    Kai Wang - 2016-04-15

    Should be fixed by [r3443]. Please verify.

     

    Related

    Commit: [r3443]

  • Ed Maste

    Ed Maste - 2016-04-15

    The ld segfault is indeed fixed.

     
  • Roger

    Roger - 2016-04-16

    Thanks, I can confirm the issue is also solved on my side :).

     
  • Kai Wang

    Kai Wang - 2016-04-16
    • status: accepted --> closed
     
  • Kai Wang

    Kai Wang - 2016-04-16

    Issue fixed.

     

Log in to post a comment.