public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks
@ 2018-06-07  9:50 Rasmus Villemoes
  2018-06-12  9:17 ` Olivier Hainque
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus Villemoes @ 2018-06-07  9:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: bkorb, Olivier Hainque, Rasmus Villemoes

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(-)

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_;
 };
-- 
2.15.1

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

* Re: [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks
  2018-06-07  9:50 [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks Rasmus Villemoes
@ 2018-06-12  9:17 ` Olivier Hainque
  2018-06-12 14:58   ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Olivier Hainque @ 2018-06-12  9:17 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Olivier Hainque, gcc-patches, bkorb

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

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

* Re: [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks
  2018-06-12  9:17 ` Olivier Hainque
@ 2018-06-12 14:58   ` Jeff Law
  2018-06-12 15:19     ` Olivier Hainque
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2018-06-12 14:58 UTC (permalink / raw)
  To: Olivier Hainque, Rasmus Villemoes; +Cc: gcc-patches, bkorb

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

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

* Re: [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks
  2018-06-12 14:58   ` Jeff Law
@ 2018-06-12 15:19     ` Olivier Hainque
  2018-06-12 15:24       ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Olivier Hainque @ 2018-06-12 15:19 UTC (permalink / raw)
  To: Jeff Law; +Cc: Olivier Hainque, Rasmus Villemoes, gcc-patches, bkorb



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



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

* Re: [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks
  2018-06-12 15:19     ` Olivier Hainque
@ 2018-06-12 15:24       ` Jeff Law
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Law @ 2018-06-12 15:24 UTC (permalink / raw)
  To: Olivier Hainque; +Cc: Rasmus Villemoes, gcc-patches, bkorb

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

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

end of thread, other threads:[~2018-06-12 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07  9:50 [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks Rasmus Villemoes
2018-06-12  9:17 ` Olivier Hainque
2018-06-12 14:58   ` Jeff Law
2018-06-12 15:19     ` Olivier Hainque
2018-06-12 15:24       ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).