diff options
-rw-r--r-- | .pre-commit-config.yaml | 8 | ||||
-rw-r--r-- | bfd/version.h | 2 | ||||
-rwxr-xr-x | gdb/contrib/codespell-log.sh | 95 | ||||
-rw-r--r-- | gdb/dwarf2/cu.h | 9 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 9 | ||||
-rw-r--r-- | gdb/solib.c | 2 | ||||
-rwxr-xr-x | gdb/syscalls/riscv-canonicalize-syscall-gen.py | 2 | ||||
-rw-r--r-- | ld/emultempl/emulation.em | 3 | ||||
-rw-r--r-- | ld/emultempl/pe.em | 50 | ||||
-rw-r--r-- | ld/ld.texi | 4 | ||||
-rw-r--r-- | ld/ldemul.c | 8 | ||||
-rw-r--r-- | ld/ldemul.h | 8 | ||||
-rw-r--r-- | ld/ldlang.c | 34 | ||||
-rw-r--r-- | sim/d10v/gencode.c | 2 |
14 files changed, 208 insertions, 28 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b55685b..7cb7008 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,6 +38,7 @@ # See https://pre-commit.com/hooks.html for more hooks minimum_pre_commit_version: 3.2.0 +default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/psf/black-pre-commit-mirror rev: 25.1.0 @@ -80,3 +81,10 @@ repos: # All gdb header files, but not headers in the test suite. files: '^(gdb(support|server)?)/.*\.h$' exclude: '.*/testsuite/.*' + - id: codespell-log + name: codespell-log + language: script + entry: gdb/contrib/codespell-log.sh + verbose: true + always_run: true + stages: [commit-msg] diff --git a/bfd/version.h b/bfd/version.h index 90e53a8..61a84a9 100644 --- a/bfd/version.h +++ b/bfd/version.h @@ -16,7 +16,7 @@ In releases, the date is not included in either version strings or sonames. */ -#define BFD_VERSION_DATE 20250425 +#define BFD_VERSION_DATE 20250426 #define BFD_VERSION @bfd_version@ #define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@ #define REPORT_BUGS_TO @report_bugs_to@ diff --git a/gdb/contrib/codespell-log.sh b/gdb/contrib/codespell-log.sh new file mode 100755 index 0000000..10780f8 --- /dev/null +++ b/gdb/contrib/codespell-log.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +# Copyright (C) 2025 Free Software Foundation, Inc. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Script to be used as pre-commit commit-msg hook to spell-check the commit +# log using codespell. +# +# Using codespell directly as a pre-commit commit-msg hook has the drawback +# that: +# - if codespell fails, the commit fails +# - if the commit log mentions a typo correction, it'll require a +# codespell:ignore annotation. +# +# This script works around these problems by treating codespell output as a +# hint, and ignoring codespell exit status. +# +# Implementation note: rather than using codespell directly, this script uses +# pre-commit to call codespell, because it allows us to control the codespell +# version that is used. + +# Exit on error. +set -e + +# Initialize temporary file names. +cfg="" +output="" + +cleanup() +{ + for f in "$cfg" "$output"; do + if [ "$f" != "" ]; then + rm -f "$f" + fi + done +} + +# Schedule cleanup. +trap cleanup EXIT + +# Create temporary files. +cfg=$(mktemp) +output=$(mktemp) + +gen_cfg () +{ + cat > "$1" <<EOF +repos: +- repo: https://github.com/codespell-project/codespell + rev: v2.4.1 + hooks: + - id: codespell + name: codespell-log-internal + stages: [manual] + args: [--config, gdb/contrib/setup.cfg] +EOF +} + +# Generate pre-commit configuration file. +gen_cfg "$cfg" + +# Setup pre-commit command to run. +cmd=(pre-commit \ + run \ + -c "$cfg" \ + codespell \ + --hook-stage manual \ + --files "$@") + +# Run pre-commit command. +if "${cmd[@]}" \ + > "$output" \ + 2>&1; then + # Command succeeded quietly, we're done. + exit 0 +fi + +# Command failed quietly, now show the output. +# +# Simply doing "cat $output" doesn't produce colored output, so we just +# run the command again, that should be fast enough. +# +# Ignore codespell exit status. +"${cmd[@]}" || true diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 5683291..6eda19b 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -99,6 +99,15 @@ struct dwarf2_cu void add_dependence (dwarf2_per_cu *ref_per_cu) { m_dependencies.emplace (ref_per_cu); } + /* Find the DIE at section offset SECT_OFF. + + Return nullptr if not found. */ + die_info *find_die (sect_offset sect_off) const + { + auto it = die_hash.find (sect_off); + return it != die_hash.end () ? *it : nullptr; + } + /* The header of the compilation unit. */ struct comp_unit_head header; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2523ca8..6b7f2c7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18260,8 +18260,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz, *ref_cu = target_cu; - auto it = target_cu->die_hash.find (sect_off); - return it != target_cu->die_hash.end () ? *it : nullptr; + return target_cu->find_die (sect_off); } /* Follow reference attribute ATTR of SRC_DIE. @@ -18629,8 +18628,8 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, gdb_assert (sig_cu != NULL); gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0); - if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section); - die_it != sig_cu->die_hash.end ()) + if (die_info *die = sig_cu->find_die (sig_type->type_offset_in_section); + die != nullptr) { /* For .gdb_index version 7 keep track of included TUs. http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ @@ -18639,7 +18638,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, (*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu); *ref_cu = sig_cu; - return *die_it; + return die; } return NULL; diff --git a/gdb/solib.c b/gdb/solib.c index 5c5cfbd..85ec6bb 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1230,7 +1230,7 @@ info_linker_namespace_command (const char *pattern, int from_tty) break; } uiout->message - (_ ("There are %ld libraries loaded in linker namespace [[%d]]\n"), + (_ ("There are %zu libraries loaded in linker namespace [[%d]]\n"), solibs_to_print.size (), ns); uiout->message (_ ("Displaying libraries for linker namespace [[%d]]:\n"), ns); diff --git a/gdb/syscalls/riscv-canonicalize-syscall-gen.py b/gdb/syscalls/riscv-canonicalize-syscall-gen.py index 40039bb..c7dda93 100755 --- a/gdb/syscalls/riscv-canonicalize-syscall-gen.py +++ b/gdb/syscalls/riscv-canonicalize-syscall-gen.py @@ -111,7 +111,7 @@ class Generator: canon_syscalls[syscall_num] = value # this is a place for corner cases elif syscall_name == "mmap": - gdb_old_syscall_name = "gdb_sys_old_mmap" + gdb_old_syscall_name = "gdb_old_mmap" value = ( f" case {syscall_num}: return {gdb_old_syscall_name};\n" ) diff --git a/ld/emultempl/emulation.em b/ld/emultempl/emulation.em index 7fe821a..8ff71d6 100644 --- a/ld/emultempl/emulation.em +++ b/ld/emultempl/emulation.em @@ -36,6 +36,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = ${LDEMUL_EMIT_CTF_EARLY-NULL}, ${LDEMUL_ACQUIRE_STRINGS_FOR_CTF-NULL}, ${LDEMUL_NEW_DYNSYM_FOR_CTF-NULL}, - ${LDEMUL_PRINT_SYMBOL-NULL} + ${LDEMUL_PRINT_SYMBOL-NULL}, + ${LDEMUL_FIND_START_SYMBOL-NULL} }; EOF diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 50bb082..b522687 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -2448,6 +2448,55 @@ gld${EMULATION_NAME}_find_potential_libraries { return ldfile_open_file_search (name, entry, "", ".lib"); } + +static struct bfd_link_hash_entry * +gld${EMULATION_NAME}_find_alt_start_symbol + (struct bfd_sym_chain *entry) +{ +#if defined (TARGET_IS_i386pe) + bool entry_has_stdcall_suffix; +#endif + struct bfd_link_hash_entry *h; + size_t entry_name_len; + char *symbol_name; + const char *prefix; + const char *suffix; + + entry_name_len = strlen (entry->name); + + if (is_underscoring ()) + prefix = "_"; + else + prefix = ""; + +#if defined (TARGET_IS_i386pe) + if ((entry_name_len > 2 && entry->name[entry_name_len-2] == '@' && ISDIGIT (entry->name[entry_name_len-1])) + || (entry_name_len > 3 && entry->name[entry_name_len-3] == '@' && ISDIGIT (entry->name[entry_name_len-2]) && ISDIGIT (entry->name[entry_name_len-1])) + || (entry_name_len > 4 && entry->name[entry_name_len-4] == '@' && ISDIGIT (entry->name[entry_name_len-3]) && ISDIGIT (entry->name[entry_name_len-2]) && ISDIGIT (entry->name[entry_name_len-1]))) + entry_has_stdcall_suffix = true; + else + entry_has_stdcall_suffix = false; + + if (!entry_has_stdcall_suffix && (bfd_link_dll (&link_info) || dll)) + suffix = "@12"; + else if (!entry_has_stdcall_suffix && pe_subsystem == 1 /* NT kernel driver */) + suffix = "@8"; + else +#endif + suffix = ""; + + if (*prefix == '\0' && *suffix == '\0') + return NULL; + + symbol_name = xmalloc (entry_name_len + 5); + strcpy (symbol_name, prefix); + strcat (symbol_name, entry->name); + strcat (symbol_name, suffix); + + h = bfd_link_hash_lookup (link_info.hash, symbol_name, false, false, true); + free (symbol_name); + return h; +} static char * gld${EMULATION_NAME}_get_script (int *isfile) @@ -2526,5 +2575,6 @@ LDEMUL_UNRECOGNIZED_FILE=gld${EMULATION_NAME}_unrecognized_file LDEMUL_LIST_OPTIONS=gld${EMULATION_NAME}_list_options LDEMUL_RECOGNIZED_FILE=gld${EMULATION_NAME}_recognized_file LDEMUL_FIND_POTENTIAL_LIBRARIES=gld${EMULATION_NAME}_find_potential_libraries +LDEMUL_FIND_START_SYMBOL=gld${EMULATION_NAME}_find_alt_start_symbol source_em ${srcdir}/emultempl/emulation.em @@ -531,7 +531,9 @@ named @var{entry}, the linker will try to parse @var{entry} as a number, and use that as the entry address (the number will be interpreted in base 10; you may use a leading @samp{0x} for base 16, or a leading @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults -and other ways of specifying the entry point. +and other ways of specifying the entry point. For i386 PE, @var{entry} +can be also the original function name (without the leading underscore +and/or the trailing stdcall @samp{@@number} when applicable). @kindex --exclude-libs @item --exclude-libs @var{lib},@var{lib},... diff --git a/ld/ldemul.c b/ld/ldemul.c index dce0d38..35f91a2 100644 --- a/ld/ldemul.c +++ b/ld/ldemul.c @@ -35,6 +35,14 @@ static ld_emulation_xfer_type *ld_emulation; +struct bfd_link_hash_entry * +ldemul_find_alt_start_symbol (struct bfd_sym_chain *entry) +{ + if (ld_emulation->find_alt_start_symbol) + return ld_emulation->find_alt_start_symbol (entry); + return NULL; +} + void ldemul_hll (char *name) { diff --git a/ld/ldemul.h b/ld/ldemul.h index aa014ae..c58d4c2 100644 --- a/ld/ldemul.h +++ b/ld/ldemul.h @@ -115,9 +115,10 @@ extern void ldemul_acquire_strings_for_ctf (struct ctf_dict *, struct elf_strtab_hash *); extern void ldemul_new_dynsym_for_ctf (struct ctf_dict *, int symidx, struct elf_internal_sym *); - extern bool ldemul_print_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr); +extern struct bfd_link_hash_entry * ldemul_find_alt_start_symbol + (struct bfd_sym_chain *); typedef struct ld_emulation_xfer_struct { /* Run before parsing the command line and script file. @@ -259,6 +260,11 @@ typedef struct ld_emulation_xfer_struct { bool (*print_symbol) (struct bfd_link_hash_entry *hash_entry, void *ptr); + /* Called when ENTRY->name cannot be found by a direct lookup in INFO->hash. + Allows emulations to try variations of the name. */ + struct bfd_link_hash_entry * (*find_alt_start_symbol) + (struct bfd_sym_chain *entry); + } ld_emulation_xfer_type; typedef enum { diff --git a/ld/ldlang.c b/ld/ldlang.c index 97fdb91..e036817 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2486,11 +2486,18 @@ lang_map (void) } static bool +is_defined (struct bfd_link_hash_entry *h) +{ + return h != NULL + && (h->type == bfd_link_hash_defined + || h->type == bfd_link_hash_defweak); +} + +static bool sort_def_symbol (struct bfd_link_hash_entry *hash_entry, void *info ATTRIBUTE_UNUSED) { - if ((hash_entry->type == bfd_link_hash_defined - || hash_entry->type == bfd_link_hash_defweak) + if (is_defined (hash_entry) && hash_entry->u.def.section->owner != link_info.output_bfd && hash_entry->u.def.section->owner != NULL) { @@ -4184,9 +4191,7 @@ ldlang_check_require_defined_symbols (void) h = bfd_link_hash_lookup (link_info.hash, ptr->name, false, false, true); - if (h == NULL - || (h->type != bfd_link_hash_defined - && h->type != bfd_link_hash_defweak)) + if (! is_defined (h)) einfo(_("%X%P: required symbol `%s' not defined\n"), ptr->name); } } @@ -4892,9 +4897,7 @@ print_assignment (lang_assignment_statement_type *assignment, h = bfd_link_hash_lookup (link_info.hash, assignment->exp->assign.dst, false, false, true); - if (h != NULL - && (h->type == bfd_link_hash_defined - || h->type == bfd_link_hash_defweak)) + if (is_defined (h)) { value = h->u.def.value; value += h->u.def.section->output_section->vma; @@ -4939,8 +4942,7 @@ print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr) { asection *sec = (asection *) ptr; - if ((hash_entry->type == bfd_link_hash_defined - || hash_entry->type == bfd_link_hash_defweak) + if (is_defined (hash_entry) && sec == hash_entry->u.def.section) { print_spaces (SECTION_NAME_MAP_LENGTH); @@ -7234,9 +7236,7 @@ lang_end (void) { h = bfd_link_hash_lookup (link_info.hash, sym->name, false, false, false); - if (h != NULL - && (h->type == bfd_link_hash_defined - || h->type == bfd_link_hash_defweak) + if (is_defined (h) && !bfd_is_const_section (h->u.def.section)) break; } @@ -7255,9 +7255,11 @@ lang_end (void) h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name, false, false, true); - if (h != NULL - && (h->type == bfd_link_hash_defined - || h->type == bfd_link_hash_defweak) + + if (! is_defined (h) || h->u.def.section->output_section == NULL) + h = ldemul_find_alt_start_symbol (&entry_symbol); + + if (is_defined (h) && h->u.def.section->output_section != NULL) { bfd_vma val; diff --git a/sim/d10v/gencode.c b/sim/d10v/gencode.c index 3a37bac..763e2f5 100644 --- a/sim/d10v/gencode.c +++ b/sim/d10v/gencode.c @@ -150,5 +150,5 @@ write_opcodes (void) printf ("},\n"); } } - printf ("{ 0,0,0,0,0,0,0,(void (*)())0,0,{0,0,0}},\n};\n"); + printf ("{ 0,0,0,0,0,0,0,0,0,{0,0,0}},\n};\n"); } |