All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-24 13:17 ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

This draft series adds PPC32 support to Sathvika's series.
Verified on pmac32 on QEMU.

It should in principle also work for PPC64 BE but for the time being
something goes wrong. In the beginning I had a segfaut hence the first
patch. But I still get no mcount section in the files.

Christophe Leroy (3):
  objtool: Fix SEGFAULT
  objtool: Use target file endianness instead of a compiled constant
  objtool: Use target file class size instead of a compiled constant

Sathvika Vasireddy (4):
  objtool: Add --mnop as an option to --mcount
  objtool: Enable objtool to run only on files with ftrace enabled
  objtool/powerpc: Enable objtool to be built on ppc
  objtool/powerpc: Add --mcount specific implementation

 Makefile                                      |  4 +-
 arch/powerpc/Kconfig                          |  2 +
 arch/x86/Kconfig                              |  1 +
 scripts/Makefile.build                        |  5 +-
 tools/objtool/arch/powerpc/Build              |  2 +
 tools/objtool/arch/powerpc/decode.c           | 88 +++++++++++++++++++
 .../arch/powerpc/include/arch/cfi_regs.h      | 11 +++
 tools/objtool/arch/powerpc/include/arch/elf.h |  8 ++
 .../arch/powerpc/include/arch/special.h       | 21 +++++
 tools/objtool/arch/powerpc/special.c          | 19 ++++
 .../arch/x86/include/arch/endianness.h        |  9 --
 tools/objtool/builtin-check.c                 | 14 +++
 tools/objtool/check.c                         | 51 ++++++-----
 tools/objtool/elf.c                           | 23 ++++-
 tools/objtool/include/objtool/builtin.h       |  1 +
 tools/objtool/include/objtool/elf.h           |  9 ++
 tools/objtool/include/objtool/endianness.h    | 29 +++---
 tools/objtool/orc_dump.c                      | 11 ++-
 tools/objtool/orc_gen.c                       |  4 +-
 tools/objtool/special.c                       |  3 +-
 20 files changed, 257 insertions(+), 58 deletions(-)
 create mode 100644 tools/objtool/arch/powerpc/Build
 create mode 100644 tools/objtool/arch/powerpc/decode.c
 create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
 create mode 100644 tools/objtool/arch/powerpc/special.c
 delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

-- 
2.35.3


^ permalink raw reply	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-24 13:17 ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

This draft series adds PPC32 support to Sathvika's series.
Verified on pmac32 on QEMU.

It should in principle also work for PPC64 BE but for the time being
something goes wrong. In the beginning I had a segfaut hence the first
patch. But I still get no mcount section in the files.

Christophe Leroy (3):
  objtool: Fix SEGFAULT
  objtool: Use target file endianness instead of a compiled constant
  objtool: Use target file class size instead of a compiled constant

Sathvika Vasireddy (4):
  objtool: Add --mnop as an option to --mcount
  objtool: Enable objtool to run only on files with ftrace enabled
  objtool/powerpc: Enable objtool to be built on ppc
  objtool/powerpc: Add --mcount specific implementation

 Makefile                                      |  4 +-
 arch/powerpc/Kconfig                          |  2 +
 arch/x86/Kconfig                              |  1 +
 scripts/Makefile.build                        |  5 +-
 tools/objtool/arch/powerpc/Build              |  2 +
 tools/objtool/arch/powerpc/decode.c           | 88 +++++++++++++++++++
 .../arch/powerpc/include/arch/cfi_regs.h      | 11 +++
 tools/objtool/arch/powerpc/include/arch/elf.h |  8 ++
 .../arch/powerpc/include/arch/special.h       | 21 +++++
 tools/objtool/arch/powerpc/special.c          | 19 ++++
 .../arch/x86/include/arch/endianness.h        |  9 --
 tools/objtool/builtin-check.c                 | 14 +++
 tools/objtool/check.c                         | 51 ++++++-----
 tools/objtool/elf.c                           | 23 ++++-
 tools/objtool/include/objtool/builtin.h       |  1 +
 tools/objtool/include/objtool/elf.h           |  9 ++
 tools/objtool/include/objtool/endianness.h    | 29 +++---
 tools/objtool/orc_dump.c                      | 11 ++-
 tools/objtool/orc_gen.c                       |  4 +-
 tools/objtool/special.c                       |  3 +-
 20 files changed, 257 insertions(+), 58 deletions(-)
 create mode 100644 tools/objtool/arch/powerpc/Build
 create mode 100644 tools/objtool/arch/powerpc/decode.c
 create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
 create mode 100644 tools/objtool/arch/powerpc/special.c
 delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

-- 
2.35.3


^ permalink raw reply	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 1/7] objtool: Fix SEGFAULT
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 190b2f6e360a..6cb07e151588 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -203,7 +203,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		return false;
 
 	insn = find_insn(file, func->sec, func->offset);
-	if (!insn->func)
+	if (!insn || !insn->func)
 		return false;
 
 	func_for_each_insn(file, func, insn) {
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 1/7] objtool: Fix SEGFAULT
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 190b2f6e360a..6cb07e151588 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -203,7 +203,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		return false;
 
 	insn = find_insn(file, func->sec, func->offset);
-	if (!insn->func)
+	if (!insn || !insn->func)
 		return false;
 
 	func_for_each_insn(file, func, insn) {
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 2/7] objtool: Use target file endianness instead of a compiled constant
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

Some architectures like powerpc support both endianness, it's
therefore not possible to fix the endianness via arch/endianness.h
because there is no easy way to get the target endianness at
build time.

Use the endianness recorded in the file objtool is working on.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 .../arch/x86/include/arch/endianness.h        |  9 ------
 tools/objtool/check.c                         |  2 +-
 tools/objtool/include/objtool/endianness.h    | 29 +++++++++----------
 tools/objtool/orc_dump.c                      | 11 +++++--
 tools/objtool/orc_gen.c                       |  4 +--
 tools/objtool/special.c                       |  3 +-
 6 files changed, 27 insertions(+), 31 deletions(-)
 delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

diff --git a/tools/objtool/arch/x86/include/arch/endianness.h b/tools/objtool/arch/x86/include/arch/endianness.h
deleted file mode 100644
index 7c362527da20..000000000000
--- a/tools/objtool/arch/x86/include/arch/endianness.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef _ARCH_ENDIANNESS_H
-#define _ARCH_ENDIANNESS_H
-
-#include <endian.h>
-
-#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _ARCH_ENDIANNESS_H */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 6cb07e151588..cef1dd54d505 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1971,7 +1971,7 @@ static int read_unwind_hints(struct objtool_file *file)
 			return -1;
 		}
 
-		cfi.cfa.offset = bswap_if_needed(hint->sp_offset);
+		cfi.cfa.offset = bswap_if_needed(file->elf, hint->sp_offset);
 		cfi.type = hint->type;
 		cfi.end = hint->end;
 
diff --git a/tools/objtool/include/objtool/endianness.h b/tools/objtool/include/objtool/endianness.h
index 10241341eff3..ab0515ba0538 100644
--- a/tools/objtool/include/objtool/endianness.h
+++ b/tools/objtool/include/objtool/endianness.h
@@ -2,33 +2,30 @@
 #ifndef _OBJTOOL_ENDIANNESS_H
 #define _OBJTOOL_ENDIANNESS_H
 
-#include <arch/endianness.h>
 #include <linux/kernel.h>
 #include <endian.h>
-
-#ifndef __TARGET_BYTE_ORDER
-#error undefined arch __TARGET_BYTE_ORDER
-#endif
-
-#if __BYTE_ORDER != __TARGET_BYTE_ORDER
-#define __NEED_BSWAP 1
-#else
-#define __NEED_BSWAP 0
-#endif
+#include <objtool/elf.h>
 
 /*
- * Does a byte swap if target endianness doesn't match the host, i.e. cross
+ * Does a byte swap if target file endianness doesn't match the host, i.e. cross
  * compilation for little endian on big endian and vice versa.
  * To be used for multi-byte values conversion, which are read from / about
  * to be written to a target native endianness ELF file.
  */
