From nobody Sat Nov 23 18:30:05 2024 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86A5A14F9FD for ; Fri, 22 Nov 2024 04:50:25 +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=1732251029; cv=none; b=YtsNemOgj/Dk5OGTVdWFv/2z2HHKLD6/gIfHOF1QdWpP21AfUgpXG9XqqOOkWYVI+d5fEgg9A3bIblejP9ghr5BmR7k7wDY/XVPvtmcPGzEh795Xbvxo7sAph2LgbBxe8RPtcfdvXgIEthoK5AZeYZSudwb71JbdOPxVd5svjnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732251029; c=relaxed/simple; bh=WQBjV7XvQFc38Q87Jv1cXvfn27Td+pGBvefYsoaVrgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PZmEm1D71J7r2SywkhZpVeFGq5hNBcvObrFtZRxTDzyOsR5ig+vlAeVuyAbhxn2vkBnohziMbNi/m9Ua2BzcSJCedoHbs7BuymFnHZpeul8/2ttyZY1Vexir39BmQ3k+2c4er4bi2VkAXYKS7WK5Y0zVDgKRphLgxDU4fwL7cgM= 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 _____8AxEK+KDUBn87xFAA--.32039S3; Fri, 22 Nov 2024 12:50:18 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMCxdcCIDUBnIJJiAA--.33733S3; Fri, 22 Nov 2024 12:50:17 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/10] objtool: Handle various symbol types of rodata Date: Fri, 22 Nov 2024 12:49:56 +0800 Message-ID: <20241122045005.14617-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241122045005.14617-1-yangtiezhu@loongson.cn> References: <20241122045005.14617-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: qMiowMCxdcCIDUBnIJJiAA--.33733S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJFWDKF4kAF4kGFWfGw18Xrc_yoW5Ww4xpF sxG3y5Kr45Xr1fWws7tFW0gF9xGws7WrnrJ39rKr1rA3sIqF1rKFWSkr1ay3WDGr1Fva17 XF1Y9ry7uF4UA3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVj vjDU0xZFpf9x07j5xhLUUUUU= Content-Type: text/plain; charset="utf-8" In the relocation section ".rela.rodata" of each .o file compiled with LoongArch toolchain, there are various symbol types such as STT_NOTYPE, STT_OBJECT, STT_FUNC in addition to the usual STT_SECTION, it needs to use reloc symbol offset instead of reloc addend to find the destination instruction in find_jump_table() and add_jump_table(). This is preparation for later patch on LoongArch, there is no effect for the other archs with this patch. Signed-off-by: Tiezhu Yang --- tools/objtool/check.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6604f5d038aa..9601235e908d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2079,6 +2079,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, unsigned int prev_offset =3D 0; struct reloc *reloc =3D table; struct alternative *alt; + unsigned long offset; =20 /* * Each @reloc is a switch table relocation which points to the target @@ -2094,12 +2095,19 @@ static int add_jump_table(struct objtool_file *file= , struct instruction *insn, if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) break; =20 + if (reloc->sym->type =3D=3D STT_SECTION) { + /* Addend field in the relocation entry associated with the symbol */ + offset =3D reloc_addend(reloc); + } else { + /* The address of the symbol in the relocation entry */ + offset =3D reloc->sym->offset; + } + /* Detect function pointers from contiguous objects: */ - if (reloc->sym->sec =3D=3D pfunc->sec && - reloc_addend(reloc) =3D=3D pfunc->offset) + if (reloc->sym->sec =3D=3D pfunc->sec && offset =3D=3D pfunc->offset) break; =20 - dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + dest_insn =3D find_insn(file, reloc->sym->sec, offset); if (!dest_insn) break; =20 @@ -2137,6 +2145,7 @@ static struct reloc *find_jump_table(struct objtool_f= ile *file, { struct reloc *table_reloc; struct instruction *dest_insn, *orig_insn =3D insn; + unsigned long offset; =20 /* * Backward search using the @first_jump_src links, these help avoid @@ -2160,7 +2169,16 @@ static struct reloc *find_jump_table(struct objtool_= file *file, table_reloc =3D arch_find_switch_table(file, insn); if (!table_reloc) continue; - dest_insn =3D find_insn(file, table_reloc->sym->sec, reloc_addend(table_= reloc)); + + if (table_reloc->sym->type =3D=3D STT_SECTION) { + /* Addend field in the relocation entry associated with the symbol */ + offset =3D reloc_addend(table_reloc); + } else { + /* The address of the symbol in the relocation entry */ + offset =3D table_reloc->sym->offset; + } + + dest_insn =3D find_insn(file, table_reloc->sym->sec, offset); if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) continue; =20 --=20 2.42.0