From patchwork Fri Feb 1 00:23:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 217310 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]) by ozlabs.org (Postfix) with SMTP id B1D012C0095 for ; Fri, 1 Feb 2013 11:23:43 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360283025; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=X6OPiu/ Nn6u7eCOrr7oVtCb/ZQM=; b=vqCJA8WzFBXq0wZFIEhCBBsrtgG/a7tymYMOQj+ NgOngFWVnKV99aIr8agTvijVBvbNNXe3iTdSf3YfoFaT1q1131ai5fTsvgz13Zer 0dftp9yJqqgBl3Zl1TJSoeY1ms5AlKVHzv4RKiCPrZ7YLTCDluFXE1Pzs7FDkBtn FNwQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:X-Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OneFcJX4vfMFO+fDaw65eXZICy5FEobYNQOwtZzFJwhGsK5P99WszhCZwrb7z7 npNS5jZnowrj9k3LIDyDEps6ifWAmF1acmdFT+eqwBlr2cXbHUd7Hd7JG5pHeTYl qMsFUDTiI3V4ukD5E1t8d/A2IOQNF3vmeGqV0BLzg/VP8=; Received: (qmail 32407 invoked by alias); 1 Feb 2013 00:23:36 -0000 Received: (qmail 32396 invoked by uid 22791); 1 Feb 2013 00:23:34 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CC, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-da0-f41.google.com (HELO mail-da0-f41.google.com) (209.85.210.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Feb 2013 00:23:28 +0000 Received: by mail-da0-f41.google.com with SMTP id e20so1494813dak.14 for ; Thu, 31 Jan 2013 16:23:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=qDLcacl+sJ+3W6DclnIDP+tDD4s9uzDQdw18904Bn0Q=; b=lESgQLPZAosd2yju41rQ/EXtU+L5VCJX8O01yUr94r9H1G/xdXlUQSj2sJ01i1fPdx xkD/FVRWqQf6m+lOdmDxscIwLLb6ZP29FaszJ21lXbHsKa7kPDcBFzF5idV0+Z44Lk73 vUsGQAYBaFvMLmnIQ2LxJ40KNP55eJ32lAyC6qcOHmHmLHxYMMr4NP0tQGUlbKYO0nrn tSIoXKBcEwuqpxSGo/+orq3qTDm8aPfiXLFZAIGvZPRONqS5c+RQdIaoIhLV5cHWXZL+ HSGpZdeN3Us3DXUq4ENHRsKizh6vllJ8AgLlQfsg++j4luU4dg7DxYhVuiyzvKRVh8U5 3M0A== X-Received: by 10.66.79.97 with SMTP id i1mr25038950pax.47.1359678207901; Thu, 31 Jan 2013 16:23:27 -0800 (PST) Received: from iant-glaptop.google.com ([172.26.54.189]) by mx.google.com with ESMTPS id x6sm7105119paw.0.2013.01.31.16.23.26 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 31 Jan 2013 16:23:27 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: gccgo patch committed: Don't emit methods for identical unnamed structs Date: Thu, 31 Jan 2013 16:23:23 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlAuElvZ2+gJco7BlfSwLqBMsuEhwtGHmKKAszcyEvJH1lV+GEEq0JlYapKmm9DWUn4/HRTB+dLYY1B77jEmJEMOb7Bt3MvZ/MZj2PXqV+arcOcvhz57tbCRsbSZhtM77E53B2NV/jD7A5KSZ2lUbcsiRwzLM97Tx5X7e1eu5SIZO+HEf/TpcezZqI0vZQZElA/IJty X-IsSubscribed: yes 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 When a source file has multiple identical unnamed structs, and those structs have methods, gccgo would emit multiple copies of the methods. That would be bad because each copy would have the same name, causing an assembler error about multiply defined symbols. This patch fixes the problem. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 73fde5ee3282 go/types.cc --- a/go/types.cc Thu Jan 31 15:11:34 2013 -0800 +++ b/go/types.cc Thu Jan 31 16:20:32 2013 -0800 @@ -4170,6 +4170,11 @@ // Class Struct_type. +// A hash table used to find identical unnamed structs so that they +// share method tables. + +Struct_type::Identical_structs Struct_type::identical_structs; + // Traversal. int @@ -4596,6 +4601,21 @@ { if (this->all_methods_ != NULL) return; + + // It is possible to have multiple identical structs that have + // methods. We want them to share method tables. Otherwise we will + // emit identical methods more than once, which is bad since they + // will even have the same names. + std::pair ins = + Struct_type::identical_structs.insert(std::make_pair(this, this)); + if (!ins.second) + { + // An identical struct was already entered into the hash table. + // Note that finalize_methods is, fortunately, not recursive. + this->all_methods_ = ins.first->second->all_methods_; + return; + } + Type::finalize_methods(gogo, this, this->location_, &this->all_methods_); } diff -r 73fde5ee3282 go/types.h --- a/go/types.h Thu Jan 31 15:11:34 2013 -0800 +++ b/go/types.h Thu Jan 31 16:20:32 2013 -0800 @@ -2184,6 +2184,12 @@ do_export(Export*) const; private: + // Used to merge method sets of identical unnamed structs. + typedef Unordered_map_hash(Struct_type*, Struct_type*, Type_hash_identical, + Type_identical) Identical_structs; + + static Identical_structs identical_structs; + // Used to avoid infinite loops in field_reference_depth. struct Saw_named_type {