[...@gnu-6 936]$ cat x.cc #include "foo.h" const char * x (void) { return f (); } [...@gnu-6 936]$ cat y.cc #include <stdio.h> #include "foo.h"
extern const char *x (void); int main () { printf ("%p, %p\n", x (), f ()); return 0; } [...@gnu-6 936]$ cat foo.h inline const char * f () { static const char *p = "Itanium C++ ABI"; return p; } [...@gnu-6 936]$ cat x.s .file "x.cc" .section .text._Z1fv,"axG",@progbits,_Z1fv,comdat .p2align 4,,15 .weak _Z1fv .type _Z1fv, @function _Z1fv: movq _ZZ1fvE1p(%rip), %rax ret .size _Z1fv, .-_Z1fv .text .p2align 4,,15 .globl _Z1xv .type _Z1xv, @function _Z1xv: movq _ZZ1fvE1p(%rip), %rax ret .size _Z1xv, .-_Z1xv .weak _ZZ1fvE1p .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "Itanium C++ ABI" Both x.s and y.s have a string: .string "Itanium C++ ABI" It should be put in string literal as specified in C++ ABI: http://www.codesourcery.com/public/cxx-abi/abi.html#mangling so that only one copy will be in the executable/DSO. -- Summary: G++ doesn't use string literal in inline function Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hjl dot tools at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39187