foss-for-synopsys-dwc-arc-processors / buildroot

The development tree for Buildroot support for the Synopsys DesignWare ARC processor family
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/blob/arc-dev/README.md
Other
7 stars 2 forks source link

Host gdb from SDK built by buildroot does not work due to missing opcodes and bfd libraries #39

Open gmazurkiewicz opened 4 months ago

gmazurkiewicz commented 4 months ago

The host gdb tool does not work due to missing opcodes and bfd libraries:

./bin/arc32-buildroot-linux-uclibc-gdb
./bin/arc32-buildroot-linux-uclibc-gdb: error while loading shared libraries: libopcodes-2.40.90.20230703.so: cannot open shared object file: No such file or directory
ldd ./bin/arc32-buildroot-linux-uclibc-gdb
        linux-vdso.so.1 (0x00007ffff5fbc000)
        libexpat.so.1 => /opt/output_buildroot/buildroot/output/images/arc32-buildroot-linux-uclibc_sdk-buildroot/./bin/../lib/libexpat.so.1 (0x00007f1bbd085000)
        libopcodes-2.40.90.20230703.so => not found
        libbfd-2.40.90.20230703.so => not found
        libz.so.1 => /opt/output_buildroot/buildroot/output/images/arc32-buildroot-linux-uclibc_sdk-buildroot/./bin/../lib/libz.so.1 (0x00007f1bbd067000)
        libncursesw.so.6 => /lib/x86_64-linux-gnu/libncursesw.so.6 (0x00007f1bbd02d000)
        libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f1bbcffb000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1bbcff5000)
        libmpfr.so.6 => /opt/output_buildroot/buildroot/output/images/arc32-buildroot-linux-uclibc_sdk-buildroot/./bin/../lib/libmpfr.so.6 (0x00007f1bbc750000)
        libgmp.so.10 => /opt/output_buildroot/buildroot/output/images/arc32-buildroot-linux-uclibc_sdk-buildroot/./bin/../lib/libgmp.so.10 (0x00007f1bbc6d2000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1bbc4f0000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1bbc3a1000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1bbc386000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1bbc363000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1bbc171000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f1bbd0b8000)

This happens only if the tool is executed from SDK generated by buildroot.

Steps to reproduce:

  1. Checkout branch arc-2023.09 from https://github.com/foss-for-synopsys-dwc-arc-processors/buildroot.git
  2. Enable host gdb in the defconfig
    diff --git a/configs/snps_arc32_defconfig b/configs/snps_arc32_defconfig
    index 44f4f8b91a..faabfcede5 100644
    --- a/configs/snps_arc32_defconfig
    +++ b/configs/snps_arc32_defconfig
    @@ -1,8 +1,10 @@
    BR2_arcle=y
    BR2_arc32=y
    -# BR2_STRIP_strip is not set
    BR2_TOOLCHAIN_BUILDROOT_UCLIBC=y
    BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_16=y
    +BR2_PACKAGE_HOST_GDB=y
    +BR2_PACKAGE_HOST_GDB_TUI=y
    +# BR2_STRIP_strip is not set
    BR2_ROOTFS_POST_IMAGE_SCRIPT="board/synopsys/arc64/post-image.sh"
    BR2_ROOTFS_POST_SCRIPT_ARGS="$(LINUX_DIR)"
    BR2_LINUX_KERNEL=y
  3. Build the distro: make snps_arc32_defconfig make -j
  4. Prepare sdk: make sdk
  5. Unpack the generated sdk and run the gdb from this package
  6. You will see the error from description above

I made a quick investigation and this seems to be intended that these libs are not installed:

From file: buildroot/package/gdb/gdb.mk

# When gdb sources are fetched from the binutils-gdb repository, they
# also contain the binutils sources, but binutils shouldn't be built,
# so we disable it (additionally the option --disable-install-libbfd
# prevents the un-wanted installation of libobcodes.so and libbfd.so).
GDB_DISABLE_BINUTILS_CONF_OPTS = \
    --disable-binutils \
    --disable-install-libbfd \
    --disable-ld \
    --disable-gas \
    --disable-gprof

So on one hand we choose the libs to be statically linked and disable installing libbfd and libopcodes, and on the other hand gdb links to these libs dynamically.

I changed the option --disable-install-libbfd to --enable-install-libbfd and this fixes the problem, but I'm not sure if that's the correct way of fixing this.

gmazurkiewicz commented 4 months ago

Looks like this is fixed by this commit https://github.com/buildroot/buildroot/commit/e5729d3008e4f958324fbbd9ea742badb3f41de4 I'll try to cherry pick and test it.

gmazurkiewicz commented 4 months ago

I've just confirmed that this is the proper fix of the issue.