-#define bswap_if_needed(val)						\
+static inline bool need_bswap(struct elf *elf)
+{
+	return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
+	       (elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
+}
+
+#define bswap_if_needed(elf, val)					\
 ({									\
 	__typeof__(val) __ret;						\
+	bool __need_bswap = need_bswap(elf);				\
 	switch (sizeof(val)) {						\
-	case 8: __ret = __NEED_BSWAP ? bswap_64(val) : (val); break;	\
-	case 4: __ret = __NEED_BSWAP ? bswap_32(val) : (val); break;	\
-	case 2: __ret = __NEED_BSWAP ? bswap_16(val) : (val); break;	\
+	case 8: __ret = __need_bswap ? bswap_64(val) : (val); break;	\
+	case 4: __ret = __need_bswap ? bswap_32(val) : (val); break;	\
+	case 2: __ret = __need_bswap ? bswap_16(val) : (val); break;	\
 	default:							\
 		BUILD_BUG(); break;					\
 	}								\
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index f5a8508c42d6..4f1211fec82c 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -76,6 +76,7 @@ int orc_dump(const char *_objname)
 	GElf_Rela rela;
 	GElf_Sym sym;
 	Elf_Data *data, *symtab = NULL, *rela_orc_ip = NULL;
+	struct elf dummy_elf = {};
 
 
 	objname = _objname;
@@ -94,6 +95,12 @@ int orc_dump(const char *_objname)
 		return -1;
 	}
 
+	if (!elf64_getehdr(elf)) {
+		WARN_ELF("elf64_getehdr");
+		return -1;
+	}
+	memcpy(&dummy_elf.ehdr, elf64_getehdr(elf), sizeof(dummy_elf.ehdr));
+
 	if (elf_getshdrnum(elf, &nr_sections)) {
 		WARN_ELF("elf_getshdrnum");
 		return -1;
@@ -198,11 +205,11 @@ int orc_dump(const char *_objname)
 
 		printf(" sp:");
 
-		print_reg(orc[i].sp_reg, bswap_if_needed(orc[i].sp_offset));
+		print_reg(orc[i].sp_reg, bswap_if_needed(&dummy_elf, orc[i].sp_offset));
 
 		printf(" bp:");
 
-		print_reg(orc[i].bp_reg, bswap_if_needed(orc[i].bp_offset));
+		print_reg(orc[i].bp_reg, bswap_if_needed(&dummy_elf, orc[i].bp_offset));
 
 		printf(" type:%s end:%d\n",
 		       orc_type_name(orc[i].type), orc[i].end);
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index dd3c64af9db2..1f22b7ebae58 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -97,8 +97,8 @@ static int write_orc_entry(struct elf *elf, struct section *orc_sec,
 	/* populate ORC data */
 	orc = (struct orc_entry *)orc_sec->data->d_buf + idx;
 	memcpy(orc, o, sizeof(*orc));
-	orc->sp_offset = bswap_if_needed(orc->sp_offset);
-	orc->bp_offset = bswap_if_needed(orc->bp_offset);
+	orc->sp_offset = bswap_if_needed(elf, orc->sp_offset);
+	orc->bp_offset = bswap_if_needed(elf, orc->bp_offset);
 
 	/* populate reloc for ip */
 	if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_X86_64_PC32,
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index e2223dd91c37..9c8d827f69af 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -87,7 +87,8 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry,
 	if (entry->feature) {
 		unsigned short feature;
 
-		feature = bswap_if_needed(*(unsigned short *)(sec->data->d_buf +
+		feature = bswap_if_needed(elf,
+					  *(unsigned short *)(sec->data->d_buf +
 							      offset +
 							      entry->feature));
 		arch_handle_alternative(feature, alt);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 2/7] objtool: Use target file endianness instead of a compiled constant
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

Some architectures like powerpc support both endianness, it's
therefore not possible to fix the endianness via arch/endianness.h
because there is no easy way to get the target endianness at
build time.

Use the endianness recorded in the file objtool is working on.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 .../arch/x86/include/arch/endianness.h        |  9 ------
 tools/objtool/check.c                         |  2 +-
 tools/objtool/include/objtool/endianness.h    | 29 +++++++++----------
 tools/objtool/orc_dump.c                      | 11 +++++--
 tools/objtool/orc_gen.c                       |  4 +--
 tools/objtool/special.c                       |  3 +-
 6 files changed, 27 insertions(+), 31 deletions(-)
 delete mode 100644 tools/objtool/arch/x86/include/arch/endianness.h

diff --git a/tools/objtool/arch/x86/include/arch/endianness.h b/tools/objtool/arch/x86/include/arch/endianness.h
deleted file mode 100644
index 7c362527da20..000000000000
--- a/tools/objtool/arch/x86/include/arch/endianness.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef _ARCH_ENDIANNESS_H
-#define _ARCH_ENDIANNESS_H
-
-#include <endian.h>
-
-#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _ARCH_ENDIANNESS_H */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 6cb07e151588..cef1dd54d505 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1971,7 +1971,7 @@ static int read_unwind_hints(struct objtool_file *file)
 			return -1;
 		}
 
-		cfi.cfa.offset = bswap_if_needed(hint->sp_offset);
+		cfi.cfa.offset = bswap_if_needed(file->elf, hint->sp_offset);
 		cfi.type = hint->type;
 		cfi.end = hint->end;
 
diff --git a/tools/objtool/include/objtool/endianness.h b/tools/objtool/include/objtool/endianness.h
index 10241341eff3..ab0515ba0538 100644
--- a/tools/objtool/include/objtool/endianness.h
+++ b/tools/objtool/include/objtool/endianness.h
@@ -2,33 +2,30 @@
 #ifndef _OBJTOOL_ENDIANNESS_H
 #define _OBJTOOL_ENDIANNESS_H
 
-#include <arch/endianness.h>
 #include <linux/kernel.h>
 #include <endian.h>
-
-#ifndef __TARGET_BYTE_ORDER
-#error undefined arch __TARGET_BYTE_ORDER
-#endif
-
-#if __BYTE_ORDER != __TARGET_BYTE_ORDER
-#define __NEED_BSWAP 1
-#else
-#define __NEED_BSWAP 0
-#endif
+#include <objtool/elf.h>
 
 /*
- * Does a byte swap if target endianness doesn't match the host, i.e. cross
+ * Does a byte swap if target file endianness doesn't match the host, i.e. cross
  * compilation for little endian on big endian and vice versa.
  * To be used for multi-byte values conversion, which are read from / about
  * to be written to a target native endianness ELF file.
  */
-#define bswap_if_needed(val)						\
+static inline bool need_bswap(struct elf *elf)
+{
+	return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
+	       (elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
+}
+
+#define bswap_if_needed(elf, val)					\
 ({									\
 	__typeof__(val) __ret;						\
+	bool __need_bswap = need_bswap(elf);				\
 	switch (sizeof(val)) {						\
-	case 8: __ret = __NEED_BSWAP ? bswap_64(val) : (val); break;	\
-	case 4: __ret = __NEED_BSWAP ? bswap_32(val) : (val); break;	\
-	case 2: __ret = __NEED_BSWAP ? bswap_16(val) : (val); break;	\
+	case 8: __ret = __need_bswap ? bswap_64(val) : (val); break;	\
+	case 4: __ret = __need_bswap ? bswap_32(val) : (val); break;	\
+	case 2: __ret = __need_bswap ? bswap_16(val) : (val); break;	\
 	default:							\
 		BUILD_BUG(); break;					\
 	}								\
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index f5a8508c42d6..4f1211fec82c 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -76,6 +76,7 @@ int orc_dump(const char *_objname)
 	GElf_Rela rela;
 	GElf_Sym sym;
 	Elf_Data *data, *symtab = NULL, *rela_orc_ip = NULL;
+	struct elf dummy_elf = {};
 
 
 	objname = _objname;
@@ -94,6 +95,12 @@ int orc_dump(const char *_objname)
 		return -1;
 	}
 
+	if (!elf64_getehdr(elf)) {
+		WARN_ELF("elf64_getehdr");
+		return -1;
+	}
+	memcpy(&dummy_elf.ehdr, elf64_getehdr(elf), sizeof(dummy_elf.ehdr));
+
 	if (elf_getshdrnum(elf, &nr_sections)) {
 		WARN_ELF("elf_getshdrnum");
 		return -1;
@@ -198,11 +205,11 @@ int orc_dump(const char *_objname)
 
 		printf(" sp:");
 
-		print_reg(orc[i].sp_reg, bswap_if_needed(orc[i].sp_offset));
+		print_reg(orc[i].sp_reg, bswap_if_needed(&dummy_elf, orc[i].sp_offset));
 
 		printf(" bp:");
 
-		print_reg(orc[i].bp_reg, bswap_if_needed(orc[i].bp_offset));
+		print_reg(orc[i].bp_reg, bswap_if_needed(&dummy_elf, orc[i].bp_offset));
 
 		printf(" type:%s end:%d\n",
 		       orc_type_name(orc[i].type), orc[i].end);
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index dd3c64af9db2..1f22b7ebae58 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -97,8 +97,8 @@ static int write_orc_entry(struct elf *elf, struct section *orc_sec,
 	/* populate ORC data */
 	orc = (struct orc_entry *)orc_sec->data->d_buf + idx;
 	memcpy(orc, o, sizeof(*orc));
-	orc->sp_offset = bswap_if_needed(orc->sp_offset);
-	orc->bp_offset = bswap_if_needed(orc->bp_offset);
+	orc->sp_offset = bswap_if_needed(elf, orc->sp_offset);
+	orc->bp_offset = bswap_if_needed(elf, orc->bp_offset);
 
 	/* populate reloc for ip */
 	if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_X86_64_PC32,
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index e2223dd91c37..9c8d827f69af 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -87,7 +87,8 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry,
 	if (entry->feature) {
 		unsigned short feature;
 
-		feature = bswap_if_needed(*(unsigned short *)(sec->data->d_buf +
+		feature = bswap_if_needed(elf,
+					  *(unsigned short *)(sec->data->d_buf +
 							      offset +
 							      entry->feature));
 		arch_handle_alternative(feature, alt);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 3/7] objtool: Use target file class size instead of a compiled constant
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

In order to allow using objtool on cross-built kernels,
determine size of long from elf data instead of using
sizeof(long) at build time.

For the time being this covers only mcount.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/check.c               | 16 +++++++++-------
 tools/objtool/elf.c                 |  8 ++++++--
 tools/objtool/include/objtool/elf.h |  8 ++++++++
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index cef1dd54d505..fabc0ea88747 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -802,9 +802,9 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
 static int create_mcount_loc_sections(struct objtool_file *file)
 {
 	struct section *sec;
-	unsigned long *loc;
 	struct instruction *insn;
 	int idx;
+	int size = elf_class_size(file->elf);
 
 	sec = find_section_by_name(file->elf, "__mcount_loc");
 	if (sec) {
@@ -820,23 +820,25 @@ static 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, size, idx);
 	if (!sec)
 		return -1;
 
+	sec->sh.sh_addralign = size;
+
 	idx = 0;
 	list_for_each_entry(insn, &file->mcount_loc_list, call_node) {
+		void *loc;
 
-		loc = (unsigned long *)sec->data->d_buf + idx;
-		memset(loc, 0, sizeof(unsigned long));
+		loc = sec->data->d_buf + idx;
+		memset(loc, 0, size);
 
-		if (elf_add_reloc_to_insn(file->elf, sec,
-					  idx * sizeof(unsigned long),
+		if (elf_add_reloc_to_insn(file->elf, sec, idx,
 					  R_X86_64_64,
 					  insn->sec, insn->offset))
 			return -1;
 
-		idx++;
+		idx += size;
 	}
 
 	return 0;
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index c25e957c1e52..63218f5799c2 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1124,6 +1124,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
 {
 	char *relocname;
 	struct section *sec;
+	int size = elf_class_size(elf);
 
 	relocname = malloc(strlen(base->name) + strlen(".rela") + 1);
 	if (!relocname) {
@@ -1133,7 +1134,10 @@ 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);
+	if (size == sizeof(u32))
+		sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0);
+	else
+		sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
 	free(relocname);
 	if (!sec)
 		return NULL;
@@ -1142,7 +1146,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 = size;
 	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/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index adebfbc2b518..c720c4476828 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -141,6 +141,14 @@ static inline bool has_multiple_files(struct elf *elf)
 	return elf->num_files > 1;
 }
 
+static inline int elf_class_size(struct elf *elf)
+{
+	if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+		return sizeof(u32);
+	else
+		return sizeof(u64);
+}
+
 struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
 
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 3/7] objtool: Use target file class size instead of a compiled constant
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

In order to allow using objtool on cross-built kernels,
determine size of long from elf data instead of using
sizeof(long) at build time.

For the time being this covers only mcount.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/check.c               | 16 +++++++++-------
 tools/objtool/elf.c                 |  8 ++++++--
 tools/objtool/include/objtool/elf.h |  8 ++++++++
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index cef1dd54d505..fabc0ea88747 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -802,9 +802,9 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
 static int create_mcount_loc_sections(struct objtool_file *file)
 {
 	struct section *sec;
-	unsigned long *loc;
 	struct instruction *insn;
 	int idx;
+	int size = elf_class_size(file->elf);
 
 	sec = find_section_by_name(file->elf, "__mcount_loc");
 	if (sec) {
@@ -820,23 +820,25 @@ static 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, size, idx);
 	if (!sec)
 		return -1;
 
+	sec->sh.sh_addralign = size;
+
 	idx = 0;
 	list_for_each_entry(insn, &file->mcount_loc_list, call_node) {
+		void *loc;
 
-		loc = (unsigned long *)sec->data->d_buf + idx;
-		memset(loc, 0, sizeof(unsigned long));
+		loc = sec->data->d_buf + idx;
+		memset(loc, 0, size);
 
-		if (elf_add_reloc_to_insn(file->elf, sec,
-					  idx * sizeof(unsigned long),
+		if (elf_add_reloc_to_insn(file->elf, sec, idx,
 					  R_X86_64_64,
 					  insn->sec, insn->offset))
 			return -1;
 
-		idx++;
+		idx += size;
 	}
 
 	return 0;
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index c25e957c1e52..63218f5799c2 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1124,6 +1124,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
 {
 	char *relocname;
 	struct section *sec;
+	int size = elf_class_size(elf);
 
 	relocname = malloc(strlen(base->name) + strlen(".rela") + 1);
 	if (!relocname) {
@@ -1133,7 +1134,10 @@ 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);
+	if (size == sizeof(u32))
+		sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0);
+	else
+		sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
 	free(relocname);
 	if (!sec)
 		return NULL;
@@ -1142,7 +1146,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 = size;
 	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/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index adebfbc2b518..c720c4476828 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -141,6 +141,14 @@ static inline bool has_multiple_files(struct elf *elf)
 	return elf->num_files > 1;
 }
 
+static inline int elf_class_size(struct elf *elf)
+{
+	if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+		return sizeof(u32);
+	else
+		return sizeof(u64);
+}
+
 struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
 
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 4/7] objtool: Add --mnop as an option to --mcount
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

From: Sathvika Vasireddy <sv@linux.ibm.com>

Architectures can select HAVE_NOP_MCOUNT if they choose
to nop out mcount call sites. If that config option is
selected, then --mnop is passed as an option to objtool,
along with --mcount.

Also, make sure that --mnop can be passed as an option
to objtool only when --mcount is passed.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 Makefile                                |  4 +++-
 arch/x86/Kconfig                        |  1 +
 scripts/Makefile.build                  |  1 +
 tools/objtool/builtin-check.c           | 14 ++++++++++++++
 tools/objtool/check.c                   | 19 ++++++++++---------
 tools/objtool/include/objtool/builtin.h |  1 +
 6 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 250707647359..acaf88e3c694 100644
--- a/Makefile
+++ b/Makefile
@@ -851,7 +851,9 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_CC
   endif
 endif
 ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
-  CC_FLAGS_USING	+= -DCC_USING_NOP_MCOUNT
+  ifdef CONFIG_HAVE_NOP_MCOUNT
+    CC_FLAGS_USING	+= -DCC_USING_NOP_MCOUNT
+  endif
 endif
 ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
   ifdef CONFIG_HAVE_C_RECORDMCOUNT
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1847d6e974a1..4a41bfb644f0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -189,6 +189,7 @@ config X86
 	select HAVE_CONTEXT_TRACKING_OFFSTACK	if HAVE_CONTEXT_TRACKING
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
+	select HAVE_NOP_MCOUNT			if HAVE_OBJTOOL_MCOUNT
 	select HAVE_BUILDTIME_MCOUNT_SORT
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DMA_CONTIGUOUS
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ac8167227bc0..2e0c3f9c1459 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -231,6 +231,7 @@ objtool_args =								\
 	$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr)		\
 	$(if $(CONFIG_X86_KERNEL_IBT), --ibt)				\
 	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)		\
+	$(if $(CONFIG_HAVE_NOP_MCOUNT), --mnop)				\
 	$(if $(CONFIG_UNWINDER_ORC), --orc)				\
 	$(if $(CONFIG_RETPOLINE), --retpoline)				\
 	$(if $(CONFIG_SLS), --sls)					\
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index f4c3a5091737..b05e2108c0c3 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -80,6 +80,7 @@ const struct option check_options[] = {
 	OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
 	OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"),
 	OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
+	OPT_BOOLEAN(0, "mnop", &opts.mnop, "nop out mcount call sites"),
 	OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
 	OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
 	OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
@@ -142,6 +143,16 @@ static bool opts_valid(void)
 	return false;
 }
 
+static bool mnop_opts_valid(void)
+{
+	if (opts.mnop && !opts.mcount) {
+		ERROR("--mnop requires --mcount");
+		return false;
+	}
+
+	return true;
+}
+
 static bool link_opts_valid(struct objtool_file *file)
 {
 	if (opts.link)
@@ -185,6 +196,9 @@ int objtool_run(int argc, const char **argv)
 	if (!file)
 		return 1;
 
+	if (!mnop_opts_valid())
+		return 1;
+
 	if (!link_opts_valid(file))
 		return 1;
 
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index fabc0ea88747..7f0dc504dd92 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1177,17 +1177,18 @@ static void annotate_call_site(struct objtool_file *file,
 	if (opts.mcount && sym->fentry) {
 		if (sibling)
 			WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
+		if (opts.mnop) {
+			if (reloc) {
+				reloc->type = R_NONE;
+				elf_write_reloc(file->elf, reloc);
+			}
 
-		if (reloc) {
-			reloc->type = R_NONE;
-			elf_write_reloc(file->elf, reloc);
-		}
-
-		elf_write_insn(file->elf, insn->sec,
-			       insn->offset, insn->len,
-			       arch_nop_insn(insn->len));
+			elf_write_insn(file->elf, insn->sec,
+				       insn->offset, insn->len,
+				       arch_nop_insn(insn->len));
 
-		insn->type = INSN_NOP;
+			insn->type = INSN_NOP;
+		}
 
 		list_add_tail(&insn->call_node, &file->mcount_loc_list);
 		return;
diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h
index 280ea18b7f2b..71ed3152a18e 100644
--- a/tools/objtool/include/objtool/builtin.h
+++ b/tools/objtool/include/objtool/builtin.h
@@ -29,6 +29,7 @@ struct opts {
 	bool backup;
 	bool dryrun;
 	bool link;
+	bool mnop;
 	bool module;
 	bool no_unreachable;
 	bool sec_address;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 4/7] objtool: Add --mnop as an option to --mcount
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

From: Sathvika Vasireddy <sv@linux.ibm.com>

Architectures can select HAVE_NOP_MCOUNT if they choose
to nop out mcount call sites. If that config option is
selected, then --mnop is passed as an option to objtool,
along with --mcount.

Also, make sure that --mnop can be passed as an option
to objtool only when --mcount is passed.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 Makefile                                |  4 +++-
 arch/x86/Kconfig                        |  1 +
 scripts/Makefile.build                  |  1 +
 tools/objtool/builtin-check.c           | 14 ++++++++++++++
 tools/objtool/check.c                   | 19 ++++++++++---------
 tools/objtool/include/objtool/builtin.h |  1 +
 6 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 250707647359..acaf88e3c694 100644
--- a/Makefile
+++ b/Makefile
@@ -851,7 +851,9 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_CC
   endif
 endif
 ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
-  CC_FLAGS_USING	+= -DCC_USING_NOP_MCOUNT
+  ifdef CONFIG_HAVE_NOP_MCOUNT
+    CC_FLAGS_USING	+= -DCC_USING_NOP_MCOUNT
+  endif
 endif
 ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
   ifdef CONFIG_HAVE_C_RECORDMCOUNT
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1847d6e974a1..4a41bfb644f0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -189,6 +189,7 @@ config X86
 	select HAVE_CONTEXT_TRACKING_OFFSTACK	if HAVE_CONTEXT_TRACKING
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
+	select HAVE_NOP_MCOUNT			if HAVE_OBJTOOL_MCOUNT
 	select HAVE_BUILDTIME_MCOUNT_SORT
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DMA_CONTIGUOUS
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ac8167227bc0..2e0c3f9c1459 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -231,6 +231,7 @@ objtool_args =								\
 	$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr)		\
 	$(if $(CONFIG_X86_KERNEL_IBT), --ibt)				\
 	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)		\
+	$(if $(CONFIG_HAVE_NOP_MCOUNT), --mnop)				\
 	$(if $(CONFIG_UNWINDER_ORC), --orc)				\
 	$(if $(CONFIG_RETPOLINE), --retpoline)				\
 	$(if $(CONFIG_SLS), --sls)					\
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index f4c3a5091737..b05e2108c0c3 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -80,6 +80,7 @@ const struct option check_options[] = {
 	OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
 	OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"),
 	OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
+	OPT_BOOLEAN(0, "mnop", &opts.mnop, "nop out mcount call sites"),
 	OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
 	OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
 	OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
@@ -142,6 +143,16 @@ static bool opts_valid(void)
 	return false;
 }
 
+static bool mnop_opts_valid(void)
+{
+	if (opts.mnop && !opts.mcount) {
+		ERROR("--mnop requires --mcount");
+		return false;
+	}
+
+	return true;
+}
+
 static bool link_opts_valid(struct objtool_file *file)
 {
 	if (opts.link)
@@ -185,6 +196,9 @@ int objtool_run(int argc, const char **argv)
 	if (!file)
 		return 1;
 
+	if (!mnop_opts_valid())
+		return 1;
+
 	if (!link_opts_valid(file))
 		return 1;
 
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index fabc0ea88747..7f0dc504dd92 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1177,17 +1177,18 @@ static void annotate_call_site(struct objtool_file *file,
 	if (opts.mcount && sym->fentry) {
 		if (sibling)
 			WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
+		if (opts.mnop) {
+			if (reloc) {
+				reloc->type = R_NONE;
+				elf_write_reloc(file->elf, reloc);
+			}
 
-		if (reloc) {
-			reloc->type = R_NONE;
-			elf_write_reloc(file->elf, reloc);
-		}
-
-		elf_write_insn(file->elf, insn->sec,
-			       insn->offset, insn->len,
-			       arch_nop_insn(insn->len));
+			elf_write_insn(file->elf, insn->sec,
+				       insn->offset, insn->len,
+				       arch_nop_insn(insn->len));
 
-		insn->type = INSN_NOP;
+			insn->type = INSN_NOP;
+		}
 
 		list_add_tail(&insn->call_node, &file->mcount_loc_list);
 		return;
diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h
index 280ea18b7f2b..71ed3152a18e 100644
--- a/tools/objtool/include/objtool/builtin.h
+++ b/tools/objtool/include/objtool/builtin.h
@@ -29,6 +29,7 @@ struct opts {
 	bool backup;
 	bool dryrun;
 	bool link;
+	bool mnop;
 	bool module;
 	bool no_unreachable;
 	bool sec_address;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch makes sure objtool runs only on the object files
that have ftrace enabled, instead of running on all the object
files.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 scripts/Makefile.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 2e0c3f9c1459..06ceffd92921 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -258,8 +258,8 @@ else
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
 
-$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
-	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
+$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
+        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
 
 endif
 
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch makes sure objtool runs only on the object files
that have ftrace enabled, instead of running on all the object
files.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 scripts/Makefile.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 2e0c3f9c1459..06ceffd92921 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -258,8 +258,8 @@ else
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
 
-$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
-	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
+$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
+        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
 
 endif
 
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 6/7] objtool/powerpc: Enable objtool to be built on ppc
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch adds [stub] implementations for required
functions, inorder to enable objtool build on powerpc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/Kconfig                          |  1 +
 tools/objtool/arch/powerpc/Build              |  2 +
 tools/objtool/arch/powerpc/decode.c           | 74 +++++++++++++++++++
 .../arch/powerpc/include/arch/cfi_regs.h      | 11 +++
 tools/objtool/arch/powerpc/include/arch/elf.h |  8 ++
 .../arch/powerpc/include/arch/special.h       | 21 ++++++
 tools/objtool/arch/powerpc/special.c          | 19 +++++
 7 files changed, 136 insertions(+)
 create mode 100644 tools/objtool/arch/powerpc/Build
 create mode 100644 tools/objtool/arch/powerpc/decode.c
 create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
 create mode 100644 tools/objtool/arch/powerpc/special.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 174edabb74fa..7c01229dd2e3 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -232,6 +232,7 @@ config PPC
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
+	select HAVE_OBJTOOL
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/Build b/tools/objtool/arch/powerpc/Build
new file mode 100644
index 000000000000..d24d5636a5b8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/Build
@@ -0,0 +1,2 @@
+objtool-y += decode.o
+objtool-y += special.o
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
new file mode 100644
index 000000000000..eb1542d155fe
--- /dev/null
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <objtool/check.h>
+#include <objtool/elf.h>
+#include <objtool/arch.h>
+#include <objtool/warn.h>
+#include <objtool/builtin.h>
+#include <objtool/endianness.h>
+
+unsigned long arch_dest_reloc_offset(int addend)
+{
+	return addend;
+}
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+	return false;
+}
+
+int arch_decode_hint_reg(u8 sp_reg, int *base)
+{
+	return 0;
+}
+
+const char *arch_nop_insn(int len)
+{
+	return NULL;
+}
+
+const char *arch_ret_insn(int len)
+{
+	return NULL;
+}
+
+int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
+			    unsigned long offset, unsigned int maxlen,
+			    unsigned int *len, enum insn_type *type,
+			    unsigned long *immediate,
+			    struct list_head *ops_list)
+{
+	u32 insn;
+
+	*immediate = 0;
+	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
+	*len = 4;
+	*type = INSN_OTHER;
+
+	return 0;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+	return insn->offset +  insn->immediate;
+}
+
+void arch_initial_func_cfi_state(struct cfi_init_state *state)
+{
+	int i;
+
+	for (i = 0; i < CFI_NUM_REGS; i++) {
+		state->regs[i].base = CFI_UNDEFINED;
+		state->regs[i].offset = 0;
+	}
+
+	/* initial CFA (call frame address) */
+	state->cfa.base = CFI_SP;
+	state->cfa.offset = 0;
+
+	/* initial LR (return address) */
+	state->regs[CFI_RA].base = CFI_CFA;
+	state->regs[CFI_RA].offset = 0;
+}
diff --git a/tools/objtool/arch/powerpc/include/arch/cfi_regs.h b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
new file mode 100644
index 000000000000..59638ebeafc8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_BP 1
+#define CFI_SP CFI_BP
+#define CFI_RA 32
+#define CFI_NUM_REGS 33
+
+#endif
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
new file mode 100644
index 000000000000..3c8ebb7d2a6b
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_ARCH_ELF
+#define _OBJTOOL_ARCH_ELF
+
+#define R_NONE R_PPC_NONE
+
+#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objtool/arch/powerpc/include/arch/special.h
new file mode 100644
index 000000000000..ffef9ada7133
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/special.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _PPC_ARCH_SPECIAL_H
+#define _PPC_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE 8
+#define EX_ORIG_OFFSET 0
+#define EX_NEW_OFFSET 4
+
+#define JUMP_ENTRY_SIZE 16
+#define JUMP_ORIG_OFFSET 0
+#define JUMP_NEW_OFFSET 4
+#define JUMP_KEY_OFFSET 8
+
+#define ALT_ENTRY_SIZE 12
+#define ALT_ORIG_OFFSET 0
+#define ALT_NEW_OFFSET 4
+#define ALT_FEATURE_OFFSET 8
+#define ALT_ORIG_LEN_OFFSET 10
+#define ALT_NEW_LEN_OFFSET 11
+
+#endif /* _PPC_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powerpc/special.c
new file mode 100644
index 000000000000..e3e75cbab858
--- /dev/null
+++ b/tools/objtool/arch/powerpc/special.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+
+#include <objtool/special.h>
+#include <objtool/builtin.h>
+
+
+bool arch_support_alt_relocation(struct special_alt *special_alt,
+				 struct instruction *insn,
+				 struct reloc *reloc)
+{
+	return false;
+}
+
+struct reloc *arch_find_switch_table(struct objtool_file *file,
+				    struct instruction *insn)
+{
+	return NULL;
+}
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 6/7] objtool/powerpc: Enable objtool to be built on ppc
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch adds [stub] implementations for required
functions, inorder to enable objtool build on powerpc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/Kconfig                          |  1 +
 tools/objtool/arch/powerpc/Build              |  2 +
 tools/objtool/arch/powerpc/decode.c           | 74 +++++++++++++++++++
 .../arch/powerpc/include/arch/cfi_regs.h      | 11 +++
 tools/objtool/arch/powerpc/include/arch/elf.h |  8 ++
 .../arch/powerpc/include/arch/special.h       | 21 ++++++
 tools/objtool/arch/powerpc/special.c          | 19 +++++
 7 files changed, 136 insertions(+)
 create mode 100644 tools/objtool/arch/powerpc/Build
 create mode 100644 tools/objtool/arch/powerpc/decode.c
 create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/special.h
 create mode 100644 tools/objtool/arch/powerpc/special.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 174edabb74fa..7c01229dd2e3 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -232,6 +232,7 @@ config PPC
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
+	select HAVE_OBJTOOL
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/Build b/tools/objtool/arch/powerpc/Build
new file mode 100644
index 000000000000..d24d5636a5b8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/Build
@@ -0,0 +1,2 @@
+objtool-y += decode.o
+objtool-y += special.o
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
new file mode 100644
index 000000000000..eb1542d155fe
--- /dev/null
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <objtool/check.h>
+#include <objtool/elf.h>
+#include <objtool/arch.h>
+#include <objtool/warn.h>
+#include <objtool/builtin.h>
+#include <objtool/endianness.h>
+
+unsigned long arch_dest_reloc_offset(int addend)
+{
+	return addend;
+}
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+	return false;
+}
+
+int arch_decode_hint_reg(u8 sp_reg, int *base)
+{
+	return 0;
+}
+
+const char *arch_nop_insn(int len)
+{
+	return NULL;
+}
+
+const char *arch_ret_insn(int len)
+{
+	return NULL;
+}
+
+int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
+			    unsigned long offset, unsigned int maxlen,
+			    unsigned int *len, enum insn_type *type,
+			    unsigned long *immediate,
+			    struct list_head *ops_list)
+{
+	u32 insn;
+
+	*immediate = 0;
+	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
+	*len = 4;
+	*type = INSN_OTHER;
+
+	return 0;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+	return insn->offset +  insn->immediate;
+}
+
+void arch_initial_func_cfi_state(struct cfi_init_state *state)
+{
+	int i;
+
+	for (i = 0; i < CFI_NUM_REGS; i++) {
+		state->regs[i].base = CFI_UNDEFINED;
+		state->regs[i].offset = 0;
+	}
+
+	/* initial CFA (call frame address) */
+	state->cfa.base = CFI_SP;
+	state->cfa.offset = 0;
+
+	/* initial LR (return address) */
+	state->regs[CFI_RA].base = CFI_CFA;
+	state->regs[CFI_RA].offset = 0;
+}
diff --git a/tools/objtool/arch/powerpc/include/arch/cfi_regs.h b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
new file mode 100644
index 000000000000..59638ebeafc8
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_BP 1
+#define CFI_SP CFI_BP
+#define CFI_RA 32
+#define CFI_NUM_REGS 33
+
+#endif
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
new file mode 100644
index 000000000000..3c8ebb7d2a6b
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_ARCH_ELF
+#define _OBJTOOL_ARCH_ELF
+
+#define R_NONE R_PPC_NONE
+
+#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objtool/arch/powerpc/include/arch/special.h
new file mode 100644
index 000000000000..ffef9ada7133
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/special.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _PPC_ARCH_SPECIAL_H
+#define _PPC_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE 8
+#define EX_ORIG_OFFSET 0
+#define EX_NEW_OFFSET 4
+
+#define JUMP_ENTRY_SIZE 16
+#define JUMP_ORIG_OFFSET 0
+#define JUMP_NEW_OFFSET 4
+#define JUMP_KEY_OFFSET 8
+
+#define ALT_ENTRY_SIZE 12
+#define ALT_ORIG_OFFSET 0
+#define ALT_NEW_OFFSET 4
+#define ALT_FEATURE_OFFSET 8
+#define ALT_ORIG_LEN_OFFSET 10
+#define ALT_NEW_LEN_OFFSET 11
+
+#endif /* _PPC_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powerpc/special.c
new file mode 100644
index 000000000000..e3e75cbab858
--- /dev/null
+++ b/tools/objtool/arch/powerpc/special.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+
+#include <objtool/special.h>
+#include <objtool/builtin.h>
+
+
+bool arch_support_alt_relocation(struct special_alt *special_alt,
+				 struct instruction *insn,
+				 struct reloc *reloc)
+{
+	return false;
+}
+
+struct reloc *arch_find_switch_table(struct objtool_file *file,
+				    struct instruction *insn)
+{
+	return NULL;
+}
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 7/7] objtool/powerpc: Add --mcount specific implementation
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-24 13:17   ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: Christophe Leroy, linux-kernel, linuxppc-dev

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch enables objtool --mcount on powerpc, and
adds implementation specific to powerpc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/Kconfig                |  1 +
 tools/objtool/arch/powerpc/decode.c | 14 ++++++++++++++
 tools/objtool/check.c               | 12 +++++++-----
 tools/objtool/elf.c                 | 15 +++++++++++++++
 tools/objtool/include/objtool/elf.h |  1 +
 5 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 7c01229dd2e3..5ef8bf8eb202 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -233,6 +233,7 @@ config PPC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
 	select HAVE_OBJTOOL
+	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index eb1542d155fe..048bb4cd2838 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -41,12 +41,26 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 			    struct list_head *ops_list)
 {
 	u32 insn;
+	unsigned int opcode;
 
 	*immediate = 0;
 	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
 	*len = 4;
 	*type = INSN_OTHER;
 
+	opcode = (insn >> 26);
+
+	switch (opcode) {
+	case 18: /* bl */
+		if ((insn & 3) == 1) {
+			*type = INSN_CALL;
+			*immediate = insn & 0x3fffffc;
+			if (*immediate & 0x2000000)
+				*immediate -= 0x4000000;
+		}
+		break;
+	}
+
 	return 0;
 }
 
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 7f0dc504dd92..70be5a72e838 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
 		memset(loc, 0, size);
 
 		if (elf_add_reloc_to_insn(file->elf, sec, idx,
-					  R_X86_64_64,
+					  elf_reloc_type_long(file->elf),
 					  insn->sec, insn->offset))
 			return -1;
 
@@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file *file)
 			if (arch_is_retpoline(func))
 				func->retpoline_thunk = true;
 
-			if (!strcmp(func->name, "__fentry__"))
+			if ((!strcmp(func->name, "__fentry__")) || (!strcmp(func->name, "_mcount")))
 				func->fentry = true;
 
 			if (is_profiling_func(func->name))
@@ -2261,9 +2261,11 @@ static int decode_sections(struct objtool_file *file)
 	 * Must be before add_jump_destinations(), which depends on 'func'
 	 * being set for alternatives, to enable proper sibling call detection.
 	 */
-	ret = add_special_section_alts(file);
-	if (ret)
-		return ret;
+	if (opts.stackval || opts.orc || opts.uaccess || opts.noinstr) {
+		ret = add_special_section_alts(file);
+		if (ret)
+			return ret;
+	}
 
 	ret = add_jump_destinations(file);
 	if (ret)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 63218f5799c2..34b1c6817a5e 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -793,6 +793,21 @@ elf_create_section_symbol(struct elf *elf, struct section *sec)
 	return sym;
 }
 
+int elf_reloc_type_long(struct elf *elf)
+{
+	switch (elf->ehdr.e_machine) {
+	case EM_X86_64:
+		return R_X86_64_64;
+	case EM_PPC64:
+		return R_PPC64_ADDR64;
+	case EM_PPC:
+		return R_PPC_ADDR32;
+	default:
+		WARN("unknown machine...");
+		exit(-1);
+	}
+}
+
 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
 			  unsigned long offset, unsigned int type,
 			  struct section *insn_sec, unsigned long insn_off)
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index c720c4476828..d10f4701715b 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -152,6 +152,7 @@ static inline int elf_class_size(struct elf *elf)
 struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
 
+int elf_reloc_type_long(struct elf *elf);
 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
 		  unsigned int type, struct symbol *sym, s64 addend);
 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [RFC PATCH v2 7/7] objtool/powerpc: Add --mcount specific implementation
@ 2022-05-24 13:17   ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 13:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, peterz,
	aik, sv, rostedt, jpoimboe, naveen.n.rao, mbenes
  Cc: linuxppc-dev, linux-kernel

From: Sathvika Vasireddy <sv@linux.ibm.com>

This patch enables objtool --mcount on powerpc, and
adds implementation specific to powerpc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/Kconfig                |  1 +
 tools/objtool/arch/powerpc/decode.c | 14 ++++++++++++++
 tools/objtool/check.c               | 12 +++++++-----
 tools/objtool/elf.c                 | 15 +++++++++++++++
 tools/objtool/include/objtool/elf.h |  1 +
 5 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 7c01229dd2e3..5ef8bf8eb202 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -233,6 +233,7 @@ config PPC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
 	select HAVE_OBJTOOL
+	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index eb1542d155fe..048bb4cd2838 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -41,12 +41,26 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 			    struct list_head *ops_list)
 {
 	u32 insn;
+	unsigned int opcode;
 
 	*immediate = 0;
 	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
 	*len = 4;
 	*type = INSN_OTHER;
 
+	opcode = (insn >> 26);
+
+	switch (opcode) {
+	case 18: /* bl */
+		if ((insn & 3) == 1) {
+			*type = INSN_CALL;
+			*immediate = insn & 0x3fffffc;
+			if (*immediate & 0x2000000)
+				*immediate -= 0x4000000;
+		}
+		break;
+	}
+
 	return 0;
 }
 
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 7f0dc504dd92..70be5a72e838 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
 		memset(loc, 0, size);
 
 		if (elf_add_reloc_to_insn(file->elf, sec, idx,
-					  R_X86_64_64,
+					  elf_reloc_type_long(file->elf),
 					  insn->sec, insn->offset))
 			return -1;
 
@@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file *file)
 			if (arch_is_retpoline(func))
 				func->retpoline_thunk = true;
 
-			if (!strcmp(func->name, "__fentry__"))
+			if ((!strcmp(func->name, "__fentry__")) || (!strcmp(func->name, "_mcount")))
 				func->fentry = true;
 
 			if (is_profiling_func(func->name))
@@ -2261,9 +2261,11 @@ static int decode_sections(struct objtool_file *file)
 	 * Must be before add_jump_destinations(), which depends on 'func'
 	 * being set for alternatives, to enable proper sibling call detection.
 	 */
-	ret = add_special_section_alts(file);
-	if (ret)
-		return ret;
+	if (opts.stackval || opts.orc || opts.uaccess || opts.noinstr) {
+		ret = add_special_section_alts(file);
+		if (ret)
+			return ret;
+	}
 
 	ret = add_jump_destinations(file);
 	if (ret)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 63218f5799c2..34b1c6817a5e 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -793,6 +793,21 @@ elf_create_section_symbol(struct elf *elf, struct section *sec)
 	return sym;
 }
 
+int elf_reloc_type_long(struct elf *elf)
+{
+	switch (elf->ehdr.e_machine) {
+	case EM_X86_64:
+		return R_X86_64_64;
+	case EM_PPC64:
+		return R_PPC64_ADDR64;
+	case EM_PPC:
+		return R_PPC_ADDR32;
+	default:
+		WARN("unknown machine...");
+		exit(-1);
+	}
+}
+
 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
 			  unsigned long offset, unsigned int type,
 			  struct section *insn_sec, unsigned long insn_off)
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index c720c4476828..d10f4701715b 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -152,6 +152,7 @@ static inline int elf_class_size(struct elf *elf)
 struct elf *elf_open_read(const char *name, int flags);
 struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
 
+int elf_reloc_type_long(struct elf *elf);
 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
 		  unsigned int type, struct symbol *sym, s64 addend);
 int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 3/7] objtool: Use target file class size instead of a compiled constant
  2022-05-24 13:17   ` Christophe Leroy
@ 2022-05-24 17:59     ` Peter Zijlstra
  -1 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 17:59 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aik,
	sv, rostedt, jpoimboe, naveen.n.rao, mbenes, linux-kernel,
	linuxppc-dev

On Tue, May 24, 2022 at 03:17:43PM +0200, Christophe Leroy wrote:
> -	sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
> +	if (size == sizeof(u32))
> +		sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0);
> +	else
> +		sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);

Probably best to use Elf64_* here instead of GElf_*.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 3/7] objtool: Use target file class size instead of a compiled constant
@ 2022-05-24 17:59     ` Peter Zijlstra
  0 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 17:59 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev

On Tue, May 24, 2022 at 03:17:43PM +0200, Christophe Leroy wrote:
> -	sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);
> +	if (size == sizeof(u32))
> +		sec = elf_create_section(elf, relocname, 0, sizeof(Elf32_Rela), 0);
> +	else
> +		sec = elf_create_section(elf, relocname, 0, sizeof(GElf_Rela), 0);

Probably best to use Elf64_* here instead of GElf_*.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 13:17   ` Christophe Leroy
@ 2022-05-24 18:01     ` Peter Zijlstra
  -1 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 18:01 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aik,
	sv, rostedt, jpoimboe, naveen.n.rao, mbenes, linux-kernel,
	linuxppc-dev

On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> From: Sathvika Vasireddy <sv@linux.ibm.com>
> 
> This patch makes sure objtool runs only on the object files
> that have ftrace enabled, instead of running on all the object
> files.
> 
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
>  scripts/Makefile.build | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 2e0c3f9c1459..06ceffd92921 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -258,8 +258,8 @@ else
>  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
>  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>  
> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)

I think this breaks x86, quite a bit of files have ftrace disabled but
very much must run objtool anyway.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
@ 2022-05-24 18:01     ` Peter Zijlstra
  0 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 18:01 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev

On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> From: Sathvika Vasireddy <sv@linux.ibm.com>
> 
> This patch makes sure objtool runs only on the object files
> that have ftrace enabled, instead of running on all the object
> files.
> 
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
>  scripts/Makefile.build | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 2e0c3f9c1459..06ceffd92921 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -258,8 +258,8 @@ else
>  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
>  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>  
> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)

I think this breaks x86, quite a bit of files have ftrace disabled but
very much must run objtool anyway.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 18:01     ` Peter Zijlstra
@ 2022-05-24 18:02       ` Peter Zijlstra
  -1 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 18:02 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aik,
	sv, rostedt, jpoimboe, naveen.n.rao, mbenes, linux-kernel,
	linuxppc-dev

On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> > From: Sathvika Vasireddy <sv@linux.ibm.com>
> > 
> > This patch makes sure objtool runs only on the object files
> > that have ftrace enabled, instead of running on all the object
> > files.
> > 
> > Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> > Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> > ---
> >  scripts/Makefile.build | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> > index 2e0c3f9c1459..06ceffd92921 100644
> > --- a/scripts/Makefile.build
> > +++ b/scripts/Makefile.build
> > @@ -258,8 +258,8 @@ else
> >  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> >  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
> >  
> > -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> > -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> > +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> > +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
> 
> I think this breaks x86, quite a bit of files have ftrace disabled but
> very much must run objtool anyway.

