From nobody Mon Jan 26 23:02:42 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8497833A9F7 for ; Mon, 26 Jan 2026 15:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769440465; cv=none; b=f10J48ci3Fqfu3LQSjKgFhsKthJLZJ3aFOGnvUR/8uqJJC6wfSRVVDl7uTNF3lpopDhdGH4H90/fHfUslSMQSiEoXzw2ND5JOUF6JSx0sCK8zQPX5+GGfOFUTYB+jSIYHCMGqwGvWVRH35dt7JirE2KHsV+uDbm3lZvuGYU+CuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769440465; c=relaxed/simple; bh=LWcqTdZCWMaZT4PvAOO5zfpAQbRpzep3CLoDKM/v3rU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YsXljHtsVf8OT6K3ZxYaLxSvPVjVFWdNesE1lO7acG9cwzk/8uLfFzYyhg2NWL/JcA87j+Sj+gRKeCVcjYNQ216c7mOWTIDRsZtiivyprXjO0VvbWS+ItLyAVul3ee0dK9PnjapZtsqcMXJ8DMOFAWqC649VdTY/5A7AFMJzxvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=BMlcpWgJ; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="BMlcpWgJ" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-432d2c7a8b9so4529808f8f.2 for ; Mon, 26 Jan 2026 07:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1769440462; x=1770045262; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QIxvhOul/KbCJtg62EY54hXB3dq9qYXbiZcu5EV5xSo=; b=BMlcpWgJ1r0lwxPP6IodIDIPhl6vynlWhdbsxHy40irHm7xkdcx8bWmflMhWsyLQC+ 26K3sL8FvYH3id98fglrzM4CNDrHITSfpamrsFpQ2B8d8rMxdA0IaDSsfRkqic97d5nb rBzDsUNfSHKuJe4REqf61QG3xSbTvBBUVpdb3R1LBnb0mQLz3XWXV3gSoRVoQBIZGM3I 4ALQANAwlAz/7AyWLWB6Cx1xIs3A0m1mEC0sDj5uK4evVcxoOicMhgXdw9AndTfO4Mvg xkfED3ILklmmIdh/kLjVRSqclq+75841f4dRL+A4O933O05waLb29GV1XIdgq8IKwMD5 EPKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769440462; x=1770045262; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QIxvhOul/KbCJtg62EY54hXB3dq9qYXbiZcu5EV5xSo=; b=Vk5TamTrBxSzKT0BFNiCBGQztnrLnE9f/UQTMOVZe6CIVUPYZfKiAAezkVUlgH1hCS tR0tDMEm6ahFQINfHdLUgKOTwRoyMnjXc/+Ev+MMtNKOlXbyAOvz6qUxiut7SP8bNvFu VcHXTbRApyqapprtjtVuiQgVAZ+GGB0RaN2eoKRj48Ts1TUuD68ArsAMy7SFORp/PUyf Lmxhc/FfHDzXMTC/B26Ivg5gY8LOWQzPH4IQzjwp2juR5SXWDqXas+9ib9xWvwCb/Cmr /7If2MvN6WStuepf39k4GjwyhrKEQCVjs+o4W3tqSP7es9BiT38rmy+w7gtN1rmObBx1 Fhqw== X-Gm-Message-State: AOJu0Yy1hgS+mcO9ryXX0/xSJQSxCpAO3UVnnFY/84LELiQzYzCyS0nP UgviSG91mOXqwn1/1HTyC/1a7GBCFIZn2dNefui2KEw0OtR3/rIdHW5EyX/Mi83Ijqk= X-Gm-Gg: AZuq6aKu7U1iG29voVgLwt6lUT2lC4NNcHbs39BVMfdSmHXkFFy/Jl7rnGPu4x2OGCF sfsWXamBfFqNNsO0k8Cmj75tmdKiAZ/Qx2vpPcHFkXfkcAT3MgSrZrXydWv9lJkUKjIiBzih2kl DH+KFNXgChitxoQRImgjfEefjWFoYS/HHtrQOQ1Y9Cad16oBOpmWNy8GnCNH1WBpyGk3FwffAhw OLIZgI4hr+IUNsCI4EaWZSEVDAoRZ6RmRdZRJKTiIs1ZtvYxSirxdmDGWqjt4zhq8oYI9JI6LcX CLGAnfVL4FDaSPS+1bOXiEOdXBTz7eTCyPhJ9u1s2qUW5ggve1Iyaq3sUr09PL+U0CWMcp1DmHr Dah0fyicTDIxCyrMk1pCShOq0dBFnIP/o+iwhPJ3v+JI83z29FzXZDS03NHOWWSV9Bq8XgLwpem nQfrTGOeQFNuwQbTuW0J7COEzS71diopw= X-Received: by 2002:adf:ea05:0:b0:432:aa5a:3916 with SMTP id ffacd0b85a97d-435ca1ada1fmr7101107f8f.40.1769440461784; Mon, 26 Jan 2026 07:14:21 -0800 (PST) Received: from zovi.suse.cz (109-81-1-107.rct.o2.cz. [109.81.1.107]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1f745c5sm31813347f8f.32.2026.01.26.07.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 07:14:21 -0800 (PST) From: Petr Pavlu To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Petr Pavlu Subject: [PATCH] objtool: Replace custom macros in elf.c with shared ones Date: Mon, 26 Jan 2026 16:13:48 +0100 Message-ID: <20260126151356.3924887-1-petr.pavlu@suse.com> X-Mailer: git-send-email 2.52.0 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" The source file tools/objtool/elf.c defines the macros ALIGN_UP(), ALIGN_UP_POW2() and MAX(). These macros unnecessarily duplicate functionality already available under tools/include/, specifically ALIGN(), roundup_pow_of_two() and max(). More importantly, the definition of ALIGN_UP_POW2() is incorrect when the input is 1, as it results in a call to __builtin_clz(0), which produces an undefined result. This issue impacts the function elf_alloc_reloc(). When adding the first relocation to a section, the function allocates an undefined number of relocations. Replace the custom macros with the shared functionality to resolve these issues. Fixes: 2c05ca026218 ("objtool: Add elf_create_reloc() and elf_init_reloc()") Signed-off-by: Petr Pavlu --- tools/objtool/elf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 6a8ed9c62323..2c02c7b49265 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -18,15 +18,14 @@ #include #include #include +#include +#include #include +#include #include #include #include =20 -#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1)) -#define ALIGN_UP_POW2(x) (1U << ((8 * sizeof(x)) - __builtin_clz((x) - 1U)= )) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) - static inline u32 str_hash(const char *str) { return jhash(str, strlen(str), 0); @@ -1336,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct s= ection *strtab, const char return -1; } =20 - offset =3D ALIGN_UP(strtab->sh.sh_size, strtab->sh.sh_addralign); + offset =3D ALIGN(strtab->sh.sh_size, strtab->sh.sh_addralign); =20 if (!elf_add_data(elf, strtab, str, strlen(str) + 1)) return -1; @@ -1378,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *s= ec, const void *data, size_ sec->data->d_size =3D size; sec->data->d_align =3D 1; =20 - offset =3D ALIGN_UP(sec->sh.sh_size, sec->sh.sh_addralign); + offset =3D ALIGN(sec->sh.sh_size, sec->sh.sh_addralign); sec->sh.sh_size =3D offset + size; =20 mark_sec_changed(elf, sec, true); @@ -1502,7 +1501,7 @@ static int elf_alloc_reloc(struct elf *elf, struct se= ction *rsec) rsec->data->d_size =3D nr_relocs_new * elf_rela_size(elf); rsec->sh.sh_size =3D rsec->data->d_size; =20 - nr_alloc =3D MAX(64, ALIGN_UP_POW2(nr_relocs_new)); + nr_alloc =3D max(64UL, roundup_pow_of_two(nr_relocs_new)); if (nr_alloc <=3D rsec->nr_alloc_relocs) return 0; =20 --=20 2.52.0