Skip to contentSkip to conversation

um: fix CONFIG_GCOV for built-in code

PATCH Applied Alex Hung 4 participants 6 messages Jul 27 – Sep 28 User-mode Linux (UML)

lore
Share & tools
lore

Alex Hung

author
#0 lore raw

PATCH 1/1 um: fix CONFIG_GCOV for built-in code

From: Johannes Berg <[email protected]>

With contemporary toolchains, CONFIG_GCOV doesn't work because gcov now relies on both init and exit handlers, but those are discarded from the binary. Fix the linker scripts to keep them instead, so that CONFIG_GCOV can work again.

Note that this does not make it work in modules yet, since we don't call their exit handlers.

Note: the .init_array.* wildcard and the RUNTIME_DISCARD_EXIT define are already present in this tree; only the matching .fini_array.* wildcard remained to be added.

---

This is a revived patch. The original can be found at
https://lkml.iu.edu/hypermail/linux/kernel/2103.1/06608.html

 arch/um/include/asm/common.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/um/include/asm/common.lds.S +1 -0
index fd481ac371de..2ed213913afe 100644
@@ -91,6 +91,7 @@
   .fini_array : {
 	__fini_array_start = .;
 	*(.fini_array)
+	*(.fini_array.*)
 	__fini_array_end = .;
   }
 

--
2.43.0

author
#1 lore raw

Hi,

Any comments or concerns on this patch? Is it ready to be merged?

Quoted 39 lines · Alex Hung

From: Johannes Berg <[email protected]>

With contemporary toolchains, CONFIG_GCOV doesn't work because gcov now relies on both init and exit handlers, but those are discarded from the binary. Fix the linker scripts to keep them instead, so that CONFIG_GCOV can work again.

Note that this does not make it work in modules yet, since we don't call their exit handlers.

Note: the .init_array.* wildcard and the RUNTIME_DISCARD_EXIT define are already present in this tree; only the matching .fini_array.* wildcard remained to be added.

---

This is a revived patch. The original can be found at
https://lkml.iu.edu/hypermail/linux/kernel/2103.1/06608.html

  arch/um/include/asm/common.lds.S | 1 +
  1 file changed, 1 insertion(+)
arch/um/include/asm/common.lds.S +1 -1
index fd481ac371de..2ed213913afe 100644
@@ -91,6 +91,7 @@
    .fini_array : {
  	__fini_array_start = .;
  	*(.fini_array)
+	*(.fini_array.*)
  	__fini_array_end = .;
    }
 
--

2.43.0

author
#2 lore raw

Ping for comments for this patch. Is it possible to merge for kernel 7.3 if there are no concerns?

Quoted 45 lines · Alex Hung

Hi,

Any comments or concerns on this patch? Is it ready to be merged?

Quoted 39 lines · Alex Hung

From: Johannes Berg <[email protected]>

With contemporary toolchains, CONFIG_GCOV doesn't work because gcov now relies on both init and exit handlers, but those are discarded from the binary. Fix the linker scripts to keep them instead, so that CONFIG_GCOV can work again.

Note that this does not make it work in modules yet, since we don't call their exit handlers.

Note: the .init_array.* wildcard and the RUNTIME_DISCARD_EXIT define are already present in this tree; only the matching .fini_array.* wildcard remained to be added.

---

This is a revived patch. The original can be found at
https://lkml.iu.edu/hypermail/linux/kernel/2103.1/06608.html

  arch/um/include/asm/common.lds.S | 1 +

  1 file changed, 1 insertion(+)
arch/um/include/asm/common.lds.S +1 -0
index fd481ac371de..2ed213913afe 100644
@@ -91,6 +91,7 @@
     .fini_array : {
       __fini_array_start = .;
       *(.fini_array)
+    *(.fini_array.*)
       __fini_array_end = .;
     }
 
Signature · 1 line
2.43.0
Tested-by on v1 1/1
#3 lore raw
In reply to Alex Hung

Hi Alex,

I tested this while investigating GCC/GCOV coverage under UML using KUnit.

Tested on:
Architecture: x86_64 UML
Kernel: v7.3-rc3-61-gbc77531b2a6f
KUnit configs: default.config + coverage_uml.config
Compilers: GCC 13.3.0 and GCC 16.2.0

With GCC 13.3, the unpatched tree produced 731 .gcno files and 0 .gcda files after the KUnit run. With the patch applied, the same run produced 731 .gcno files and 704 .gcda files, and LCOV was able to generate coverage successfully.

I also reproduced the same result with GCC 16.2:

without patch: 731 .gcno / 0 .gcda
with patch: 731 .gcno / 704 .gcda

LCOV coverage generation also completed successfully with GCC 16.2.

Thanks,
Mariia

Applied
#4 lore raw
In reply to Alex Hung
Quoted 9 lines · Alex Hung

With contemporary toolchains, CONFIG_GCOV doesn't work because gcov now relies on both init and exit handlers, but those are discarded from the binary. Fix the linker scripts to keep them instead, so that CONFIG_GCOV can work again.

Note that this does not make it work in modules yet, since we don't call their exit handlers.

[...]

Applied to for-next/hardening, thanks! Only a 5 year delay. :P What else is needed from the original series to get the full coverage?
https://lore.kernel.org/all/[email protected]/

[1/1] um: fix CONFIG_GCOV for built-in code

      https://git.kernel.org/kees/c/760f96b7f54b

Take care,

-Kees

Signature · 1 line
Kees Cook