From patchwork Tue Sep 10 10:50:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1160258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-508756-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tQxvylGT"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46SMJH4WdLz9sNw for ; Tue, 10 Sep 2019 20:50:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=fVVb0Narx2srdumInQJHqNYCqnSCGXeBAx5g4laMVzaDI9FX+ryV1 zJ3tIyILh5F9E8/8wKyZPpZyp1j+tNOf/RHS/h6vHANGdZRkJTIDCPcPHYZFa1B1 7QrFd4270IH+hvo4YjJZKCo/W5wODvC0BPKhxX/10RYQsOEaz/eFNI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=UCgh/4NsviWyB9p6cRwJlJd8PoM=; b=tQxvylGTM7Aly95Hl5gP PGsC+IchT7mSvrbeGG+UXPIhs+ZGxtan1515P/fnSN/4dC3PGAbM6C4wQUoKMuga oLxysj7wBbZLPo8ms70XuMN4H0GJ1w55wUwnvCPooVElOnWfrJtbUhMG8SJWJfT4 jtP2onFj1/m37IfKsXJb1OQ= Received: (qmail 49045 invoked by alias); 10 Sep 2019 10:50:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 49034 invoked by uid 89); 10 Sep 2019 10:50:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=agent, device X-HELO: esa4.mentor.iphmx.com Received: from esa4.mentor.iphmx.com (HELO esa4.mentor.iphmx.com) (68.232.137.252) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Sep 2019 10:50:28 +0000 IronPort-SDR: LBuj+VNirxtxcHUSTjJA1GwK4NGKRrhETrzQWvjRw1loz4Z595DGYcVR5F6hHPpgOLhtETYfep H0jqkP/1rK88GzHh1BjzyDls0WcwF1aU2QkfqiHhnMwJaRKC7MYYBkwyqv5llRzl6Z6oUY+9gW yo9Y4PGuXRgM9VXO+h7d+py73Asqvvdq3RQEKNEkdEDO60J8HuQl+H+eDpWn0EC9YJyv/WbUbP Fe96FlnBKQk/DbNEaK8Ks7I2BxghmgDxjwpr9Zpa/c/duW7VLedHwtHZo1p9W8+F+OD5VKHAm7 8dU= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 10 Sep 2019 02:50:25 -0800 IronPort-SDR: IuynZi7a/hn3ETGcfcBv4R3O0OkweHBG+yE7sPERjIyb96FNYOgIx8LHFqpVAHaC+4NKbOIn95 Y4pkSICbRP2z7liLLk8QmHlB+aSAL1yt3iR2iRFnuP9IjVCWZlDHotReBY2X+Y7QoIYS7FIZUk Lw/7g6b4Lp3uZG3upBXgAqBUjcGN528cCP/0sBYK4xNUHp8Bzd2T9HlE6LrHQugWIcX4/T6PoK LOGY5PhbBVnv558cMfJKL8ofzHW1V4B77y2rao5sumcc3cX2F73l12GVTwT4hFiQt4VoirZ5bd DNY= From: Andrew Stubbs Subject: [OG9, amdgcn,committed] Fix relocations with multiple devices To: "gcc-patches@gcc.gnu.org" Message-ID: <3c90ebb3-8e8e-847e-3954-9ec6b5163389@codesourcery.com> Date: Tue, 10 Sep 2019 11:50:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 This patches fixes a bug in which the relocations would not get fixed up if the same kernel was loaded to more than one device. There was a race condition if the loads occurred in parallel, but basically the first device would get loaded correctly, and the second would get no relocations at all. This fix uses an unassigned section type, rather than changing SHT_RELA to SHT_NOTE, so that we can still recognise it, but have the HSA runtime ignore the section. In theory this is less future-proof because the unassigned section type could become assigned, but it is at least re-entrant. An alternative would be to copy the entire image before modifying it, each time it is loaded. Andrew Fix relocations with multiple devices. 2019-09-10 Andrew Stubbs libgomp/ * plugin/plugin-gcn.c (obstack_chunk_alloc): Delete. (obstack_chunk_free): Delete. (obstack.h): Remove include. (create_and_finalize_hsa_program): Remove all unmodified_sections_os and use sections directly from the issue. Use "or 0x80" instead of SHT_NOTE to hide relocations, and then simply recognise that ourselves. diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index 2d46a876e6c..6c00c81b588 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -44,10 +44,6 @@ #include "oacc-int.h" #include -#define obstack_chunk_alloc GOMP_PLUGIN_malloc -#define obstack_chunk_free free -#include "obstack.h" - /* These probably won't be in elf.h for a while. */ #define R_AMDGPU_NONE 0 #define R_AMDGPU_ABS32_LO 1 /* (S + A) & 0xFFFFFFFF */ @@ -1952,9 +1948,6 @@ create_and_finalize_hsa_program (struct agent_info *agent) goto fail; } - struct obstack unmodified_sections_os; - obstack_init (&unmodified_sections_os); - /* Load any GCN modules. */ struct module_info *module = agent->module; if (module) @@ -1965,16 +1958,13 @@ create_and_finalize_hsa_program (struct agent_info *agent) Keep a copy of the unmodified section headers to use later. */ Elf64_Shdr *image_sections = (Elf64_Shdr *)((char *)image + image->e_shoff); - Elf64_Shdr *sections = malloc (sizeof (Elf64_Shdr) * image->e_shnum); - memcpy (sections, image_sections, sizeof (Elf64_Shdr) * image->e_shnum); for (int i = image->e_shnum - 1; i >= 0; i--) { if (image_sections[i].sh_type == SHT_RELA || image_sections[i].sh_type == SHT_REL) /* Change section type to something harmless. */ - image_sections[i].sh_type = SHT_NOTE; + image_sections[i].sh_type |= 0x80; } - obstack_ptr_grow (&unmodified_sections_os, sections); hsa_code_object_t co = { 0 }; status = hsa_fns.hsa_code_object_deserialize_fn @@ -2020,7 +2010,6 @@ create_and_finalize_hsa_program (struct agent_info *agent) } } - Elf64_Shdr **unmodified_sections = obstack_finish (&unmodified_sections_os); if (debug) dump_executable_symbols (agent->executable); @@ -2032,12 +2021,11 @@ create_and_finalize_hsa_program (struct agent_info *agent) goto fail; } - int s = 0; if (agent->module) { struct module_info *module = agent->module; Elf64_Ehdr *image = (Elf64_Ehdr *)module->image_desc->gcn_image->image; - Elf64_Shdr *sections = unmodified_sections[s++]; + Elf64_Shdr *sections = (Elf64_Shdr *)((char *)image + image->e_shoff); Elf64_Addr load_offset; if (!find_load_offset (&load_offset, agent, module, image, sections)) @@ -2070,7 +2058,7 @@ create_and_finalize_hsa_program (struct agent_info *agent) /* Fix up relocations. */ for (int i = 0; i < image->e_shnum; i++) { - if (sections[i].sh_type == SHT_RELA) + if (sections[i].sh_type == (SHT_RELA | 0x80)) for (size_t offset = 0; offset < sections[i].sh_size; offset += sections[i].sh_entsize) @@ -2153,10 +2141,7 @@ create_and_finalize_hsa_program (struct agent_info *agent) reloc_count++; } } - - free (sections); } - obstack_free (&unmodified_sections_os, NULL); HSA_DEBUG ("Loaded GCN kernels to device %d (%d relocations)\n", agent->device_id, reloc_count);