google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.52k stars 10.09k forks source link

Fixed gcc linker error 58 #4477

Closed tmiguelf closed 7 months ago

tmiguelf commented 7 months ago

Fixed gcc linker error 58:

How to reproduce: Step1. Build the library with a test project deployed on gcc 12.3 on Ubuntu Step2. Look at the following linker error:

lto-wrapper : warning : using serial compilation of 8 LTRANS jobs
lto-wrapper : message : see the ‘-flto’ option documentation for more information
lto-wrapper : message : In function ‘make_unique’,
E: from ‘CreateArgvFromArgs’ at \mnt\d\Code\utilities\submodules\googletest\googletest\src\gtest-death-test.cc(635): error : 58,
E: from ‘AssumeRole’ at \mnt\d\Code\utilities\submodules\googletest\googletest\src\gtest-death-test.cc(1391): error : 58:
/usr/include/c++/12/bits/unique_ptr.h(1080): error : 30: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
/usr/include/c++/12/bits/unique_ptr.h(1080): error :  1080 |     { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
/usr/include/c++/12/bits/unique_ptr.h(1080): error :       |                              ^
/usr/include/c++/12/new : error : In member function ‘AssumeRole’:
/usr/include/c++/12/new(128): error : 26: note: in a call to allocation function ‘operator new []’ declared here
128 | _GLIBCXX_NODISCARD void* operator new[](std : error : size_t) _GLIBCXX_THROW (std::bad_alloc)
128 | _GLIBCXX_NODISCARD void* operator new[](std : error :       |                          ^

This is traced back line 365: https://github.com/google/googletest/pull/4477/files#diff-97f768d897442b94f24002f6bcff7124e3c73d05b3916fb492ee29436ce0701fL635 specifically the args.size() + 1 where the code analysis tool sees the potential issue of overflowing the storage limits when expanding std::unique_ptr<[]>. This is easily fixable by abandoning the awkward std::unique_ptr<[]>, since it can be better represented by an std::vector.

granted, likely a bug in the gcc code generation, but it has been there for at least 6 months, someone should have noticed by now. std::unique_ptr<[]> is not great, should have used a std::vector anyways.

tmiguelf commented 7 months ago

Step1. Build the library with a test project deployed on gcc 12.3 on Ubuntu Step2. Look at the following linker error:

lto-wrapper : warning : using serial compilation of 8 LTRANS jobs
lto-wrapper : message : see the ‘-flto’ option documentation for more information
lto-wrapper : message : In function ‘make_unique’,
E: from ‘CreateArgvFromArgs’ at \mnt\d\Code\utilities\submodules\googletest\googletest\src\gtest-death-test.cc(635): error : 58,
E: from ‘AssumeRole’ at \mnt\d\Code\utilities\submodules\googletest\googletest\src\gtest-death-test.cc(1391): error : 58:
/usr/include/c++/12/bits/unique_ptr.h(1080): error : 30: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
/usr/include/c++/12/bits/unique_ptr.h(1080): error :  1080 |     { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
/usr/include/c++/12/bits/unique_ptr.h(1080): error :       |                              ^
/usr/include/c++/12/new : error : In member function ‘AssumeRole’:
/usr/include/c++/12/new(128): error : 26: note: in a call to allocation function ‘operator new []’ declared here
128 | _GLIBCXX_NODISCARD void* operator new[](std : error : size_t) _GLIBCXX_THROW (std::bad_alloc)
128 | _GLIBCXX_NODISCARD void* operator new[](std : error :       |                          ^

This is traced back line 365: https://github.com/google/googletest/pull/4477/files#diff-97f768d897442b94f24002f6bcff7124e3c73d05b3916fb492ee29436ce0701fL635 specifically the args.size() + 1 where the code analysis tool sees the potential issue of overflowing the storage limits when expanding std::unique_ptr<[]>. This is easily fixable by abandoning the awkward std::unique_ptr<[]>, since it can be better represented by an std::vector.

granted, likely a bug in the gcc code generation, but it has been there for at least 6 months, someone should have noticed by now. std::unique_ptr<[]> is not great, should have used a std::vector anyways.