From patchwork Wed Jan 24 22:12:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1890422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=v+3DH39S; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TKyrg1BDQz1yS7 for ; Thu, 25 Jan 2024 09:13:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1B3C385773F for ; Wed, 24 Jan 2024 22:13:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 28D5C3858D38 for ; Wed, 24 Jan 2024 22:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28D5C3858D38 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 28D5C3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706134364; cv=none; b=Dj2sMrMOMrqo85xKD7PTNvSq3wq2aPpI1LFunlgVCs+U+uVpDLD0Esf4oPtX+VXWMXeFSTbGohKENPB6BfAfIeFEnhkxMNsFZT3F8iGc5218u/whLW9snm3L74+Jms0OsNkOoS6uH4XYtdri4c4kmSTRcJJEUzWogeC1Oa30/lQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706134364; c=relaxed/simple; bh=tEvpvZO23bx0Szw1DUnOowuKfUG++sD/1PA398bSnDo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=YPWM2XvH93J6psQD4hAB87uwFRv1OrjiJ+76RR7zYmznCP9S4RiqDDFbQBJ4QSLnaZlEVuRB4Pd6E+9GqzbnE16BblsgmY+wHYRuFtelPNlLJF5AMaTsiqfRlIrPIUWpVrPk+k78ffiOEF7eq7e3tk5iExIbdIMLdVuKcX7RFvI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a30b3a9e9c6so298667466b.2 for ; Wed, 24 Jan 2024 14:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1706134360; x=1706739160; 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=tEvpvZO23bx0Szw1DUnOowuKfUG++sD/1PA398bSnDo=; b=v+3DH39S9qrAYTHYwNBEo4YMJuaJyH28jLqbkekck7kvXumEhEWzxAZAJtd4k18YCJ eJqkm4GE1RVey/0EHQi7VOEQYIfs5Ybu4d/pM+5oSFNI41F0imzJNdVMZn3gJ61ST7mZ ck9SghSroq1IzwlJnLPtu0SyVhmfBrD/8Utk0ryEx9Wre2gXa+3tmMruxiwRqDcv/Rr6 LKhhPJJ93bkMYRmcGYKDHvywiLVE23xmD5SgU1y+HPvbBdOlbxGYjbA8WYkErWZogNCq qt95sMxk2vFBV5C1eI6Vp71RXX5Ver6OO0z4VOkPikqz8AFBQqHmMKzJ6CNvbXApcgz2 rHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706134360; x=1706739160; 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=tEvpvZO23bx0Szw1DUnOowuKfUG++sD/1PA398bSnDo=; b=oMKE1eO2xGbIqH2pSeEsgcmUKwN+t5c9wK+TlAia9xp5OVlpZyAuwG1JKgfU5aTrZo KbOf5gfOFbsz6F8lyfn4OpjaUntQovpUJc+h91h2VMrdJx3RQv1xejNgCMnv5rOzjNyS +xdyzp9XY28/D8u4asIX7opi2dLQQvuKr4UYJ0SpAAkMaCBwFU2VgoFWP1ssIFdBpojq KZbu6DMeuUb4en/Nyub/BjweHeXKYHiDy4Jt2ogMWmA21fQgRSptC2PmoXJDwZSUbUGI 7kqNVYg362p6I4CtcSLRBhODE+ZPCmuiT5BbWOXIXUHLmQBREoI6st/iyr2gZeXJIDdB Zzbw== X-Gm-Message-State: AOJu0Yx8w+4AJDkfJAhF0ZDB3JKo2qeMarEhLBCsJD0smwmFcw1XRp3g hNeGyteqJq/FSb8uobpLXvUZo3CxBYcsfyu+uhAzfGPULTuJdU0ZucKWBFGeeUHjpXo3D8TcKcj 4XwN0+g== X-Google-Smtp-Source: AGHT+IHbVGhs3j/a0fZ0HzWH1pCpSMnN48hh6dvbGwRUxP02rqllggTnSapqfEdWFwVRV/uq6+e19Q== X-Received: by 2002:a17:906:e2ce:b0:a31:5bff:ef76 with SMTP id gr14-20020a170906e2ce00b00a315bffef76mr3676ejb.108.1706134359765; Wed, 24 Jan 2024 14:12:39 -0800 (PST) Received: from ?IPV6:2001:16b8:3f15:5000:be03:58ff:fe31:f74? ([2001:16b8:3f15:5000:be03:58ff:fe31:f74]) by smtp.gmail.com with ESMTPSA id cw11-20020a170907160b00b00a30b9f87a6esm314139ejd.142.2024.01.24.14.12.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Jan 2024 14:12:39 -0800 (PST) Message-ID: <45e2515e-b9aa-42a4-908d-80b2189c7aeb@baylibre.com> Date: Wed, 24 Jan 2024 23:12:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches , Andrew Stubbs From: Tobias Burnus Subject: [patch] gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966] X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch fixes "-g" debug compilation for gfx1100 and gfx1030, which fail to link when "-g" is specified. The reason is: When using gfx1100 and compiling with '-g' I was running into an error because the eflags used for the debugger file has additional eflags (elf flags) set - contrary to the compiled files; mkoffload writes files itself, hence, it also needs to get the elf flags right. It turned out that the ASM_SPEC handling was insufficiently replicated in mkoffload, leading to issues with gfx1100 and gfx1030. I think in some corner case, gfx906 also behaved differently; for gfx900 and fiji, the eflags were different before, but got reset inside copy_early_debug_info such that those difference did not matter. OK for mainline? Tobias PS: I tried hard to look at the ASM_SPEC and played with different options, looking at what really got passed to the assembler, but I might have missed something as the code is somewhat confusing. Naming wise, there is both UNSUPPORTED and UNSET for the same thing; it should be a tad more consistent (flag = UNSUPPORTED, SET/TEST functions: UNSET), still, one could also argue that a single name would do. PPS: I think the PR is about other things in addition, but it also kind of covers this "-g" issue and the one of previous commit. Even if not directly addressing the issue, it is related and having the commits listed there makes IMHO sense. gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966] Some more '-g' fixes as the .mkoffload.dbg.o debug file's has elf flags which did not match those generated for the compilation, leading to linker errors. For .mkoffload.dbg.o, the elf flags are generated by mkoffload itself - while for the other .o files, that's done by the compiler via setting default and mainly via the ASM_SPEC. This is a follow up to r14-8332-g13127dac106724 which fixed an issue caused by the default arch. In this patch, it is mainly for gfx1100 and gfx1030 which always failed. It also affects gfx906 and possibly gfx900 but only when using the -mxnack/-msram-ecc flags explicitly. What happens on the compiler side is mainly determined by gcn-hsa.h's and otherwise by some default setting. In particular for xnack and sram_ecc, there is: For gfx1100 and gfx1030, neither xnack nor sram_ecc is set (only '+wavefrontsize64'). For fiji, gfx900 and gfx906 there is always -mattr=-xnack and no -msram-ecc - independent of what has been passed to the compiler. On elf flags level, that's not quite true as for fiji those flags are set to 0 because of HSACOv3 and for gfx900 there is a remark that even if -msram-ecc were set (which it isn't), the elf flags would be still zero because of a buggy assembler. See copy_early_debug_info. For gfx90a, the -msram-ecc= and -mxnack= are passed on, or if not present, ...=any is passed on. Note that this "any" is different from argument nor present at elf flag level: For XNACK: unset/unsupported is 0, any = 0x100, off = 0x200, on = 0x300. For SRAMECC: unset/unsupported is 0, any = 0x400, off = 0x800, on = 0xc00. The obstack_ptr_grow changes are more to avoid confusion than having an actual effect as they would overwise be filtered out via the ASM_SPEC. gcc/ChangeLog: PR other/111966 * config/gcn/mkoffload.cc (SET_XNACK_UNSET, TEST_SRAM_ECC_UNSET): New. (SET_SRAM_ECC_UNSUPPORTED): Renamed to ... (SET_SRAM_ECC_UNSET): ... this. (main): Update SRAM_ECC and XNACK for the -march as done in gcn-hsa.h. Signed-off-by: Tobias Burnus gcc/config/gcn/mkoffload.cc | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 0d0e7bac9b2..218ad888aea 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -80,6 +80,8 @@ | EF_AMDGPU_FEATURE_XNACK_ANY_V4) #define SET_XNACK_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \ | EF_AMDGPU_FEATURE_XNACK_OFF_V4) +#define SET_XNACK_UNSET(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \ + | EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4) #define TEST_XNACK_ANY(VAR) ((VAR & EF_AMDGPU_FEATURE_XNACK_V4) \ == EF_AMDGPU_FEATURE_XNACK_ANY_V4) #define TEST_XNACK_ON(VAR) ((VAR & EF_AMDGPU_FEATURE_XNACK_V4) \ @@ -94,13 +96,14 @@ | EF_AMDGPU_FEATURE_SRAMECC_ANY_V4) #define SET_SRAM_ECC_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \ | EF_AMDGPU_FEATURE_SRAMECC_OFF_V4) -#define SET_SRAM_ECC_UNSUPPORTED(VAR) \ +#define SET_SRAM_ECC_UNSET(VAR) \ VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \ | EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4) #define TEST_SRAM_ECC_ANY(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \ == EF_AMDGPU_FEATURE_SRAMECC_ANY_V4) #define TEST_SRAM_ECC_ON(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \ == EF_AMDGPU_FEATURE_SRAMECC_ON_V4) +#define TEST_SRAM_ECC_UNSET(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) == 0) #ifndef R_AMDGPU_NONE #define R_AMDGPU_NONE 0 @@ -125,7 +128,7 @@ static struct obstack files_to_cleanup; enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900; // Default GPU architecture. -uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_ANY_V4; +uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4; static int gcn_stack_size = 0; /* Zero means use default. */ @@ -1007,21 +1010,26 @@ main (int argc, char **argv) gcc_unreachable (); } - /* Disable XNACK mode on architectures where it doesn't work (well). - Set default to "any" otherwise. */ + /* This must match gcn-hsa.h's settings for NO_XNACK, NO_SRAM_ECC + and ASM_SPEC. */ switch (elf_arch) { - case EF_AMDGPU_MACH_AMDGCN_GFX803: case EF_AMDGPU_MACH_AMDGCN_GFX900: case EF_AMDGPU_MACH_AMDGCN_GFX906: case EF_AMDGPU_MACH_AMDGCN_GFX908: + SET_XNACK_OFF (elf_flags); + break; + case EF_AMDGPU_MACH_AMDGCN_GFX803: case EF_AMDGPU_MACH_AMDGCN_GFX1030: case EF_AMDGPU_MACH_AMDGCN_GFX1100: - SET_XNACK_OFF (elf_flags); + SET_XNACK_UNSET (elf_flags); + SET_SRAM_ECC_UNSET (elf_flags); break; case EF_AMDGPU_MACH_AMDGCN_GFX90a: if (TEST_XNACK_UNSET (elf_flags)) SET_XNACK_ANY (elf_flags); + if (TEST_SRAM_ECC_UNSET (elf_flags)) + SET_SRAM_ECC_ANY (elf_flags); break; default: fatal_error (input_location, "unhandled architecture"); @@ -1145,14 +1153,16 @@ main (int argc, char **argv) } obstack_ptr_grow (&ld_argv_obstack, gcn_s2_name); obstack_ptr_grow (&ld_argv_obstack, "-lgomp"); - obstack_ptr_grow (&ld_argv_obstack, - (TEST_XNACK_ON (elf_flags) ? "-mxnack=on" - : TEST_XNACK_ANY (elf_flags) ? "-mxnack=any" - : "-mxnack=off")); - obstack_ptr_grow (&ld_argv_obstack, - (TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on" - : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any" - : "-msram-ecc=off")); + if (!TEST_XNACK_UNSET (elf_flags)) + obstack_ptr_grow (&ld_argv_obstack, + (TEST_XNACK_ON (elf_flags) ? "-mxnack=on" + : TEST_XNACK_ANY (elf_flags) ? "-mxnack=any" + : "-mxnack=off")); + if (!TEST_SRAM_ECC_UNSET (elf_flags)) + obstack_ptr_grow (&ld_argv_obstack, + (TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on" + : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any" + : "-msram-ecc=off")); if (verbose) obstack_ptr_grow (&ld_argv_obstack, "-v");