Skip to content

LD segmentation fault while building glibc in arc-gnu-toolchain environment #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pavelvkozlov opened this issue Apr 20, 2023 · 7 comments
Assignees
Milestone

Comments

@pavelvkozlov
Copy link

I see segmentation fault of ld while building glibc. Maybe, this problem is similar to #523

collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.
make[3]: *** [../Rules:293:/build/arc-gnu-toolchain/build-glibc-linux/support/test-run-command] Error 1

Sequence to reproduce:

  • Get arc-gnu-toolchain (master branch)
  • Change branches for gcc, binutils and glibc from arc64 to arc-2023.03 in Makefile.in
  • Configure toolchain. I used the following string:
../source/arc-gnu-toolchain/configure --target=arc64 --prefix=`pwd`/../install/arc64 --enable-linux --disable-werror
  • Run make;

All variants affected: ARC32, ARC64, ARCHS

@shahab-vahedi
Copy link
Member

shahab-vahedi commented Apr 21, 2023

The segmentation fault occurs with the following command:

/inst/arc64-lnx/arc64-linux-gnu/bin/ld                       \
  --sysroot=/inst/arc64-lnx/sysroot                          \
  --eh-frame-hdr                                             \
  -Bstatic                                                   \
  -X                                                         \
  -o /bld/arc64-lnx_good/build-glibc-linux/elf/ldconfig.good \
  -L/inst/arc64-lnx/lib/gcc/arc64-linux-gnu/12.2.1           \
  -L/inst/arc64-lnx/arc64-linux-gnu/lib                      \
  /bld/arc64-lnx/build-glibc-linux/csu/crt1.o                \
  /bld/arc64-lnx/build-glibc-linux/csu/crti.o                \
  /inst/arc64-lnx/lib/gcc/arc64-linux-gnu/12.2.1/crtbeginT.o \
  /bld/arc64-lnx/build-glibc-linux/elf/ldconfig.o            \
  /bld/arc64-lnx/build-glibc-linux/elf/cache.o               \
  /bld/arc64-lnx/build-glibc-linux/elf/chroot_canon.o        \
  /bld/arc64-lnx/build-glibc-linux/elf/readlib.o             \
  /bld/arc64-lnx/build-glibc-linux/elf/static-stubs.o        \
  /bld/arc64-lnx/build-glibc-linux/elf/stringtable.o         \
  /bld/arc64-lnx/build-glibc-linux/elf/xmalloc.o             \
  /bld/arc64-lnx/build-glibc-linux/elf/xstrdup.o             \
  --start-group                                              \
  /bld/arc64-lnx/build-glibc-linux/libc.a                    \
  -lgcc                                                      \
  --end-group                                                \
  /inst/arc64-lnx/lib/gcc/arc64-linux-gnu/12.2.1/crtend.o    \
  /bld/arc64-lnx/build-glibc-linux/csu/crtn.o

At:

/src/binutils/bfd/arc-got.h:347

static bfd_vma
relocate_fix_got_relocs_for_got_info (
    list_p=0x555555dbd830,
    type=GOT_TLS_IE,
    info=0x55555579d260 <link_info>,
    output_bfd=0x5555557bf970,
    r_symndx=662,
    local_syms=0x555564a43c00,
    local_sections=0x555564a4bf80,
    h=0x555555dbd7a0,
    reloc_data=0x7fffffffce80)
{
  ...
  if (h == NULL
      || h->forced_local == true
      || (! elf_hash_table (info)->dynamic_sections_created
          || (bfd_link_pic (info)
              && SYMBOL_REFERENCES_LOCAL (info, h))))
    {
      ...
      if (entry && !entry->processed)
        {
          int tcb_size = 0;

          switch (entry->type)
            {
            case GOT_TLS_IE:
              tcb_size = TCB_SIZE;
              /* Fall through. */
            case GOT_TLS_GD:
              {
                ...
                BFD_ASSERT (sec->output_section);
                sym_value += sec->output_section->vma + sec->output_offset;
                [ SEG FAULT ]

  ...
}

Because sec->output_section holds a non-zero but yet invalid value (e.g. 0xbac266) which is garbage.

@abrodkin abrodkin added this to the 2023.03 milestone Apr 24, 2023
@abrodkin abrodkin added the bug label Apr 25, 2023
@pavelvkozlov
Copy link
Author

pavelvkozlov commented Apr 26, 2023

Interesting note.
I've checked upstream version of binutils-gdb (commit c8b3d02c4994) for ARCv2.
I've used arc-gnu-toolchain environment with gcc from 2023.03 and glibc from 2023.03 but upstream version of binutils-gdb and I haven't seen build issue (LD segmentation fault).
It seems than one of our patches is not suitable with upstream version.

@pavelvkozlov
Copy link
Author

My evening bisect pointed me to the commit 5d277de as first bad commit. It is not for sure because I've added several changes to be able to built binutils and this commit is a part of commit series that provides new arc64 architecture support, and it can provide issue because changes not finished at this point. But starting from this commit I see segmentation fault of ld with each further commit (that I can build). It is not for sure, but I hope it can be a good point to start.

@pavelvkozlov
Copy link
Author

Archive with object files and Makefile to reproduce this ld fault issue: ld-fault-example.zip
I've created it based on my bisect search. This example is about ARCv2 and about my previous two comments,
My sequence to reproduce:

Configure, build, install buinutils
$ ../configure --target=arc-linux-gnu --prefix=/tmp/install/arc --disable-multilib --disable-werror --disable-nls --with-expat=yes --disable-sim
$ make -j8 && make install

Link example object files:
$ cd /tmp/ls-fault-example
$ make LD_PATH=/tmp/install/arc/bin/
/tmp/install/arc/bin/arc-linux-gnu-ld -o ./test-run-command -nostdlib  -static ./crt1.o ./crti.o \
        ./test-run-command.o  ./static-stubs.o ./libsupport_nonshared.a ./libc.a \
        ./libgcc.a ./crtn.o
make: *** [Makefile:5: test-run-command] Segmentation fault
make: *** Deleting file 'test-run-command'

@claziss claziss assigned claziss and unassigned shahab-vahedi May 4, 2023
@claziss
Copy link
Contributor

claziss commented May 4, 2023

@pavelvkozlov please check the latest arc-2023.03 branch and let me know how does it work. Fix here: foss-for-synopsys-dwc-arc-processors/binutils-gdb@8f36066

@pavelvkozlov
Copy link
Author

I've checked ld with fix to build glibc for ARCv2, ARCv3/32, ARCv3/64.
I can confirm, build issue has gone. Now I'm going to run glibc tests.

@abrodkin
Copy link
Member

abrodkin commented May 4, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants