Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp691938iog; Fri, 24 Jun 2022 11:51:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tylS90SlJgSi1x8dJu7JViIT4pfKefOqY5ZWJbxLUn6Akm70bS9uK3njR0f+v5hyhD2VPi X-Received: by 2002:a17:906:b795:b0:722:e662:cffe with SMTP id dt21-20020a170906b79500b00722e662cffemr411395ejb.121.1656096709761; Fri, 24 Jun 2022 11:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656096709; cv=none; d=google.com; s=arc-20160816; b=Y8BNooXiE9zXhTbo673HQpgZ/O+DxgwaM6PnKfpOXAR7JGPiLLqY+WEh7JiCY8mfik HyBg6IUYPqDPXC43Wtpobytj6aLM+yYqwjW0OsFzPIhm3k9pM3K3trR0nzTQ5eX70ECV 6F3IxDvCv5Y3x92VsmbC9TqVP7d75MZ8/UTAlo739rD7Z9YFa3RVMsmDeJbwHkSz0ek+ X21Eza5QHAZ+GDM5uB6Ka8ehIbZfKshuF9vfs2aaL6U6hBGszch02cRGjqTDGVtS3hf5 O90YQ6UaUCY7jDFVznliY3tf9TXfMmUaIs4dStE5KHtY0cHSy7Z09JoN9iAkbRskoF0I 07lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NzHBotMACtPxvgxmObHX5vHdxoBGGuZmZpyUzQETn9s=; b=kCh/4CJDxWYVaadFsikw/ux9oiFYLRQIcoNlFijw8W1cnMSD8UMnDtqJSDWbLiixAc 5HKOxSaG2BnU/CgahbEGBooRrzlV7bGoagYfRfD51t6LD/tfOTPbBM2sbMpVJl8Ytxya uzPvuNwD+bOHY5H/4vw4mrJnAVuTnZW3Fk3VY8jEpglA97vyZiVB2jHel23RgjJy/Iiu XhFp+dZKkpL4ZQFHwL/QvkjDRFvNrMv06trsjMxUu4F0oAdJVf+FZyROFRNFSPm8Vfwd Vh6M0dBkLZkvsReI5QRnRSH4zlNJez/MuPphslmvt//pbvg/zGa3Ls74DEsIjQ7dqIQB UN/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Is2wHavM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a1709065e4900b006fec40443b6si3780377eju.23.2022.06.24.11.51.23; Fri, 24 Jun 2022 11:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Is2wHavM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231496AbiFXSdz (ORCPT + 99 others); Fri, 24 Jun 2022 14:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231434AbiFXSdw (ORCPT ); Fri, 24 Jun 2022 14:33:52 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA4D280507 for ; Fri, 24 Jun 2022 11:33:50 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25OHjUwV022150; Fri, 24 Jun 2022 18:33:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=NzHBotMACtPxvgxmObHX5vHdxoBGGuZmZpyUzQETn9s=; b=Is2wHavMF9AnVuCfGTjkMOR+NVhcQoFiNtvUd9sr2/v8vH6t1Kv4aDUI0IK3kis0wyz8 MQ4wQAyr5P/DG+fhoLtYgh18wdvH83FFnKMaEnh8y63/wGJuDfGpEbzaazZGlIL6Zjpu LBjVmmnb9NYTgnoV45DPCvQQ5o0WgPVPaGUbqJVZetBscooM+DmWjS83pGLWExecRDcm G2PQHve2tiHPRConu/DDcN+gkpUsJS1/nyYqtMTJ2rJhb/K1PQ8cOWRtZGmDbipoSiIU 9VHS3dCKlPgp4TZgId0mjMiIdR4WkihYbnClX45HxD8adcZrRFGJKhcfDsRkLggB5E56 iw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gwhxx18m9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jun 2022 18:33:27 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25OIUcWI025790; Fri, 24 Jun 2022 18:33:27 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gwhxx18kg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jun 2022 18:33:27 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25OILd0x017347; Fri, 24 Jun 2022 18:33:25 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04fra.de.ibm.com with ESMTP id 3gs6b8ycuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jun 2022 18:33:25 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25OIXNVA19923386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jun 2022 18:33:23 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06D6D5204F; Fri, 24 Jun 2022 18:33:23 +0000 (GMT) Received: from li-c3569c4c-1ef8-11b2-a85c-ee139cda3133.ibm.com.com (unknown [9.43.0.85]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 218B452054; Fri, 24 Jun 2022 18:33:18 +0000 (GMT) From: Sathvika Vasireddy To: linuxppc-dev@lists.ozlabs.org Cc: jpoimboe@redhat.com, peterz@infradead.org, linux-kernel@vger.kernel.org, aik@ozlabs.ru, mpe@ellerman.id.au, christophe.leroy@csgroup.eu, mingo@redhat.com, rostedt@goodmis.org, naveen.n.rao@linux.vnet.ibm.com, sv@linux.ibm.com, mbenes@suse.cz, benh@kernel.crashing.org, paulus@samba.org Subject: [RFC PATCH v3 03/12] objtool: Use target file class size instead of a compiled constant Date: Sat, 25 Jun 2022 00:02:29 +0530 Message-Id: <20220624183238.388144-4-sv@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220624183238.388144-1-sv@linux.ibm.com> References: <20220624183238.388144-1-sv@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: inRIedWEvOdzWxskrDtme6_N0bzh4qr_ X-Proofpoint-GUID: q0kqo_w1PkVsU2_jK5YHsP1C2Z_0SHH0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-24_08,2022-06-23_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 priorityscore=1501 spamscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 bulkscore=0 mlxscore=0 mlxlogscore=969 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206240072 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy In order to allow using objtool on cross-built kernels, determine size of long from elf data instead of using sizeof(long) at build time. For the time being this covers only mcount. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 16 +++++++++------- tools/objtool/elf.c | 8 ++++++-- tools/objtool/include/objtool/elf.h | 8 ++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index cef1dd54d505..fabc0ea88747 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -802,9 +802,9 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) static int create_mcount_loc_sections(struct objtool_file *file) { struct section *sec; - unsigned long *loc; struct instruction *insn; int idx; + int size = elf_class_size(file->elf); sec = find_section_by_name(file->elf, "__mcount_loc"); if (sec) { @@ -820,23 +820,25 @@ static int create_mcount_loc_sections(struct objtool_file *file) list_for_each_entry(insn, &file->mcount_loc_list, call_node) idx++; - sec = elf_create_section(file->elf, "__mcount_loc", 0, sizeof(unsigned long), idx); + sec = elf_create_section(file->elf, "__mcount_loc", 0, size, idx); if (!sec) return -1; + sec->sh.sh_addralign = size; + idx = 0; list_for_each_entry(insn, &file->mcount_loc_list, call_node) { + void *loc; - loc = (unsigned long *)sec->data->d_buf + idx; - memset(loc, 0, sizeof(unsigned long)); + loc = sec->data->d_buf + idx; + memset(loc, 0, size); - if (elf_add_reloc_to_insn(file->elf, sec, - idx * sizeof(unsigned long), + if (elf_add_reloc_to_insn(file->elf, sec, idx, R_X86_64_64, insn->sec, insn->offset)) return -1; - idx++; + idx += size; } return 0; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index c25e957c1e52..63218f5799c2 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1124,6 +1124,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec { char *relocname; struct section *sec; + int size = elf_class_size(elf); relocname = malloc(strlen(base->name) + strlen(".rela") + 1); if (!relocname) { @@ -1133,7 +1134,10 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec strcpy(relocname, ".rela"); strcat(relocname, base->name); - sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); + if (size == sizeof(u32)) + sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0); + else + sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0); free(relocname); if (!sec) return NULL; @@ -1142,7 +1146,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec sec->base = base; sec->sh.sh_type = SHT_RELA; - sec->sh.sh_addralign = 8; + sec->sh.sh_addralign = size; sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; sec->sh.sh_info = base->idx; sec->sh.sh_flags = SHF_INFO_LINK; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index adebfbc2b518..c720c4476828 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -141,6 +141,14 @@ static inline bool has_multiple_files(struct elf *elf) return elf->num_files > 1; } +static inline int elf_class_size(struct elf *elf) +{ + if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32) + return sizeof(u32); + else + return sizeof(u64); +} + struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr); -- 2.25.1