From 0924e88e48280daaefd7ed5f9ee2d32b1659b504 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 14 Oct 2022 07:55:04 +0000 Subject: [PATCH] main/gdb: fix compilation and crash and add -dbg Compilation with GCC 12.1.1 failed as an implicit cast from `const char *` to `char *` is no longer accepted without -fpermissive. A patch to make the cast explicit is added. In addition debug symbols are provided as a subpackage. --- main/gdb/APKBUILD | 18 +- main/gdb/fix-arm-segfault.patch | 155 ++++++++++++++++++ .../gdb/fix-invalid-implicit-conversion.patch | 13 ++ 3 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 main/gdb/fix-arm-segfault.patch create mode 100644 main/gdb/fix-invalid-implicit-conversion.patch diff --git a/main/gdb/APKBUILD b/main/gdb/APKBUILD index 7f668314358..575fe2e18e6 100644 --- a/main/gdb/APKBUILD +++ b/main/gdb/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: Natanael Copa pkgname=gdb pkgver=12.1 -pkgrel=1 +pkgrel=2 pkgdesc="The GNU Debugger" url="https://www.gnu.org/software/gdb/" arch="all" @@ -10,12 +10,14 @@ makedepends="ncurses-dev expat-dev texinfo readline-dev python3-dev zlib-dev autoconf automake libtool linux-headers perl gmp-dev" options="!check" [ "$CARCH" = "riscv64" ] && options="$options textrels" -subpackages="$pkgname-doc $pkgname-multiarch" +subpackages="$pkgname-dbg $pkgname-doc $pkgname-multiarch" source="https://ftp.gnu.org/gnu/gdb/gdb-$pkgver.tar.xz s390x-use-elf-gdb_fpregset_t.patch ppc-musl.patch ppc-ptregs.patch musl-signals.patch + fix-arm-segfault.patch + fix-invalid-implicit-conversion.patch " prepare() { @@ -36,6 +38,9 @@ build() { --mandir=/usr/share/man --infodir=/usr/share/info" + export CFLAGS="$CFLAGS -g1" + export CXXFLAGS="$CXXFLAGS -g1" + # use system readline if not cross compiling [ "$CBUILD" = "$CHOST" ] && _config="$_config --with-system-readline" @@ -75,14 +80,17 @@ package() { # those are provided by binutils rm -rf "$pkgdir"/usr/include rm -rf "$pkgdir"/usr/lib + + # install gdb-multiarch here for default dbg() split function to work + install -Dm755 "$builddir"/multiarch/gdb/gdb \ + "$pkgdir"/usr/bin/gdb-multiarch } multiarch() { depends="$pkgname" pkgdesc="The GNU Debugger for all supported architectures" - install -Dm755 "$builddir"/multiarch/gdb/gdb \ - "$subpkgdir"/usr/bin/gdb-multiarch + amove usr/bin/gdb-multiarch } sha512sums=" @@ -91,4 +99,6 @@ sha512sums=" 04911f87904b62dd7662435f9182b20485afb29ddb3d6398a9d31fef13495f7b70639c77fdae3a40e2775e270d7cd40d0cfd7ddf832372b506808d33c8301e01 ppc-musl.patch ab554899bbb2aa98261fd1b6beb4a71ed7c713a714bddd3fa7ec875258e39bd5474dc96a11accb4dadd316f3834f215e8395d3b373bf3affd122dc5b4a8fe710 ppc-ptregs.patch 58aacc7cdc119eab729a3c5a5521f6a0db41c6a5bc2d09d6e32cbdd071d85dd1a31b5e6559616f8da1237c5b79ad9e04aab485211e957b4d1ca752c0c5ad660b musl-signals.patch +81a6014318aaa768715de5c8e6a384a028e76bc9650951220a0e2e4e9fc67617e78ab23a0591cd6fa00d5a9709fbc2fc9c166da3aa19e6545fcc298800781fa9 fix-arm-segfault.patch +97ee00c68d8df2b04a141d4b0489e339a2d64c2c790d336767dbe28bf1510d596ea46142383ce09043a0bfc47f7d262082287448ded99fefa1f7e2b5ddad3df2 fix-invalid-implicit-conversion.patch " diff --git a/main/gdb/fix-arm-segfault.patch b/main/gdb/fix-arm-segfault.patch new file mode 100644 index 00000000000..d7c1b58973b --- /dev/null +++ b/main/gdb/fix-arm-segfault.patch @@ -0,0 +1,155 @@ +From: Alan Modra +Date: Fri, 30 Sep 2022 00:56:30 +0000 (+0930) +Subject: PR29626, Segfault when disassembling ARM code +X-Git-Url: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff_plain;h=4eeb0013059856b8660b4a0351589b096167b4d1;hp=478fced3a8904bed9a99ecf9c0374a49c3ac2115 + +PR29626, Segfault when disassembling ARM code + + PR 29626 + * arm-dis.c (mapping_symbol_for_insn): Return false on zero + symtab_size. Delete later symtab_size test. +--- + +diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c +index 684c74f7f20..caf3531ae3d 100644 +--- a/opcodes/arm-dis.c ++++ b/opcodes/arm-dis.c +@@ -11865,77 +11865,75 @@ mapping_symbol_for_insn (bfd_vma pc, struct disassemble_info *info, + struct arm_private_data *private_data; + + if (info->private_data == NULL ++ || info->symtab_size == 0 + || bfd_asymbol_flavour (*info->symtab) != bfd_target_elf_flavour) + return false; + + private_data = info->private_data; + + /* First, look for mapping symbols. */ +- if (info->symtab_size != 0) +- { +- if (pc <= private_data->last_mapping_addr) +- private_data->last_mapping_sym = -1; +- +- /* Start scanning at the start of the function, or wherever +- we finished last time. */ +- n = info->symtab_pos + 1; +- +- /* If the last stop offset is different from the current one it means we +- are disassembling a different glob of bytes. As such the optimization +- would not be safe and we should start over. */ +- can_use_search_opt_p +- = private_data->last_mapping_sym >= 0 +- && info->stop_offset == private_data->last_stop_offset; +- +- if (n >= private_data->last_mapping_sym && can_use_search_opt_p) +- n = private_data->last_mapping_sym; +- +- /* Look down while we haven't passed the location being disassembled. +- The reason for this is that there's no defined order between a symbol +- and an mapping symbol that may be at the same address. We may have to +- look at least one position ahead. */ +- for (; n < info->symtab_size; n++) +- { +- addr = bfd_asymbol_value (info->symtab[n]); +- if (addr > pc) +- break; +- if (get_map_sym_type (info, n, &type)) +- { +- last_sym = n; +- found = true; +- } +- } ++ if (pc <= private_data->last_mapping_addr) ++ private_data->last_mapping_sym = -1; ++ ++ /* Start scanning at the start of the function, or wherever ++ we finished last time. */ ++ n = info->symtab_pos + 1; ++ ++ /* If the last stop offset is different from the current one it means we ++ are disassembling a different glob of bytes. As such the optimization ++ would not be safe and we should start over. */ ++ can_use_search_opt_p ++ = (private_data->last_mapping_sym >= 0 ++ && info->stop_offset == private_data->last_stop_offset); ++ ++ if (n >= private_data->last_mapping_sym && can_use_search_opt_p) ++ n = private_data->last_mapping_sym; ++ ++ /* Look down while we haven't passed the location being disassembled. ++ The reason for this is that there's no defined order between a symbol ++ and an mapping symbol that may be at the same address. We may have to ++ look at least one position ahead. */ ++ for (; n < info->symtab_size; n++) ++ { ++ addr = bfd_asymbol_value (info->symtab[n]); ++ if (addr > pc) ++ break; ++ if (get_map_sym_type (info, n, &type)) ++ { ++ last_sym = n; ++ found = true; ++ } ++ } + +- if (!found) +- { +- n = info->symtab_pos; +- if (n >= private_data->last_mapping_sym && can_use_search_opt_p) +- n = private_data->last_mapping_sym; +- +- /* No mapping symbol found at this address. Look backwards +- for a preceeding one, but don't go pass the section start +- otherwise a data section with no mapping symbol can pick up +- a text mapping symbol of a preceeding section. The documentation +- says section can be NULL, in which case we will seek up all the +- way to the top. */ +- if (info->section) +- section_vma = info->section->vma; +- +- for (; n >= 0; n--) +- { +- addr = bfd_asymbol_value (info->symtab[n]); +- if (addr < section_vma) +- break; ++ if (!found) ++ { ++ n = info->symtab_pos; ++ if (n >= private_data->last_mapping_sym && can_use_search_opt_p) ++ n = private_data->last_mapping_sym; ++ ++ /* No mapping symbol found at this address. Look backwards ++ for a preceeding one, but don't go pass the section start ++ otherwise a data section with no mapping symbol can pick up ++ a text mapping symbol of a preceeding section. The documentation ++ says section can be NULL, in which case we will seek up all the ++ way to the top. */ ++ if (info->section) ++ section_vma = info->section->vma; ++ ++ for (; n >= 0; n--) ++ { ++ addr = bfd_asymbol_value (info->symtab[n]); ++ if (addr < section_vma) ++ break; + +- if (get_map_sym_type (info, n, &type)) +- { +- last_sym = n; +- found = true; +- break; +- } +- } +- } +- } ++ if (get_map_sym_type (info, n, &type)) ++ { ++ last_sym = n; ++ found = true; ++ break; ++ } ++ } ++ } + + /* If no mapping symbol was found, try looking up without a mapping + symbol. This is done by walking up from the current PC to the nearest diff --git a/main/gdb/fix-invalid-implicit-conversion.patch b/main/gdb/fix-invalid-implicit-conversion.patch new file mode 100644 index 00000000000..d55f099ec5a --- /dev/null +++ b/main/gdb/fix-invalid-implicit-conversion.patch @@ -0,0 +1,13 @@ +An implicit cast from `const char *` to `char *` is not possible without +adding `-fpermissive`. But let's rather make the cast explicit here. +--- a/gdb/completer.c ++++ b/gdb/completer.c +@@ -2011,7 +2011,7 @@ + rl_basic_quote_characters = NULL; + } + +- return rl_completer_word_break_characters; ++ return (char *)rl_completer_word_break_characters; + } + + char * -- GitLab