fixincludes: partly repair broken fix for assert.h in vxworks

Message ID 20180607095023.30654-1-rasmus.villemoes@prevas.dk
State New
Headers show
Series
  • fixincludes: partly repair broken fix for assert.h in vxworks
Related show

Commit Message

Rasmus Villemoes June 7, 2018, 9:50 a.m.
The current "fix" for assert.h on vxworks is itself broken in a number
of ways.

First, assert.h is special in that it should _not_ have an include
guard - the user is allowed to include it multiple times with
different definedness of _NDEBUG to enable and disable assert() in
parts of a TU.

Second, apparently gcc does not implicitly do the extern "C" dance for
include-fixed headers, so C++ code ends up with undefined references
to _Z8__assertPKc.

Third, the ASSERT_STRINGIFY macros are in the user's namespace.

Fourth (not strictly a violation), it is a bad idea to macro-expand
the test expression, as that can easily lead to completely unreadable
gibberish. glibc fixed that in 2015, and incidentally, the original
vxworks assert.h also just uses #test.

This fixes 1,2 and 4. I still define _ASSERT_H in case somebody has
some cpp logic based on whether assert.h has been included at least
once. 4 is of course somewhat of a value judgement, but I think it
makes sense to be consistent with both the original vxworks header as
well as modern glibc. (In extreme cases, it can also save several KBs
of precious memory).

We still need to stringify __LINE__ since the underlying __assert
function just takes a single string, so we can't get completely rid of
the stringifying macros. I left the names alone since the risk of
clashing with real user code is quite minimal, and somebody might even
have used them.

2018-06-07    Rasmus Villemoes <rasmus.villemoes@prevas.dk>

fixinclude/

	* inclhack.def: Fix fixup for assert.h on vxworks.
	* fixincl.x: Regenerate.
---
 fixincludes/inclhack.def | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

-- 
2.15.1

Comments

Olivier Hainque June 12, 2018, 9:17 a.m. | #1
Hello Rasmus,

> On 7 Jun 2018, at 11:50, Rasmus Villemoes <rasmus.villemoes@prevas.dk> wrote:

> 

> 2018-06-07    Rasmus Villemoes <rasmus.villemoes@prevas.dk>

> 

> fixinclude/

> 

> 	* inclhack.def: Fix fixup for assert.h on vxworks.

> 	* fixincl.x: Regenerate.


Ok by me, thanks.

Olivier
Jeff Law June 12, 2018, 2:58 p.m. | #2
On 06/12/2018 03:17 AM, Olivier Hainque wrote:
> Hello Rasmus,

> 

>> On 7 Jun 2018, at 11:50, Rasmus Villemoes <rasmus.villemoes@prevas.dk> wrote:

>>

>> 2018-06-07    Rasmus Villemoes <rasmus.villemoes@prevas.dk>

>>

>> fixinclude/

>>

>> 	* inclhack.def: Fix fixup for assert.h on vxworks.

>> 	* fixincl.x: Regenerate.

> 

> Ok by me, thanks.

Installed on the trunk.
jeff
Olivier Hainque June 12, 2018, 3:19 p.m. | #3
> On 12 Jun 2018, at 16:58, Jeff Law <law@redhat.com> wrote:


> Installed on the trunk.


Thanks Jeff. I missed that Rasmus doesn't have commit rights.
Jeff Law June 12, 2018, 3:24 p.m. | #4
On 06/12/2018 09:19 AM, Olivier Hainque wrote:
> 

> 

>> On 12 Jun 2018, at 16:58, Jeff Law <law@redhat.com> wrote:

> 

>> Installed on the trunk.

> 

> Thanks Jeff. I missed that Rasmus doesn't have commit rights.

No worries.  I'm thinking that Rasmus ought to go ahead and get commit
privs since it seems like he's making regular contributions.

Rasmus, you'll want to fill out this form.  List me as approving/sponsoring:

https://sourceware.org/cgi-bin/pdw/ps_form.cgi

Jeff

Patch

diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
index 5ec5a50a2e2..c1f5a13eda4 100644
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -377,11 +377,15 @@  fix = {
     mach        = "*-*-vxworks*";
         
     replace     = <<- _EndOfHeader_
-	#ifndef _ASSERT_H
+	#ifdef _ASSERT_H
+	#undef _ASSERT_H
+	#undef assert
+	#endif
+
 	#define _ASSERT_H
 
-	#ifdef assert
-	#undef assert
+	#ifdef __cplusplus
+	extern "C" {
 	#endif
 
 	#if defined(__STDC__) || defined(__cplusplus)
@@ -399,11 +403,13 @@  fix = {
 
 	#define assert(test) ((void) \
 	        ((test) ? ((void)0) : \
-	        __assert("Assertion failed: " ASSERT_STRINGIFY(test) ", file " \
+	        __assert("Assertion failed: " #test ", file " \
 	        __FILE__ ", line " ASSERT_STRINGIFY(__LINE__) "\n")))
 
 	#endif
 
+	#ifdef __cplusplus
+	}
 	#endif
 	_EndOfHeader_;
 };