From: Vasily Gorbik <gor@linux.ibm.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
David Laight <David.Laight@aculab.com>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Miroslav Benes <mbenes@suse.cz>,
Alexandre Chartre <alexandre.chartre@oracle.com>,
Julien Thierry <jthierry@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH v4 3/4] objtool: correct rebuilding of reloc sections
Date: Sun, 4 Oct 2020 16:30:50 +0200 [thread overview]
Message-ID: <patch-3.thread-a8def4.git-2ef676be9306.your-ad-here.call-01601818410-ext-7687@work.hours> (raw)
In-Reply-To: <cover.thread-a8def4.your-ad-here.call-01601818410-ext-7687@work.hours>
From: Martin Schwidefsky <schwidefsky@de.ibm.com>
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 <schwidefsky@de.ibm.com>
Co-developed-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
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++;
}
--
⣿⣿⣿⣿⢋⡀⣀⠹⣿⣿⣿⣿
⣿⣿⣿⣿⠠⣶⡦⠀⣿⣿⣿⣿
⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿
⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿
⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿
⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
next prev parent reply other threads:[~2020-10-04 14:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 22:17 [RFC PATCH v3 0/4] objtool and cross compilation Vasily Gorbik
2020-09-30 22:17 ` [RFC PATCH v3 1/4] objtool: allow nested externs to enable BUILD_BUG() Vasily Gorbik
2020-09-30 22:17 ` [RFC PATCH v3 2/4] objtool: x86 instruction decoder and big endian cross compiles Vasily Gorbik
2020-10-02 15:18 ` Josh Poimboeuf
2020-10-05 3:41 ` Masami Hiramatsu
2020-09-30 22:17 ` [RFC PATCH v3 3/4] objtool: correct rebuilding of reloc sections Vasily Gorbik
2020-09-30 22:17 ` [RFC PATCH v3 4/4] objtool: fix x86 orc generation on big endian cross compiles Vasily Gorbik
2020-10-02 16:01 ` Josh Poimboeuf
2020-10-04 14:30 ` [RFC PATCH v4 0/4] objtool and cross compilation Vasily Gorbik
2020-10-04 14:30 ` [RFC PATCH v4 1/4] objtool: allow nested externs to enable BUILD_BUG() Vasily Gorbik
2020-10-04 14:30 ` [RFC PATCH v4 2/4] x86/insn: instruction decoder and big endian cross compiles Vasily Gorbik
2020-10-04 14:30 ` Vasily Gorbik [this message]
2020-10-04 14:30 ` [RFC PATCH v4 4/4] objtool: fix x86 orc generation on " Vasily Gorbik
2020-10-05 14:03 ` Josh Poimboeuf
2020-10-05 15:50 ` [RFC PATCH RESEND v4 0/4] objtool and cross compilation Vasily Gorbik
2020-10-05 15:50 ` [RFC PATCH RESEND v4 1/4] objtool: allow nested externs to enable BUILD_BUG() Vasily Gorbik
2020-10-05 15:50 ` [RFC PATCH RESEND v4 2/4] x86/insn: instruction decoder and big endian cross compiles Vasily Gorbik
2020-10-05 15:50 ` [RFC PATCH RESEND v4 3/4] objtool: correct rebuilding of reloc sections Vasily Gorbik
2020-10-05 15:50 ` [RFC PATCH RESEND v4 4/4] objtool: fix x86 orc generation on big endian cross compiles Vasily Gorbik
2020-10-05 15:50 ` [PATCH v2] objtool: avoid ../ headers includes and name clashes Vasily Gorbik
2020-10-05 15:56 ` [RFC PATCH v4 4/4] objtool: fix x86 orc generation on big endian cross compiles Vasily Gorbik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-3.thread-a8def4.git-2ef676be9306.your-ad-here.call-01601818410-ext-7687@work.hours \
--to=gor@linux.ibm.com \
--cc=David.Laight@aculab.com \
--cc=alexandre.chartre@oracle.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).