Also; since the Changelog gives 0 clue as to what problem it's trying to
solve, I can't suggest anything.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
@ 2022-05-24 18:02       ` Peter Zijlstra
  0 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 18:02 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev

On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> > From: Sathvika Vasireddy <sv@linux.ibm.com>
> > 
> > This patch makes sure objtool runs only on the object files
> > that have ftrace enabled, instead of running on all the object
> > files.
> > 
> > Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> > Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> > ---
> >  scripts/Makefile.build | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> > index 2e0c3f9c1459..06ceffd92921 100644
> > --- a/scripts/Makefile.build
> > +++ b/scripts/Makefile.build
> > @@ -258,8 +258,8 @@ else
> >  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> >  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
> >  
> > -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> > -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> > +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> > +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
> 
> I think this breaks x86, quite a bit of files have ftrace disabled but
> very much must run objtool anyway.

Also; since the Changelog gives 0 clue as to what problem it's trying to
solve, I can't suggest anything.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 18:02       ` Peter Zijlstra
@ 2022-05-24 18:59         ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 18:59 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev



Le 24/05/2022 à 20:02, Peter Zijlstra a écrit :
> On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
>> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
>>> From: Sathvika Vasireddy <sv@linux.ibm.com>
>>>
>>> This patch makes sure objtool runs only on the object files
>>> that have ftrace enabled, instead of running on all the object
>>> files.
>>>
>>> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
>>> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>>> ---
>>>   scripts/Makefile.build | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
>>> index 2e0c3f9c1459..06ceffd92921 100644
>>> --- a/scripts/Makefile.build
>>> +++ b/scripts/Makefile.build
>>> @@ -258,8 +258,8 @@ else
>>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
>>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>>>   
>>> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
>>> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
>>> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
>>> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
>>
>> I think this breaks x86, quite a bit of files have ftrace disabled but
>> very much must run objtool anyway.
> 
> Also; since the Changelog gives 0 clue as to what problem it's trying to
> solve, I can't suggest anything.

