[llvm-bugs] [Bug 40307] New: Debug info generates undefined reference for template value which causes linker failure

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 14 08:17:47 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40307

            Bug ID: 40307
           Summary: Debug info generates undefined reference for template
                    value which causes linker failure
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: brock.wyma at intel.com
                CC: jdevlieghere at apple.com, keith.walker at arm.com,
                    llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com

$ cat global-template-value.cpp
template <const char* U> struct One {
  static const char string [4];
};

int main() {
  One< One<nullptr>::string > one;
  return 0;
}

The GNU compiler compiles/links this code and produces debug information for
the template value parameter "U" with no location:
$ g++ -g global-template-value.cpp
$ readelf -wi a.out
...
 <2><6e>: Abbrev Number: 8 (DW_TAG_template_value_param)
    <6f>   DW_AT_name        : U
    <71>   DW_AT_type        : <0xaf>
...

With no debug information CLANG compiles/links the code with a helpful warning
message:
$ clang++ global-template-value.cpp
global-template-value.cpp:6:22: warning: instantiation of variable
      'One<nullptr>::string' required here, but no definition is available
      [-Wundefined-var-template]
  One< One<nullptr>::string > one;
                     ^
global-template-value.cpp:2:21: note: forward declaration of template entity is
      here
  static const char string [4];
                    ^
global-template-value.cpp:6:22: note: add an explicit instantiation declaration
to
      suppress this warning if 'One<nullptr>::string' is explicitly
instantiated
      in another translation unit
  One< One<nullptr>::string > one;
                     ^
1 warning generated.

But when debug information is enabled CLANG fails to link:
$ clang++ -g global-template-value.cpp
...
/tmp/global-template-value-5c4370.o:(.debug_info+0x78): undefined reference to
`One<(char const*)0>::string'
clang-8: error: linker command failed with exit code 1 (use -v to see
invocation)

The linker failure is caused because of a global variable reference in the
debug metadata here:
!21 = !DITemplateValueParameter(name: "U", type: !22, value: [4 x i8]*
@_ZN3OneILPKc0EE6stringE)

Obviously if the global had been defined in the source then the debug
information would link correctly, but it seems more friendly to emit the
DW_TAG_template_value_param with no location like GCC does.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190114/46522d28/attachment-0001.html>


More information about the llvm-bugs mailing list