diff mbox series

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

Message ID 20201026233445.18622-1-ericonr@disroot.org
State Superseded
Headers show
Series Allow elf header to be used when __BEGIN_DECLS and __END_DECLS aren't defined. | expand

Commit Message

Érico Nogueira Oct. 26, 2020, 11:34 p.m. UTC
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(-)

Comments

Florian Weimer Oct. 27, 2020, 7:46 a.m. UTC | #1
* Érico Nogueira via Libc-alpha:

> 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!

extern "C++" does not have any effect for this header because it does
not declare anything that has language linkage.

I think you need to remove <features.h> to make the file self-contained.

Thanks,
Florian
Érico Nogueira Oct. 27, 2020, 2:18 p.m. UTC | #2
On Tue Oct 27, 2020 at 5:46 AM -03, Florian Weimer wrote:
> * Érico Nogueira via Libc-alpha:
>
> > 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!
>
> extern "C++" does not have any effect for this header because it does
> not declare anything that has language linkage.
>
> I think you need to remove <features.h> to make the file self-contained.
>
> Thanks,
> Florian
> --
> Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
> Commercial register: Amtsgericht Muenchen, HRB 153243,
> Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael
> O'Neill

I've sent a v2 that removes <features.h> and the DECL macros, then.

Thanks for the input,
Érico
diff mbox series

Patch

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>
 
-__BEGIN_DECLS
+/* C++ needs to know that types and declarations are C, not C++.  */
+#ifdef	__cplusplus
+extern "C" {
+#endif
 
 /* Standard ELF types.  */
 
@@ -4105,6 +4108,8 @@  enum
 #define R_ARC_TLS_LE_S9		0x4a
 #define R_ARC_TLS_LE_32		0x4b
 
-__END_DECLS
+#ifdef	__cplusplus
+}
+#endif
 
 #endif	/* elf.h */