From patchwork Tue Nov 13 05:39:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 30130 Received: (qmail 62116 invoked by alias); 13 Nov 2018 05:39:09 -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 62095 invoked by uid 89); 13 Nov 2018 05:39:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:w22-v6s, a0, Hx-spam-relays-external:209.85.214.195, H*RU:209.85.214.195 X-HELO: mail-pl1-f195.google.com Received: from mail-pl1-f195.google.com (HELO mail-pl1-f195.google.com) (209.85.214.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 05:39:07 +0000 Received: by mail-pl1-f195.google.com with SMTP id w22-v6so5449627plk.0 for ; Mon, 12 Nov 2018 21:39:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lPvC/WsjmHTIr8/9wPyqjsbvie3QKkZP0R/TX/jPpmg=; b=gRmlbg8A19ESk91Dl4RA0u5bScWx67IlmAE4JH2B1tN4CEHmAsqHXnQPFTsSxeTXWU AD0WOiVk3UHkbgLOC3pEIsVSzL8Uf2fP7T88G3/3/oF1QeZPRrj4BomXseoxNV2qCaZn /nbZt5I3zqD7HAe5d3Od0u1vJo0kMD05yp+iXFTb8yZCD1+OagoPM/Dw0WKNd9SdWTIs f1MIPkt2AorSkMNRAfI+RCl8m+pEOrGBzxiuThrsnE24/WoWDkWXOKBZxaN36NXUBPCb mzYpFD1AltKWR3h+qJqWwT6fyw+dFLkGW1M1peUJVtaVoRb8g5tVMCSk1b20cnRZGh/q HF2A== Return-Path: Received: from rohan.hsd1.ca.comcast.net ([2601:646:c100:8240:b06e:359d:dfe4:197]) by smtp.gmail.com with ESMTPSA id i24-v6sm993035pfj.82.2018.11.12.21.39.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:39:05 -0800 (PST) From: Jim Wilson To: gdb-patches@sourceware.org Cc: andrew.burgess@embecosm.com, Jim Wilson Subject: [PATCH 3/3 v2] RISC-V: Fix unnamed arg alignment in registers. Date: Mon, 12 Nov 2018 21:39:01 -0800 Message-Id: <20181113053901.5109-1-jimw@sifive.com> In-Reply-To: References: For riscv64-linux target, second half of fix for FAIL: gdb.base/gnu_vector.exp: call add_various_floatvecs Unnamed arguments with 2*XLEN alignment are passed in aligned register pairs. gdb/ * riscv-tdep.c (struct riscv_arg_info): New field is_unnamed. (riscv_call_arg_scalar_int): If unnamed arg with twice xlen alignment, then increment next_regnum if odd. (riscv_arg_location): New arg is_unnamed. Set ainfo->is_unnamed. (riscv_push_dummy_call): New local ftype. Call check_typedef to set function type. Pass new arg to riscv_arg_location based on function type. (riscv_return_value): Pass new arg to riscv_arg_location. --- gdb/riscv-tdep.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 58dca3b86e..6b2f977efd 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -1737,6 +1737,9 @@ struct riscv_arg_info then this offset will be set to 0. */ int c_offset; } argloc[2]; + + /* TRUE if this is an unnamed argument. */ + bool is_unnamed; }; /* Information about a set of registers being used for passing arguments as @@ -1933,6 +1936,12 @@ riscv_call_arg_scalar_int (struct riscv_arg_info *ainfo, int len = std::min (ainfo->length, cinfo->xlen); int align = std::max (ainfo->align, cinfo->xlen); + /* Unnamed arguments in registers that require 2*XLEN alignment are + passed in an aligned register pair. */ + if (ainfo->is_unnamed && (align == cinfo->xlen * 2) + && cinfo->int_regs.next_regnum & 1) + cinfo->int_regs.next_regnum++; + if (!riscv_assign_reg_location (&ainfo->argloc[0], &cinfo->int_regs, len, 0)) riscv_assign_stack_location (&ainfo->argloc[0], @@ -2213,7 +2222,9 @@ riscv_call_arg_struct (struct riscv_arg_info *ainfo, selected from CINFO which holds information about what call argument locations are available for use next. The TYPE is the type of the argument being passed, this information is recorded into AINFO (along - with some additional information derived from the type). + with some additional information derived from the type). IS_UNNAMED + is true if this is an unnamed (stdarg) argument, this info is also + recorded into AINFO. After assigning a location to AINFO, CINFO will have been updated. */ @@ -2221,11 +2232,12 @@ static void riscv_arg_location (struct gdbarch *gdbarch, struct riscv_arg_info *ainfo, struct riscv_call_info *cinfo, - struct type *type) + struct type *type, bool is_unnamed) { ainfo->type = type; ainfo->length = TYPE_LENGTH (ainfo->type); ainfo->align = riscv_type_alignment (ainfo->type); + ainfo->is_unnamed = is_unnamed; ainfo->contents = nullptr; switch (TYPE_CODE (ainfo->type)) @@ -2374,6 +2386,11 @@ riscv_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR osp = sp; + struct type *ftype = check_typedef (value_type (function)); + + if (TYPE_CODE (ftype) == TYPE_CODE_PTR) + ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); + /* We'll use register $a0 if we're returning a struct. */ if (struct_return) ++call_info.int_regs.next_regnum; @@ -2387,7 +2404,8 @@ riscv_push_dummy_call (struct gdbarch *gdbarch, arg_value = args[i]; arg_type = check_typedef (value_type (arg_value)); - riscv_arg_location (gdbarch, info, &call_info, arg_type); + riscv_arg_location (gdbarch, info, &call_info, arg_type, + TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype)); if (info->type != arg_type) arg_value = value_cast (info->type, arg_value); @@ -2564,7 +2582,7 @@ riscv_return_value (struct gdbarch *gdbarch, struct type *arg_type; arg_type = check_typedef (type); - riscv_arg_location (gdbarch, &info, &call_info, arg_type); + riscv_arg_location (gdbarch, &info, &call_info, arg_type, false); if (riscv_debug_infcall > 0) {