From patchwork Wed Jan 16 15:57:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 31074 Received: (qmail 104811 invoked by alias); 16 Jan 2019 15:57:50 -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 104684 invoked by uid 89); 16 Jan 2019 15:57:49 -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_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=807, containing X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr140059.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.107.14.59) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Jan 2019 15:57:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WSKwFUvnMGc/2WUH2xBu/yi2Qh63KKUUBXjrTvytaW4=; b=gYspCJ5HO/2vVeqyKshw64tIo3cfcxjoEmCiGRpEAjYprA18Qgjd1NtkrWxRhZFKwuQtc65fb4jH7VNz33zeVHD8bMU8QclW8+jENVZaTs4OwtBEHv3wRBe/p0oeteuvXftgq7WqMgBBfExWj4bkERyABSVooJ+aapPFSf28a/s= Received: from AM4PR0802MB2129.eurprd08.prod.outlook.com (10.172.216.148) by AM4PR0802MB2306.eurprd08.prod.outlook.com (10.172.218.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Wed, 16 Jan 2019 15:57:44 +0000 Received: from AM4PR0802MB2129.eurprd08.prod.outlook.com ([fe80::5d0e:5d40:2f35:2aa3]) by AM4PR0802MB2129.eurprd08.prod.outlook.com ([fe80::5d0e:5d40:2f35:2aa3%9]) with mapi id 15.20.1537.018; Wed, 16 Jan 2019 15:57:44 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH 1/2] AArch64 AAPCS: Empty structs have non zero size in C++ Date: Wed, 16 Jan 2019 15:57:44 +0000 Message-ID: <20190116155734.53824-2-alan.hayward@arm.com> References: <20190116155734.53824-1-alan.hayward@arm.com> In-Reply-To: <20190116155734.53824-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) MIME-Version: 1.0 X-IsSubscribed: yes When gdb.base/infcall-nested-structs.c is complied as C++, the structs containing empty structs are no longer passed via float arguments. This is because structs in C++ have a minimum size of 1. This can then cause padding in the struct, which is disallowed for AAPCS. Add padding checks to AArch64 and add C++ compile variant to the test. gdb/ChangeLog: 2019-01-16 Alan Hayward * aarch64-tdep.c (aapcs_is_vfp_call_or_return_candidate_1): Check for padding. gdb/testsuite/ChangeLog: 2019-01-16 Alan Hayward * gdb.base/infcall-nested-structs.exp: Test C++ in addition to C. --- gdb/aarch64-tdep.c | 8 ++++ .../gdb.base/infcall-nested-structs.exp | 42 +++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 407adc8a42..ff6ca5c6e0 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -1392,6 +1392,14 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type, return -1; count += sub_count; } + + /* Ensure there is no padding between the fields (allowing for empty + zero length structs) */ + int ftype_length = (*fundamental_type == nullptr) + ? 0 : TYPE_LENGTH (*fundamental_type); + if (count * ftype_length != TYPE_LENGTH (type)) + return -1; + return count; } diff --git a/gdb/testsuite/gdb.base/infcall-nested-structs.exp b/gdb/testsuite/gdb.base/infcall-nested-structs.exp index b10e6d21eb..543702ac9a 100644 --- a/gdb/testsuite/gdb.base/infcall-nested-structs.exp +++ b/gdb/testsuite/gdb.base/infcall-nested-structs.exp @@ -24,6 +24,20 @@ if [target_info exists gdb,cannot_call_functions] { continue } +# Only test C++ if we are able. Always use C. +if { [skip_cplus_tests] || [get_compiler_info "c++"] } { + set lang {c} +} else { + set lang {c c++} +} + +foreach l $lang { + set dir "$l" + remote_exec build "rm -rf [standard_output_file ${dir}]" + remote_exec build "mkdir -p [standard_output_file ${dir}]" +} + + set int_types { tc ts ti tl tll } set float_types { tf td tld } set complex_types { tfc tdc tldc } @@ -44,7 +58,7 @@ proc I2A { n } { # types of the struct fields within the source. Run up to main. # Also updates the global "testfile" to reflect the most recent build. -proc start_nested_structs_test { types } { +proc start_nested_structs_test { lang types } { global testfile global srcfile global binfile @@ -53,9 +67,11 @@ proc start_nested_structs_test { types } { global compile_flags standard_testfile .c + set dir "$lang" # Create the additional flags set flags $compile_flags + lappend flags $lang for {set n 0} {$n<[llength ${types}]} {incr n} { set m [I2A ${n}] @@ -64,7 +80,7 @@ proc start_nested_structs_test { types } { append testfile "-" "$t" } - set binfile [standard_output_file ${testfile}] + set binfile [standard_output_file ${dir}/${testfile}] if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } { unresolved "failed to compile" return 0 @@ -125,48 +141,50 @@ proc run_tests {} { # Set up a test prefix, compile the test binary, run to main, and then # run some tests. -proc start_gdb_and_run_tests { types } { +proc start_gdb_and_run_tests { lang types } { set prefix "types" foreach t $types { append prefix "-" "${t}" } - with_test_prefix $prefix { - if { [start_nested_structs_test $types] } { - run_tests + foreach_with_prefix l $lang { + with_test_prefix $prefix { + if { [start_nested_structs_test $l $types] } { + run_tests + } } } } foreach ta $int_types { - start_gdb_and_run_tests $ta + start_gdb_and_run_tests $lang $ta } if [support_complex_tests] { foreach ta $complex_types { - start_gdb_and_run_tests $ta + start_gdb_and_run_tests $lang $ta } } if ![gdb_skip_float_test] { foreach ta $float_types { - start_gdb_and_run_tests $ta + start_gdb_and_run_tests $lang $ta } foreach ta $int_types { foreach tb $float_types { - start_gdb_and_run_tests [list $ta $tb] + start_gdb_and_run_tests $lang [list $ta $tb] } } foreach ta $float_types { foreach tb $int_types { - start_gdb_and_run_tests [list $ta $tb] + start_gdb_and_run_tests $lang [list $ta $tb] } foreach tb $float_types { - start_gdb_and_run_tests [list $ta $tb] + start_gdb_and_run_tests $lang [list $ta $tb] } } }