From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jb3Kn-0005qk-7q for mharc-grub-devel@gnu.org; Tue, 19 May 2020 10:35:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jb3Kl-0005pD-MD for grub-devel@gnu.org; Tue, 19 May 2020 10:35:07 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jb3Kk-00076e-2G for grub-devel@gnu.org; Tue, 19 May 2020 10:35:07 -0400 Received: by mail-pf1-x444.google.com with SMTP id 145so6615593pfw.13 for ; Tue, 19 May 2020 07:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=sAOP8HyZshcM8i6MQgtaL199aVW4GqyrXr1g+9QN0+I=; b=P5BxDxnvfy0BHo977HDZLHjVe5d0OJs2OWPLNRnODNdYqrs6prykH3jZf6taztfQ2K +eHBMnCXMaFpwtI5ktGpBg4OR4+xBBQGHbKWrVUzcuc5HLKS+SgH2GoPZu5TJOGz/rRj 6LaTJUlGDHZkYNTb5KlwNCMo0s5KWCN9Ulyhw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=sAOP8HyZshcM8i6MQgtaL199aVW4GqyrXr1g+9QN0+I=; b=T2vVYIT8eCiV95c1IKb51OAje41OgvqRK4cZH2VMFf+QSQlP97wgZBAUQr8LTVtoSV vCXB5cldix3nHqrC4uBJC7WnkRtxceTvZRBkGRU60oEAYOz8QazXip9HyGCNIgV5ppGx sstI77ucj1A3oGvuBljjINXa98aXm0/8ON9UB5MHX2EPdaP/rW6+bF3Fud3Drw87uoSk 06mxb+pCmr7TV5IycP01vOHvwj0E5ftAiAI9xlke6QMe6pTosbmodNPNDt04UcjtZdLn 1U1OyWkvcE2otaaW+xQiDbxhsBCdj9I6dru8R5clpoQdJ+qh8jyIE8sIPAMQJ+Yqefj2 APWA== X-Gm-Message-State: AOAM532sT7b2nmRRPmMy+I83KJ1wLKO+fSq1OaZtZ4dnZa4DnZGPptx5 r16vkTwZ6RHTXSZdl0XSHG1qPA== X-Google-Smtp-Source: ABdhPJyuK6iFA4cvZP+b9LlRXfyKzkxhWd7tkhXxbC3JL/tx9fmsAPOoSAEfcsZzfvrWLQodI2k6tQ== X-Received: by 2002:a62:e51a:: with SMTP id n26mr21922446pff.301.1589898904426; Tue, 19 May 2020 07:35:04 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-b5ed-d3ff-25d3-7e68.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:b5ed:d3ff:25d3:7e68]) by smtp.gmail.com with ESMTPSA id q15sm8088388pfh.188.2020.05.19.07.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 07:35:03 -0700 (PDT) From: Daniel Axtens To: Javier Martinez Canillas , grub-devel@gnu.org Cc: Javier Martinez Canillas , Daniel Kiper Subject: Re: [PATCH] net: Don't use nested functions to allow building with clang In-Reply-To: <20200519083422.950041-1-javierm@redhat.com> References: <20200519083422.950041-1-javierm@redhat.com> Date: Wed, 20 May 2020 00:35:00 +1000 Message-ID: <87ftbwhu23.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=dja@axtens.net; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 14:35:07 -0000 Hi Javier, Thanks! > Nested functions are supported as an extension in GNU C, but are not in > the clang compiler. Commit cb2f15c5448 ("normal/main: Search for specific > config files for netboot") added a nested function which caused the build > to break when compiling with clang. > > Reported-by: Daniel Axtens > Signed-off-by: Javier Martinez Canillas With this patch, clang-9 builds and runs mainline grub-emu. Tested-by: Daniel Axtens # emu platform only clang still doesn't like 'make check', but that looks like a different issue around relocations. clang isn't a huge priority for me, so it might take a while. But this patch is good to go in regardless. Thanks again, Daniel > --- > > grub-core/net/net.c | 65 +++++++++++++++++++++++---------------------- > 1 file changed, 33 insertions(+), 32 deletions(-) > > diff --git a/grub-core/net/net.c b/grub-core/net/net.c > index c42f0f4f71d..ec7e2899ed5 100644 > --- a/grub-core/net/net.c > +++ b/grub-core/net/net.c > @@ -1735,42 +1735,43 @@ grub_net_restore_hw (void) > return GRUB_ERR_NONE; > } > > -grub_err_t > -grub_net_search_config_file (char *config) > +static int grub_config_search_through (char *config, char *suffix, > + grub_size_t num_tries, > + grub_size_t slice_size) > { > - grub_size_t config_len; > - char *suffix; > + while (num_tries-- > 0) > + { > + grub_file_t file; > > - auto int search_through (grub_size_t num_tries, grub_size_t slice_size); > - int search_through (grub_size_t num_tries, grub_size_t slice_size) > - { > - while (num_tries-- > 0) > - { > - grub_file_t file; > + grub_dprintf ("net", "attempt to fetch config %s\n", config); > > - grub_dprintf ("net", "attempt to fetch config %s\n", config); > + file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); > > - file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); > + if (file) > + { > + grub_file_close (file); > + return 0; > + } > + else > + { > + if (grub_errno == GRUB_ERR_IO) > + grub_errno = GRUB_ERR_NONE; > + } > > - if (file) > - { > - grub_file_close (file); > - return 0; > - } > - else > - { > - if (grub_errno == GRUB_ERR_IO) > - grub_errno = GRUB_ERR_NONE; > - } > + if (grub_strlen (suffix) < slice_size) > + break; > > - if (grub_strlen (suffix) < slice_size) > - break; > + config[grub_strlen (config) - slice_size] = '\0'; > + } > > - config[grub_strlen (config) - slice_size] = '\0'; > - } > + return 1; > +} > > - return 1; > - } > +grub_err_t > +grub_net_search_config_file (char *config) > +{ > + grub_size_t config_len; > + char *suffix; > > config_len = grub_strlen (config); > config[config_len] = '-'; > @@ -1801,7 +1802,7 @@ grub_net_search_config_file (char *config) > if (client_uuid) > { > grub_strcpy (suffix, client_uuid); > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > } > > @@ -1816,7 +1817,7 @@ grub_net_search_config_file (char *config) > if (*ptr == ':') > *ptr = '-'; > > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > > /* By IP address */ > @@ -1831,7 +1832,7 @@ grub_net_search_config_file (char *config) > ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ > ((n >> 8) & 0xff), ((n >> 0) & 0xff)); > > - if (search_through (8, 1) == 0) > + if (grub_config_search_through (config, suffix, 8, 1) == 0) > return GRUB_ERR_NONE; > break; > } > @@ -1848,7 +1849,7 @@ grub_net_search_config_file (char *config) > *ptr = '-'; > > grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > break; > } > -- > 2.26.2