From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9906CC41604 for ; Wed, 7 Oct 2020 16:20:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3698D216C4 for ; Wed, 7 Oct 2020 16:20:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="e1IzbuiU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qTYNRXcm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727935AbgJGQUY (ORCPT ); Wed, 7 Oct 2020 12:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727881AbgJGQUV (ORCPT ); Wed, 7 Oct 2020 12:20:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEEC3C0613D2; Wed, 7 Oct 2020 09:20:20 -0700 (PDT) Date: Wed, 07 Oct 2020 16:20:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1602087619; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2CQOWLh81C1ASv08nLkbGSIyHBxPmkM+chlpE/DUPx0=; b=e1IzbuiUDmyzCgIsJjSixkr6J1PS6KWa913B0TQogaL7750s2WYvNvOMtnYl03cMB9XoUt zqpmhfExNzccKmZMys2a/djBmQeqV2HMt+x36+nACfPX72HNjPRCunwK8bQ+kDfLUA1d6V DT5HgDnJ5Gd9GCP/pim8iSKF4h7iENuAxUWJ0uUGSkYg6xay4umwWvYWNpL8HghBpJW3oM hE2E7bPjcx9B71YAVoAmcV6lIaosm6QssU9taBYNEmIs9o5CJaJ6g1yFu7v2ggf9uvtA6T 8DrD1o+eLaRb8ATjHbnF+u4Js7Grwe7pvTO03oGVNi3eOGPYHc0I+6zPQSXgVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1602087619; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2CQOWLh81C1ASv08nLkbGSIyHBxPmkM+chlpE/DUPx0=; b=qTYNRXcmj7dEV3puEvYeYItkvr9B/qkL0bmW7m4tUDfHxokEk38jJi6u7zJHiWMlcH/3ub POHfcd+7VwC7XcDg== From: "tip-bot2 for Martin Schwidefsky" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Fix reloc generation on big endian cross compiles Cc: Martin Schwidefsky , Vasily Gorbik , Josh Poimboeuf , x86 , LKML MIME-Version: 1.0 Message-ID: <160208761875.7002.3433729729331164826.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the objtool/core branch of tip: Commit-ID: 317664a7fcc99d9bcc0cb33ac05e27764f3024e4 Gitweb: https://git.kernel.org/tip/317664a7fcc99d9bcc0cb33ac05e27764f3024e4 Author: Martin Schwidefsky AuthorDate: Sun, 04 Oct 2020 16:30:50 +02:00 Committer: Josh Poimboeuf CommitterDate: Tue, 06 Oct 2020 09:36:48 -05:00 objtool: Fix reloc generation on big endian cross compiles 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 Signed-off-by: Josh Poimboeuf --- 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 4e1d746..5c0341b 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++; }