2019-05-19 16:51:43 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-07-11 18:33:42 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-09-04 18:30:27 +03:00
|
|
|
#include <linux/objtool.h>
|
|
|
|
#include <asm/orc_types.h>
|
|
|
|
|
2020-11-13 02:03:32 +03:00
|
|
|
#include <objtool/check.h>
|
|
|
|
#include <objtool/warn.h>
|
|
|
|
#include <objtool/endianness.h>
|
2017-07-11 18:33:42 +03:00
|
|
|
|
|
|
|
int create_orc(struct objtool_file *file)
|
|
|
|
{
|
|
|
|
struct instruction *insn;
|
|
|
|
|
|
|
|
for_each_insn(file, insn) {
|
|
|
|
struct orc_entry *orc = &insn->orc;
|
2020-03-25 16:04:45 +03:00
|
|
|
struct cfi_reg *cfa = &insn->cfi.cfa;
|
|
|
|
struct cfi_reg *bp = &insn->cfi.regs[CFI_BP];
|
2017-07-11 18:33:42 +03:00
|
|
|
|
2020-08-25 15:47:41 +03:00
|
|
|
if (!insn->sec->text)
|
|
|
|
continue;
|
|
|
|
|
2020-03-25 16:04:45 +03:00
|
|
|
orc->end = insn->cfi.end;
|
2018-05-18 09:47:12 +03:00
|
|
|
|
2017-07-11 18:33:42 +03:00
|
|
|
if (cfa->base == CFI_UNDEFINED) {
|
|
|
|
orc->sp_reg = ORC_REG_UNDEFINED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfa->base) {
|
|
|
|
case CFI_SP:
|
|
|
|
orc->sp_reg = ORC_REG_SP;
|
|
|
|
break;
|
|
|
|
case CFI_SP_INDIRECT:
|
|
|
|
orc->sp_reg = ORC_REG_SP_INDIRECT;
|
|
|
|
break;
|
|
|
|
case CFI_BP:
|
|
|
|
orc->sp_reg = ORC_REG_BP;
|
|
|
|
break;
|
|
|
|
case CFI_BP_INDIRECT:
|
|
|
|
orc->sp_reg = ORC_REG_BP_INDIRECT;
|
|
|
|
break;
|
|
|
|
case CFI_R10:
|
|
|
|
orc->sp_reg = ORC_REG_R10;
|
|
|
|
break;
|
|
|
|
case CFI_R13:
|
|
|
|
orc->sp_reg = ORC_REG_R13;
|
|
|
|
break;
|
|
|
|
case CFI_DI:
|
|
|
|
orc->sp_reg = ORC_REG_DI;
|
|
|
|
break;
|
|
|
|
case CFI_DX:
|
|
|
|
orc->sp_reg = ORC_REG_DX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_FUNC("unknown CFA base reg %d",
|
|
|
|
insn->sec, insn->offset, cfa->base);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(bp->base) {
|
|
|
|
case CFI_UNDEFINED:
|
|
|
|
orc->bp_reg = ORC_REG_UNDEFINED;
|
|
|
|
break;
|
|
|
|
case CFI_CFA:
|
|
|
|
orc->bp_reg = ORC_REG_PREV_SP;
|
|
|
|
break;
|
|
|
|
case CFI_BP:
|
|
|
|
orc->bp_reg = ORC_REG_BP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_FUNC("unknown BP base reg %d",
|
|
|
|
insn->sec, insn->offset, bp->base);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
orc->sp_offset = cfa->offset;
|
|
|
|
orc->bp_offset = bp->offset;
|
2020-03-25 16:04:45 +03:00
|
|
|
orc->type = insn->cfi.type;
|
2017-07-11 18:33:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
static int create_orc_entry(struct elf *elf, struct section *u_sec, struct section *ip_relocsec,
|
2017-07-11 18:33:42 +03:00
|
|
|
unsigned int idx, struct section *insn_sec,
|
|
|
|
unsigned long insn_off, struct orc_entry *o)
|
|
|
|
{
|
|
|
|
struct orc_entry *orc;
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
struct reloc *reloc;
|
2017-07-11 18:33:42 +03:00
|
|
|
|
|
|
|
/* populate ORC data */
|
|
|
|
orc = (struct orc_entry *)u_sec->data->d_buf + idx;
|
|
|
|
memcpy(orc, o, sizeof(*orc));
|
2020-11-13 02:03:29 +03:00
|
|
|
orc->sp_offset = bswap_if_needed(orc->sp_offset);
|
|
|
|
orc->bp_offset = bswap_if_needed(orc->bp_offset);
|
2017-07-11 18:33:42 +03:00
|
|
|
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
/* populate reloc for ip */
|
|
|
|
reloc = malloc(sizeof(*reloc));
|
|
|
|
if (!reloc) {
|
2017-07-11 18:33:42 +03:00
|
|
|
perror("malloc");
|
|
|
|
return -1;
|
|
|
|
}
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
memset(reloc, 0, sizeof(*reloc));
|
2017-07-11 18:33:42 +03:00
|
|
|
|
2020-12-15 01:04:20 +03:00
|
|
|
insn_to_reloc_sym_addend(insn_sec, insn_off, reloc);
|
|
|
|
if (!reloc->sym) {
|
|
|
|
WARN("missing symbol for insn at offset 0x%lx",
|
|
|
|
insn_off);
|
|
|
|
return -1;
|
2020-04-01 21:23:27 +03:00
|
|
|
}
|
|
|
|
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
reloc->type = R_X86_64_PC32;
|
|
|
|
reloc->offset = idx * sizeof(int);
|
|
|
|
reloc->sec = ip_relocsec;
|
2017-07-11 18:33:42 +03:00
|
|
|
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
elf_add_reloc(elf, reloc);
|
2017-07-11 18:33:42 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int create_orc_sections(struct objtool_file *file)
|
|
|
|
{
|
|
|
|
struct instruction *insn, *prev_insn;
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
struct section *sec, *u_sec, *ip_relocsec;
|
2017-07-11 18:33:42 +03:00
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
struct orc_entry empty = {
|
|
|
|
.sp_reg = ORC_REG_UNDEFINED,
|
|
|
|
.bp_reg = ORC_REG_UNDEFINED,
|
2020-09-04 18:30:27 +03:00
|
|
|
.type = UNWIND_HINT_TYPE_CALL,
|
2017-07-11 18:33:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
sec = find_section_by_name(file->elf, ".orc_unwind");
|
|
|
|
if (sec) {
|
|
|
|
WARN("file already has .orc_unwind section, skipping");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* count the number of needed orcs */
|
|
|
|
idx = 0;
|
|
|
|
for_each_sec(file, sec) {
|
|
|
|
if (!sec->text)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
prev_insn = NULL;
|
|
|
|
sec_for_each_insn(file, sec, insn) {
|
|
|
|
if (!prev_insn ||
|
|
|
|
memcmp(&insn->orc, &prev_insn->orc,
|
|
|
|
sizeof(struct orc_entry))) {
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
prev_insn = insn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* section terminator */
|
|
|
|
if (prev_insn)
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
if (!idx)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* create .orc_unwind_ip and .rela.orc_unwind_ip sections */
|
2020-08-18 16:57:45 +03:00
|
|
|
sec = elf_create_section(file->elf, ".orc_unwind_ip", 0, sizeof(int), idx);
|
2017-12-30 23:43:32 +03:00
|
|
|
if (!sec)
|
|
|
|
return -1;
|
2017-07-11 18:33:42 +03:00
|
|
|
|
2020-05-30 00:01:14 +03:00
|
|
|
ip_relocsec = elf_create_reloc_section(file->elf, sec, SHT_RELA);
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
if (!ip_relocsec)
|
2017-07-11 18:33:42 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* create .orc_unwind section */
|
2020-08-18 16:57:45 +03:00
|
|
|
u_sec = elf_create_section(file->elf, ".orc_unwind", 0,
|
2017-07-11 18:33:42 +03:00
|
|
|
sizeof(struct orc_entry), idx);
|
|
|
|
|
|
|
|
/* populate sections */
|
|
|
|
idx = 0;
|
|
|
|
for_each_sec(file, sec) {
|
|
|
|
if (!sec->text)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
prev_insn = NULL;
|
|
|
|
sec_for_each_insn(file, sec, insn) {
|
|
|
|
if (!prev_insn || memcmp(&insn->orc, &prev_insn->orc,
|
|
|
|
sizeof(struct orc_entry))) {
|
|
|
|
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
if (create_orc_entry(file->elf, u_sec, ip_relocsec, idx,
|
2017-07-11 18:33:42 +03:00
|
|
|
insn->sec, insn->offset,
|
|
|
|
&insn->orc))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
prev_insn = insn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* section terminator */
|
|
|
|
if (prev_insn) {
|
objtool: Rename rela to reloc
Before supporting additional relocation types rename the relevant
types and functions from "rela" to "reloc". This work be done with
the following regex:
sed -e 's/struct rela/struct reloc/g' \
-e 's/\([_\*]\)rela\(s\{0,1\}\)/\1reloc\2/g' \
-e 's/tmprela\(s\{0,1\}\)/tmpreloc\1/g' \
-e 's/relasec/relocsec/g' \
-e 's/rela_list/reloc_list/g' \
-e 's/rela_hash/reloc_hash/g' \
-e 's/add_rela/add_reloc/g' \
-e 's/rela->/reloc->/g' \
-e '/rela[,\.]/{ s/\([^\.>]\)rela\([\.,]\)/\1reloc\2/g ; }' \
-e 's/rela =/reloc =/g' \
-e 's/relas =/relocs =/g' \
-e 's/relas\[/relocs[/g' \
-e 's/relaname =/relocname =/g' \
-e 's/= rela\;/= reloc\;/g' \
-e 's/= relas\;/= relocs\;/g' \
-e 's/= relaname\;/= relocname\;/g' \
-e 's/, rela)/, reloc)/g' \
-e 's/\([ @]\)rela\([ "]\)/\1reloc\2/g' \
-e 's/ rela$/ reloc/g' \
-e 's/, relaname/, relocname/g' \
-e 's/sec->rela/sec->reloc/g' \
-e 's/(\(!\{0,1\}\)rela/(\1reloc/g' \
-i \
arch.h \
arch/x86/decode.c \
check.c \
check.h \
elf.c \
elf.h \
orc_gen.c \
special.c
Notable exceptions which complicate the regex include gelf_*
library calls and standard/expected section names which still use
"rela" because they encode the type of relocation expected. Also, keep
"rela" in the struct because it encodes a specific type of relocation
we currently expect.
It will eventually turn into a member of an anonymous union when a
susequent patch adds implicit addend, or "rel", relocation support.
Signed-off-by: Matt Helsley <mhelsley@vmware.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-05-30 00:01:13 +03:00
|
|
|
if (create_orc_entry(file->elf, u_sec, ip_relocsec, idx,
|
2017-07-11 18:33:42 +03:00
|
|
|
prev_insn->sec,
|
|
|
|
prev_insn->offset + prev_insn->len,
|
|
|
|
&empty))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:55:29 +03:00
|
|
|
if (elf_rebuild_reloc_section(file->elf, ip_relocsec))
|
2017-07-11 18:33:42 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|