public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Benson <abenson@carnegiescience.edu>
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 21:49:00 -0000	[thread overview]
Message-ID: <1767259.yRpc3bzoFC@andrew-precision-3520> (raw)
In-Reply-To: <5056833.bhCz5HFUgy@andrew-precision-3520>

[-- Attachment #1: Type: text/plain, Size: 2654 bytes --]

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1658 bytes --]

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

[-- Attachment #3: ChangeLog --]
[-- Type: text/x-changelog, Size: 217 bytes --]

2020-01-27  Andrew Benson  <abensonca@gmail.com>

	* 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.

  parent reply	other threads:[~2020-01-27 20:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1642803.1Q0mUWRIpW@andrew-precision-3520>
2018-09-04 16:43 ` [patch, fortan] PR87103 - [OOP] ICE in gfc_new_symbol() due to overlong symbol name Andrew Benson
2018-09-04 17:43   ` Bernhard Reutner-Fischer
     [not found]     ` <5aa0135b-1bdd-46de-e235-daed0a9a97e1@charter.net>
2018-09-05 10:35       ` Bernhard Reutner-Fischer
2018-09-05 14:24         ` Andrew Benson
2019-08-24 14:50         ` Andrew Benson
2019-08-28 19:58           ` Bernhard Reutner-Fischer
2019-08-28 20:08             ` Andrew Benson
2020-01-29 22:49             ` Andrew Benson
2020-01-30 16:50               ` Bernhard Reutner-Fischer
2020-01-30 20:39                 ` Andrew Benson
2020-01-27 21:49   ` Andrew Benson [this message]
2020-01-28  8:50     ` [patch, fortran] PR93461 - Bogus "symbol is already defined" with long subroutine names in submodule Tobias Burnus
2020-01-28 16:46       ` Andrew Benson
2020-01-28 18:05         ` Tobias Burnus
2020-01-28 18:58           ` Andrew Benson
2020-01-29  2:11           ` [patch, fortran, wwwdocs] " Andrew Benson
2020-01-29  9:53             ` Gerald Pfeifer
2020-01-29 11:12             ` Tobias Burnus
2020-01-29 17:45               ` Andrew Benson
2020-01-28  0:03   ` [patch, fortran] PR93473 - ICE on valid with long module + submodule names Andrew Benson
2020-01-28  8:57     ` Tobias Burnus
2020-01-28 16:45       ` Andrew Benson
2020-01-28 17:51         ` Tobias Burnus
2020-01-28 18:49           ` Andrew Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1767259.yRpc3bzoFC@andrew-precision-3520 \
    --to=abenson@carnegiescience.edu \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).