Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1480928pxv; Fri, 25 Jun 2021 14:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuDh4l2/GOh20z2hW2H4D9ikRGftjTvOGh0QHHF3i0IRjZlrpkmLUaoJV1yAOmj7mHNO7Q X-Received: by 2002:a92:c642:: with SMTP id 2mr9016812ill.109.1624655365771; Fri, 25 Jun 2021 14:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624655365; cv=none; d=google.com; s=arc-20160816; b=ykcg9fCmTGYT+AW4RRaFTaxMTs8NYHCj8XxJeJ5U/j3uIkydt6BK9cTNI2hy1hHDRE bhDxrlU1AOxwTpx6KfE0VTJCu2DBG4osfZaDzKgjoD0wnKDL4uFNSR2WJUavGW7uMVBY ecdfTWUJ7QLvDh4iQImETABPElOgGi08q1rvzcH/LV2GXEe0JxsBqE99SZcOyQGEc8Xd l/2wJMyTagTqC18ftHBN5D1bVFcW9PCbBJf3YwImiX4OxSoA/itz2HPFunlSINbo/b/N lU+I0rUd0ShJ0qpZ34Da7rxR2zuz+9y4sqB3bmBtylZOXX3PUDM3ObT2SprjtJFhYtfW ifGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4Dhe8/CAj5PZCZSBsa0GRqc4jLrXUf6ZA1ktPfUMj38=; b=NlzbSsPDQ3pGddT09sZl/+O+M+rFUu9cYb+O5Hs9B82sdSgd/lxZkGeFedU4okLZKS hpacUphIpIGG3q2Cjzk48ujAVvyf8koLSLnMxKWxJ5njOPOgZu9TJjApUHuOotHWn1cH H3Cg1suMTESxltZTPJUeq+7AzXWcFBDcRAXt7aGIH76vwq875tEdVyfj4/8zCQioKeRE ILQF7LFHeaU7Qdw05ygLMlDu9lQF226V+AE2e/fmkIzurY7NtSWZssIQcpTX9RXV/YmD AdyH4hJmywxqDXfjARjojfNDVDe3gH23om2hNtKvnl3poAAwTzGIdcMNEIMPJJSw7acW qjGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=lVT9Su4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m44si5547028jav.74.2021.06.25.14.08.47; Fri, 25 Jun 2021 14:09:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=lVT9Su4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbhFYVJ6 (ORCPT + 99 others); Fri, 25 Jun 2021 17:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbhFYVJ6 (ORCPT ); Fri, 25 Jun 2021 17:09:58 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B932C061574 for ; Fri, 25 Jun 2021 14:07:36 -0700 (PDT) Received: from zn.tnic (p200300ec2f0dae0029e536978a2ce722.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:ae00:29e5:3697:8a2c:e722]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 29BF11EC05A0; Fri, 25 Jun 2021 23:07:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1624655255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=4Dhe8/CAj5PZCZSBsa0GRqc4jLrXUf6ZA1ktPfUMj38=; b=lVT9Su4T0hg8fFQUfoItYeFKmx9oadggibbEId2g5K1l2AuZ4VZIPX90/9SzKzYficEb75 l2VkCmuliWIDmQHBmox4EnSBc1hWEUGY40N0CK9lRR3LGqPPy+2zVmx9cn0PaUy3B0bJHj UUcArFsd09Oa5xerDOJOiHjttQ34y4c= Date: Fri, 25 Jun 2021 23:07:28 +0200 From: Borislav Petkov To: "H. Peter Anvin" Cc: Greg Kroah-Hartman , x86@kernel.org, Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [RESEND PATCH] x86/tools/relocs: add __printf attribute to die() Message-ID: References: <1EFF7FE1-D341-41DF-8681-D386A1BD6F7A@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1EFF7FE1-D341-41DF-8681-D386A1BD6F7A@zytor.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 25, 2021 at 01:38:51PM -0700, H. Peter Anvin wrote: > 64-bit cross build on a 32-bit platform... or Windows. Meh, nobody cares about those... :) Hmm, so looking at the PRI* inttypes.h things again, they're C99 and they kinda look more elegant as they don't make us cast stuff. So how does that look? --- diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 04c5a44b9682..2582991ba216 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -26,6 +26,9 @@ static struct relocs relocs32; #if ELF_BITS == 64 static struct relocs relocs32neg; static struct relocs relocs64; +#define FMT PRIu64 +#else +#define FMT PRIu32 #endif struct section { @@ -389,7 +392,7 @@ static void read_ehdr(FILE *fp) Elf_Shdr shdr; if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) - die("Seek to %d failed: %s\n", ehdr.e_shoff, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", ehdr.e_shoff, strerror(errno)); if (fread(&shdr, sizeof(shdr), 1, fp) != 1) die("Cannot read initial ELF section header: %s\n", strerror(errno)); @@ -412,17 +415,17 @@ static void read_shdrs(FILE *fp) secs = calloc(shnum, sizeof(struct section)); if (!secs) { - die("Unable to allocate %d section headers\n", + die("Unable to allocate %ld section headers\n", shnum); } if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - ehdr.e_shoff, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + ehdr.e_shoff, strerror(errno)); } for (i = 0; i < shnum; i++) { struct section *sec = &secs[i]; if (fread(&shdr, sizeof(shdr), 1, fp) != 1) - die("Cannot read ELF section headers %d/%d: %s\n", + die("Cannot read ELF section headers %d/%ld: %s\n", i, shnum, strerror(errno)); sec->shdr.sh_name = elf_word_to_cpu(shdr.sh_name); sec->shdr.sh_type = elf_word_to_cpu(shdr.sh_type); @@ -450,12 +453,12 @@ static void read_strtabs(FILE *fp) } sec->strtab = malloc(sec->shdr.sh_size); if (!sec->strtab) { - die("malloc of %d bytes for strtab failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for strtab failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -475,12 +478,12 @@ static void read_symtabs(FILE *fp) } sec->symtab = malloc(sec->shdr.sh_size); if (!sec->symtab) { - die("malloc of %d bytes for symtab failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for symtab failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -508,12 +511,12 @@ static void read_relocs(FILE *fp) } sec->reltab = malloc(sec->shdr.sh_size); if (!sec->reltab) { - die("malloc of %d bytes for relocs failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for relocs failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h index 43c83c0fd22c..4c49c82446eb 100644 --- a/arch/x86/tools/relocs.h +++ b/arch/x86/tools/relocs.h @@ -17,6 +17,7 @@ #include #include +__attribute__((__format__(printf, 1, 2))) void die(char *fmt, ...) __attribute__((noreturn)); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette