Variables in Fortran modules compiled in -fPIC shared libraries will get unique address by a copy relocation to the main executable. Still .debug_info of the library contains absolute DW_AT_location of the variable - without any indirection through the GOT vector.
Debugger will then print the variable location not in active use. Current FSF GDB cannot resolve these variables but it was found by a new patch for modules: http://sourceware.org/gdb/wiki/ArcherBranchManagement archer-jankratochvil-fortran-module Assuming no DW_AT_location should exist for such variables. DW_AT_declaration should be present there as such variables are NOT optimized-out. Or DW_AT_location using DW_FORM_block* indirecting GOT could be present? For C the problem does not happen with GCC as it will put there _two_ DIEs and the first one is just a declaration. Current FSF GDB ignores any non-first DIEs for a named object. Still the second invalid DIE is redundant + invalid even in the C case. GNU Fortran (GCC) 4.4.0 20090427 (Red Hat 4.4.0-3) GNU Fortran (GCC) 4.5.0 20090501 (experimental) ------------------------------------------------------------------------------ cat >lib.f90 <<EOH module lib integer :: var = 1 end module lib EOH cat >main.f90 <<EOH use lib if (var .ne. 1) call abort end EOH F="gfortran -Wall -g"; $F -o lib.so -shared -fPIC lib.f90; $F -o main main.f90 ./lib.so $ nm -D lib.so | grep var 0000000000200798 D __lib_MOD_var $ nm -D main | grep var 0000000000600c38 B __lib_MOD_var $ readelf -a lib.so | approx-grep var Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [21] .data PROGBITS 0000000000200798 00000798 0000000000000004 0000000000000000 WA 0 0 4 Symbol table '.dynsym' contains 11 entries: Num: Value Size Type Bind Vis Ndx Name 9: 0000000000200798 4 OBJECT GLOBAL DEFAULT 21 __lib_MOD_var Symbol table '.symtab' contains 57 entries: Num: Value Size Type Bind Vis Ndx Name 50: 0000000000200798 4 OBJECT GLOBAL DEFAULT 21 __lib_MOD_var $ readelf -a main | approx-grep var Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [25] .bss NOBITS 0000000000600c38 00000c34 0000000000000018 0000000000000000 WA 0 0 8 Relocation section '.rela.dyn' at offset 0x560 contains 2 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000600c38 000c00000005 R_X86_64_COPY 0000000000600c38 __lib_MOD_var + 0 Symbol table '.dynsym' contains 14 entries: Num: Value Size Type Bind Vis Ndx Name 12: 0000000000600c38 4 OBJECT GLOBAL DEFAULT 25 __lib_MOD_var Symbol table '.symtab' contains 77 entries: Num: Value Size Type Bind Vis Ndx Name 59: 0000000000600c38 4 OBJECT GLOBAL DEFAULT 25 __lib_MOD_var $ readelf -wi lib.so | approx-grep var <1><2d>: Abbrev Number: 2 (DW_TAG_module) <2e> DW_AT_name : lib <2><38>: Abbrev Number: 3 (DW_TAG_variable) <39> DW_AT_name : var <3f> DW_AT_type : <0x4f> <43> DW_AT_external : 1 <44> DW_AT_location : 9 byte block: 3 98 7 20 0 0 0 0 0 (DW_OP_addr: 200798) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid DW_AT_location $ readelf -wi main | approx-grep var <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram) <2f> DW_AT_name : (indirect string, offset: 0x9): MAIN__ <2><50>: Abbrev Number: 4 (DW_TAG_imported_module) <53> DW_AT_import : <0x58> [Abbrev Number: 5 (DW_TAG_module)] <1><58>: Abbrev Number: 5 (DW_TAG_module) <59> DW_AT_name : lib <5d> DW_AT_declaration : 1 cat >clib.c <<EOH int var = 1; int func (void) { return var; } EOH cat >cmain.c <<EOH extern int var; extern int func (void); int main (void) { var = 2; return var == func () ? 0 : 1; } EOH C="gcc -Wall -g"; $C -o clib.so -shared -fPIC clib.c; $C -o cmain cmain.c ./clib.so $ nm -D clib.so | grep var 0000000000200800 D var $ nm -D cmain | grep var 00000000006009c0 B var $ readelf -wi clib.so | approx-grep var <1><55>: Abbrev Number: 4 (DW_TAG_variable) <56> DW_AT_name : var <5c> DW_AT_type : <0x4e> <60> DW_AT_external : 1 <61> DW_AT_declaration : 1 <1><62>: Abbrev Number: 5 (DW_TAG_variable) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ redundant+invalid DIE <63> DW_AT_name : var <69> DW_AT_type : <0x4e> <6d> DW_AT_external : 1 <6e> DW_AT_location : 9 byte block: 3 0 8 20 0 0 0 0 0 (DW_OP_addr: 200800) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid DW_AT_location -- Summary: gfortran invalid DW_AT_location for overridable variables Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jan dot kratochvil at redhat dot com GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40040