Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp13545pxk; Wed, 30 Sep 2020 16:18:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpxy7WehzVptZV+l3Nv/dfXTwhpqjQNtofbajn5jiEsjYkvL7X2EIO6gDKw8put19Bow9d X-Received: by 2002:a17:906:2714:: with SMTP id z20mr5080671ejc.409.1601507909368; Wed, 30 Sep 2020 16:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601507909; cv=none; d=google.com; s=arc-20160816; b=mLRcDVJL4X3aJPE2TmsW+Hk6SY8xhxXoxbij/0lugAqdXj4rQF4bOCkcrEG9JVP1IA q5Hp4dG78Drh44pwLANjVHG6+ifQ/qL4zqW8OVjNxF8WMa/Hw77PwkrDPnmGTXIZGSDa ogASmEF9pGRh4FCedPQDOveRqp1EQPzTtiq7pZjaBIYwLrC7biahoAkpE0OeKXZYyAJG 1qSc5WndX/BEWCAHcAqNWsCvBkZgF7iRCr/1NJyLzydazjG4tWdLNISK0JuSb6WYRkf2 78gAiJccf1ke8dNxVSzMmWCUhNGeWdHEPJWvbfyOqydCItp0dBtb+LKhBhBunCE5w1d5 Yy5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vFMZTjfglZghT+DVaeJGAUx1EnEkxjAxPyqdKGGrdvI=; b=HDObVC0bxmCZnUhf2ZT09kbTjAtPY6oDgaVLeiG64vYdydIc0Q6qs75VvV6sqfza9b 7ND4J9gWZKmdqEBL+jlkeKomn3uxQ6zLKwYZTvaJAlHJ8zwrpUByLknErWJcfwkK6+ho DqWNKOiodPvtoQqN+6lv/XBbLojPl9lbfUBfXFwWbe1bgfmbJBJhtJtYUvZsjCnZnLwL u7cbolHIv03JvA+ylpA5eKwQdLcACYepoXtKjBdGo2D9RmZfj3nDEleDL3s6X3pkY+8/ wv+5Wx6nITSZhdVykr37j+VbjQlTDA4x9iS9nYnbno54RmAapJJa7qcg1xUmj3Zgrccx Zq9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=M9sKJRW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh20si2296227ejb.294.2020.09.30.16.18.07; Wed, 30 Sep 2020 16:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=M9sKJRW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731336AbgI3WSB (ORCPT + 99 others); Wed, 30 Sep 2020 18:18:01 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:27164 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730090AbgI3WR4 (ORCPT ); Wed, 30 Sep 2020 18:17:56 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08UM1s8V036353; Wed, 30 Sep 2020 18:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to; s=pp1; bh=vFMZTjfglZghT+DVaeJGAUx1EnEkxjAxPyqdKGGrdvI=; b=M9sKJRW0z04WVJb9E6S4bZL+X9Q162RrMt9oen9WcENulV5fj2/aIhSdSclEYvhpoe5p FGVsDrQvHJiEcSfBW6zpVnMRlIXZansdkViIskoMvuSF+42LVvnFUB15qLhwRdAaBFXW kxnkZItgwAkWt986Chtp/mK4KwhogBI7SQEqhqJxPmrbR1xMI2m7BfrbnmRwb4C0Pc2s Kz+9/mqknzJ5BUefHqzmlK+5BxbFLRbHYa4YCd+k5IFTFJYKT9p+0qClKwSvMERLHYpn A9jgdDBxQkuzSwpRdsHIK6BXWoKb8jRXNd0OvwY7Tz+HGYP6fWBEEESnbDO31OKTIQ+P 7w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33w1vhh54r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2020 18:17:36 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08UM4BqS047099; Wed, 30 Sep 2020 18:17:35 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 33w1vhh54a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2020 18:17:35 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08UMCGJm002264; Wed, 30 Sep 2020 22:17:33 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 33v5kg0sra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2020 22:17:33 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08UMHVJ520644174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Sep 2020 22:17:31 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A27AAE045; Wed, 30 Sep 2020 22:17:31 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 92AA0AE056; Wed, 30 Sep 2020 22:17:30 +0000 (GMT) Received: from localhost (unknown [9.145.18.215]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 30 Sep 2020 22:17:30 +0000 (GMT) Date: Thu, 1 Oct 2020 00:17:29 +0200 From: Vasily Gorbik To: Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner Cc: Masami Hiramatsu , David Laight , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Miroslav Benes , Alexandre Chartre , Julien Thierry , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 3/4] objtool: correct rebuilding of reloc sections Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Patchwork-Bot: notify X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-30_13:2020-09-30,2020-09-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 impostorscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009300174 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Schwidefsky Currently relocations generated in elf_rebuild_rel_reloc_section/ elf_rebuild_rela_reloc_section functions are broken if the objtool is built and run on big endian system. E.g. the following errors pop up during x86 cross compilation: x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x2000000 >= 0x22) for offset 0 in section `.orc_unwind_ip' x86_64-9.1.0-ld: final link failed: bad value To address that convert those functions to do things similar to elf_write_reloc(), reuse gelf_update_rel/gelf_update_rela libelf library functions. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- tools/objtool/elf.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..5c0341b0cde3 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -829,25 +829,27 @@ static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rel *relocs; + void *buf; /* Allocate a buffer for relocations */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rel); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_REL; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, &sec->reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rel.r_offset = reloc->offset; + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rel(sec->data, idx, &reloc->rel); idx++; } @@ -858,26 +860,28 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rela *relocs; + void *buf; /* Allocate a buffer for relocations with addends */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rela); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_RELA; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, &sec->reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_addend = reloc->addend; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rela.r_offset = reloc->offset; + reloc->rela.r_addend = reloc->addend; + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rela(sec->data, idx, &reloc->rela); idx++; } -- ⣿⣿⣿⣿⢋⡀⣀⠹⣿⣿⣿⣿ ⣿⣿⣿⣿⠠⣶⡦⠀⣿⣿⣿⣿ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