On 2024/03/14 11:04, lijiang wrote:
 On Wed, Mar 13, 2024 at 3:23 PM HAGIO KAZUHITO(萩尾 一仁)
<k-hagio-ab(a)nec.com <mailto:k-hagio-ab@nec.com>> wrote:
 
     On 2024/03/08 12:18, Ming Wang wrote:
      > The following link error exists when building with LOONGARCH64
      > machine:
      >
      > /usr/bin/ld: proc-service.o: in function `.LVL71':
      > proc-service.c:(.text+0x324): undefined reference to `fill_gregset ...
      > /usr/bin/ld: proc-service.o: in function `.LVL77':
      > proc-service.c:(.text+0x364): undefined reference to `supply_gregset ...
      > /usr/bin/ld: proc-service.o: in function `.LVL87':
      > proc-service.c:(.text+0x3c4): undefined reference to `fill_fpregset ...
      > /usr/bin/ld: proc-service.o: in function `.LVL93':
      > proc-service.c:(.text+0x404): undefined reference to `supply_fpregset
      > collect2: error: ld returned 1 exit status
      >
      > The cause of the error is that the definition of a function such as
      > fill_gregset is not implemented. This patch is used to fix this error.
      >
      > v1 -> v2:
      > Fix compilation errors.
 
     Thanks for the v2, the warnings are gone.  but I found another problem..
 
     When we add a patch to gdb-10.2.patch, a LOONGARCH64 build will fail with
     the following redefinition errors.  There is need to remove the gdb-10.2
     directory before rebuilding.  It looks like it's because the patch command
     cannot detect previously applied patches for newly created loongarch files,
     and those files get duplicated code..
 
     $ git am /tmp/0001-LoongArch64-Fixed-link-errors-when-build-on-LOO.patch
     Applying: LoongArch64: Fixed link errors when build on LOONGARCH64 machine
     $ make -j 16 warn target=LOONGARCH64
     ...
     patching file gdb-10.2/bfd/configure.ac <
http://configure.ac>
     Reversed (or previously applied) patch detected!  Skipping patch.
     1 out of 1 hunk ignored
     patching file gdb-10.2/bfd/cpu-loongarch.c   <<-- cannot detect previously
applied patch
     patching file gdb-10.2/bfd/elf-bfd.h
     patching file gdb-10.2/bfd/elf.c
     ...
     libtool: compile:  gcc -DHAVE_CONFIG_H -I. -DBINDIR=\"/usr/local/bin\"
-DLIBDIR=\"/usr/local/lib\" -I. -I. -I./../include -DHAVE_loongarch_elf64_vec
-DHAVE_loongarch_elf32_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec
-DHAVE_elf32_be_vec -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow
-Wstack-usage=262144 -I./../zlib -g -O2 -MT elf-properties.lo -
     MD -MP -MF .deps/elf-properties.Tpo -c elf-properties.c -o elf-properties.o
     cpu-loongarch.c:86:33: error: redefinition of 'bfd_loongarch32_arch'
          static const bfd_arch_info_type bfd_loongarch32_arch =
                                          ^~~~~~~~~~~~~~~~~~~~
     ...
     make: *** [Makefile:254: all] Error 2
 
     $ grep BFD gdb-10.2/bfd/cpu-loongarch.c
     /* BFD support for LoongArch.
            This file is part of BFD, the Binary File Descriptor library.
     /* BFD support for LoongArch.
            This file is part of BFD, the Binary File Descriptor library.
 
 
     I found that it's due to not using '/dev/null' for the newly added
files
     in gdb-10.2.patch.  I'd like to fix this issue before applying this patch.
 
     I've attached two patches:
     - 1/2 fixes the issue above.
     - 2/2 is Ming's patch and I added "rm -f
gdb-10.2/gdb/loongarch-linux-tdep.c"
         for the file modified multiple times (but not included in gdb-10.2.tar.gz.)
 
 
 For these two patches: Ack.
 
Thank you, applied.
on the other architectures e.g. x86_64, there may be already duplicated 
code as many as re-applied, though no error occurs for x86_64 build.  If 
duplicated, please remove the gdb-10.2 directory once to clean them up.
$ grep "BFD support" gdb-10.2/bfd/cpu-loongarch.c
/* BFD support for LoongArch.
/* BFD support for LoongArch.
/* BFD support for LoongArch.
/* BFD support for LoongArch.
/* BFD support for LoongArch.
$ rm -rf gdb-10.2
$ make ...
Thanks,
Kazu