From patchwork Mon Sep 18 18:41:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 141514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2874257vqi; Mon, 18 Sep 2023 11:42:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiaEF/YjmHuIgWKm4dozA/2xVIRITWcGbLJSkJx33LzBE5kcpSIFMcxK2C1cDoA7DTslzf X-Received: by 2002:a2e:b953:0:b0:2bf:f985:7725 with SMTP id 19-20020a2eb953000000b002bff9857725mr4767449ljs.15.1695062555703; Mon, 18 Sep 2023 11:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695062555; cv=none; d=google.com; s=arc-20160816; b=vwnzBklislReiLBBADPbDtdVfUmItlVmZmAc/km8OOjLxxSQ3OqIHvmr0woD+f6Uq4 6L/EuORONjJ8X2LIyMslvE59CdyoU2bKo3Q6ixy/2DL/v7kQUuWFoKMc5Zi5OiF2wf2x VnlHYfq1flE2BmdJrIRtCpZP/f1TbGz9qgxq4e/FzBG6vN3EPVXw1FvnywTNWam809nH c985tuZnz4s4Ld8jU8oBJklg7siGc71ibjcLl+KnD3Qqx3g8BWxC2V/HlbpT805a6Nw2 0LnL9oNlEWlE0pKGhjPdxT4Fhak22CfcHThWAGrPeGFB5+Xl5VNGiwOeSAbKywDcFHyy iSBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vc3Cp3tWArd8YEe8L9PabtyebEk+6f95bIANCHShQ1s=; fh=hKkF4Qm4zMpuuPSvBuLljwLCLYziV8/JqYgl0gS1cUA=; b=iP1GB4q+q31sf56yomVrd8H73NntEuZ13/ho7Aa8nxj2x43LslVxxQOp5+oWBBoAG/ gW6YTVlAxlT0/DlQcxWHY5+EA8la6iutdtEVmmeqwJX/UUaadDzWzR9y+aRicDTx+di1 snVc5/Rwwcg+ZQubevePrDn00Sc7LhcqpNqU6DEDCUKrFkwRZ9FGh8x/weQ/EPW69w/6 4jDyG9Tep44CNcJ5heudBkZ0mCWs02WGE+r88KHWCD/BOoJYaHfRs+DDo6k+WGlvZNdK f2D8DAiUBvjpNoOVyS7FrHUOms1wQk4uezEFEbkkMPAU5fcdBcA3n9BXPtrbD/U1r0BA 9BuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=F8LTvWke; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb31-20020a1709077e9f00b009adc76a4fe4si8943673ejc.917.2023.09.18.11.42.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:42:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=F8LTvWke; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BB693857016 for ; Mon, 18 Sep 2023 18:42:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BB693857016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695062552; bh=vc3Cp3tWArd8YEe8L9PabtyebEk+6f95bIANCHShQ1s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=F8LTvWke9mhH4PoTIbnE2fuhN+4AOCpNQ5Q/teQXaiunSQqHO/5HiSecHBy2WAbcc fTADbotnaWHcDU3CzNaTnNwHLIGBpgQtljEgbhu0/b/fZ72g2Fvxg7pxJSehob3ip6 wlKRpvG47jZ8/hIB+jxNIiAU6WJ0IzPtWv61TfzA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 4DC39385700C for ; Mon, 18 Sep 2023 18:41:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DC39385700C Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3215f19a13aso796152f8f.3 for ; Mon, 18 Sep 2023 11:41:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695062507; x=1695667307; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vc3Cp3tWArd8YEe8L9PabtyebEk+6f95bIANCHShQ1s=; b=bYvJ4TbCzlPul5w1ACRBQ2kVAdF/fPhgG27il+yCG2jfld5/sCvsL7foQrxDhUvO4p 5kpti7nuo5UFDXQgXWDc3BFxclLoClwB9LgvJ1Hfein2AyqYVeKIKQIdBdBx4m2yEX+Q KqDlRISHDbKQDp58fqQKCfRTASzdw/2+begEr71a4wCDSMkK+JUlq+CVsgiWTY+4tL79 Yi/tfFoHVo77S+m0couyX1uPItTjvOWZk6jXYEi2WVkaaBwB5v07cZdBtGu0DVMRFp1J YBX9X/h7fv6lthdjWF4b0FBQalbAS10yqYNlTzuWHRQ900zUmcKRFcFhA0uBOcX8g5Lu 4bPA== X-Gm-Message-State: AOJu0YztPR/O1lKGXwMl4Bxbe91Tt8Alh7GsfztnbjrwT0ZHV0fMALCv YprVaCHqJ/9i5PYW8jQC13xjhvfVe4Q= X-Received: by 2002:adf:fb52:0:b0:313:fe1b:f441 with SMTP id c18-20020adffb52000000b00313fe1bf441mr8515378wrs.29.1695062506580; Mon, 18 Sep 2023 11:41:46 -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 q30-20020adfab1e000000b003177074f830sm11890075wrc.59.2023.09.18.11.41.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 11:41:46 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] Darwin, debug : Switch to DWARF 3 or 4 when dsymutil supports it. Date: Mon, 18 Sep 2023 19:41:44 +0100 Message-Id: <20230918184144.41108-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: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777401914367174882 X-GMAIL-MSGID: 1777401914367174882 Tested on i686, x86_64 and aarch64 Darwin, also on x86_64 and aarch64 Linux. Having said this, some fallout might well be expected on Darwin since the consumers have not had much use with GCC output where the DWARF version is > 2, we will have to tackle that as it arises. pushed to trunk, thanks, Iain --- 8< --- The main reason that Darwin has been using DWARF2 only as debug is that earlier debug linkers (dsymutil) did not support any extensions to this so that the default "non-strict" mode used in GCC would cause tool errors. There are two sources for dsymutil, those based off a closed source base "dwarfutils" and those based off LLVM. For dsymutil versions based off LLVM-7+ we can use up to DWARF-4, and for versions based on dwarfutils 121+ we can use DWARF-3. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin-protos.h (enum darwin_external_toolchain): New. * config/darwin.cc (DSYMUTIL_VERSION): New. (darwin_override_options): Choose the default debug DWARF version depending on the configured dsymutil version. --- gcc/config/darwin-protos.h | 11 +++++++++++ gcc/config/darwin.cc | 33 +++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index 747745fa577..9df358ee7d3 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -129,4 +129,15 @@ extern void darwin_patch_builtins (void); extern void darwin_rename_builtins (void); extern bool darwin_libc_has_function (enum function_class fn_class, tree); +/* For this port, there are several possible sources for external toolchain + components (e.g. as, ld, dsymutil) and we have to alter the allowable + output in response to which version and source is in use. */ +enum darwin_external_toolchain { + DET_UNKNOWN=0, + CCTOOLS, + DWARFUTILS, + LLVM, + CLANG +}; + #endif /* CONFIG_DARWIN_PROTOS_H */ diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc index 154a2b2755a..d8c8607892b 100644 --- a/gcc/config/darwin.cc +++ b/gcc/config/darwin.cc @@ -114,6 +114,19 @@ static bool ld_needs_eh_markers = false; /* Emit a section-start symbol for mod init and term sections. */ static bool ld_init_term_start_labels = false; +/* The source and version of dsymutil in use. */ +#ifndef DSYMUTIL_VERSION +# warning Darwin toolchain without a defined dsymutil. +# define DSYMUTIL_VERSION DET_UNKNOWN,0,0,0 +#endif + +struct { + darwin_external_toolchain kind; /* cctools, llvm, clang etc. */ + int major; /* version number. */ + int minor; + int tiny; +} dsymutil_version = {DSYMUTIL_VERSION}; + /* Section names. */ section * darwin_sections[NUM_DARWIN_SECTIONS]; @@ -3357,14 +3370,26 @@ darwin_override_options (void) global_options.x_flag_objc_abi); } - /* Don't emit DWARF3/4 unless specifically selected. This is a - workaround for tool bugs. */ + /* Limit DWARF to the chosen version, the linker and debug linker might not + be able to consume newer structures. */ if (!OPTION_SET_P (dwarf_strict)) dwarf_strict = 1; + if (!OPTION_SET_P (dwarf_version)) - dwarf_version = 2; + { + /* External toolchains based on LLVM or clang 7+ have support for + dwarf-4. */ + if ((dsymutil_version.kind == LLVM && dsymutil_version.major >= 7) + || (dsymutil_version.kind == CLANG && dsymutil_version.major >= 7)) + dwarf_version = 4; + else if (dsymutil_version.kind == DWARFUTILS + && dsymutil_version.major >= 121) + dwarf_version = 3; /* From XC 6.4. */ + else + dwarf_version = 2; /* Older cannot safely exceed dwarf-2. */ + } - if (OPTION_SET_P (dwarf_split_debug_info)) + if (OPTION_SET_P (dwarf_split_debug_info) && dwarf_split_debug_info) { inform (input_location, "%<-gsplit-dwarf%> is not supported on this platform, ignored");