From patchwork Fri Jun 21 15:15:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1950858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (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=CYaSseJa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W5LXn2zjHz1ydW for ; Sat, 22 Jun 2024 01:16:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C42343899081 for ; Fri, 21 Jun 2024 15:16:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 583103896C3A for ; Fri, 21 Jun 2024 15:15:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 583103896C3A 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 583103896C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718982943; cv=none; b=DuoffDy5TQeaB6tB16c40IS+cjdXcfte1hK/pmYv500ntgpuLvl11Bln9AFUY73L6SEIDQrmD8FoNtZ1JHDn4GE73Kig476JpL/81fZsP95jrUYXmoo25cgyVcDx6lETd8cOkgtNF1dk0n+kVGDKgMfAgTL40cJ/Cl2/jwuu0cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718982943; c=relaxed/simple; bh=/92bD5zTw/kk3m4L4eoLWnaUrTpYX0QiG+pAO6Ws0OE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=uoQhbHMfyjoZO8hz0HH+YReO/Tpqpfo6x0/u6KGtllXu2R9kzWrRTegWM76schxlfyAiBfFldrCy7DctqnJbujaXd5nEOD3SV+5Stuy7HkSWdaxrSnfwMvEmynp74Tw98wGrk0sjeEeEVe8Er7h/vPcrRZXv18Ep7NVSpRbeKiI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42172ed3597so12991495e9.0 for ; Fri, 21 Jun 2024 08:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718982939; x=1719587739; 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=mdPErMVYw2e+n4/E7DI4DuVvHmGr5fzfucOpIrxNJnM=; b=CYaSseJaV1zhRrtjlcDOMcEAwzOV7vGD5i/Gz/tDPeen0D4vk7Con4LJ8oiRj61lwA 4BYxdHhA3jygAbvdecHRrohkgJx+zabjYTBfHoqJg3hTHJ7U3PndCtgnSC6v8Max/vUw 5D/kp8H6zg/lUaaWVYSaf0rlfWLXekeaBjAL02J14lTActJk8V5kCtROdd5FxGBWwK9o y/2FMFQnmfT3SDcXzCNPdG3QpHcCnXFmJklaJx6ok0DLjOVnSuRcpSPWW1CC/vd3aZOo +ckXth3/CdSXYSumILMDcwUk/8VFtOdPX2bgtoMWFPxis1wUAEE/UEztyq62yby6/dTt Y1Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718982939; x=1719587739; 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=mdPErMVYw2e+n4/E7DI4DuVvHmGr5fzfucOpIrxNJnM=; b=LveniePft+T/stw/sjLLicumj90yxyeVtOT9NyfTe9SaWjE+ouhuZtJY1BvFL55SK+ WoRM+E7N7xZeCjuGMkfI+CjU6cs85kroyruFP8/fAkCvO7wa8BPbgxCbJbzh6pG0YV5f w9gxw8YvKfTaKWkDA/30bUE8auvalXqFQmo6vD8Gl7w4ucZjKtB5+idlhPb5xLxGCSMN r0BMRRs+f0GUBPG5X1pZ/4fpiCWx2ytfUPKSWvEFqjhfV+0tDGAxw8aPz7D9dwUmIzIS P3+3W5l2rx40cKhyLsMLuN6RcIYay6NPH/Lqq78hFaPal+9W2By0VDkxMc/HFwMk5Xr2 uwSg== X-Gm-Message-State: AOJu0Yzzkc+agq43QL2BCt0Fz3Ja6zOM2tgzaCx3ZWzKEVUpGqnN7tyL 4saQlkMOuEqkOF55HJ8McDVfAYAvW79tvs+yYUeNpM+KkxlANoS/g3TSgdarYWwpvT8yJuGsPRE c X-Google-Smtp-Source: AGHT+IFpKUgpvTjVGLCsYEbuW58UKLygMfaU423jbDVf8cGB6/UMXuVff8Bced3JHylFGvWXvsAEoQ== X-Received: by 2002:a05:600c:1504:b0:421:8179:6127 with SMTP id 5b1f17b1804b1-42486342e1emr1152365e9.20.1718982938951; Fri, 21 Jun 2024 08:15:38 -0700 (PDT) Received: from ?IPV6:2001:16b8:3d04:bf00:3f92:7f17:8619:5a80? ([2001:16b8:3d04:bf00:3f92:7f17:8619:5a80]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42481922428sm30235925e9.43.2024.06.21.08.15.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jun 2024 08:15:38 -0700 (PDT) Message-ID: <48aa0cd1-20cd-4a95-a729-699e2c02a9d9@baylibre.com> Date: Fri, 21 Jun 2024 17:15:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches , Jakub Jelinek , Andrew Stubbs From: Tobias Burnus Subject: [Patch] gcn/mkoffload.cc: Use #embed for including the generated ELF file X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org mkoffload's generated .c file looks much nicer with '#embed'. This patch depends on Jakub's #embed patch at https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655012.html It might be a tiny bit faster than currently (or not); however, once #embed has a large-file mode, it should also speed up the offloading compilation quit a bit. OK for mainline, once '#embed' support is in? Tobias gcn/mkoffload.cc: Use #embed for including the generated ELF file gcc/ChangeLog: * config/gcn/mkoffload.cc (read_file): Remove. (process_obj): Generate C file that uses #embed. (main): Update call to it; remove no longer needed file I/O. gcc/config/gcn/mkoffload.cc | 66 +++++++++------------------------------------ 1 file changed, 12 insertions(+), 54 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 810298a799b..0ccb874398a 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -182,44 +182,6 @@ xputenv (const char *string) putenv (CONST_CAST (char *, string)); } -/* Read the whole input file. It will be NUL terminated (but - remember, there could be a NUL in the file itself. */ - -static const char * -read_file (FILE *stream, size_t *plen) -{ - size_t alloc = 16384; - size_t base = 0; - char *buffer; - - if (!fseek (stream, 0, SEEK_END)) - { - /* Get the file size. */ - long s = ftell (stream); - if (s >= 0) - alloc = s + 100; - fseek (stream, 0, SEEK_SET); - } - buffer = XNEWVEC (char, alloc); - - for (;;) - { - size_t n = fread (buffer + base, 1, alloc - base - 1, stream); - - if (!n) - break; - base += n; - if (base + 1 == alloc) - { - alloc *= 2; - buffer = XRESIZEVEC (char, buffer, alloc); - } - } - buffer[base] = 0; - *plen = base; - return buffer; -} - /* Parse STR, saving found tokens into PVALUES and return their number. Tokens are assumed to be delimited by ':'. */ @@ -725,31 +687,27 @@ process_asm (FILE *in, FILE *out, FILE *cfile) /* Embed an object file into a C source file. */ static void -process_obj (FILE *in, FILE *cfile, uint32_t omp_requires) +process_obj (const char *fname_in, FILE *cfile, uint32_t omp_requires) { - size_t len = 0; - const char *input = read_file (in, &len); - /* Dump out an array containing the binary. FIXME: do this with objcopy. */ - fprintf (cfile, "static unsigned char gcn_code[] = {"); - for (size_t i = 0; i < len; i += 17) - { - fprintf (cfile, "\n\t"); - for (size_t j = i; j < i + 17 && j < len; j++) - fprintf (cfile, "%3u,", (unsigned char) input[j]); - } - fprintf (cfile, "\n};\n\n"); + fprintf (cfile, + "static unsigned char gcn_code[] = {\n" + "#if defined(__STDC_EMBED_FOUND__) && __has_embed (\"%s\") == __STDC_EMBED_FOUND__\n" + "#embed \"%s\"\n" + "#else\n" + "#error \"#embed '%s' failed\"\n" + "#endif\n" + "};\n\n", fname_in, fname_in, fname_in); fprintf (cfile, "static const struct gcn_image {\n" " size_t size;\n" " void *image;\n" "} gcn_image = {\n" - " %zu,\n" + " sizeof(gcn_code),\n" " gcn_code\n" - "};\n\n", - len); + "};\n\n"); fprintf (cfile, "static const struct gcn_data {\n" @@ -1316,7 +1274,7 @@ main (int argc, char **argv) if (!in) fatal_error (input_location, "cannot open intermediate gcn obj file"); - process_obj (in, cfile, omp_requires); + process_obj (gcn_o_name, cfile, omp_requires); fclose (in);