I asked Sathvika on the previous series, see 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220523175548.922671-3-sv@linux.ibm.com/

He says it is to solve the problem I reported at 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220318105140.43914-4-sv@linux.ibm.com/#2861128

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
@ 2022-05-24 18:59         ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-24 18:59 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aik,
	sv, rostedt, jpoimboe, naveen.n.rao, mbenes, linux-kernel,
	linuxppc-dev



Le 24/05/2022 à 20:02, Peter Zijlstra a écrit :
> On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
>> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
>>> From: Sathvika Vasireddy <sv@linux.ibm.com>
>>>
>>> This patch makes sure objtool runs only on the object files
>>> that have ftrace enabled, instead of running on all the object
>>> files.
>>>
>>> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
>>> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>>> ---
>>>   scripts/Makefile.build | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
>>> index 2e0c3f9c1459..06ceffd92921 100644
>>> --- a/scripts/Makefile.build
>>> +++ b/scripts/Makefile.build
>>> @@ -258,8 +258,8 @@ else
>>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
>>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>>>   
>>> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
>>> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
>>> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
>>> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
>>
>> I think this breaks x86, quite a bit of files have ftrace disabled but
>> very much must run objtool anyway.
> 
> Also; since the Changelog gives 0 clue as to what problem it's trying to
> solve, I can't suggest anything.

I asked Sathvika on the previous series, see 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220523175548.922671-3-sv@linux.ibm.com/

He says it is to solve the problem I reported at 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220318105140.43914-4-sv@linux.ibm.com/#2861128

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 18:59         ` Christophe Leroy
@ 2022-05-24 19:50           ` Peter Zijlstra
  -1 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 19:50 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aik,
	sv, rostedt, jpoimboe, naveen.n.rao, mbenes, linux-kernel,
	linuxppc-dev

On Tue, May 24, 2022 at 06:59:50PM +0000, Christophe Leroy wrote:
> 
> 
> Le 24/05/2022 à 20:02, Peter Zijlstra a écrit :
> > On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
> >> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> >>> From: Sathvika Vasireddy <sv@linux.ibm.com>
> >>>
> >>> This patch makes sure objtool runs only on the object files
> >>> that have ftrace enabled, instead of running on all the object
> >>> files.
> >>>
> >>> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> >>> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> >>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> >>> ---
> >>>   scripts/Makefile.build | 4 ++--
> >>>   1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> >>> index 2e0c3f9c1459..06ceffd92921 100644
> >>> --- a/scripts/Makefile.build
> >>> +++ b/scripts/Makefile.build
> >>> @@ -258,8 +258,8 @@ else
> >>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> >>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
> >>>   
> >>> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> >>> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> >>> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> >>> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
> >>
> >> I think this breaks x86, quite a bit of files have ftrace disabled but
> >> very much must run objtool anyway.
> > 
> > Also; since the Changelog gives 0 clue as to what problem it's trying to
> > solve, I can't suggest anything.
> 
> I asked Sathvika on the previous series, see 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220523175548.922671-3-sv@linux.ibm.com/
> 
> He says it is to solve the problem I reported at 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220318105140.43914-4-sv@linux.ibm.com/#2861128

So on x86 we have:

arch/x86/entry/vdso/Makefile:OBJECT_FILES_NON_STANDARD       := y

to kill objtool for the whole of the VDSO. When we run objtool on
vmlinux it isn't a problem, because the VDSO ends up as a data section
through linker scripts.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
@ 2022-05-24 19:50           ` Peter Zijlstra
  0 siblings, 0 replies; 43+ messages in thread
From: Peter Zijlstra @ 2022-05-24 19:50 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev

On Tue, May 24, 2022 at 06:59:50PM +0000, Christophe Leroy wrote:
> 
> 
> Le 24/05/2022 à 20:02, Peter Zijlstra a écrit :
> > On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
> >> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
> >>> From: Sathvika Vasireddy <sv@linux.ibm.com>
> >>>
> >>> This patch makes sure objtool runs only on the object files
> >>> that have ftrace enabled, instead of running on all the object
> >>> files.
> >>>
> >>> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> >>> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> >>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> >>> ---
> >>>   scripts/Makefile.build | 4 ++--
> >>>   1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> >>> index 2e0c3f9c1459..06ceffd92921 100644
> >>> --- a/scripts/Makefile.build
> >>> +++ b/scripts/Makefile.build
> >>> @@ -258,8 +258,8 @@ else
> >>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> >>>   # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
> >>>   
> >>> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
> >>> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> >>> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
> >>> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
> >>
> >> I think this breaks x86, quite a bit of files have ftrace disabled but
> >> very much must run objtool anyway.
> > 
> > Also; since the Changelog gives 0 clue as to what problem it's trying to
> > solve, I can't suggest anything.
> 
> I asked Sathvika on the previous series, see 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220523175548.922671-3-sv@linux.ibm.com/
> 
> He says it is to solve the problem I reported at 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220318105140.43914-4-sv@linux.ibm.com/#2861128

So on x86 we have:

arch/x86/entry/vdso/Makefile:OBJECT_FILES_NON_STANDARD       := y

to kill objtool for the whole of the VDSO. When we run objtool on
vmlinux it isn't a problem, because the VDSO ends up as a data section
through linker scripts.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-05-24 13:17 ` Christophe Leroy
@ 2022-05-25 10:14   ` Sathvika Vasireddy
  -1 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-05-25 10:14 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy

Hi Christophe,

On 24/05/22 18:47, Christophe Leroy wrote:
> This draft series adds PPC32 support to Sathvika's series.
> Verified on pmac32 on QEMU.
>
> It should in principle also work for PPC64 BE but for the time being
> something goes wrong. In the beginning I had a segfaut hence the first
> patch. But I still get no mcount section in the files.
Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
And so, the relocation records in case of PPC64BE point to "._mcount",
rather than just "_mcount". We should be looking for "._mcount" to be
able to generate mcount_loc section in the files.

Like:

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 70be5a72e838..7da5bf8c7236 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file *file)
                         if (arch_is_retpoline(func))
                                 func->retpoline_thunk = true;

-                       if ((!strcmp(func->name, "__fentry__")) || 
(!strcmp(func->name, "_mcount")))
+                       if ((!strcmp(func->name, "__fentry__")) || 
(!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
                                 func->fentry = true;

                         if (is_profiling_func(func->name))


With this change, I could see __mcount_loc section being
generated in individual ppc64be object files.

- Sathvika



^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-25 10:14   ` Sathvika Vasireddy
  0 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-05-25 10:14 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

Hi Christophe,

On 24/05/22 18:47, Christophe Leroy wrote:
> This draft series adds PPC32 support to Sathvika's series.
> Verified on pmac32 on QEMU.
>
> It should in principle also work for PPC64 BE but for the time being
> something goes wrong. In the beginning I had a segfaut hence the first
> patch. But I still get no mcount section in the files.
Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
And so, the relocation records in case of PPC64BE point to "._mcount",
rather than just "_mcount". We should be looking for "._mcount" to be
able to generate mcount_loc section in the files.

Like:

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 70be5a72e838..7da5bf8c7236 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file *file)
                         if (arch_is_retpoline(func))
                                 func->retpoline_thunk = true;

