https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103764

            Bug ID: 103764
           Summary: Global std::string constructor not called
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeanmichael.celerier at gmail dot com
  Target Milestone: ---

Repro:

foo.cpp: 

    #include <string>

    std::string my_global_string(100, 'x');

main.cpp:

    #include <string>
    #include <iostream>

    extern std::string my_global_string;

    int main() {
      std::cout << my_global_string << std::endl; 
    }


Build:

    $ g++ foo.cpp -shared -O3 -fPIC -o libfoo.so
    $ g++ main.cpp -shared -O3 -fPIC -L$PWD -lfoo

Run: 

    $ LD_LIBRARY_PATH=$PWD ./a.out
    [1]    66470 segmentation fault (core dumped)  ./a.out

Valgrind:

$ valgrind -s ./a.out 
==66587== Memcheck, a memory error detector
==66587== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==66587== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==66587== Command: ./a.out
==66587== 
==66587== Invalid read of size 8
==66587==    at 0x1090B5: main (in /tmp/a.out)
==66587==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==66587== 
==66587== 
==66587== Process terminating with default action of signal 11 (SIGSEGV):
dumping core
==66587==  Access not within mapped region at address 0x8
==66587==    at 0x1090B5: main (in /tmp/a.out)
==66587==  If you believe this happened as a result of a stack
==66587==  overflow in your program's main thread (unlikely but
==66587==  possible), you can try to increase the size of the
==66587==  main thread stack using the --main-stacksize= flag.
==66587==  The main thread stack size used in this run was 8388608.
==66587== 
==66587== HEAP SUMMARY:
==66587==     in use at exit: 0 bytes in 0 blocks
==66587==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==66587== 
==66587== All heap blocks were freed -- no leaks are possible
==66587== 
==66587== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==66587== 
==66587== 1 errors in context 1 of 1:
==66587== Invalid read of size 8
==66587==    at 0x1090B5: main (in /tmp/a.out)
==66587==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==66587== 
==66587== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
[1]    66587 segmentation fault (core dumped)  valgrind -s ./a.out

Reply via email to