diff options
28 files changed, 898 insertions, 39 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b0964f5..155b261 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,7 +62,7 @@ repos: files: '^gdb/(gdb-gdb\.py\.in|[^/]+\.py|python/.+\.py|testsuite/[^/]+\.py)$' args: [--config, gdb/setup.cfg] - repo: https://github.com/pycqa/isort - rev: 6.1.0 + rev: 7.0.0 hooks: - id: isort types_or: [file] @@ -89,6 +89,14 @@ repos: verbose: true always_run: true stages: [commit-msg] + - id: check-gnu-style + name: check-gnu-style + language: script + entry: gdb/contrib/check-gnu-style-pre-commit.sh + files: '^(gdb(support|server)?)/.*\.(c|h|cc)$' + exclude: '.*/testsuite/.*' + verbose: true + stages: [pre-commit] - repo: https://github.com/nmoroze/tclint rev: v0.6.1 hooks: diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index 56c613d..0d04663 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -2059,6 +2059,7 @@ elf_s390_relocate_section (bfd *output_bfd, int tls_type; asection *base_got = htab->elf.sgot; bool resolved_to_zero; + bool relax; r_type = ELF32_R_TYPE (rel->r_info); if (r_type == (int) R_390_GNU_VTINHERIT @@ -2154,6 +2155,11 @@ elf_s390_relocate_section (bfd *output_bfd, resolved_to_zero = (h != NULL && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); + /* Rewrite instructions and related relocations if (1) relaxation + disabled by default, (2) enabled by target, or (3) enabled by + user. Suppress rewriting if linker option --no-relax is used. */ + relax = info->disable_target_specific_optimizations <= 1; + switch (r_type) { case R_390_GOTPLT12: @@ -2261,8 +2267,9 @@ elf_s390_relocate_section (bfd *output_bfd, h->got.offset |= 1; } - if ((h->def_regular - && SYMBOL_REFERENCES_LOCAL (info, h)) + if (relax + && h->def_regular + && SYMBOL_REFERENCES_LOCAL (info, h) /* lrl rx,sym@GOTENT -> larl rx, sym */ && ((r_type == R_390_GOTENT && (bfd_get_16 (input_bfd, @@ -2282,6 +2289,7 @@ elf_s390_relocate_section (bfd *output_bfd, bfd_put_16 (output_bfd, new_insn, contents + rel->r_offset - 2); r_type = R_390_PC32DBL; + rel->r_info = ELF32_R_INFO (r_symndx, r_type); rel->r_addend = 2; howto = elf_howto_table + r_type; relocation = h->root.u.def.value diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index 555395c..16daf98 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -2296,6 +2296,7 @@ elf_s390_relocate_section (bfd *output_bfd, bfd_reloc_status_type r; int tls_type; bool resolved_to_zero; + bool relax; r_type = ELF64_R_TYPE (rel->r_info); if (r_type == (int) R_390_GNU_VTINHERIT @@ -2395,6 +2396,11 @@ elf_s390_relocate_section (bfd *output_bfd, resolved_to_zero = (h != NULL && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); + /* Rewrite instructions and related relocations if (1) relaxation + disabled by default, (2) enabled by target, or (3) enabled by + user. Suppress rewriting if linker option --no-relax is used. */ + relax = info->disable_target_specific_optimizations <= 1; + switch (r_type) { case R_390_GOTPLT12: @@ -2517,7 +2523,8 @@ elf_s390_relocate_section (bfd *output_bfd, reference using larl we have to make sure that the symbol is 1. properly aligned and 2. it is no ABS symbol or will become one. */ - if (h->def_regular + if (relax + && h->def_regular && SYMBOL_REFERENCES_LOCAL (info, h) /* lgrl rx,sym@GOTENT -> larl rx, sym */ && ((r_type == R_390_GOTENT @@ -2545,6 +2552,7 @@ elf_s390_relocate_section (bfd *output_bfd, bfd_put_16 (output_bfd, new_insn, contents + rel->r_offset - 2); r_type = R_390_PC32DBL; + rel->r_info = ELF64_R_INFO (r_symndx, r_type); rel->r_addend = 2; howto = elf_howto_table + r_type; relocation = h->root.u.def.value @@ -2666,7 +2674,8 @@ elf_s390_relocate_section (bfd *output_bfd, either a load address of 0 or a trapping insn. This prevents the PLT32DBL relocation from overflowing in case the binary will be loaded at 4GB or more. */ - if (h->root.type == bfd_link_hash_undefweak + if (relax + && h->root.type == bfd_link_hash_undefweak && !h->root.linker_def && (bfd_link_executable (info) || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) @@ -2685,6 +2694,8 @@ elf_s390_relocate_section (bfd *output_bfd, /* larl rX,<weak sym> -> lay rX,0(0) */ bfd_put_16 (output_bfd, 0xe300 | reg, insn_start); bfd_put_32 (output_bfd, 0x71, insn_start + 2); + rel->r_info = ELF64_R_INFO (0, R_390_NONE); + rel->r_addend = 0; continue; } /* Replace branch relative and save long (brasl) with a trap. */ @@ -2693,6 +2704,8 @@ elf_s390_relocate_section (bfd *output_bfd, /* brasl rX,<weak sym> -> jg .+2 (6-byte trap) */ bfd_put_16 (output_bfd, 0xc0f4, insn_start); bfd_put_32 (output_bfd, 0x1, insn_start + 2); + rel->r_info = ELF64_R_INFO (0, R_390_NONE); + rel->r_addend = 0; continue; } } @@ -2777,7 +2790,8 @@ elf_s390_relocate_section (bfd *output_bfd, either a load address of 0, a NOP, or a trapping insn. This prevents the PC32DBL relocation from overflowing in case the binary will be loaded at 4GB or more. */ - if (h != NULL + if (relax + && h != NULL && h->root.type == bfd_link_hash_undefweak && !h->root.linker_def && (bfd_link_executable (info) @@ -2797,6 +2811,8 @@ elf_s390_relocate_section (bfd *output_bfd, /* larl rX,<weak sym> -> lay rX,0(0) */ bfd_put_16 (output_bfd, 0xe300 | reg, insn_start); bfd_put_32 (output_bfd, 0x71, insn_start + 2); + rel->r_info = ELF64_R_INFO (0, R_390_NONE); + rel->r_addend = 0; continue; } /* Replace prefetch data relative long (pfdrl) with a NOP */ @@ -2805,6 +2821,8 @@ elf_s390_relocate_section (bfd *output_bfd, /* Emit a 6-byte NOP: jgnop . */ bfd_put_16 (output_bfd, 0xc004, insn_start); bfd_put_32 (output_bfd, 0x0, insn_start + 2); + rel->r_info = ELF64_R_INFO (0, R_390_NONE); + rel->r_addend = 0; continue; } /* Replace the following instructions with a trap: @@ -2822,6 +2840,8 @@ elf_s390_relocate_section (bfd *output_bfd, /* Emit a 6-byte trap: jg .+2 */ bfd_put_16 (output_bfd, 0xc0f4, insn_start); bfd_put_32 (output_bfd, 0x1, insn_start + 2); + rel->r_info = ELF64_R_INFO (0, R_390_NONE); + rel->r_addend = 0; continue; } } diff --git a/bfd/version.h b/bfd/version.h index 5f07afc..95d17a1 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 20251015 +#define BFD_VERSION_DATE 20251017 #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/contrib/check_GNU_style.py b/contrib/check_GNU_style.py new file mode 100755 index 0000000..b359bd8 --- /dev/null +++ b/contrib/check_GNU_style.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017-2025 Free Software Foundation, Inc. +# +# Checks some of the GNU style formatting rules in a set of patches. +# The script is a rewritten of the same bash script and should eventually +# replace the former script. +# +# This file is part of GCC. +# +# GCC 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, or (at your option) any later +# version. +# +# GCC 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 GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +import argparse +import sys +from check_GNU_style_lib import check_GNU_style_file + +def main(): + parser = argparse.ArgumentParser(description='Check GNU coding style.') + parser.add_argument('file', help = 'File with a patch') + parser.add_argument('-f', '--format', default = 'stdio', + help = 'Display format', + choices = ['stdio', 'quickfix']) + args = parser.parse_args() + filename = args.file + format = args.format + + if filename == '-': + check_GNU_style_file(sys.stdin, format) + else: + with open(filename, newline='\n') as diff_file: + check_GNU_style_file(diff_file, format) + +main() diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py new file mode 100755 index 0000000..8b930ef --- /dev/null +++ b/contrib/check_GNU_style_lib.py @@ -0,0 +1,326 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017-2025 Free Software Foundation, Inc. +# +# Checks some of the GNU style formatting rules in a set of patches. +# The script is a rewritten of the same bash script and should eventually +# replace the former script. +# +# This file is part of GCC. +# +# GCC 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, or (at your option) any later +# version. +# +# GCC 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 GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. +# +# The script requires python packages, which can be installed via pip3 +# like this: +# $ pip3 install unidiff termcolor + +import sys +import re +import unittest + +def import_pip3(*args): + missing=[] + for (module, names) in args: + try: + lib = __import__(module) + except ImportError: + missing.append(module) + continue + if not isinstance(names, list): + names=[names] + for name in names: + globals()[name]=getattr(lib, name) + if len(missing) > 0: + missing_and_sep = ' and '.join(missing) + missing_space_sep = ' '.join(missing) + print('%s %s missing (run: pip3 install %s)' + % (missing_and_sep, + ("module is" if len(missing) == 1 else "modules are"), + missing_space_sep)) + exit(3) + +import_pip3(('termcolor', 'colored'), + ('unidiff', 'PatchSet')) + +from itertools import * + +ws_char = 'â–ˆ' +ts = 8 + +def error_string(s): + return colored(s, 'red', attrs = ['bold']) + +class CheckError: + def __init__(self, filename, lineno, console_error, error_message, + column = -1): + self.filename = filename + self.lineno = lineno + self.console_error = console_error + self.error_message = error_message + self.column = column + + def error_location(self): + return '%s:%d:%d:' % (self.filename, self.lineno, + self.column if self.column != -1 else -1) + +class LineLengthCheck: + def __init__(self): + self.limit = 80 + self.expanded_tab = ' ' * ts + + def check(self, filename, lineno, line): + line_expanded = line.replace('\t', self.expanded_tab) + if len(line_expanded) > self.limit: + return CheckError(filename, lineno, + line_expanded[:self.limit] + + error_string(line_expanded[self.limit:]), + 'lines should not exceed 80 characters', self.limit) + + return None + +class SpacesCheck: + def __init__(self): + self.expanded_tab = ' ' * ts + + def check(self, filename, lineno, line): + i = line.find(self.expanded_tab) + if i != -1: + return CheckError(filename, lineno, + line.replace(self.expanded_tab, error_string(ws_char * ts)), + 'blocks of 8 spaces should be replaced with tabs', i) + +class SpacesAndTabsMixedCheck: + def __init__(self): + self.re = re.compile(r'\ \t') + + def check(self, filename, lineno, line): + stripped = line.lstrip() + start = line[:len(line) - len(stripped)] + if self.re.search(line): + return CheckError(filename, lineno, + error_string(start.replace('\t', ws_char * ts)) + line[len(start):], + 'a space should not precede a tab', 0) + +class TrailingWhitespaceCheck: + def __init__(self): + self.re = re.compile(r'(\s+)$') + + def check(self, filename, lineno, line): + assert(len(line) == 0 or line[-1] != '\n') + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(ws_char * len(m.group(1))) + + line[m.end(1):], + 'trailing whitespace', m.start(1)) + +class SentenceSeparatorCheck: + def __init__(self): + self.re = re.compile(r'\w\.(\s|\s{3,})\w') + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(ws_char * len(m.group(1))) + + line[m.end(1):], + 'dot, space, space, new sentence', m.start(1)) + +class SentenceEndOfCommentCheck: + def __init__(self): + self.re = re.compile(r'\w\.(\s{0,1}|\s{3,})\*/') + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(ws_char * len(m.group(1))) + + line[m.end(1):], + 'dot, space, space, end of comment', m.start(1)) + +class SentenceDotEndCheck: + def __init__(self): + self.re = re.compile(r'\w(\s*\*/)') + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):], + 'dot, space, space, end of comment', m.start(1)) + +class FunctionParenthesisCheck: + # TODO: filter out GTY stuff + def __init__(self): + self.re = re.compile(r'\w(\s{2,})?(\()') + + def check(self, filename, lineno, line): + if '#define' in line: + return None + + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(2)] + error_string(m.group(2)) + line[m.end(2):], + 'there should be exactly one space between function name ' \ + 'and parenthesis', m.start(2)) + +class SquareBracketCheck: + def __init__(self): + self.re = re.compile(r'\w\s+(\[)') + + def check(self, filename, lineno, line): + if filename.endswith('.md'): + return None + + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):], + 'there should be no space before a left square bracket', + m.start(1)) + +class ClosingParenthesisCheck: + def __init__(self): + self.re = re.compile(r'\S\s+(\))') + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):], + 'there should be no space before closing parenthesis', + m.start(1)) + +class BracesOnSeparateLineCheck: + # This will give false positives for C99 compound literals. + + def __init__(self): + self.re = re.compile(r'(\)|else)\s*({)') + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(2)] + error_string(m.group(2)) + line[m.end(2):], + 'braces should be on a separate line', m.start(2)) + +class TrailinigOperatorCheck: + def __init__(self): + regex = r'^\s.*(([^a-zA-Z_]\*)|([-%<=&|^?])|([^*]/)|([^:][+]))$' + self.re = re.compile(regex) + + def check(self, filename, lineno, line): + m = self.re.search(line) + if m != None: + return CheckError(filename, lineno, + line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):], + 'trailing operator', m.start(1)) + +class LineLengthTest(unittest.TestCase): + def setUp(self): + self.check = LineLengthCheck() + + def test_line_length_check_basic(self): + r = self.check.check('foo', 123, self.check.limit * 'a' + ' = 123;') + self.assertIsNotNone(r) + self.assertEqual('foo', r.filename) + self.assertEqual(80, r.column) + self.assertEqual(r.console_error, + self.check.limit * 'a' + error_string(' = 123;')) + +class TrailingWhitespaceTest(unittest.TestCase): + def setUp(self): + self.check = TrailingWhitespaceCheck() + + def test_trailing_whitespace_check_basic(self): + r = self.check.check('foo', 123, 'a = 123;') + self.assertIsNone(r) + r = self.check.check('foo', 123, 'a = 123; ') + self.assertIsNotNone(r) + r = self.check.check('foo', 123, 'a = 123;\t') + self.assertIsNotNone(r) + +class SpacesAndTabsMixedTest(unittest.TestCase): + def setUp(self): + self.check = SpacesAndTabsMixedCheck() + + def test_trailing_whitespace_check_basic(self): + r = self.check.check('foo', 123, ' \ta = 123;') + self.assertEqual('foo', r.filename) + self.assertEqual(0, r.column) + self.assertIsNotNone(r.console_error) + r = self.check.check('foo', 123, ' \t a = 123;') + self.assertIsNotNone(r.console_error) + r = self.check.check('foo', 123, '\t a = 123;') + self.assertIsNone(r) + +def check_GNU_style_file(file, format): + checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(), + SentenceSeparatorCheck(), SentenceEndOfCommentCheck(), + SentenceDotEndCheck(), FunctionParenthesisCheck(), + SquareBracketCheck(), ClosingParenthesisCheck(), + BracesOnSeparateLineCheck(), TrailinigOperatorCheck(), + SpacesAndTabsMixedCheck()] + errors = [] + + patch = PatchSet(file) + + for pfile in patch.added_files + patch.modified_files: + t = pfile.target_file + if t.startswith('b/'): + t = t[2:] + # Skip testsuite files + if 'testsuite' in t or t.endswith('.py'): + continue + + for hunk in pfile: + delta = 0 + for line in hunk: + if line.is_added and line.target_line_no != None: + for check in checks: + line_chomp = line.value.replace('\n', '') + e = check.check(t, line.target_line_no, line_chomp) + if e != None: + errors.append(e) + + if format == 'stdio': + fn = lambda x: x.error_message + i = 1 + for (k, errors) in groupby(sorted(errors, key = fn), fn): + errors = list(errors) + print('=== ERROR type #%d: %s (%d error(s)) ===' + % (i, k, len(errors))) + i += 1 + for e in errors: + print(e.error_location () + e.console_error) + print() + + exit(0 if len(errors) == 0 else 1) + elif format == 'quickfix': + f = 'errors.err' + with open(f, 'w+') as qf: + for e in errors: + qf.write('%s%s\n' % (e.error_location(), e.error_message)) + if len(errors) == 0: + exit(0) + else: + print('%d error(s) written to %s file.' % (len(errors), f)) + exit(1) + else: + assert False + +if __name__ == '__main__': + unittest.main() diff --git a/gdb/contrib/check-gnu-style-pre-commit.sh b/gdb/contrib/check-gnu-style-pre-commit.sh new file mode 100755 index 0000000..ab4b5e7 --- /dev/null +++ b/gdb/contrib/check-gnu-style-pre-commit.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# 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/>. + +set -e + +scriptdir=$(cd "$(dirname "$0")" || exit 1; pwd -P) + +tmp="" + +cleanup() +{ + if [ "$tmp" != "" ]; then + rm -f "$tmp" + fi +} + +# Schedule cleanup. +trap cleanup EXIT + +# Get temporary file. +tmp=$(mktemp) + +# Generate patch. +git diff --staged "$@" \ + > "$tmp" + +# Verify patch. Ignore exit status. +"$scriptdir"/../../contrib/check_GNU_style.py "$tmp" \ + || true diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 7cfb545..5d459da 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -165,7 +165,7 @@ inspect_type (struct demangle_parse_info *info, { const char *new_name = (*finder) (otype, data); - if (new_name != NULL) + if (new_name != nullptr && strcmp (new_name, name) != 0) { ret_comp->u.s_name.s = new_name; ret_comp->u.s_name.len = strlen (new_name); @@ -378,9 +378,10 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, struct demangle_component newobj; buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len); - newobj.type = DEMANGLE_COMPONENT_NAME; - newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); - newobj.u.s_name.len = buf.size (); + cplus_demangle_fill_name (&newobj, + obstack_strdup (&info->obstack, + buf.string ()), + buf.size ()); if (inspect_type (info, &newobj, finder, data)) { char *s; diff --git a/gdb/testsuite/gdb.cp/pretty-print.cc b/gdb/testsuite/gdb.cp/pretty-print.cc new file mode 100644 index 0000000..9065e15 --- /dev/null +++ b/gdb/testsuite/gdb.cp/pretty-print.cc @@ -0,0 +1,80 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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/>. */ + +namespace std +{ + +inline namespace __cxx11 {} + +template <typename> struct allocator {}; + +template <class> struct char_traits; + +inline namespace __cxx11 { + +template <typename _CharT, typename = char_traits<_CharT>, + typename = allocator<_CharT>> + +class basic_string; + +} // namespace __cx11 + +typedef basic_string<char> string; + +template <typename> struct allocator_traits; + +template <typename _Tp> struct allocator_traits<allocator<_Tp>> { + using pointer = _Tp *; +}; + +} // namespace std + +struct __alloc_traits : std::allocator_traits<std::allocator<char>> {}; + +namespace std +{ + +inline namespace __cxx11 +{ + +template <typename, typename, typename> struct basic_string +{ + typedef long size_type; + + size_type npos; + + struct _Alloc_hider + { + _Alloc_hider(__alloc_traits::pointer, const allocator<char> &); + } _M_dataplus; + + basic_string(char *, allocator<char> __a = allocator<char>()) + : _M_dataplus(0, __a) {} +}; + +} // namespace __cxx11 + +} // namespace std + +static char bar[] = "bar"; + +int +main (void) +{ + std::string foo = bar; + return 0; +} diff --git a/gdb/testsuite/gdb.cp/pretty-print.exp b/gdb/testsuite/gdb.cp/pretty-print.exp new file mode 100644 index 0000000..e1f0475 --- /dev/null +++ b/gdb/testsuite/gdb.cp/pretty-print.exp @@ -0,0 +1,53 @@ +# Copyright 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/>. + +# Print std::string::npos using c++ pretty-printer. Todo: convert this to a +# DWARF assembly test-case, such that the regression test also works for clang. + +standard_testfile .cc + +set opts {} +lappend opts debug +lappend opts c++ +if {[have_compile_flag -fno-eliminate-unused-debug-symbols]} { + lappend opts additional_flags=-fno-eliminate-unused-debug-symbols + # Work around clang warning -Wunused-command-line-argument. + lappend opts nowarnings +} + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} { + return +} + +gdb_test_no_output "source $srcdir/$subdir/pretty-print.py" \ + "load libstdc++ pretty printers" + +gdb_test_no_output \ + "python register_type_printers(gdb.current_objfile())" \ + "register libstdc++ pretty printers" + +gdb_test "whatis std::string" \ + "std::string" + +# Regression test for PR c++/33480. GDB used to hang, at least if the GDB +# build optimization flags triggered some uninitialized variables in the right +# way. I was not able to reproduce the hang with clang, due to different +# debug info. +# +# Prints different strings due to different debug info: +# - std::string::size_type with gcc, and +# - size_type with clang +gdb_test "whatis std::string::npos" \ + "(std::string::)?size_type" diff --git a/gdb/testsuite/gdb.cp/pretty-print.py b/gdb/testsuite/gdb.cp/pretty-print.py new file mode 100644 index 0000000..6ee8d71 --- /dev/null +++ b/gdb/testsuite/gdb.cp/pretty-print.py @@ -0,0 +1,82 @@ +# Copyright (C) 2008-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/>. + +# Reduced copy of /usr/share/gcc-15/python/libstdcxx/v6/printers.py. + +import gdb +import gdb.printing +import gdb.types + + +class FilteringTypePrinter(object): + + def __init__(self, template, name, targ1=None): + self._template = template + self.name = name + self._targ1 = targ1 + self.enabled = True + + class _recognizer(object): + def __init__(self, template, name, targ1): + self._template = template + self.name = name + self._targ1 = targ1 + self._type_obj = None + + def recognize(self, type_obj): + if type_obj.tag is None: + return None + + if self._type_obj is None: + if self._targ1 is not None: + s = "{}<{}".format(self._template, self._targ1) + if not type_obj.tag.startswith(s): + return None + elif not type_obj.tag.startswith(self._template): + return None + + try: + self._type_obj = gdb.lookup_type(self.name).strip_typedefs() + except: + pass + + if self._type_obj is None: + return None + + t1 = gdb.types.get_basic_type(self._type_obj) + t2 = gdb.types.get_basic_type(type_obj) + if t1 == t2: + return self.name + + if self._template.split("::")[-1] == "basic_string": + s1 = self._type_obj.tag.replace("__cxx11::", "") + s2 = type_obj.tag.replace("__cxx11::", "") + if s1 == s2: + return self.name + + return None + + def instantiate(self): + return self._recognizer(self._template, self.name, self._targ1) + + +def add_one_type_printer(obj, template, name, targ1=None): + printer = FilteringTypePrinter("std::" + template, "std::" + name, targ1) + gdb.types.register_type_printer(obj, printer) + + +def register_type_printers(obj): + for ch in (("", "char"),): + add_one_type_printer(obj, "__cxx11::basic_string", ch[0] + "string", ch[1]) diff --git a/ld/testsuite/ld-s390/gotreloc_31-1.dd b/ld/testsuite/ld-s390/gotreloc_31-1a.dd index b1cf37c..52fb16a 100644 --- a/ld/testsuite/ld-s390/gotreloc_31-1.dd +++ b/ld/testsuite/ld-s390/gotreloc_31-1a.dd @@ -1,13 +1,20 @@ -tmpdir/gotreloc_31-1: file format elf32-s390 +tmpdir/gotreloc_31-1a: file format elf32-s390 Disassembly of section .text: .* <foo>: .*: c4 18 00 00 08 56 [ ]*lgrl %r1,11b4 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 .*: e3 10 c0 14 00 04 [ ]*lg %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar .*: c0 10 00 00 08 52 [ ]*larl %r1,11b8 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: 58 10 c0 14 [ ]*l %r1,20\(%r12\) +[ ]*.*: R_390_GOT12 bar .*: c0 10 00 00 08 4d [ ]*larl %r1,11b8 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c4 18 00 00 08 46 [ ]*lgrl %r1,11b0 <_GLOBAL_OFFSET_TABLE_\+0x10> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 .*: c4 18 00 00 08 41 [ ]*lgrl %r1,11ac <_GLOBAL_OFFSET_TABLE_\+0xc> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_31-1b.dd b/ld/testsuite/ld-s390/gotreloc_31-1b.dd new file mode 100644 index 0000000..9513e16 --- /dev/null +++ b/ld/testsuite/ld-s390/gotreloc_31-1b.dd @@ -0,0 +1,20 @@ + +tmpdir/gotreloc_31-1b: file format elf32-s390 + +Disassembly of section .text: + +.* <foo>: +.*: c4 18 00 00 08 56 [ ]*lgrl %r1,11b4 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: e3 10 c0 14 00 04 [ ]*lg %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 1d 00 00 08 50 [ ]*lrl %r1,11b4 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: 58 10 c0 14 [ ]*l %r1,20\(%r12\) +[ ]*.*: R_390_GOT12 bar +.*: e3 10 c0 14 00 58 [ ]*ly %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 18 00 00 08 46 [ ]*lgrl %r1,11b0 <_GLOBAL_OFFSET_TABLE_\+0x10> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 +.*: c4 18 00 00 08 41 [ ]*lgrl %r1,11ac <_GLOBAL_OFFSET_TABLE_\+0xc> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1a.dd index 2e0d2cd..57bc3bc 100644 --- a/ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd +++ b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1a.dd @@ -1,13 +1,20 @@ -tmpdir/gotreloc_31-1: file format elf32-s390 +tmpdir/gotreloc_31-1a: file format elf32-s390 Disassembly of section .text: .* <foo>: .*: c4 18 00 00 08 1e [ ]*lgrl %r1,4010b0 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 .*: e3 10 c0 14 00 04 [ ]*lg %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar .*: c0 10 00 00 08 1a [ ]*larl %r1,4010b4 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: 58 10 c0 14 [ ]*l %r1,20\(%r12\) +[ ]*.*: R_390_GOT12 bar .*: c0 10 00 00 08 15 [ ]*larl %r1,4010b4 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c4 18 00 00 08 0e [ ]*lgrl %r1,4010ac <_GLOBAL_OFFSET_TABLE_\+0x10> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 .*: c4 18 00 00 08 09 [ ]*lgrl %r1,4010a8 <_GLOBAL_OFFSET_TABLE_\+0xc> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_31-no-pie-1b.dd b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1b.dd new file mode 100644 index 0000000..5688e47 --- /dev/null +++ b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1b.dd @@ -0,0 +1,20 @@ + +tmpdir/gotreloc_31-1b: file format elf32-s390 + +Disassembly of section .text: + +.* <foo>: +.*: c4 18 00 00 08 1e [ ]*lgrl %r1,4010b0 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: e3 10 c0 14 00 04 [ ]*lg %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 1d 00 00 08 18 [ ]*lrl %r1,4010b0 <_GLOBAL_OFFSET_TABLE_\+0x14> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: 58 10 c0 14 [ ]*l %r1,20\(%r12\) +[ ]*.*: R_390_GOT12 bar +.*: e3 10 c0 14 00 58 [ ]*ly %r1,20\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 18 00 00 08 0e [ ]*lgrl %r1,4010ac <_GLOBAL_OFFSET_TABLE_\+0x10> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 +.*: c4 18 00 00 08 09 [ ]*lgrl %r1,4010a8 <_GLOBAL_OFFSET_TABLE_\+0xc> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1a.dd index 751b7a8..cef446d 100644 --- a/ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd +++ b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1a.dd @@ -1,12 +1,19 @@ -tmpdir/gotreloc_64-1: file format elf64-s390 +tmpdir/gotreloc_64-1a: file format elf64-s390 Disassembly of section .text: .* <foo>: .*: c0 10 00 00 08 2c [ ]*larl %r1,1001108 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c0 10 00 00 08 29 [ ]*larl %r1,1001108 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c4 1d 00 00 08 22 [ ]*lrl %r1,1001100 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 .*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar .*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar .*: c4 18 00 00 08 16 [ ]*lgrl %r1,10010f8 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 .*: c4 18 00 00 08 0f [ ]*lgrl %r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-no-pie-1b.dd b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1b.dd new file mode 100644 index 0000000..344701c --- /dev/null +++ b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1b.dd @@ -0,0 +1,19 @@ +tmpdir/gotreloc_64-1b: file format elf64-s390 + +Disassembly of section .text: + +.* <foo>: +.*: c4 18 00 00 08 28 [ ]*lgrl %r1,1001100 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: e3 10 c0 28 00 04 [ ]*lg %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 1d 00 00 08 22 [ ]*lrl %r1,1001100 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar +.*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 18 00 00 08 16 [ ]*lgrl %r1,10010f8 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 +.*: c4 18 00 00 08 0f [ ]*lgrl %r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd b/ld/testsuite/ld-s390/gotreloc_64-norelro-1a.dd index 8debd97..4e6387d 100644 --- a/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd +++ b/ld/testsuite/ld-s390/gotreloc_64-norelro-1a.dd @@ -1,12 +1,19 @@ -tmpdir/gotreloc_64-1: file format elf64-s390 +tmpdir/gotreloc_64-1a: file format elf64-s390 Disassembly of section .text: .* <foo>: .*: c0 10 00 00 08 9c [ ]*larl %r1,12e8 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c0 10 00 00 08 99 [ ]*larl %r1,12e8 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c4 1d 00 00 08 92 [ ]*lrl %r1,12e0 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 .*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar .*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar .*: c4 18 00 00 08 86 [ ]*lgrl %r1,12d8 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 .*: c4 18 00 00 08 7f [ ]*lgrl %r1,12d0 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-norelro-1b.dd b/ld/testsuite/ld-s390/gotreloc_64-norelro-1b.dd new file mode 100644 index 0000000..2dc84f2 --- /dev/null +++ b/ld/testsuite/ld-s390/gotreloc_64-norelro-1b.dd @@ -0,0 +1,19 @@ +tmpdir/gotreloc_64-1b: file format elf64-s390 + +Disassembly of section .text: + +.* <foo>: +.*: c4 18 00 00 08 98 [ ]*lgrl %r1,12e0 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: e3 10 c0 28 00 04 [ ]*lg %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 1d 00 00 08 92 [ ]*lrl %r1,12e0 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar +.*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 18 00 00 08 86 [ ]*lgrl %r1,12d8 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 +.*: c4 18 00 00 08 7f [ ]*lgrl %r1,12d0 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd b/ld/testsuite/ld-s390/gotreloc_64-relro-1a.dd index 64151d1..6273c3f 100644 --- a/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd +++ b/ld/testsuite/ld-s390/gotreloc_64-relro-1a.dd @@ -1,12 +1,19 @@ -tmpdir/gotreloc_64-1: file format elf64-s390 +tmpdir/gotreloc_64-1a: file format elf64-s390 Disassembly of section .text: .* <foo>: .*: c0 10 00 00 0f 0c [ ]*larl %r1,2000 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c0 10 00 00 0f 09 [ ]*larl %r1,2000 <bar> +[ ]*.*: R_390_PC32DBL bar\+0x2 .*: c4 1d 00 00 0f 02 [ ]*lrl %r1,1ff8 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 .*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar .*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar .*: c4 18 00 00 0e f6 [ ]*lgrl %r1,1ff0 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 .*: c4 18 00 00 0e ef [ ]*lgrl %r1,1fe8 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/gotreloc_64-relro-1b.dd b/ld/testsuite/ld-s390/gotreloc_64-relro-1b.dd new file mode 100644 index 0000000..b8f7f20 --- /dev/null +++ b/ld/testsuite/ld-s390/gotreloc_64-relro-1b.dd @@ -0,0 +1,19 @@ +tmpdir/gotreloc_64-1b: file format elf64-s390 + +Disassembly of section .text: + +.* <foo>: +.*: c4 18 00 00 0f 08 [ ]*lgrl %r1,1ff8 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: e3 10 c0 28 00 04 [ ]*lg %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 1d 00 00 0f 02 [ ]*lrl %r1,1ff8 <_GLOBAL_OFFSET_TABLE_\+0x28> +[ ]*.*: R_390_GOTENT bar\+0x2 +.*: 58 10 c0 28 [ ]*l %r1,40\(%r12\) +[ ]*.*: R_390_GOT12 bar +.*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\) +[ ]*.*: R_390_GOT20 bar +.*: c4 18 00 00 0e f6 [ ]*lgrl %r1,1ff0 <_GLOBAL_OFFSET_TABLE_\+0x20> +[ ]*.*: R_390_GOTENT _GLOBAL_OFFSET_TABLE_\+0x2 +.*: c4 18 00 00 0e ef [ ]*lgrl %r1,1fe8 <_GLOBAL_OFFSET_TABLE_\+0x18> +[ ]*.*: R_390_GOTENT misaligned_sym\+0x2 diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp index 452811d..eaf74c4 100644 --- a/ld/testsuite/ld-s390/s390.exp +++ b/ld/testsuite/ld-s390/s390.exp @@ -50,15 +50,25 @@ set s390tests { {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}} "tlsbin"} {"GOT: symbol address load from got to larl" - "-shared -melf_s390 --hash-style=sysv --version-script=gotreloc-1.ver" "" + "-shared -melf_s390 --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs" "" "-m31" {gotreloc-1.s} - {{objdump -dzrj.text gotreloc_31-1.dd}} - "gotreloc_31-1"} + {{objdump -dzrj.text gotreloc_31-1a.dd}} + "gotreloc_31-1a"} + {"GOT: no symbol address load from got to larl (--no-relax)" + "-shared -melf_s390 --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs --no-relax" "" + "-m31" {gotreloc-1.s} + {{objdump -dzrj.text gotreloc_31-1b.dd}} + "gotreloc_31-1b"} {"GOT: no-pie symbol address load from got to larl" - "-shared -melf_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver" "" + "-shared -melf_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs" "" + "-m31" {gotreloc-1.s} + {{objdump -dzrj.text gotreloc_31-no-pie-1a.dd}} + "gotreloc_31-1a"} + {"GOT: no no-pie symbol address load from got to larl (--no-relax)" + "-shared -melf_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs --no-relax" "" "-m31" {gotreloc-1.s} - {{objdump -dzrj.text gotreloc_31-no-pie-1.dd}} - "gotreloc_31-1"} + {{objdump -dzrj.text gotreloc_31-no-pie-1b.dd}} + "gotreloc_31-1b"} {"Helper shared library (PLT test)" "-shared -m elf_s390" "" "-m31" {pltlib.s} {} @@ -88,31 +98,46 @@ set s390xtests { {objdump -sj.got tlsbin_64.sd} {objdump -sj.tdata tlsbin_64.td}} "tlsbin_64"} {"GOT: norelro symbol address load from got to larl" - "-shared -melf64_s390 -z norelro --hash-style=sysv --version-script=gotreloc-1.ver" "" + "-shared -melf64_s390 -z norelro --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs" "" + "-m64" {gotreloc-1.s} + {{objdump -dzrj.text gotreloc_64-norelro-1a.dd}} + "gotreloc_64-1a"} + {"GOT: no norelro symbol address load from got (--no-relax)" + "-shared -melf64_s390 -z norelro --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs --no-relax" "" "-m64" {gotreloc-1.s} - {{objdump -dzrj.text gotreloc_64-norelro-1.dd}} - "gotreloc_64-1"} + {{objdump -dzrj.text gotreloc_64-norelro-1b.dd}} + "gotreloc_64-1b"} {"GOT: relro symbol address load from got to larl" - "-shared -melf64_s390 -z relro --hash-style=sysv --version-script=gotreloc-1.ver" "" + "-shared -melf64_s390 -z relro --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs" "" "-m64" {gotreloc-1.s} - {{objdump -dzrj.text gotreloc_64-relro-1.dd}} - "gotreloc_64-1"} + {{objdump -dzrj.text gotreloc_64-relro-1a.dd}} + "gotreloc_64-1a"} + {"GOT: relro symbol address load from got (--no-relax)" + "-shared -melf64_s390 -z relro --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs --no-relax" "" + "-m64" {gotreloc-1.s} + {{objdump -dzrj.text gotreloc_64-relro-1b.dd}} + "gotreloc_64-1b"} {"GOT: no-pie symbol address load from got to larl" - "-shared -melf64_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver" "" + "-shared -melf64_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs" "" + "-m64" {gotreloc-1.s} + {{objdump -dzrj.text gotreloc_64-no-pie-1a.dd}} + "gotreloc_64-1a"} + {"GOT: no-pie symbol address load from got (--no-relax)" + "-shared -melf64_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver --emit-relocs --no-relax" "" "-m64" {gotreloc-1.s} - {{objdump -dzrj.text gotreloc_64-no-pie-1.dd}} - "gotreloc_64-1"} + {{objdump -dzrj.text gotreloc_64-no-pie-1b.dd}} + "gotreloc_64-1b"} {"PLT: offset test" "-shared -m elf64_s390 -dT pltoffset-1.ld --no-error-rwx-segments" "" "-m64" {pltoffset-1.s} {{objdump "-dzrj.text --stop-address=16" pltoffset-1.dd}} "pltoffset-1"} {"WEAKUNDEF1: overflow test (PC32DBL)" - "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments" "" "-m64" {weakundef-1.s} - {{objdump "-dzrj.text" weakundef-1.dd}} "weakundef-1"} + "-m elf64_s390 -dT 8GB.ld --emit-relocs --no-error-rwx-segments" "" "-m64" {weakundef-1.s} + {{objdump "-dzrj.text" weakundef-1a.dd}} "weakundef-1a"} {"WEAKUNDEF2: overflow test (PLT32DBL)" - "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments -no-pie" "" "-m64" {weakundef-2.s} - {{objdump "-dzrj.text" weakundef-2.dd}} "weakundef-2"} + "-m elf64_s390 -dT 8GB.ld --emit-relocs --no-error-rwx-segments -no-pie" "" "-m64" {weakundef-2.s} + {{objdump "-dzrj.text" weakundef-2a.dd}} "weakundef-2a"} {"Helper shared library (PLT test)" "-shared -m elf64_s390" "" "-m64" {pltlib.s} {} @@ -147,6 +172,9 @@ if { [istarget "s390-*-*"] || [istarget "s390x-*-*"] } { if [istarget "s390x-*-*"] { run_ld_link_tests $s390xtests + run_dump_test "weakundef-1b" + run_dump_test "weakundef-2b" + if { ![skip_sframe_tests] } { run_dump_test "sframe-simple-1" run_dump_test "sframe-plt-1" diff --git a/ld/testsuite/ld-s390/weakundef-1.dd b/ld/testsuite/ld-s390/weakundef-1a.dd index 04d53c9..49b6823 100644 --- a/ld/testsuite/ld-s390/weakundef-1.dd +++ b/ld/testsuite/ld-s390/weakundef-1a.dd @@ -1,15 +1,24 @@ -tmpdir/weakundef-1: file format elf64-s390 +tmpdir/weakundef-1a: file format elf64-s390 Disassembly of section .text: .* <foo>: .*: c0 10 00 00 00 1c [ ]*larl %r1,200000038 <d> +[ ]*.*: R_390_PC32DBL \.data\+0x2 .*: c0 10 00 00 00 1d [ ]*larl %r1,200000040 <wd> +[ ]*.*: R_390_PC32DBL wd\+0x2 .*: e3 10 00 00 00 71 [ ]*lay %r1,0 +[ ]*.*: R_390_NONE \*ABS\* .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* .*: c0 04 00 00 00 00 [ ]*jgnop .* +[ ]*.*: R_390_NONE \*ABS\* .*: 07 07 [ ]*nopr %r7 diff --git a/ld/testsuite/ld-s390/weakundef-1b.d b/ld/testsuite/ld-s390/weakundef-1b.d new file mode 100644 index 0000000..3cba83d --- /dev/null +++ b/ld/testsuite/ld-s390/weakundef-1b.d @@ -0,0 +1,12 @@ +#source: weakundef-1.s +#as: -m64 +#ld: -m elf64_s390 -dT 8GB.ld --emit-relocs --no-error-rwx-segments --no-relax +#objdump: -dzrj.text +#error: tmpdir/weakundef-1.o: in function `foo':\n +#error: \(\.text\+0xe\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x14\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x1a\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x20\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x26\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x2c\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x32\): relocation truncated to fit: R_390_PC32DBL against undefined symbol `wu'\n? diff --git a/ld/testsuite/ld-s390/weakundef-2.dd b/ld/testsuite/ld-s390/weakundef-2a.dd index e7f0e22..08e1824 100644 --- a/ld/testsuite/ld-s390/weakundef-2.dd +++ b/ld/testsuite/ld-s390/weakundef-2a.dd @@ -1,14 +1,20 @@ -tmpdir/weakundef-2: file format elf64-s390 +tmpdir/weakundef-2a: file format elf64-s390 Disassembly of section .text: 0+200000000 <foo>: .*: c0 10 00 00 00 12 [ ]*larl %r1,200000024 <d> +[ ]*.*: R_390_PLT32DBL d\+0x2 .*: c0 10 00 00 00 10 [ ]*larl %r1,200000026 <wd> +[ ]*.*: R_390_PLT32DBL wd\+0x2 .*: e3 10 00 00 00 71 [ ]*lay %r1,0 +[ ]*.*: R_390_NONE \*ABS\* .*: c0 e5 00 00 00 09 [ ]*brasl %r14,200000024 <d> +[ ]*.*: R_390_PLT32DBL d\+0x2 .*: c0 e5 00 00 00 07 [ ]*brasl %r14,200000026 <wd> +[ ]*.*: R_390_PLT32DBL wd\+0x2 .*: c0 f4 00 00 00 01 [ ]*jg .* +[ ]*.*: R_390_NONE \*ABS\* 0+200000024 <d>: .*: 07 fe [ ]*br %r14 diff --git a/ld/testsuite/ld-s390/weakundef-2b.d b/ld/testsuite/ld-s390/weakundef-2b.d new file mode 100644 index 0000000..b61f49d --- /dev/null +++ b/ld/testsuite/ld-s390/weakundef-2b.d @@ -0,0 +1,7 @@ +#source: weakundef-2.s +#as: -m64 +#ld: -m elf64_s390 -dT 8GB.ld --no-pie --emit-relocs --no-error-rwx-segments --no-relax +#objdump: -dzrj.text +#error: tmpdir/weakundef-2.o: in function `foo':\n +#error: \(\.text\+0xe\): relocation truncated to fit: R_390_PLT32DBL against undefined symbol `wu'\n? +#error: \(\.text\+0x20\): relocation truncated to fit: R_390_PLT32DBL against undefined symbol `wu'\n? diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp index 7175e14..da44396 100644 --- a/libctf/testsuite/lib/ctf-lib.exp +++ b/libctf/testsuite/lib/ctf-lib.exp @@ -298,7 +298,7 @@ proc run_lookup_test { name } { } if { $opts(link) == "objects" } { - set obj "[file rootname $src].o" + set obj "tmpdir/[file rootname [file tail $src]].o" set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags $src -c -o $obj"]] if { $comp_output != ""} { diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 9d20f2e..65f2c6c 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -290,7 +290,7 @@ sframe_fre_start_addr_size (uint32_t fre_type) /* Check if the FREP has valid data. */ static bool -sframe_fre_sanity_check_p (sframe_frame_row_entry *frep) +sframe_fre_sanity_check_p (const sframe_frame_row_entry *frep) { uint8_t offset_size, offset_cnt; uint8_t fre_info; |