-                       if ((!strcmp(func->name, "__fentry__")) || 
(!strcmp(func->name, "_mcount")))
+                       if ((!strcmp(func->name, "__fentry__")) || 
(!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
                                 func->fentry = true;

                         if (is_profiling_func(func->name))


With this change, I could see __mcount_loc section being
generated in individual ppc64be object files.

- Sathvika



^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled
  2022-05-24 19:50           ` Peter Zijlstra
  (?)
@ 2022-05-25 11:00           ` Sathvika Vasireddy
  -1 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-05-25 11:00 UTC (permalink / raw)
  To: Peter Zijlstra, Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, sv, Paul Mackerras,
	naveen.n.rao, mbenes, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 2687 bytes --]

Hi Peter,

On 25/05/22 01:20, Peter Zijlstra wrote:
> On Tue, May 24, 2022 at 06:59:50PM +0000, Christophe Leroy wrote:
>>
>> Le 24/05/2022 à 20:02, Peter Zijlstra a écrit :
>>> On Tue, May 24, 2022 at 08:01:39PM +0200, Peter Zijlstra wrote:
>>>> On Tue, May 24, 2022 at 03:17:45PM +0200, Christophe Leroy wrote:
>>>>> From: Sathvika Vasireddy<sv@linux.ibm.com>
>>>>>
>>>>> This patch makes sure objtool runs only on the object files
>>>>> that have ftrace enabled, instead of running on all the object
>>>>> files.
>>>>>
>>>>> Signed-off-by: Naveen N. Rao<naveen.n.rao@linux.vnet.ibm.com>
>>>>> Signed-off-by: Sathvika Vasireddy<sv@linux.ibm.com>
>>>>> Signed-off-by: Christophe Leroy<christophe.leroy@csgroup.eu>
>>>>> ---
>>>>>    scripts/Makefile.build | 4 ++--
>>>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
>>>>> index 2e0c3f9c1459..06ceffd92921 100644
>>>>> --- a/scripts/Makefile.build
>>>>> +++ b/scripts/Makefile.build
>>>>> @@ -258,8 +258,8 @@ else
>>>>>    # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
>>>>>    # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>>>>>    
>>>>> -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
>>>>> -	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
>>>>> +$(obj)/%.o: objtool-enabled = $(and $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y),        \
>>>>> +        $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),y),y)
>>>> I think this breaks x86, quite a bit of files have ftrace disabled but
>>>> very much must run objtool anyway.
>>> Also; since the Changelog gives 0 clue as to what problem it's trying to
>>> solve, I can't suggest anything.
>> I asked Sathvika on the previous series, see
>> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220523175548.922671-3-sv@linux.ibm.com/
>>
>> He says it is to solve the problem I reported at
>> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220318105140.43914-4-sv@linux.ibm.com/#2861128
> So on x86 we have:
>
> arch/x86/entry/vdso/Makefile:OBJECT_FILES_NON_STANDARD       := y
>
> to kill objtool for the whole of the VDSO. When we run objtool on
> vmlinux it isn't a problem, because the VDSO ends up as a data section
> through linker scripts.
Right.. Like you and Christophe mentioned,
arch/powerpc/kernel/vdso/Makefile:OBJECT_FILES_NON_STANDARD := y
should solve it for powerpc as well.


I'll drop this patch and replace it with the above change as part of next
revision series.


Thanks for reviewing!



- Sathvika


[-- Attachment #2: Type: text/html, Size: 6948 bytes --]

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-05-25 10:14   ` Sathvika Vasireddy
@ 2022-05-25 16:51     ` Segher Boessenkool
  -1 siblings, 0 replies; 43+ messages in thread
From: Segher Boessenkool @ 2022-05-25 16:51 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: aik, linux-kernel, rostedt, peterz, Paul Mackerras, jpoimboe,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

On Wed, May 25, 2022 at 03:44:04PM +0530, Sathvika Vasireddy wrote:
> On 24/05/22 18:47, Christophe Leroy wrote:
> >This draft series adds PPC32 support to Sathvika's series.
> >Verified on pmac32 on QEMU.
> >
> >It should in principle also work for PPC64 BE but for the time being
> >something goes wrong. In the beginning I had a segfaut hence the first
> >patch. But I still get no mcount section in the files.
> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
> And so, the relocation records in case of PPC64BE point to "._mcount",
> rather than just "_mcount". We should be looking for "._mcount" to be
> able to generate mcount_loc section in the files.

The dotted symbol is on the actual function.  The "normal" symbol is on
the "official procedure descriptor" (opd), which is what you get if you
(in C) take the address of a function.  A procedure descriptor holds one
or two more pointers, the GOT and environment pointers.  We don't use
the environment one, but the GOT pointer is necessary everywhere :-)


Segher

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-25 16:51     ` Segher Boessenkool
  0 siblings, 0 replies; 43+ messages in thread
From: Segher Boessenkool @ 2022-05-25 16:51 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: Christophe Leroy, aik, jpoimboe, linux-kernel, rostedt, peterz,
	Paul Mackerras, Sathvika Vasireddy, Naveen N. Rao, mbenes,
	linuxppc-dev

On Wed, May 25, 2022 at 03:44:04PM +0530, Sathvika Vasireddy wrote:
> On 24/05/22 18:47, Christophe Leroy wrote:
> >This draft series adds PPC32 support to Sathvika's series.
> >Verified on pmac32 on QEMU.
> >
> >It should in principle also work for PPC64 BE but for the time being
> >something goes wrong. In the beginning I had a segfaut hence the first
> >patch. But I still get no mcount section in the files.
> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
> And so, the relocation records in case of PPC64BE point to "._mcount",
> rather than just "_mcount". We should be looking for "._mcount" to be
> able to generate mcount_loc section in the files.

The dotted symbol is on the actual function.  The "normal" symbol is on
the "official procedure descriptor" (opd), which is what you get if you
(in C) take the address of a function.  A procedure descriptor holds one
or two more pointers, the GOT and environment pointers.  We don't use
the environment one, but the GOT pointer is necessary everywhere :-)


Segher

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-05-25 10:14   ` Sathvika Vasireddy
@ 2022-05-25 17:39     ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-25 17:39 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy

Hi Sathvika,

Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
> Hi Christophe,
> 
> On 24/05/22 18:47, Christophe Leroy wrote:
>> This draft series adds PPC32 support to Sathvika's series.
>> Verified on pmac32 on QEMU.
>>
>> It should in principle also work for PPC64 BE but for the time being
>> something goes wrong. In the beginning I had a segfaut hence the first
>> patch. But I still get no mcount section in the files.
> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
> And so, the relocation records in case of PPC64BE point to "._mcount",
> rather than just "_mcount". We should be looking for "._mcount" to be
> able to generate mcount_loc section in the files.
> 
> Like:
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 70be5a72e838..7da5bf8c7236 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file 
> *file)
>                          if (arch_is_retpoline(func))
>                                  func->retpoline_thunk = true;
> 
> -                       if ((!strcmp(func->name, "__fentry__")) || 
> (!strcmp(func->name, "_mcount")))
> +                       if ((!strcmp(func->name, "__fentry__")) || 
> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>                                  func->fentry = true;
> 
>                          if (is_profiling_func(func->name))
> 
> 
> With this change, I could see __mcount_loc section being
> generated in individual ppc64be object files.
> 

Or should we implement an equivalent of arch_ftrace_match_adjust() in 
objtool ?

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-25 17:39     ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-05-25 17:39 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

Hi Sathvika,

Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
> Hi Christophe,
> 
> On 24/05/22 18:47, Christophe Leroy wrote:
>> This draft series adds PPC32 support to Sathvika's series.
>> Verified on pmac32 on QEMU.
>>
>> It should in principle also work for PPC64 BE but for the time being
>> something goes wrong. In the beginning I had a segfaut hence the first
>> patch. But I still get no mcount section in the files.
> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
> And so, the relocation records in case of PPC64BE point to "._mcount",
> rather than just "_mcount". We should be looking for "._mcount" to be
> able to generate mcount_loc section in the files.
> 
> Like:
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 70be5a72e838..7da5bf8c7236 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file 
> *file)
>                          if (arch_is_retpoline(func))
>                                  func->retpoline_thunk = true;
> 
> -                       if ((!strcmp(func->name, "__fentry__")) || 
> (!strcmp(func->name, "_mcount")))
> +                       if ((!strcmp(func->name, "__fentry__")) || 
> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>                                  func->fentry = true;
> 
>                          if (is_profiling_func(func->name))
> 
> 
> With this change, I could see __mcount_loc section being
> generated in individual ppc64be object files.
> 

Or should we implement an equivalent of arch_ftrace_match_adjust() in 
objtool ?

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-05-25 17:39     ` Christophe Leroy
@ 2022-05-25 18:12       ` Sathvika Vasireddy
  -1 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-05-25 18:12 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy


On 25/05/22 23:09, Christophe Leroy wrote:
> Hi Sathvika,
>
> Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
>> Hi Christophe,
>>
>> On 24/05/22 18:47, Christophe Leroy wrote:
>>> This draft series adds PPC32 support to Sathvika's series.
>>> Verified on pmac32 on QEMU.
>>>
>>> It should in principle also work for PPC64 BE but for the time being
>>> something goes wrong. In the beginning I had a segfaut hence the first
>>> patch. But I still get no mcount section in the files.
>> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
>> And so, the relocation records in case of PPC64BE point to "._mcount",
>> rather than just "_mcount". We should be looking for "._mcount" to be
>> able to generate mcount_loc section in the files.
>>
>> Like:
>>
>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>> index 70be5a72e838..7da5bf8c7236 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file
>> *file)
>>                           if (arch_is_retpoline(func))
>>                                   func->retpoline_thunk = true;
>>
>> -                       if ((!strcmp(func->name, "__fentry__")) ||
>> (!strcmp(func->name, "_mcount")))
>> +                       if ((!strcmp(func->name, "__fentry__")) ||
>> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>>                                   func->fentry = true;
>>
>>                           if (is_profiling_func(func->name))
>>
>>
>> With this change, I could see __mcount_loc section being
>> generated in individual ppc64be object files.
>>
> Or should we implement an equivalent of arch_ftrace_match_adjust() in
> objtool ?

Yeah, I think it makes more sense if we make it arch specific.
Thanks for the suggestion. I'll make this change in next revision :-)

- Sathvika



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-05-25 18:12       ` Sathvika Vasireddy
  0 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-05-25 18:12 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev


On 25/05/22 23:09, Christophe Leroy wrote:
> Hi Sathvika,
>
> Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
>> Hi Christophe,
>>
>> On 24/05/22 18:47, Christophe Leroy wrote:
>>> This draft series adds PPC32 support to Sathvika's series.
>>> Verified on pmac32 on QEMU.
>>>
>>> It should in principle also work for PPC64 BE but for the time being
>>> something goes wrong. In the beginning I had a segfaut hence the first
>>> patch. But I still get no mcount section in the files.
>> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
>> And so, the relocation records in case of PPC64BE point to "._mcount",
>> rather than just "_mcount". We should be looking for "._mcount" to be
>> able to generate mcount_loc section in the files.
>>
>> Like:
>>
>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>> index 70be5a72e838..7da5bf8c7236 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file
>> *file)
>>                           if (arch_is_retpoline(func))
>>                                   func->retpoline_thunk = true;
>>
>> -                       if ((!strcmp(func->name, "__fentry__")) ||
>> (!strcmp(func->name, "_mcount")))
>> +                       if ((!strcmp(func->name, "__fentry__")) ||
>> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>>                                   func->fentry = true;
>>
>>                           if (is_profiling_func(func->name))
>>
>>
>> With this change, I could see __mcount_loc section being
>> generated in individual ppc64be object files.
>>
> Or should we implement an equivalent of arch_ftrace_match_adjust() in
> objtool ?

Yeah, I think it makes more sense if we make it arch specific.
Thanks for the suggestion. I'll make this change in next revision :-)

- Sathvika



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-05-25 18:12       ` Sathvika Vasireddy
@ 2022-06-15 16:03         ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-06-15 16:03 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy



Le 25/05/2022 à 20:12, Sathvika Vasireddy a écrit :
> 
> On 25/05/22 23:09, Christophe Leroy wrote:
>> Hi Sathvika,
>>
>> Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
>>> Hi Christophe,
>>>
>>> On 24/05/22 18:47, Christophe Leroy wrote:
>>>> This draft series adds PPC32 support to Sathvika's series.
>>>> Verified on pmac32 on QEMU.
>>>>
>>>> It should in principle also work for PPC64 BE but for the time being
>>>> something goes wrong. In the beginning I had a segfaut hence the first
>>>> patch. But I still get no mcount section in the files.
>>> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
>>> And so, the relocation records in case of PPC64BE point to "._mcount",
>>> rather than just "_mcount". We should be looking for "._mcount" to be
>>> able to generate mcount_loc section in the files.
>>>
>>> Like:
>>>
>>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>>> index 70be5a72e838..7da5bf8c7236 100644
>>> --- a/tools/objtool/check.c
>>> +++ b/tools/objtool/check.c
>>> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file
>>> *file)
>>>                           if (arch_is_retpoline(func))
>>>                                   func->retpoline_thunk = true;
>>>
>>> -                       if ((!strcmp(func->name, "__fentry__")) ||
>>> (!strcmp(func->name, "_mcount")))
>>> +                       if ((!strcmp(func->name, "__fentry__")) ||
>>> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>>>                                   func->fentry = true;
>>>
>>>                           if (is_profiling_func(func->name))
>>>
>>>
>>> With this change, I could see __mcount_loc section being
>>> generated in individual ppc64be object files.
>>>
>> Or should we implement an equivalent of arch_ftrace_match_adjust() in
>> objtool ?
> 
> Yeah, I think it makes more sense if we make it arch specific.
> Thanks for the suggestion. I'll make this change in next revision :-)
> 

Do you have any idea when you plan to send next revision ?

I'm really looking forward to submitting the inline static calls on top 
of your series.

Thanks
Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-06-15 16:03         ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-06-15 16:03 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev



Le 25/05/2022 à 20:12, Sathvika Vasireddy a écrit :
> 
> On 25/05/22 23:09, Christophe Leroy wrote:
>> Hi Sathvika,
>>
>> Le 25/05/2022 à 12:14, Sathvika Vasireddy a écrit :
>>> Hi Christophe,
>>>
>>> On 24/05/22 18:47, Christophe Leroy wrote:
>>>> This draft series adds PPC32 support to Sathvika's series.
>>>> Verified on pmac32 on QEMU.
>>>>
>>>> It should in principle also work for PPC64 BE but for the time being
>>>> something goes wrong. In the beginning I had a segfaut hence the first
>>>> patch. But I still get no mcount section in the files.
>>> Since PPC64 BE uses older elfv1 ABI, it prepends a dot to symbols.
>>> And so, the relocation records in case of PPC64BE point to "._mcount",
>>> rather than just "_mcount". We should be looking for "._mcount" to be
>>> able to generate mcount_loc section in the files.
>>>
>>> Like:
>>>
>>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>>> index 70be5a72e838..7da5bf8c7236 100644
>>> --- a/tools/objtool/check.c
>>> +++ b/tools/objtool/check.c
>>> @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file
>>> *file)
>>>                           if (arch_is_retpoline(func))
>>>                                   func->retpoline_thunk = true;
>>>
>>> -                       if ((!strcmp(func->name, "__fentry__")) ||
>>> (!strcmp(func->name, "_mcount")))
>>> +                       if ((!strcmp(func->name, "__fentry__")) ||
>>> (!strcmp(func->name, "_mcount")) || (!strcmp(func->name, "._mcount")))
>>>                                   func->fentry = true;
>>>
>>>                           if (is_profiling_func(func->name))
>>>
>>>
>>> With this change, I could see __mcount_loc section being
>>> generated in individual ppc64be object files.
>>>
>> Or should we implement an equivalent of arch_ftrace_match_adjust() in
>> objtool ?
> 
> Yeah, I think it makes more sense if we make it arch specific.
> Thanks for the suggestion. I'll make this change in next revision :-)
> 

