[RFC PATCH 3/3] objtool/mcount: Add powerpc specific functions
Christophe Leroy
christophe.leroy at csgroup.eu
Sat Mar 26 18:58:28 AEDT 2022
Le 21/03/2022 a 08:56, Christophe Leroy a ecrit :
>
>
> Le 21/03/2022 a 03:27, Michael Ellerman a ecrit :
>> Christophe Leroy <christophe.leroy at csgroup.eu> writes:
>>> Le 18/03/2022 a 13:26, Peter Zijlstra a ecrit :
>>>> On Fri, Mar 18, 2022 at 04:21:40PM +0530, Sathvika Vasireddy wrote:
>>>>> This patch adds powerpc specific functions required for
>>>>> 'objtool mcount' to work, and enables mcount for ppc.
>>>>
>>>> I would love to see more objtool enablement for Power :-)
>>>
>>> I have not received this series and I can't see it on powerpc patchwork
>>> either (https://patchwork.ozlabs.org/project/linuxppc-dev/list/)
>>>
>>> Did you send it to linuxppc-dev list ? If not can you resend it there ?
>>
>> It is there, might have been delayed?
>>
>> http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=291129
>>
>> There are some CI failures.
>>
>
> On PPC32 I get :
>
> [ 0.000000] ftrace: No functions to be traced?
>
> Without this series I get:
>
> [ 0.000000] ftrace: allocating 22508 entries in 17 pages
> [ 0.000000] ftrace: allocated 17 pages with 2 groups
>
With the changes below I managed to get a working ftrace on a PPC32 target.
Christophe
---------
From: Christophe Leroy <christophe.leroy at csgroup.eu>
Subject: [PATCH] powerpc/objtool: Set to big endian and 32 bits
Small ack to crossbuild a PPC32 kernel with a x86_64 host.
Signed-off-by: Christophe Leroy <christophe.leroy at csgroup.eu>
---
tools/objtool/arch/powerpc/decode.c | 3 ++-
tools/objtool/arch/powerpc/include/arch/endianness.h | 9 +++++++++
tools/objtool/elf.c | 4 ++--
tools/objtool/utils.c | 12 +++++++-----
4 files changed, 20 insertions(+), 8 deletions(-)
create mode 100644 tools/objtool/arch/powerpc/include/arch/endianness.h
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index 58988f88b315..330af382e39f 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -8,6 +8,7 @@
#include <objtool/arch.h>
#include <objtool/warn.h>
#include <objtool/builtin.h>
+#include <objtool/endianness.h>
int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
unsigned long offset, unsigned int maxlen,
@@ -20,7 +21,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
u64 imm;
*immediate = imm = 0;
- memcpy(&insn, sec->data->d_buf+offset, 4);
+ insn = bswap_if_needed(*(u32 *)(sec->data->d_buf + offset));
*len = 4;
*type = INSN_OTHER;
diff --git a/tools/objtool/arch/powerpc/include/arch/endianness.h b/tools/objtool/arch/powerpc/include/arch/endianness.h
new file mode 100644
index 000000000000..275087bfcc16
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/endianness.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _ARCH_ENDIANNESS_H
+#define _ARCH_ENDIANNESS_H
+
+#include <endian.h>
+
+#define __TARGET_BYTE_ORDER __BIG_ENDIAN
+
+#endif /* _ARCH_ENDIANNESS_H */
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 4b384c907027..433f0e327b68 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -867,7 +867,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
strcpy(relocname, ".rela");
strcat(relocname, base->name);
- sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
+ sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0);
free(relocname);
if (!sec)
return NULL;
@@ -876,7 +876,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
sec->base = base;
sec->sh.sh_type = SHT_RELA;
- sec->sh.sh_addralign = 8;
+ sec->sh.sh_addralign = 4;
sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx;
sec->sh.sh_info = base->idx;
sec->sh.sh_flags = SHF_INFO_LINK;
diff --git a/tools/objtool/utils.c b/tools/objtool/utils.c
index c9c14fa0dfd7..f77695c81386 100644
--- a/tools/objtool/utils.c
+++ b/tools/objtool/utils.c
@@ -151,7 +151,7 @@ int decode_instructions(struct objtool_file *file)
int create_mcount_loc_sections(struct objtool_file *file)
{
struct section *sec;
- unsigned long *loc;
+ unsigned int *loc;
struct instruction *insn;
int idx;
@@ -169,15 +169,17 @@ int create_mcount_loc_sections(struct objtool_file *file)
list_for_each_entry(insn, &file->mcount_loc_list, call_node)
idx++;
- sec = elf_create_section(file->elf, "__mcount_loc", 0, sizeof(unsigned long), idx);
+ sec = elf_create_section(file->elf, "__mcount_loc", 0, sizeof(unsigned int), idx);
if (!sec)
return -1;
+ sec->sh.sh_addralign = 4;
+
idx = 0;
list_for_each_entry(insn, &file->mcount_loc_list, call_node) {
- loc = (unsigned long *)sec->data->d_buf + idx;
- memset(loc, 0, sizeof(unsigned long));
+ loc = (unsigned int *)sec->data->d_buf + idx;
+ memset(loc, 0, sizeof(unsigned int));
if (file->elf->ehdr.e_machine == EM_X86_64) {
if (elf_add_reloc_to_insn(file->elf, sec,
@@ -197,7 +199,7 @@ int create_mcount_loc_sections(struct objtool_file *file)
if (file->elf->ehdr.e_machine == EM_PPC) {
if (elf_add_reloc_to_insn(file->elf, sec,
- idx * sizeof(unsigned long),
+ idx * sizeof(unsigned int),
R_PPC_ADDR32,
insn->sec, insn->offset))
return -1;
--
2.35.1
More information about the Linuxppc-dev
mailing list