From patchwork Fri Apr 12 23:25:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32274 Received: (qmail 40305 invoked by alias); 12 Apr 2019 23:25:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 40204 invoked by uid 89); 12 Apr 2019 23:25:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=PCS X-HELO: mail-wm1-f54.google.com Received: from mail-wm1-f54.google.com (HELO mail-wm1-f54.google.com) (209.85.128.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Apr 2019 23:25:44 +0000 Received: by mail-wm1-f54.google.com with SMTP id c1so13114370wml.4 for ; Fri, 12 Apr 2019 16:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4suWyyx0tlVs1Il7xt5rsoqPvnN0yZxeuF/HwIvrDy0=; b=ECgltEksDrHw+uYXDzC46QK+IkKY+zBpVw06H1ej9bw1lMAV/CnogU0Y4MCHMpNqF3 uYfX/sukXjA1ambualamXqdeex91j58WNLNm4H+h8Q/KOaBbUO8B/DJ1BB9/jqZQX1mU G5cZPh4zs3qVWPuBsl/jT357YH/R+oenwX2sLtPlx0fqRQ9itGN4Qb6lyumzvmkQY7r3 +5gcf6tzO2515e/zoT5zCszCm6Nz0bXoI2ZXgS0jTKkqNhdGYQB+Af+rEOiwVRP2sJOb 4XVANYCPkpO65IFZLduwolw83hzSBHwGyQyF4BTyl74Vm4VgbBVg2NFTQRAknlnEM/FM tLeg== Return-Path: Received: from localhost (host86-164-133-98.range86-164.btcentralplus.com. [86.164.133.98]) by smtp.gmail.com with ESMTPSA id h131sm15003059wmh.1.2019.04.12.16.25.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2019 16:25:40 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: alan.hayward@arm.com, Andrew Burgess Subject: [PATCH 1/3] gdb/aarch64: Use type_align instead of aarch64_type_align Date: Sat, 13 Apr 2019 00:25:32 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Replaces use of aarch64_type_align with common type_align function. Doing this fixes a bug in aarch64_type_align where static fields are considered as part of the alignment calculation of a struct, which results in arguments passed on the stack being misaligned. This bug is exposed in the new test gdb.cp/many-args.exp. Part of the old aarch64_type_align is retained and used as the gdbarch type align callback in order to correctly align vectors. gdb/ChangeLog: * aarch64-tdep.c (aarch64_type_align): Only handle vector override case. (pass_on_stack): Use type_align. (aarch64_gdbarch_init): Register aarch64_type_align gdbarch function. gdb/testsuite/ChangeLog: * gdb.cp/many-args.cc: New file. * gdb.cp/many-args.exp: New file. --- gdb/ChangeLog | 8 ++++ gdb/aarch64-tdep.c | 66 ++++++++------------------------- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.cp/many-args.cc | 76 ++++++++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.cp/many-args.exp | 37 +++++++++++++++++++ 5 files changed, 141 insertions(+), 51 deletions(-) create mode 100644 gdb/testsuite/gdb.cp/many-args.cc create mode 100644 gdb/testsuite/gdb.cp/many-args.exp diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 1b3977bfaf2..8e44442c33a 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -1218,62 +1218,25 @@ typedef struct DEF_VEC_O (stack_item_t); -/* Return the alignment (in bytes) of the given type. */ +/* Implement the gdbarch type alignment method, overrides the generic + alignment algorithm for anything that is aarch64 specific. */ -static int -aarch64_type_align (struct type *t) +static ULONGEST +aarch64_type_align (gdbarch *gdbarch, struct type *t) { - int n; - int align; - int falign; - t = check_typedef (t); - switch (TYPE_CODE (t)) + if (TYPE_CODE (t) == TYPE_CODE_ARRAY && TYPE_VECTOR (t)) { - default: - /* Should never happen. */ - internal_error (__FILE__, __LINE__, _("unknown type alignment")); - return 4; - - case TYPE_CODE_PTR: - case TYPE_CODE_ENUM: - case TYPE_CODE_INT: - case TYPE_CODE_FLT: - case TYPE_CODE_SET: - case TYPE_CODE_RANGE: - case TYPE_CODE_BITSTRING: - case TYPE_CODE_REF: - case TYPE_CODE_RVALUE_REF: - case TYPE_CODE_CHAR: - case TYPE_CODE_BOOL: - return TYPE_LENGTH (t); - - case TYPE_CODE_ARRAY: - if (TYPE_VECTOR (t)) - { - /* Use the natural alignment for vector types (the same for - scalar type), but the maximum alignment is 128-bit. */ - if (TYPE_LENGTH (t) > 16) - return 16; - else - return TYPE_LENGTH (t); - } + /* Use the natural alignment for vector types (the same for + scalar type), but the maximum alignment is 128-bit. */ + if (TYPE_LENGTH (t) > 16) + return 16; else - return aarch64_type_align (TYPE_TARGET_TYPE (t)); - case TYPE_CODE_COMPLEX: - return aarch64_type_align (TYPE_TARGET_TYPE (t)); - - case TYPE_CODE_STRUCT: - case TYPE_CODE_UNION: - align = 1; - for (n = 0; n < TYPE_NFIELDS (t); n++) - { - falign = aarch64_type_align (TYPE_FIELD_TYPE (t, n)); - if (falign > align) - align = falign; - } - return align; + return TYPE_LENGTH (t); } + + /* Allow the common code to calculate the alignment. */ + return 0; } /* Worker function for aapcs_is_vfp_call_or_return_candidate. @@ -1540,7 +1503,7 @@ pass_on_stack (struct aarch64_call_info *info, struct type *type, info->argnum++; - align = aarch64_type_align (type); + align = type_align (type); /* PCS C.17 Stack should be aligned to the larger of 8 bytes or the Natural alignment of the argument's type. */ @@ -3370,6 +3333,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_float_format (gdbarch, floatformats_ieee_single); set_gdbarch_double_format (gdbarch, floatformats_ieee_double); set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); + set_gdbarch_type_align (gdbarch, aarch64_type_align); /* Internal <-> external register number maps. */ set_gdbarch_dwarf2_reg_to_regnum (gdbarch, aarch64_dwarf_reg_to_regnum); diff --git a/gdb/testsuite/gdb.cp/many-args.cc b/gdb/testsuite/gdb.cp/many-args.cc new file mode 100644 index 00000000000..389a69ae32b --- /dev/null +++ b/gdb/testsuite/gdb.cp/many-args.cc @@ -0,0 +1,76 @@ +/* Copyright 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#include + +/* Vector type will align on a 16-byte boundary. */ +typedef int v4si __attribute__ ((vector_size (16))); + +struct ss +{ + static v4si static_field; + + unsigned char aa; + + bool operator== (const ss &rhs) + { + return (memcmp (&this->static_field, &rhs.static_field, + sizeof (this->static_field)) == 0 + && this->aa == rhs.aa); + } +}; + +v4si ss::static_field = { 1, 2, 3, 4 }; + +ss ref_val = { 'a' }; + +bool +check_val (ss v1, ss v2, ss v3, ss v4, ss v5, ss v6, ss v7, ss v8, + ss v9, ss v10, ss v11, ss v12, ss v13, ss v14, ss v15, + ss v16, ss v17, ss v18, ss v19, ss v20, ss v21, ss v22, + ss v23, ss v24, ss v25, ss v26, ss v27, ss v28, ss v29, + ss v30, ss v31, ss v32, ss v33, ss v34, ss v35, ss v36, + ss v37, ss v38, ss v39, ss v40) +{ + return (v1 == ref_val && v2 == ref_val && v3 == ref_val && v4 == ref_val + && v5 == ref_val && v6 == ref_val && v7 == ref_val + && v8 == ref_val && v9 == ref_val && v10 == ref_val + && v11 == ref_val && v12 == ref_val && v13 == ref_val + && v14 == ref_val && v15 == ref_val && v16 == ref_val + && v17 == ref_val && v18 == ref_val && v19 == ref_val + && v20 == ref_val && v21 == ref_val && v22 == ref_val + && v23 == ref_val && v24 == ref_val && v25 == ref_val + && v26 == ref_val && v27 == ref_val && v28 == ref_val + && v29 == ref_val && v30 == ref_val && v31 == ref_val + && v32 == ref_val && v33 == ref_val && v34 == ref_val + && v35 == ref_val && v36 == ref_val && v37 == ref_val + && v38 == ref_val && v39 == ref_val && v40 == ref_val); +} + +int +main () +{ + bool flag = check_val (ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val, + ref_val, ref_val, ref_val, ref_val, ref_val); + return (flag ? 0 : 1); /* break-here */ +} diff --git a/gdb/testsuite/gdb.cp/many-args.exp b/gdb/testsuite/gdb.cp/many-args.exp new file mode 100644 index 00000000000..57da1748397 --- /dev/null +++ b/gdb/testsuite/gdb.cp/many-args.exp @@ -0,0 +1,37 @@ +# Copyright 2019 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 . + +# This file is part of the gdb testsuite. +# It tests various aspects of iostream that have caused problems for gdb. + +if { [skip_cplus_tests] } { continue } + +standard_testfile .cc + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { + return -1 +} + +if ![runto_main] { + perror "couldn't run to breakpoint" + continue +} + +gdb_breakpoint [gdb_get_line_number "break-here"] +gdb_continue_to_breakpoint "break-here" + +gdb_test "p check_val (ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val, ref_val)" \ + "= true" \ + "check passing many structures"