Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2049128ybk; Mon, 11 May 2020 10:37:38 -0700 (PDT) X-Google-Smtp-Source: APiQypJLz5zaV5nTAhuZ3/R55D/KuNwEONOTT2+lRFfrUYU1VBkRqPf1lUzF7rX4SfUSnXy5+z7t X-Received: by 2002:a50:bb6b:: with SMTP id y98mr14031908ede.296.1589218658659; Mon, 11 May 2020 10:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589218658; cv=none; d=google.com; s=arc-20160816; b=e45SEJwWVdX5INdrv+QTx7Id9tCI/TkZRtwPfh/YbA+ZgKEK7SWK2/o3CcFYI0D4XY J17rXEJUWYGcs6kPCvCGXdnr2clEDnO3lUjg538w0Wzqeisj6zBIR4eGRjhnyDLziEYi nhriMi7AvewicKhS7LqIhiXg/SPqpAhIL0zjtb5q/f8CDWP5yAP9NPWaMZ5UV6qBob82 X170r/mODb8q5RzKByv48rOzDEQhsbNFgCV4Yn/bfyS2QAIpbNGBHeID9oYiwsjXxjI2 e8jR3BySfS5uA3e0LOMGVHnGhIUrHKSAEx9YujhutFUBoQ2dwsSTy1c9TtU3r3IoA6GQ AMag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jJdbm7nqbyvieKgv91ep/K7109Uvqq/DgwV+/smCnP4=; b=HNjB6axnvqvKiDJGA7uGzShcyPaPDw7bP0m2su/0JO/I1WK3qQcSp82L3fv7lz1I6m +TAR3JCrEDwG0GZs4Xq2OulCJ0zin1/DLzr+oDMYMJlfDin0lfOkPag+rUaUvTXE5aff XZvyu0dcDK97Ukaj8K9KnyrJME9RZXp5H+7k43Qeem0aw5n1aLSW1LlevqqjVwPLmAsg AA0Q3/MqrO+473cfO7MKyTStpaGLnssNExo/m1YtKkRrLpXUrj696e00VYiRDVxAnNE6 RIaTgEQ+a66TPIO+VfnCLm5rMuBdQ6qMF0DxTpZxy+pfvwlJIcO1NhRvgGspGjSAoAuz GJUw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gl22si3065009ejb.297.2020.05.11.10.37.15; Mon, 11 May 2020 10:37:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731054AbgEKRfm (ORCPT + 99 others); Mon, 11 May 2020 13:35:42 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:37716 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729698AbgEKRfi (ORCPT ); Mon, 11 May 2020 13:35:38 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Mon, 11 May 2020 10:35:35 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.200.192.41]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 49DDB401CB; Mon, 11 May 2020 10:35:36 -0700 (PDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Julien Thierry , Miroslav Benes , Steven Rostedt , Matt Helsley Subject: [RFC][PATCH 3/5] objtool: Add support for relocations without addends Date: Mon, 11 May 2020 10:35:11 -0700 Message-ID: <17ee3f6f2a246008aaae70f92df24ae92fa0e21e.1588888003.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-001.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently objtool only collects information about relocations with addends. In recordmcount, which we are about to merge into objtool, some supported architectures do not use rela relocations. Since object files use one or the other the list can be reused. Signed-off-by: Matt Helsley --- tools/objtool/elf.c | 55 ++++++++++++++++++++++++++++++++++++--------- tools/objtool/elf.h | 5 ++++- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index c4857fa3f1d1..cd841e3df87d 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -465,12 +465,14 @@ static int read_relas(struct elf *elf) unsigned long nr_rela, max_rela = 0, tot_rela = 0; list_for_each_entry(sec, &elf->sections, list) { - if (sec->sh.sh_type != SHT_RELA) + if ((sec->sh.sh_type != SHT_RELA) && + (sec->sh.sh_type != SHT_REL)) continue; - sec->base = find_section_by_name(elf, sec->name + 5); + sec->base = find_section_by_name(elf, sec->name + + ((sec->sh.sh_type != SHT_REL) ? 5 : 4)); if (!sec->base) { - WARN("can't find base section for rela section %s", + WARN("can't find base section for relocation section %s", sec->name); return -1; } @@ -486,13 +488,26 @@ static int read_relas(struct elf *elf) } memset(rela, 0, sizeof(*rela)); - if (!gelf_getrela(sec->data, i, &rela->rela)) { - WARN_ELF("gelf_getrela"); - return -1; + switch(sec->sh.sh_type) { + case SHT_REL: + if (!gelf_getrel(sec->data, i, &rela->rel)) { + WARN_ELF("gelf_getrel"); + return -1; + } + rela->addend = 0; + break; + case SHT_RELA: + if (!gelf_getrela(sec->data, i, &rela->rela)) { + WARN_ELF("gelf_getrela"); + return -1; + } + rela->addend = rela->rela.r_addend; + break; + default: + break; } rela->type = GELF_R_TYPE(rela->rela.r_info); - rela->addend = rela->rela.r_addend; rela->offset = rela->rela.r_offset; symndx = GELF_R_SYM(rela->rela.r_info); rela->sym = find_symbol_by_index(elf, symndx); @@ -717,17 +732,27 @@ int elf_rebuild_rela_section(struct section *sec) struct rela *rela; int nr, idx = 0, size; GElf_Rela *relas; + GElf_Rel *rels; nr = 0; list_for_each_entry(rela, &sec->rela_list, list) nr++; + /* + * Allocate a buffer for relocations with addends but also use + * it for other relocations too. The section type determines + * the size of the section, the buffer used, and the entries. + */ size = nr * sizeof(*relas); relas = malloc(size); if (!relas) { perror("malloc"); return -1; } + rels = (void *)relas; + if (sec->sh.sh_type == SHT_REL) { + size = nr * sizeof(*rels); + } sec->data->d_buf = relas; sec->data->d_size = size; @@ -736,9 +761,19 @@ int elf_rebuild_rela_section(struct section *sec) idx = 0; list_for_each_entry(rela, &sec->rela_list, list) { - relas[idx].r_offset = rela->offset; - relas[idx].r_addend = rela->addend; - relas[idx].r_info = GELF_R_INFO(rela->sym->idx, rela->type); + switch(sec->sh.sh_type) { + case SHT_REL: + rels[idx].r_offset = rela->offset; + rels[idx].r_info = GELF_R_INFO(rela->sym->idx, rela->type); + break; + case SHT_RELA: + relas[idx].r_addend = rela->addend; + relas[idx].r_offset = rela->offset; + relas[idx].r_info = GELF_R_INFO(rela->sym->idx, rela->type); + break; + default: + break; + } idx++; } diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h index 0b79c2353a21..71bd47055963 100644 --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -61,7 +61,10 @@ struct symbol { struct rela { struct list_head list; struct hlist_node hash; - GElf_Rela rela; + union { + GElf_Rela rela; + GElf_Rel rel; + }; struct section *sec; struct symbol *sym; unsigned int type; -- 2.20.1