From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108817 invoked by alias); 27 Jan 2020 20:57:09 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@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) Return-Path: 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 20:57:00 -0000 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 Content-Type: multipart/mixed; boundary="nextPart3316391.VcNvfWqiJJ" Content-Transfer-Encoding: 7Bit X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg00129.txt.bz2 This is a multi-part message in MIME format. --nextPart3316391.VcNvfWqiJJ Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 2654 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 -- * Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html * Galacticus: https://github.com/galacticusorg/galacticus --nextPart3316391.VcNvfWqiJJ Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="patch.diff" Content-length: 1658 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 --nextPart3316391.VcNvfWqiJJ Content-Disposition: attachment; filename="ChangeLog" Content-Transfer-Encoding: 7Bit Content-Type: text/x-changelog; charset="UTF-8"; name="ChangeLog" Content-length: 217 2020-01-27 Andrew Benson * trans.h: Increase GFC_MAX_MANGLED_SYMBOL_LEN to GFC_MAX_SYMBOL_LEN*3+5 to allow for inclusion of submodule name, plus the "." between module and submodule names. --nextPart3316391.VcNvfWqiJJ--