[PATCH] Allow elf header to be used when __BEGIN_DECLS and __END_DECLS aren't defined.

Érico Nogueira ericonr@disroot.org
Mon Oct 26 23:34:45 GMT 2020

From: Érico Rolim <ericonr@disroot.org>

The elf/elf.h header is shared, verbatim, by the elfutils project.
However, elfutils can be used on systems with libcs other than glibc,
making the presence of __BEGIN_DECLS and __END_DECLS in the file
something that downstream distros have to add patches for.

Per https://sourceware.org/pipermail/elfutils-devel/2020q4/002994.html ,
the elfutils project would prefer to keep maintenance to a minimum,
which can be achieved by making this single header more portable.

This is mostly an initial PoC, and an additional comment for why this
is needed could be added to the file.

I accidentally sent the wrong patch a while ago, sorry!

 elf/elf.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/elf/elf.h b/elf/elf.h
index ff9f1dadd5..d6578e8d72 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -21,7 +21,10 @@
 #include <features.h>
+/* C++ needs to know that types and declarations are C, not C++.  */
+#ifdef	__cplusplus
+extern "C" {
 /* Standard ELF types.  */
@@ -4105,6 +4108,8 @@ enum
 #define R_ARC_TLS_LE_S9		0x4a
 #define R_ARC_TLS_LE_32		0x4b
+#ifdef	__cplusplus
 #endif	/* elf.h */

More information about the Elfutils-devel mailing list