From nobody Fri Dec 19 07:03:47 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDB791804E for ; Sat, 7 Dec 2024 01:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536768; cv=none; b=VV5kq42sp5gGqEtmcDzuITCXlUhQftTbucK2p6f06dwESh39VXGF4D5/1XfJjETUNkXZ/KjI0EhlkvnFbebbubo9ECbFsZmSKsCceEsPLk+kROyEbsudjZEtuKWWoh9h20cH3R2GKgG4bO71xYNIlsF+5Ix/K2FacDFeWC2ULJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536768; c=relaxed/simple; bh=0CbpOPI4Xa7ty6GYDZyXKqQGKZIAwaVBL6eU1ORjlx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G5Kr8FL5sEe/A3A6LNQo/mH3dP8WgAPDeUA3B8VHclpoL0FF2rR4pXitUPIk4QkOwKgjKBLPxmIYBuGBxUoXo61U56VP+/uLbP0PPfnkvL91A+R9dcqJlZeH838WHP239nsmIks5t4e+wkQ3SMy7MWW5LliECDmuz+CP9jF7WUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Axjq_6q1NnFq1SAA--.6130S3; Sat, 07 Dec 2024 09:59:22 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S4; Sat, 07 Dec 2024 09:59:21 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/10] objtool: Handle different entry size of rodata Date: Sat, 7 Dec 2024 09:59:07 +0800 Message-ID: <20241207015915.1159-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-1-yangtiezhu@loongson.cn> 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 X-CM-TRANSID: qMiowMBx_uD1q1Nn3Wd5AA--.42544S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4fuF4DtryruF45CF13WrX_yoW5AF45pF srC3yrGr4Fgry3Gwnrta1kurZ8Gws2gryIqF9rJry8ArZrXr15JFWSyryUtF18XwsYgFWf XFZYgr15AF4qy3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8N6pPUUUUU== Content-Type: text/plain; charset="utf-8" In the most cases, the entry size of rodata is 8 bytes because the relocation type is 64 bit, but when compiling with Clang on LoongArch, there exists 32 bit relocation type, the entry size of rodata should be 4 bytes in this case. Add an arch-specific function arch_reloc_size() to assign the entry size of rodata, the default value is 8 in the weak definition, it can be overridden by archs that have different requirements. Signed-off-by: Tiezhu Yang --- tools/objtool/arch/loongarch/decode.c | 11 +++++++++++ tools/objtool/check.c | 10 +++++++++- tools/objtool/include/objtool/arch.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 69b66994f2a1..b64205b89f6b 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -363,3 +363,14 @@ void arch_initial_func_cfi_state(struct cfi_init_state= *state) state->cfa.base =3D CFI_SP; state->cfa.offset =3D 0; } + +unsigned int arch_reloc_size(struct reloc *reloc) +{ + switch (reloc_type(reloc)) { + case R_LARCH_32: + case R_LARCH_32_PCREL: + return 4; + default: + return 8; + } +} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f64435ad3514..7271e959520e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1943,6 +1943,11 @@ static int add_special_section_alts(struct objtool_f= ile *file) return ret; } =20 +__weak unsigned int arch_reloc_size(struct reloc *reloc) +{ + return 8; +} + static int add_jump_table(struct objtool_file *file, struct instruction *i= nsn, struct reloc *next_table) { @@ -1954,6 +1959,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, struct reloc *reloc =3D table; struct alternative *alt; unsigned long sym_offset; + unsigned int entry_size; =20 /* * Each @reloc is a switch table relocation which points to the target @@ -1967,8 +1973,10 @@ static int add_jump_table(struct objtool_file *file,= struct instruction *insn, if (reloc !=3D table && reloc =3D=3D next_table) break; =20 + entry_size =3D arch_reloc_size(reloc); + /* Make sure the table entries are consecutive: */ - if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) + if (prev_offset && reloc_offset(reloc) !=3D prev_offset + entry_size) break; =20 sym_offset =3D reloc->sym->offset + reloc_addend(reloc); diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index d63b46a19f39..396f7c6c81c0 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -97,4 +97,6 @@ int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); =20 +unsigned int arch_reloc_size(struct reloc *reloc); + #endif /* _ARCH_H */ --=20 2.42.0