From patchwork Mon Jan 27 20:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Benson X-Patchwork-Id: 1230045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518342-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=carnegiescience.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=kkhK8Sl0; dkim-atps=neutral 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 4862BC4kjQz9sPn for ; Tue, 28 Jan 2020 07:57:21 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=BFZa6QAU0maLfN55MiLepFMWe0Ks9HPlGS04UYKqEeazFP0sA/HKD fUoE3BuzHadCk4MVFMg9hMh9Lin9BEtfxJ3WFDGnvEEHzA47ucWDFQWOLAecYhql Kteai/ncNdrJraJG1UXVE0DLpapquYSodZVs033CO0sWrADmO6Azhs= 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:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=7IiUK3UbYrUzWFmhmj6wk8bb0Fk=; b=kkhK8Sl0J19TPlXAbN44Ps0M07F8 Ra3Dq3z0Yq+9TogXog42b2N/hnHOe1mzPl9q7xJCP3a5E/r5Lr9CBq76qYDkNhMn zHHqElAVAN48t7udZG55CEd9O4SxzHH6YCZTjyKkrqXIMlrhICQjWhkEvQU21NKh jIoeCxFH073il2c= Received: (qmail 108818 invoked by alias); 27 Jan 2020 20:57:09 -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 108798 invoked by uid 89); 27 Jan 2020 20:57:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:4531, H*r:sk:andrew-, HX-Spam-Relays-External:sk:andrew-, H*RU:sk:andrew- X-HELO: mail-pj1-f49.google.com Received: from mail-pj1-f49.google.com (HELO mail-pj1-f49.google.com) (209.85.216.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Jan 2020 20:57:06 +0000 Received: by mail-pj1-f49.google.com with SMTP id m13so14214pjb.2; Mon, 27 Jan 2020 12:57:06 -0800 (PST) Received: from andrew-precision-3520.localnet (pool-239.obs.carnegiescience.edu. [192.91.178.239]) by smtp.gmail.com with ESMTPSA id a9sm3440352pfo.35.2020.01.27.12.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jan 2020 12:57:03 -0800 (PST) From: Andrew Benson To: fortran@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Subject: [patch, fortran] PR93461 - Bogus "symbol is already defined" with long subroutine names in submodule Date: Mon, 27 Jan 2020 12:57:03 -0800 Message-ID: <1767259.yRpc3bzoFC@andrew-precision-3520> User-Agent: KMail/5.2.3 (Linux/4.4.0-170-generic; KDE/5.36.0; x86_64; ; ) In-Reply-To: <5056833.bhCz5HFUgy@andrew-precision-3520> References: <1642803.1Q0mUWRIpW@andrew-precision-3520> <5056833.bhCz5HFUgy@andrew-precision-3520> MIME-Version: 1.0 I created PR93461 for this issue: The following code causes a bogus "symbol is already defined" error (using git commit 73380abd6b2783215c7950a2ade5e3f4b271e2bc): module aModuleWithAnAllowedName interface module subroutine aShortName() end subroutine aShortName end interface end module aModuleWithAnAllowedName submodule (aModuleWithAnAllowedName) aSubmoduleWithAVeryVeryVeryLongButEntirelyLegalName contains subroutine aShortName() call aSubroutineWithAVeryLongNameThatWillCauseAProblem() call aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso() end subroutine aShortName subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblem() end subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblem subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso() end subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso end submodule aSubmoduleWithAVeryVeryVeryLongButEntirelyLegalName $ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/data001/abenson/Galacticus/Tools_Devel_Install/bin/../ libexec/gcc/x86_64-pc-linux-gnu/10.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-git/configure --prefix=/home/abenson/Galacticus/ Tools_Devel --enable-languages=c,c++,fortran --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.0.1 20200124 (experimental) (GCC) $ gfortran -c symlength.F90 -o symlength.o -ffree-line-length-none - frecursive -pthread -Wall -fbacktrace -ffpe-trap=invalid,zero,overflow -fdump- core -O3 -ffinite-math-only -fno-math-errno -fopenmp -g /tmp/cc8B4Hmp.s: Assembler messages: /tmp/cc8B4Hmp.s:20: Error: symbol `__amodulewithanallowedname.asubmodulewithaveryveryverylongbutentirelylegalname_MOD_asubroutinewithaverylongnamethatwillcauseaprobl' is already defined The problem occurs because GFC_MAX_MANGLED_SYMBOL_LEN is set to GFC_MAX_SYMBOL_LEN*2+4, which is sufficient for a module name plus function name (plus the additional "_"'s that get prepended), but insufficient if a submodule name is included. The name then gets truncated and can lead to two different functions having the same (truncated) symbol name. The fix is to increase this length to GFC_MAX_SYMBOL_LEN*3+5 - which allows for the submodule name plus the "." added between module and submodule names. I've attached a patch for this which includes a new test case for this PR. The patch regression tests cleanly. OK to commit? -Andrew diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 52bc045..5942320 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "predict.h" /* For enum br_predictor and PRED_*. */ /* Mangled symbols take the form __module__name. */ -#define GFC_MAX_MANGLED_SYMBOL_LEN (GFC_MAX_SYMBOL_LEN*2+4) +#define GFC_MAX_MANGLED_SYMBOL_LEN (GFC_MAX_SYMBOL_LEN*3+5) /* Struct for holding a block of statements. It should be treated as an opaque entity and not modified directly. This allows us to change the diff --git a/gcc/testsuite/gfortran.dg/pr93461.f90 b/gcc/testsuite/gfortran.dg/pr93461.f90 new file mode 100644 index 0000000..3bef326 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93461.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! PR fortran/93461 +module aModuleWithAnAllowedName + interface + module subroutine aShortName() + end subroutine aShortName + end interface +end module aModuleWithAnAllowedName + +submodule (aModuleWithAnAllowedName) aSubmoduleWithAVeryVeryVeryLongButEntirelyLegalName +contains + subroutine aShortName() + call aSubroutineWithAVeryLongNameThatWillCauseAProblem() + call aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso() + end subroutine aShortName + + subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblem() + end subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblem + + subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso() + end subroutine aSubroutineWithAVeryLongNameThatWillCauseAProblemAlso +end submodule aSubmoduleWithAVeryVeryVeryLongButEntirelyLegalName