From nobody Tue Dec 16 12:38:44 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD77726A0CC; Fri, 9 May 2025 20:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821880; cv=none; b=NbTYR0Q0PlA6DGnmN4sJhzicRfdMzWYP28sDCitPUjFqCPUsdt14XLVJbHLJ+MzY+sMI7UXfw40CC0NjhUgohh/3y8p50YjxY/pWDzlVM18rJEqz+6YN7vQoDPpD0M3we8VdbgDsSOQVXoZpMq3FjXcAbdem3+k9vzozix/ME28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821880; c=relaxed/simple; bh=ATnjVeDvFHZYfIgFa9Cjs6eAsIVU/U1FXzQfK6EwYZs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AhpkbAqSKIi0gXoprxTR3OjGkstAhcCiwTxNlmBxWJD6TwSo46bO/SnbFGfnF+JfgLK4ITNUoN4XQa7SpsQ7TYjCkgoHnw5i8wtZLrI6wym7Bh+FKDPSnM3gxBlrJNqKsDnn/x6QTQ+h1/i0XhkoY3JKJqI+4AVTP4rxT32o7Us= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q4lfrQ4s; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q4lfrQ4s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EC73C4CEF0; Fri, 9 May 2025 20:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746821880; bh=ATnjVeDvFHZYfIgFa9Cjs6eAsIVU/U1FXzQfK6EwYZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q4lfrQ4sn+DkONUip8khR8lUOW1y9hSoHIu9c5VDGJJUVNgQvSKnMP2srG/rDOeDB X9dIVQezhuWHks6PBRF2Sq05D+QnL/Ga+ZsdOKnb4OkPu6PFa2W9YIq73CUB+wiIAo AY9EPb9WfNdw6XOOwPSEaAwkKFOrtdp+bUCiUYxHN9lohzQHssvTF+tnVyM6x2SlGP ENVwTrwbHvwGSkWKtSXmFjL3OLcm60mVPn6ERF0Z2F1IHJPAHyRY5nKGjII2SRLvbS WVasM5D+j30kiPLZ7gwqKYOf7usw7wEoqZcA685A+WQ3NoWpVGZvx0zVgalG5h+ALM AZBKRxFvpdUSQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Petr Mladek , Miroslav Benes , Joe Lawrence , live-patching@vger.kernel.org, Song Liu , laokz , Jiri Kosina , Marcos Paulo de Souza , Weinan Liu , Fazla Mehrab , Chen Zhongjin , Puranjay Mohan Subject: [PATCH v2 23/62] objtool: Clean up compiler flag usage Date: Fri, 9 May 2025 13:16:47 -0700 Message-ID: <23a069d2e00c6b0c9305f05282bad7ea6f8bed07.1746821544.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS aren't defined when objtool is built standalone. Also, the EXTRA_WARNINGS flags are rather arbitrary. Make things simpler and more consistent by specifying compiler flags explicitly and tweaking the warnings. Also make a few code tweaks to make the new warnings happy. Signed-off-by: Josh Poimboeuf --- tools/objtool/Makefile | 15 ++++++++++----- tools/objtool/check.c | 4 ++-- tools/objtool/elf.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 8c20361dd100..fc82d47f2b9a 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -23,6 +23,11 @@ LIBELF_LIBS :=3D $(shell $(HOSTPKG_CONFIG) libelf --lib= s 2>/dev/null || echo -lel =20 all: $(OBJTOOL) =20 +WARNINGS :=3D -Werror -Wall -Wextra -Wmissing-prototypes \ + -Wmissing-declarations -Wwrite-strings \ + -Wno-implicit-fallthrough -Wno-sign-compare \ + -Wno-unused-parameter + INCLUDES :=3D -I$(srctree)/tools/include \ -I$(srctree)/tools/include/uapi \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ @@ -30,11 +35,11 @@ INCLUDES :=3D -I$(srctree)/tools/include \ -I$(srctree)/tools/objtool/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ -I$(LIBSUBCMD_OUTPUT)/include -# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it -# is passed here to match a legacy behavior. -WARNINGS :=3D $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-= packed -Wno-nested-externs -OBJTOOL_CFLAGS :=3D -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES= ) $(LIBELF_FLAGS) -OBJTOOL_LDFLAGS :=3D $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) + +OBJTOOL_CFLAGS :=3D -std=3Dgnu11 -fomit-frame-pointer -O2 -g \ + $(WARNINGS) $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS) + +OBJTOOL_LDFLAGS :=3D $(LIBSUBCMD) $(LIBELF_LIBS) $(HOSTLDFLAGS) =20 # Allow old libelf to be used: elfshdr :=3D $(shell echo '$(pound)include ' | $(HOSTCC) $(OBJTO= OL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0cdc2fc85439..5e62d3ce3cc6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -459,7 +459,7 @@ static int decode_instructions(struct objtool_file *fil= e) =20 for (offset =3D 0; offset < sec->sh.sh_size; offset +=3D insn->len) { if (!insns || idx =3D=3D INSN_CHUNK_MAX) { - insns =3D calloc(sizeof(*insn), INSN_CHUNK_SIZE); + insns =3D calloc(INSN_CHUNK_SIZE, sizeof(*insn)); if (!insns) { ERROR_GLIBC("calloc"); return -1; @@ -608,7 +608,7 @@ static int init_pv_ops(struct objtool_file *file) return 0; =20 nr =3D sym->len / sizeof(unsigned long); - file->pv_ops =3D calloc(sizeof(struct pv_state), nr); + file->pv_ops =3D calloc(nr, sizeof(struct pv_state)); if (!file->pv_ops) { ERROR_GLIBC("calloc"); return -1; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 2ea6d591c3c2..c27edeed2dd0 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -736,7 +736,7 @@ static int elf_update_symbol(struct elf *elf, struct se= ction *symtab, } =20 /* setup extended section index magic and write the symbol */ - if ((shndx >=3D SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) { + if (shndx < SHN_LORESERVE || is_special_shndx) { sym->sym.st_shndx =3D shndx; if (!shndx_data) shndx =3D 0; --=20 2.49.0