mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 13:41:51 +00:00
objtool: Fix reloc generation on big endian cross-compiles
Relocations generated in elf_rebuild_rel[a]_reloc_section() are broken if objtool is built and run on a big endian system. 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 Convert those functions to use gelf_update_rel[a](), similar to what elf_write_reloc() does. 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> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
parent
1d509f2a6e
commit
a1a664ece5
@ -855,25 +855,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++;
|
||||
}
|
||||
|
||||
@ -884,26 +886,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++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user