Do you have any idea when you plan to send next revision ?

I'm really looking forward to submitting the inline static calls on top 
of your series.

Thanks
Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-06-15 16:03         ` Christophe Leroy
@ 2022-06-18  4:56           ` Sathvika Vasireddy
  -1 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-06-18  4:56 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy

Hi Christophe,

On 15/06/22 21:33, Christophe Leroy wrote:
> Do you have any idea when you plan to send next revision ?
>
> I'm really looking forward to submitting the inline static calls on top
> of your series.

I'm planning to send RFC v3 next week.

- Sathvika


^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-06-18  4:56           ` Sathvika Vasireddy
  0 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-06-18  4:56 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

Hi Christophe,

On 15/06/22 21:33, Christophe Leroy wrote:
> Do you have any idea when you plan to send next revision ?
>
> I'm really looking forward to submitting the inline static calls on top
> of your series.

I'm planning to send RFC v3 next week.

- Sathvika


^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-06-18  4:56           ` Sathvika Vasireddy
@ 2022-06-24  7:08             ` Christophe Leroy
  -1 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-06-24  7:08 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy

Hi Sathvika

Le 18/06/2022 à 06:56, Sathvika Vasireddy a écrit :
> Hi Christophe,
> 
> On 15/06/22 21:33, Christophe Leroy wrote:
>> Do you have any idea when you plan to send next revision ?
>>
>> I'm really looking forward to submitting the inline static calls on top
>> of your series.
> 
> I'm planning to send RFC v3 next week.
> 

Is everything going ok ? Don't hesitate if you need help.

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-06-24  7:08             ` Christophe Leroy
  0 siblings, 0 replies; 43+ messages in thread
From: Christophe Leroy @ 2022-06-24  7:08 UTC (permalink / raw)
  To: Sathvika Vasireddy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

Hi Sathvika

Le 18/06/2022 à 06:56, Sathvika Vasireddy a écrit :
> Hi Christophe,
> 
> On 15/06/22 21:33, Christophe Leroy wrote:
>> Do you have any idea when you plan to send next revision ?
>>
>> I'm really looking forward to submitting the inline static calls on top
>> of your series.
> 
> I'm planning to send RFC v3 next week.
> 

Is everything going ok ? Don't hesitate if you need help.

Christophe

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
  2022-06-24  7:08             ` Christophe Leroy
@ 2022-06-24 18:44               ` Sathvika Vasireddy
  -1 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-06-24 18:44 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: linux-kernel, linuxppc-dev, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, mbenes, peterz, rostedt,
	jpoimboe, Naveen N. Rao, Sathvika Vasireddy

Hi Christophe,

On 24/06/22 12:38, Christophe Leroy wrote:
> Is everything going ok ? Don't hesitate if you need help.

Yeah, sure. Thanks!

I just posted RFC v3 here: 
https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20220624183238.388144-1-sv@linux.ibm.com/


^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc
@ 2022-06-24 18:44               ` Sathvika Vasireddy
  0 siblings, 0 replies; 43+ messages in thread
From: Sathvika Vasireddy @ 2022-06-24 18:44 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: aik, jpoimboe, linux-kernel, rostedt, peterz, Paul Mackerras,
	Sathvika Vasireddy, Naveen N. Rao, mbenes, linuxppc-dev

Hi Christophe,

On 24/06/22 12:38, Christophe Leroy wrote:
> Is everything going ok ? Don't hesitate if you need help.

Yeah, sure. Thanks!

I just posted RFC v3 here: 
https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20220624183238.388144-1-sv@linux.ibm.com/


^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2022-06-24 18:47 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 13:17 [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc Christophe Leroy
2022-05-24 13:17 ` Christophe Leroy
2022-05-24 13:17 ` [RFC PATCH v2 1/7] objtool: Fix SEGFAULT Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 13:17 ` [RFC PATCH v2 2/7] objtool: Use target file endianness instead of a compiled constant Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 13:17 ` [RFC PATCH v2 3/7] objtool: Use target file class size " Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 17:59   ` Peter Zijlstra
2022-05-24 17:59     ` Peter Zijlstra
2022-05-24 13:17 ` [RFC PATCH v2 4/7] objtool: Add --mnop as an option to --mcount Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 13:17 ` [RFC PATCH v2 5/7] objtool: Enable objtool to run only on files with ftrace enabled Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 18:01   ` Peter Zijlstra
2022-05-24 18:01     ` Peter Zijlstra
2022-05-24 18:02     ` Peter Zijlstra
2022-05-24 18:02       ` Peter Zijlstra
2022-05-24 18:59       ` Christophe Leroy
2022-05-24 18:59         ` Christophe Leroy
2022-05-24 19:50         ` Peter Zijlstra
2022-05-24 19:50           ` Peter Zijlstra
2022-05-25 11:00           ` Sathvika Vasireddy
2022-05-24 13:17 ` [RFC PATCH v2 6/7] objtool/powerpc: Enable objtool to be built on ppc Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-24 13:17 ` [RFC PATCH v2 7/7] objtool/powerpc: Add --mcount specific implementation Christophe Leroy
2022-05-24 13:17   ` Christophe Leroy
2022-05-25 10:14 ` [RFC PATCH v2 0/7] objtool: Enable and implement --mcount option on powerpc Sathvika Vasireddy
2022-05-25 10:14   ` Sathvika Vasireddy
2022-05-25 16:51   ` Segher Boessenkool
2022-05-25 16:51     ` Segher Boessenkool
2022-05-25 17:39   ` Christophe Leroy
2022-05-25 17:39     ` Christophe Leroy
2022-05-25 18:12     ` Sathvika Vasireddy
2022-05-25 18:12       ` Sathvika Vasireddy
2022-06-15 16:03       ` Christophe Leroy
2022-06-15 16:03         ` Christophe Leroy
2022-06-18  4:56         ` Sathvika Vasireddy
2022-06-18  4:56           ` Sathvika Vasireddy
2022-06-24  7:08           ` Christophe Leroy
2022-06-24  7:08             ` Christophe Leroy
2022-06-24 18:44             ` Sathvika Vasireddy
2022-06-24 18:44               ` Sathvika Vasireddy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.