From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81511 invoked by alias); 7 Jun 2018 09:50:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 81433 invoked by uid 89); 7 Jun 2018 09:50:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=repair, HCc:D*dk, stringify X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0123.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.123) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Jun 2018 09:50:41 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Rasmus.Villemoes@prevas.se; Received: from prevas-ravi.vestasvisitor.net (193.47.71.171) by VI1PR10MB0446.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:41::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.12; Thu, 7 Jun 2018 09:50:37 +0000 From: Rasmus Villemoes To: gcc-patches@gcc.gnu.org Cc: bkorb@gnu.org, Olivier Hainque , Rasmus Villemoes Subject: [PATCH] fixincludes: partly repair broken fix for assert.h in vxworks Date: Thu, 07 Jun 2018 09:50:00 -0000 Message-Id: <20180607095023.30654-1-rasmus.villemoes@prevas.dk> MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: AM6PR0502CA0024.eurprd05.prod.outlook.com (2603:10a6:209:1::37) To VI1PR10MB0446.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:41::18) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR10MB0446: X-Exchange-Antispam-Report-Test: UriScan:(788757137089); X-MS-Exchange-SenderADCheck: 1 X-Forefront-PRVS: 06968FD8C4 Received-SPF: None (protection.outlook.com: prevas.se does not designate permitted sender hosts) SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Office365-Filtering-Correlation-Id: 3903af3e-a4f1-4263-aa92-08d5cc5c1f1e X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2018 09:50:37.0360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3903af3e-a4f1-4263-aa92-08d5cc5c1f1e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB0446 X-SW-Source: 2018-06/txt/msg00370.txt.bz2 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 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