From patchwork Thu Oct 26 19:23:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 158660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp116322vqb; Thu, 26 Oct 2023 12:23:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPcuKwgDNdiyrPcA0/avOCUmhCrwhBBwnGUzLjhS0EUPlzxT7nZePr0WFyYzAlhc/Hl/Ks X-Received: by 2002:ad4:5bab:0:b0:66f:ae60:8c51 with SMTP id 11-20020ad45bab000000b0066fae608c51mr750370qvq.11.1698348212878; Thu, 26 Oct 2023 12:23:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698348212; cv=pass; d=google.com; s=arc-20160816; b=LeK7C9knOgcFT6Ia1H1zSufA+QR6+jYedDEFO2oD7zYaTIYuhBjsWibK0T7+kZUj8x qavd6V0eaT0vZL1iYuf+S5j1X1rn5xWmvdP5tkAbsJoiHMJPFFI8jl/kvyDU6l72NVQ/ 1W4hG2mCJnXujunmElMhNfjkiWrjftx2aiCsTA2Xxi6s/nKEWrOc8GFhPUb3uAYhBB3g Q0XA6AK088qh/4sXISfXOtrjJAZnhzMxSQn5hBQ/9s2yvqfLY1gLkR/LFY4IezpA5NIb UXVGtsgEAYhbgYUCoa0kYOCBf+dv1XuTosTxJTMXg+lCQQYFcwr5wnb+bcABc4sb9g9H Epxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=y9JSjLqzlGCem2ZsXSuO/TmVpc/6ZticicpAYlRF4Dk=; fh=rGXkZtj57EMYOd6pvgovDtoafMKZXgySZJhxmToqW+g=; b=OweEcZQ6fVchm43FgvyYF3RKQBKgTWx+8RJ6/RdZHldCrBdiSkXx0K9EIzFrcrtH9s nuebeLqcCEJN+Pb/u/Yu5hgd9fOYqNp0/31nndjTOk/LcBiQMHHKaYeyKiBvSNcOKJoZ T2R8RlPTY6pOEc+Rql+DLc5NaFujgJfp8MYBJi2gIWNjfrHrE81oOls2ou4aRZJNnIEz 0IgevP9+V2Az22hZm7UkZY4WwYYRNADj+mb7vaYozPtDfN51j36qc9OyqJ9I86YsV+un NFbnod9ydyyYDppbbMWDsYqvItm9mGbcQz1XTMqiPO5SPVxe+xHWhRj+1JCoPptT214v 25Ww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OqRkCmOB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l4-20020a056214028400b0066d101766d5si51907qvv.569.2023.10.26.12.23.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 12:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OqRkCmOB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A44B03856DE2 for ; Thu, 26 Oct 2023 19:23:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 5F081385842C for ; Thu, 26 Oct 2023 19:23:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F081385842C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F081385842C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698348189; cv=none; b=XqLufqDaJQLHAla9zj0pCkbeF7xK/PkmonvKYAkSMHMesb/MijCxWAnPYCvvgQjgiukKggyfts3swL1sIFXsaitV+zwNUhHhlqOrBVSFQrpDrXz6RsdLNk/Lu7UYNXTdrmnY5Qp8DAArum8Ap1o4ha91ScOoc4PU6nYQ8EPtgyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698348189; c=relaxed/simple; bh=j3R1Z73xPaeB9tm6pw0HRnpPW+KGARX4FpRs5/WW+j4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=owfPJ+RxifsJxo+NKvnk/KfAKohdbuarVWbzxxZOWsLge13deReRryk+bGx8hncR2Z3tFfDBqKZqz2ChcNlBqJ4Svru0k0dGA5rf9Jkz2UcddU2LNTd/4Rtd/GjmZfGa1CfK3eYmCgotj4R3WPA6ipIumG+oRXmUCEC8VIKVqc4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4083740f92dso10184345e9.3 for ; Thu, 26 Oct 2023 12:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698348183; x=1698952983; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=y9JSjLqzlGCem2ZsXSuO/TmVpc/6ZticicpAYlRF4Dk=; b=OqRkCmOBY5oz0Z5ES2CgfhaDwGpsEMgN0RdqTCNyHMbDWoT6nGGTduoUEN/N5VESrR AjZ4cW+trkRZFObpNtO7voJ91svH3YCJyRCbk84RiWML1GFCj4UYGCJQ2Sd41DaFH20c I+HRhb4lXJV4IqmW4nF5LCNMTG5CkBl4Jf5waZPSAzZ9ar56O+KpsUCvkaSri0KPGR/n 3H2T+FkHaPIBjxgE8l19jWjYga0ysINceZiOfs6brbR/fcsEIKx+UsYrANiPs6Y1tliD PtK9GGHsdjwVssYeuWwmVdL0aUNVWzmqHWWoivIursXSbDUvBW+g4XeNnOTEmCW9Juik jDWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698348183; x=1698952983; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y9JSjLqzlGCem2ZsXSuO/TmVpc/6ZticicpAYlRF4Dk=; b=eqGmgLiwZG0Uv60QNOdZnQBB7ux3PfIBagSO1igXhvmSJ3hQzWxkkrq7bssuKdEWoE 0O/GDssTslVJJNUcWGJ5PiSaY0mSlwDSzGrW8p4h44bHCmO4fEwFiJYQyAJDdqgRBq1Z jS0d8cYZUoalkDwh3aJ4yWrqM5LoziTRTwfmzUla706oYoRITleYtnld2wbDeBnreShW xlIpqNAVcyMjCm6ilmCs12pw410uN81fhsVS8NA9HGPWaDGmg5Wy+lREJVcRcdeF4fxy JdNiXXyQhCfRZiu12CkI4gOnuUbvxyuAItR++3sJA8ZhQKXA0I76dK2lJrZ8eA5eixCl xrhQ== X-Gm-Message-State: AOJu0Yx42trhlbjoogF8PteswfZExBLJeWDTVB74KGGuvRgDfhb1BSBD uSLBiEUHEkrABfzMCTBtRyCs3RHhraY= X-Received: by 2002:adf:e881:0:b0:32d:7162:7ffe with SMTP id d1-20020adfe881000000b0032d71627ffemr427257wrm.69.1698348182555; Thu, 26 Oct 2023 12:23:02 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id x3-20020a5d54c3000000b0031f3ad17b2csm97943wrv.52.2023.10.26.12.23.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 26 Oct 2023 12:23:02 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, thomas@codesourcery.com Subject: [PATCH] testsuite, Darwin: Add support for Mach-O function body scans. Date: Thu, 26 Oct 2023 20:23:01 +0100 Message-Id: <20231026192301.58329-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780847175709821419 X-GMAIL-MSGID: 1780847175709821419 This was written before Thomas' modification to the ELF-handling to allow a config-based change for target details. I did consider updating this to try and use that scheme, but I think that it would sit a little awkwardly, since there are some differences in the start-up scanning for Mach-O. I would say that in all probability we could improve things but I'd like to put this forward as a well-tested initial implementation. It has been in use for more than 2 years on the aarch64 Darwin devt. branch. Tested also in configurations on x86_64-linux and aarch64-linux. Obviously, this is not aarch64-specific but that is out initial use-case. OK for trunk? thanks Iain --- 8< --- We need to process the source slightly differently from ELF, especially in that we have __USER_LABEL_PREFIX__ and there are no function start and end assembler directives. This means we cannot delineate functions when frame output is switched off. TODO: consider adding -mtest-markers or something similar to inject assembler comments that can be scanned for. gcc/testsuite/ChangeLog: * lib/scanasm.exp: Initial handling for Mach-O function body scans. Signed-off-by: Iain Sandoe --- gcc/testsuite/lib/scanasm.exp | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 5df80325dff..fab4b0669ec 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -851,6 +851,44 @@ proc parse_function_bodies { config filename result } { close $fd } +proc parse_MACHO_function_bodies { filename result } { + upvar $result up_result + + # Regexp for the start of a function definition (name in \1). + set label {^(_[a-zA-Z_]\S+):$} + set start {^LFB[0-9]+} + + # Regexp for the end of a function definition. + set terminator {^LFE[0-9]+} + + # Regexp for lines that aren't interesting. + set fluff {^\s*(?:\.|//|@)} + set fluff3 {^L[0-9ACESV]} + + set fd [open $filename r] + set in_function 0 + while { [gets $fd line] >= 0 } { + if { !$in_function && [regexp $label $line dummy function_name] } { + set in_function 1 + set function_body "" + } elseif { $in_function == 1 } { + if { [regexp $start $line] } { + set in_function 2 + } else { + set in_function 0 + } + } elseif { $in_function == 2 } { + if { [regexp $terminator $line] } { + set up_result($function_name) $function_body + set in_function 0 + } elseif { ![regexp $fluff $line] && ![regexp $fluff3 $line] } { + append function_body $line "\n" + } + } + } + close $fd +} + # FUNCTIONS is an array that maps function names to function bodies. # Return true if it contains a definition of function NAME and if # that definition matches BODY_REGEXP. @@ -883,6 +921,14 @@ proc check-function-bodies { args } { error "too many arguments to check-function-bodies" } + set isELF 1 + # some targets have a __USER_LABEL_PREFIX__ + set needsULP 0 + if { [istarget *-*-darwin*] } { + set isELF 0 + set needsULP 1 + } + if { [llength $args] >= 3 } { set required_flags [lindex $args 2] @@ -944,7 +990,11 @@ proc check-function-bodies { args } { remote_upload host "$filename" } if { [file exists $output_filename] } { - parse_function_bodies config $output_filename functions + if { $isELF } { + parse_function_bodies config $output_filename functions + } else { + parse_MACHO_function_bodies $output_filename functions + } set have_bodies 1 } else { verbose -log "$testcase: output file does not exist" @@ -988,6 +1038,9 @@ proc check-function-bodies { args } { if { $xfail_all || [string equal $selector "F"] } { setup_xfail "*-*-*" } + if { $needsULP } { + set function_name "_$function_name" + } set testname "$testcase check-function-bodies $function_name" if { !$have_bodies } { unresolved $testname