From patchwork Wed Apr 3 09:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 87957 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 260C13846402 for ; Wed, 3 Apr 2024 09:06:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id B3F413847700 for ; Wed, 3 Apr 2024 09:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3F413847700 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B3F413847700 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712135160; cv=none; b=YnEGHiAdFaBqeXYJFDiWxLKNTfnSKok6wNKrTFFxE8g21AovvLALY3xI7Qe77BFb5qU7rVDXBv76S4Arrd9f0VREgeHHo3wxYGj4NbFuQJ6whjSxiyEfwJYgtayp5NZ/u3wXk4Dvsb+zeAxoh94WZxvXuQs3ilbOUqKvFNvfJYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712135160; c=relaxed/simple; bh=ZFIJ6UGmgRZh28Igvo4DJvwkNxJiPiB7r4XuxuoD+yY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=dOL7vbP6Gx0dsbOn228CXHpy1Nac0jVsJoL0gcPwELvFg37NRCzce5JjC+MUaguywNflRGkhUfMrm02fb6BP3raGK2Z0YU3sL3dX7UkKUBXH6apobo2FbZcDT0zyvg2ZUmufsf38goY++5yjVXNueiSworiLG0DZVplvGerDU4I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d715638540so68432821fa.3 for ; Wed, 03 Apr 2024 02:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1712135156; x=1712739956; darn=gcc.gnu.org; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=EQIoyKnOAk5FEVDIJD9jTx0kx6DQsAW21Iz1C6fcy7I=; b=JU/gQRn9Ebk5z6H2TmJWCOBFdB84+1MXFNefRf4eE2OX4DOJObSZ6arMuvttQgJ+UG gA0U66WI49YyTc3KT14yUzlfiZKLO9Cp+sxcSdmzCxHzIDSJzHmU8HvSJfy7OEfeqRjB r3MyIeYlp+sIgsWR2USJeAya/S/7ACsDfjcEPZPdTc/MwKnFe7OLXktSQBwXt2Y4XOQT lGIrJfWgMdu/6DMFSEfU4CIk4A0odmJ4AmuUE9Vy//ajOt6FBlhUCRqONxVOq5JprfSx 2USv1eCy4DbDmCXFAy+ORf73s+pTaWBzRhbqXqY+iLB/F7+rj4+kMI61m3uyZqOSXLX9 3tcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712135156; x=1712739956; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EQIoyKnOAk5FEVDIJD9jTx0kx6DQsAW21Iz1C6fcy7I=; b=k1Kvxl8zYoJETens/7RmlxyMkyTrlN5PDz1Nc4/H+YZEuBU6m71pfYfTtDz+wqn9e8 n80SsH7Pm9+TrBzbbSXWKhjkmb9ZBaN89cxu3P5yiif1en2SRq+k8pCCz3JTgSAcTmL7 rSQOTA+wcRBrRSGbrHYn0FssLFjZ6ynCWRKP38wDV0FPDi9aSnZJhobXdOVqEkQLOizq E1cf/kUv7hjjs7M6BNStRDOwk0bZtJcP9rNm97dXLqynPGTP6+uHcGXuq4AtOQiPOufV a3bxcwAmmwDwffirpS7tavVHbxdWG081GEyizkpf3rsSeT2dKnnthryKeq1PwnzJTLyX GhEQ== X-Gm-Message-State: AOJu0Yzp3MQ30vF2yciIy6EhlAoxNoywl4FPAE47mp5ejJ1SdpxSALQa ih3O5JaSLeSkwNz6yMPXzbZnVDVnK/6YYujQ091/0wIb8tpYORXzHRjd7MIBg4k7QDeQVP999cN V X-Google-Smtp-Source: AGHT+IEmnDdPOL2XwwmHigJDt1H+W7xEJxGMK2F6Ug2B2hbyV3TGiH3JxQ2LOMKZSRKmlqUQaFaXZQ== X-Received: by 2002:a2e:9bd8:0:b0:2d8:319b:7d34 with SMTP id w24-20020a2e9bd8000000b002d8319b7d34mr2173598ljj.2.1712135156059; Wed, 03 Apr 2024 02:05:56 -0700 (PDT) Received: from ?IPV6:2001:16b8:2ad3:b600:23:e49d:37af:1a62? (200116b82ad3b6000023e49d37af1a62.dip.versatel-1u1.de. [2001:16b8:2ad3:b600:23:e49d:37af:1a62]) by smtp.gmail.com with ESMTPSA id d2-20020a05600c34c200b004156c006fa5sm7446429wmq.36.2024.04.03.02.05.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Apr 2024 02:05:55 -0700 (PDT) Message-ID: <5b635551-a171-4cc2-bf5e-a71070740b14@baylibre.com> Date: Wed, 3 Apr 2024 11:05:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches , Andrew Stubbs From: Tobias Burnus Subject: [Patch] GCN: Fix --with-arch= handling in mkoffload [PR111966] X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This patch handles --with-arch= in GCN's mkoffload.cc While mkoffload mostly does not know this and passes it through to the GCN lto1 compiler, it writes an .o file with debug information - and here the -march= in the ELF flags must agree with the one in the other files. Hence, it uses now the --with-arch= config argument. Doing so, there is now a diagnostic if the -march= or --with-arch= is unknown. While the latter should be rejected at GCC compile time, the latter was not diagnosed in mkoffload but only later in GCN's compiler. But as there is now a fatal_error in mkoffload, which comes before the GCN-compiler call, the 'note:' which devices are available were lost. This has been reinstated by using the multilib settings. (That's not identical to the compiler supported flags the output is reasonable, arguable better or worse than lto1.) Advantage: The output is less cluttered than a later fail. To make mkoffload errors - and especially this one - more useful, it now also initializes the colorization / bold. OK for mainline? * * * Example error: gcn mkoffload: error: unrecognized argument in option '-march=gfx1111' gcn mkoffload: note: valid arguments to '-march=' are: gfx906, gfx908, gfx90a, gfx1030, gfx1036, gfx1100, gfx1103 where on my TERM=xterm-256color, 'gcn mkoffload:' and the quoted texts are in bold, 'error:' is red and 'note:' is cyan. Compared to cc1, the 'note:' lacks 'fiji', the list is separated by ', ' instead of ' ', and cc1 has a "; did you mean 'gfx1100'?". And the program name is 'gcn mkoffload' instead of 'cc1'. Tobias PS: The generated multilib list could be later changed to be based on the gcn-.def file; or we just keep the multiconfig variant of this patch. GCN: Fix --with-arch= handling in mkoffload [PR111966] The default -march= setting used in mkoffload did not reflect the modified default set by GCC's configure-time --with-arch=, causing issues when generating debug code. gcc/ChangeLog: PR other/111966 * config/gcn/mkoffload.cc (get_arch): New; moved -march= flag handling from ... (main): ... here; call it to handle --with-arch config option and -march= commandline. gcc/config/gcn/mkoffload.cc | 90 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 18 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 04356b86195..31266d2099b 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -35,6 +35,8 @@ #include "gomp-constants.h" #include "simple-object.h" #include "elf.h" +#include "configargs.h" /* For configure_default_options. */ +#include "multilib.h" /* For multilib_options. */ /* These probably won't (all) be in elf.h for a while. */ #undef EM_AMDGPU @@ -846,6 +848,62 @@ compile_native (const char *infile, const char *outfile, const char *compiler, obstack_free (&argv_obstack, NULL); } +int +get_arch (const char *str, const char *with_arch_str) +{ + if (strcmp (str, "fiji") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX803; + else if (strcmp (str, "gfx900") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX900; + else if (strcmp (str, "gfx906") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX906; + else if (strcmp (str, "gfx908") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX908; + else if (strcmp (str, "gfx90a") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX90a; + else if (strcmp (str, "gfx1030") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX1030; + else if (strcmp (str, "gfx1036") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX1036; + else if (strcmp (str, "gfx1100") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX1100; + else if (strcmp (str, "gfx1103") == 0) + return EF_AMDGPU_MACH_AMDGCN_GFX1103; + + error ("unrecognized argument in option %<-march=%s%>", str); + + /* The suggestions are based on the configured multilib support; the compiler + itself might support more. */ + if (multilib_options[0] != '\0') + { + /* Example: "march=gfx900/march=gfx906" */ + char *args = (char *) alloca (strlen (multilib_options)); + const char *p = multilib_options, *q = NULL; + args[0] = '\0'; + while (true) + { + p = strchr (p, '='); + if (!p) + break; + if (q) + strcat (args, ", "); + ++p; + q = strchr (p, '/'); + if (q) + strncat (args, p, q-p); + else + strcat (args, p); + } + inform (UNKNOWN_LOCATION, "valid arguments to %<-march=%> are: %s", args); + } + else if (with_arch_str) + inform (UNKNOWN_LOCATION, "valid argument to %<-march=%> is %qs", with_arch_str); + + exit (FATAL_EXIT_CODE); + + return 0; +} + int main (int argc, char **argv) { @@ -853,9 +911,21 @@ main (int argc, char **argv) FILE *out = stdout; FILE *cfile = stdout; const char *outname = 0; + const char *with_arch_str = NULL; progname = tool_name; + gcc_init_libintl (); diagnostic_initialize (global_dc, 0); + diagnostic_color_init (global_dc); + + for (size_t i = 0; i < ARRAY_SIZE (configure_default_options); i++) + if (configure_default_options[i].name != NULL + && strcmp (configure_default_options[i].name, "arch") == 0) + { + with_arch_str = configure_default_options[0].value; + elf_arch = get_arch (configure_default_options[0].value, NULL); + break; + } obstack_init (&files_to_cleanup); if (atexit (mkoffload_cleanup) != 0) @@ -961,24 +1031,8 @@ main (int argc, char **argv) else if (strcmp (argv[i], "-dumpbase") == 0 && i + 1 < argc) dumppfx = argv[++i]; - else if (strcmp (argv[i], "-march=fiji") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803; - else if (strcmp (argv[i], "-march=gfx900") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900; - else if (strcmp (argv[i], "-march=gfx906") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX906; - else if (strcmp (argv[i], "-march=gfx908") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX908; - else if (strcmp (argv[i], "-march=gfx90a") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX90a; - else if (strcmp (argv[i], "-march=gfx1030") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1030; - else if (strcmp (argv[i], "-march=gfx1036") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1036; - else if (strcmp (argv[i], "-march=gfx1100") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1100; - else if (strcmp (argv[i], "-march=gfx1103") == 0) - elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX1103; + else if (startswith (argv[i], "-march=")) + elf_arch = get_arch (argv[i] + strlen ("-march="), with_arch_str); #define STR "-mstack-size=" else if (startswith (argv[i], STR)) gcn_stack_size = atoi (argv[i] + strlen (STR));