From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9775A3858D3C; Thu, 14 Apr 2022 06:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9775A3858D3C From: "nils-christian.kempke at intel dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/105272] New: Using entry inside module contained subroutines changes subroutine's scope in DWARF Date: Thu, 14 Apr 2022 06:51:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nils-christian.kempke at intel dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 06:51:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105272 Bug ID: 105272 Summary: Using entry inside module contained subroutines changes subroutine's scope in DWARF Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nils-christian.kempke at intel dot com Target Milestone: --- When compiling a subroutine inside a module like $ cat f_no_entry.f90 module a contains subroutine b print *, "b" end subroutine b end module a program prog print *, "hi" end program prog $ gfortran -O0 -g ./f.f90 $ gfortran --version GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 ... the DWARF emitted shows that the DW_TAG_subprogram for subroutine b is a ch= ild of the DW_TAG_module for a. This seems reasonable and puts b into the scop= e of a: $ objdump --dwarf=3Dinfo ./a.out ... <1>: Abbrev Number: 8 (DW_TAG_module) DW_AT_name : a DW_AT_decl_file : 1 DW_AT_decl_line : 1 <2>: Abbrev Number: 9 (DW_TAG_subprogram) DW_AT_external : 1 DW_AT_name : b DW_AT_decl_file : 1 DW_AT_decl_line : 3 DW_AT_linkage_name: (indirect string, offset: 0x0): __a_MOD_b DW_AT_low_pc : 0x1179 DW_AT_high_pc : 0x73 DW_AT_frame_base : 1 byte block: 9c=20=20=20=20=20=20=20=20 (DW_OP_call_frame_cfa) DW_AT_GNU_all_tail_call_sites: 1 <2>: Abbrev Number: 0 <1>: Abbrev Number: 0 Changing this example seemingly just a bit by adding an alternative entry p= oint to b via the 'entry' moves the subroutine (and the entry point) out of the module and puts them into the scope of the whole compile unit TAG: $ cat f_entry.f90 module a contains subroutine b entry bbb print *, "b" end subroutine b end module a program prog print *, "hi" end program prog $ gfortran -O0 -g ./f_entry.f90 $ objdump --dwarf=3Dinfo ./a.out ... <1>: Abbrev Number: 8 (DW_TAG_module) DW_AT_name : a DW_AT_decl_file : 1 DW_AT_decl_line : 1 DW_AT_sibling : <0xd1> <2>: Abbrev Number: 9 (DW_TAG_subprogram) DW_AT_name : (indirect string, offset: 0xa): master.0.b DW_AT_decl_file : 1 DW_AT_decl_line : 7 DW_AT_low_pc : 0x1199 DW_AT_high_pc : 0x8c DW_AT_frame_base : 1 byte block: 9c=20=20=20=20=20=20=20=20 (DW_OP_call_frame_cfa) DW_AT_GNU_all_tail_call_sites: 1 <3>: Abbrev Number: 10 (DW_TAG_formal_parameter) DW_AT_name : (indirect string, offset: 0x57): __entry DW_AT_type : <0xd8> DW_AT_artificial : 1 DW_AT_location : 3 byte block: 91 d8 7b (DW_OP_fbreg: -55= 2) <3>: Abbrev Number: 0 <2>: Abbrev Number: 0 ... <1>: Abbrev Number: 4 (DW_TAG_base_type) DW_AT_byte_size : 8 DW_AT_encoding : 5 (signed) DW_AT_name : (indirect string, offset: 0x27): integer(kind=3D8) <1>
: Abbrev Number: 11 (DW_TAG_subprogram) DW_AT_external : 1 DW_AT_name : bbb DW_AT_decl_file : 1 DW_AT_decl_line : 4 DW_AT_linkage_name: (indirect string, offset: 0x142): __a_MOD_= bbb DW_AT_low_pc : 0x1189 DW_AT_high_pc : 0x10 DW_AT_frame_base : 1 byte block: 9c=20=20=20=20=20=20=20=20 (DW_OP_call_frame_cfa) DW_AT_GNU_all_tail_call_sites: 1 <1>: Abbrev Number: 11 (DW_TAG_subprogram) DW_AT_external : 1 DW_AT_name : b DW_AT_decl_file : 1 DW_AT_decl_line : 3 DW_AT_linkage_name: (indirect string, offset: 0x0): __a_MOD_b <103> DW_AT_low_pc : 0x1179 <10b> DW_AT_high_pc : 0x10 <113> DW_AT_frame_base : 1 byte block: 9c=20=20=20=20=20=20=20 (DW_OP_call_frame_cfa) <115> DW_AT_GNU_all_tail_call_sites: 1 <1><115>: Abbrev Number: 0 This behavior seems odd. I stumbled upon this when trying to access the ent= ry point bbb in gdb via a::bbb (as bbb is in the module's scope) which I could not. There is a likely related issue about gfortran not emitting a DW_TAG_entry_point for entry points https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D37134.=