From patchwork Mon Mar 9 23:41:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 448291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9DF661401AF for ; Tue, 10 Mar 2015 10:41:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=JSMoRVp2; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=ebRAsoSBW3g7YBE0pyha/g0pSx9H2GeyMg+gKKvIdAgI7I 8IQTwjOe+SCAFK5Wh8SxRobn9rqeSVtru9NrmVU1rvpnjTBS78B0gyvX9sCaa07e QiXkM/muc217UOZsm66xZ+Y0V4PAj46mTkE8d1Efjz7OqT1DOPhFXenY5tiWg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=864iQ4RFG3Hr/IUmgKS0LZYz39o=; b=JSMoRVp21Rb+Ys4vqcS4 mQAk2RSdgei63/89tKuwhC8BiCmkmaXh6FjKkbzT/UbdVJXWEWsFhv9WvTEzadkh q6yW96DQDGmiKdiQxDhcHNJSf2ToFBvlMM7J/NC9K36daRkV5uQIc6kR+Lc9jKld bJuXhFms4IA3RjgLUBoHc/E= Received: (qmail 105620 invoked by alias); 9 Mar 2015 23:41:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 105605 invoked by uid 89); 9 Mar 2015 23:41:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yh0-f45.google.com Received: from mail-yh0-f45.google.com (HELO mail-yh0-f45.google.com) (209.85.213.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 09 Mar 2015 23:41:03 +0000 Received: by yhot59 with SMTP id t59so37842577yho.7 for ; Mon, 09 Mar 2015 16:41:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=17eP2alwEK+XPpujLZYS5z4L0YMLgVXs7n7H459DEsE=; b=jtxaDBUQDorq4lJ363+1HkiXB/rt9+Y1EsOavoV0ouLmSau0MGstpXjX9Hz0NPuIFA cCHJ7t6cPEhwQvVlo1aisPIwLI9Pymdh8kzyPQM2XbdugXK4rq49eFZlt4HoNt5T3ano rUPWH24bV+WQwIV54elvY1wBDTTSTl4abcKneoJnDYxAPQpLaZBlqAGvjkcmOhr90419 FfYC93VEEU2dlGXoIscE5hsZEgU2UkBzSHw6Zzm1i5G5Gm7UxTq9Ee7jHbdOqbt8BY// Ns9EEkbzru5/kQTPJv+e9oNWZSRYYo6hkm95kdf9C55cbR1zanjdjAzKlmrgMDK56BEX S41Q== X-Gm-Message-State: ALoCoQl+YfbsuIxItcDqAWWcoPJQPnf2qLufSL9IGDHqWzSCPTuI0lWXd0XNvDms/69awiDgei01 MIME-Version: 1.0 X-Received: by 10.170.37.141 with SMTP id 135mr12405798ykf.94.1425944461593; Mon, 09 Mar 2015 16:41:01 -0700 (PDT) Received: by 10.170.230.205 with HTTP; Mon, 9 Mar 2015 16:41:01 -0700 (PDT) Date: Mon, 9 Mar 2015 16:41:01 -0700 Message-ID: Subject: libgo patch committed: Don't crash if crashing on signal due to heap corruption From: Ian Lance Taylor To: gcc-patches , "gofrontend-dev@googlegroups.com" Previously, if a Go program was crashing due to a signal due to heap corruption, it could in some cases invoke the Go malloc function while the Go malloc lock was held, leading to a recursive crash. This patch fixes the problem by making __go_file_line simply assume that libbacktrace keeps strings in memory, as runtime.Callers already does. This error showed in PR 65349. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 2169f7d99472 libgo/runtime/go-caller.c --- a/libgo/runtime/go-caller.c Fri Mar 06 08:17:57 2015 -0800 +++ b/libgo/runtime/go-caller.c Mon Mar 09 16:21:20 2015 -0700 @@ -37,36 +37,12 @@ { struct caller *c = (struct caller *) data; - if (function == NULL) - { - c->fn.str = NULL; - c->fn.len = 0; - } - else - { - byte *s; - - c->fn.len = __builtin_strlen (function); - s = runtime_malloc (c->fn.len); - __builtin_memcpy (s, function, c->fn.len); - c->fn.str = s; - } - - if (filename == NULL) - { - c->file.str = NULL; - c->file.len = 0; - } - else - { - byte *s; - - c->file.len = __builtin_strlen (filename); - s = runtime_malloc (c->file.len); - __builtin_memcpy (s, filename, c->file.len); - c->file.str = s; - } - + /* The libbacktrace library says that these strings might disappear, + but with the current implementation they won't. We can't easily + allocate memory here, so for now assume that we can save a + pointer to the strings. */ + c->fn = runtime_gostringnocopy ((const byte *) function); + c->file = runtime_gostringnocopy ((const byte *) filename); c->line = lineno; return 0;