Skip to content

[clang] 7 tests started to fail with the new glibc qsort() #73145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tuliom opened this issue Nov 22, 2023 · 4 comments · Fixed by #73146 or llvm/llvm-project-release-prs#788
Closed

[clang] 7 tests started to fail with the new glibc qsort() #73145

tuliom opened this issue Nov 22, 2023 · 4 comments · Fixed by #73146 or llvm/llvm-project-release-prs#788
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules release:backport test-suite

Comments

@tuliom
Copy link
Contributor

tuliom commented Nov 22, 2023

The following tests started to fail with the new qsort() in glibc 2.39:

Failed Tests (7):
  Clang :: Modules/Werror-Wsystem-headers.m
  Clang :: Modules/compiler_builtins.m
  Clang :: Modules/context-hash.c
  Clang :: Modules/cstd.m
  Clang :: Modules/darwin_specific_modulemap_hacks.m
  Clang :: Modules/dependency-gen.m
  Clang :: Modules/pch-used.m

They're crashing with the following message:

free(): invalid pointer
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/bin/clang -cc1 -internal-isystem /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/bin/../lib/clang/17/include -nostdsysteminc -x objective-c-header -emit-pch /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/pch-used.h -o /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/test/Modules/Output/pch-used.m.tmp/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=/builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/test/Modules/Output/pch-used.m.tmp/cache -O0 -isystem /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/System/usr/include
1.      /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/pch-used.h:1:19: current parser token ';'
 #0 0x00007fdc34d3df7a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib64/libLLVM-17.so+0x93df7a)
 #1 0x00007fdc34d3b934 llvm::sys::RunSignalHandlers() (/usr/lib64/libLLVM-17.so+0x93b934)
 #2 0x00007fdc34d3e7eb (/usr/lib64/libLLVM-17.so+0x93e7eb)
 #3 0x00007fdc33e5b9a0 __restore_rt (/usr/lib64/libc.so.6+0x3e9a0)
 #4 0x00007fdc33eadb44 __pthread_kill_implementation (/usr/lib64/libc.so.6+0x90b44)
 #5 0x00007fdc33e5b8ee gsignal (/usr/lib64/libc.so.6+0x3e8ee)
 #6 0x00007fdc33e438ff abort (/usr/lib64/libc.so.6+0x268ff)
 #7 0x00007fdc33e447d0 _IO_peekc_locked.cold (/usr/lib64/libc.so.6+0x277d0)
 #8 0x00007fdc33eb7ab5 (/usr/lib64/libc.so.6+0x9aab5)
 #9 0x00007fdc33eb9dec _int_free (/usr/lib64/libc.so.6+0x9cdec)
#10 0x00007fdc33ebc72e cfree@GLIBC_2.2.5 (/usr/lib64/libc.so.6+0x9f72e)
#11 0x00007fdc3c2c853c std::__new_allocator<char>::deallocate(char*, unsigned long) /usr/bin/../lib/gcc/x86_64
-redhat-linux/13/../../../../include/c++/13/bits/new_allocator.h:0:2
#12 0x00007fdc3c2c853c std::allocator_traits<std::allocator<char>>::deallocate(std::allocator<char>&, char*, u
nsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:517:13
#13 0x00007fdc3c2c853c std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dest
roy(unsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:2
89:9
#14 0x00007fdc3c2c853c std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_disp
ose() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:283:4
#15 0x00007fdc3c2c853c std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_
string() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:804:9
#16 0x00007fdc3c2c853c clang::Module::Header::~Header() /builddir/build/BUILD/clang-17.0.5.src/include/clang/B
asic/Module.h:241:10
#17 0x00007fdc3c2c853c clang::ModuleMapParser::parseUmbrellaDirDecl(clang::SourceLocation) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:2558:7
#18 0x00007fdc3c2c2049 clang::ModuleMapParser::parseModuleDecl() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:9
#19 0x00007fdc3c2c1e9f clang::ModuleMapParser::parseModuleDecl() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:7
#20 0x00007fdc3c2bce5b clang::ModuleMapParser::parseModuleMapFile() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:7
#21 0x00007fdc3c2bce5b clang::ModuleMap::parseModuleMapFile(clang::FileEntry const*, bool, clang::DirectoryEntryRef, clang::FileID, unsigned int*, clang::SourceLocation) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:3119:24
#22 0x00007fdc3c28e6da clang::HeaderSearch::loadModuleMapFileImpl(clang::FileEntryRef, bool, clang::DirectoryEntryRef, clang::FileID, unsigned int*) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/HeaderSearch.cpp:1738:7
#23 0x00007fdc3c287d8e clang::HeaderSearch::loadModuleMapFile(clang::DirectoryEntryRef, bool, bool) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/HeaderSearch.cpp:1830:9
@tuliom tuliom self-assigned this Nov 22, 2023
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 22, 2023
@EugeneZelenko EugeneZelenko added test-suite clang:modules C++20 modules and Clang Header Modules and removed clang Clang issues not falling into any other category labels Nov 22, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2023

@llvm/issue-subscribers-clang-modules

Author: Tulio Magno Quites Machado Filho (tuliom)

The following tests started to fail with the new `qsort()` in glibc 2.39:
Failed Tests (7):
  Clang :: Modules/Werror-Wsystem-headers.m
  Clang :: Modules/compiler_builtins.m
  Clang :: Modules/context-hash.c
  Clang :: Modules/cstd.m
  Clang :: Modules/darwin_specific_modulemap_hacks.m
  Clang :: Modules/dependency-gen.m
  Clang :: Modules/pch-used.m

They're crashing with the following message:

free(): invalid pointer
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/bin/clang -cc1 -internal-isystem /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/bin/../lib/clang/17/include -nostdsysteminc -x objective-c-header -emit-pch /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/pch-used.h -o /builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/test/Modules/Output/pch-used.m.tmp/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=/builddir/build/BUILD/clang-17.0.5.src/redhat-linux-build/test/Modules/Output/pch-used.m.tmp/cache -O0 -isystem /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/System/usr/include
1.      /builddir/build/BUILD/clang-17.0.5.src/test/Modules/Inputs/pch-used.h:1:19: current parser token ';'
 #<!-- -->0 0x00007fdc34d3df7a llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/usr/lib64/libLLVM-17.so+0x93df7a)
 #<!-- -->1 0x00007fdc34d3b934 llvm::sys::RunSignalHandlers() (/usr/lib64/libLLVM-17.so+0x93b934)
 #<!-- -->2 0x00007fdc34d3e7eb (/usr/lib64/libLLVM-17.so+0x93e7eb)
 #<!-- -->3 0x00007fdc33e5b9a0 __restore_rt (/usr/lib64/libc.so.6+0x3e9a0)
 #<!-- -->4 0x00007fdc33eadb44 __pthread_kill_implementation (/usr/lib64/libc.so.6+0x90b44)
 #<!-- -->5 0x00007fdc33e5b8ee gsignal (/usr/lib64/libc.so.6+0x3e8ee)
 #<!-- -->6 0x00007fdc33e438ff abort (/usr/lib64/libc.so.6+0x268ff)
 #<!-- -->7 0x00007fdc33e447d0 _IO_peekc_locked.cold (/usr/lib64/libc.so.6+0x277d0)
 #<!-- -->8 0x00007fdc33eb7ab5 (/usr/lib64/libc.so.6+0x9aab5)
 #<!-- -->9 0x00007fdc33eb9dec _int_free (/usr/lib64/libc.so.6+0x9cdec)
#<!-- -->10 0x00007fdc33ebc72e cfree@<!-- -->GLIBC_2.2.5 (/usr/lib64/libc.so.6+0x9f72e)
#<!-- -->11 0x00007fdc3c2c853c std::__new_allocator&lt;char&gt;::deallocate(char*, unsigned long) /usr/bin/../lib/gcc/x86_64
-redhat-linux/13/../../../../include/c++/13/bits/new_allocator.h:0:2
#<!-- -->12 0x00007fdc3c2c853c std::allocator_traits&lt;std::allocator&lt;char&gt;&gt;::deallocate(std::allocator&lt;char&gt;&amp;, char*, u
nsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:517:13
#<!-- -->13 0x00007fdc3c2c853c std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;::_M_dest
roy(unsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:2
89:9
#<!-- -->14 0x00007fdc3c2c853c std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;::_M_disp
ose() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:283:4
#<!-- -->15 0x00007fdc3c2c853c std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;::~basic_
string() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:804:9
#<!-- -->16 0x00007fdc3c2c853c clang::Module::Header::~Header() /builddir/build/BUILD/clang-17.0.5.src/include/clang/B
asic/Module.h:241:10
#<!-- -->17 0x00007fdc3c2c853c clang::ModuleMapParser::parseUmbrellaDirDecl(clang::SourceLocation) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:2558:7
#<!-- -->18 0x00007fdc3c2c2049 clang::ModuleMapParser::parseModuleDecl() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:9
#<!-- -->19 0x00007fdc3c2c1e9f clang::ModuleMapParser::parseModuleDecl() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:7
#<!-- -->20 0x00007fdc3c2bce5b clang::ModuleMapParser::parseModuleMapFile() /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:0:7
#<!-- -->21 0x00007fdc3c2bce5b clang::ModuleMap::parseModuleMapFile(clang::FileEntry const*, bool, clang::DirectoryEntryRef, clang::FileID, unsigned int*, clang::SourceLocation) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/ModuleMap.cpp:3119:24
#<!-- -->22 0x00007fdc3c28e6da clang::HeaderSearch::loadModuleMapFileImpl(clang::FileEntryRef, bool, clang::DirectoryEntryRef, clang::FileID, unsigned int*) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/HeaderSearch.cpp:1738:7
#<!-- -->23 0x00007fdc3c287d8e clang::HeaderSearch::loadModuleMapFile(clang::DirectoryEntryRef, bool, bool) /builddir/build/BUILD/clang-17.0.5.src/lib/Lex/HeaderSearch.cpp:1830:9

@tbaederr tbaederr changed the title [clang] 7 tests started to with with the new glibc qsort() [clang] 7 tests started to fail with with the new glibc qsort() Nov 22, 2023
@kwk kwk changed the title [clang] 7 tests started to fail with with the new glibc qsort() [clang] 7 tests started to fail with the new glibc qsort() Nov 23, 2023
@nikic nikic added this to the LLVM 17.0.X Release milestone Nov 24, 2023
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Nov 24, 2023
tuliom added a commit that referenced this issue Nov 24, 2023
Struct Module::Header is not a POD type. As such, qsort() and
llvm::array_pod_sort() must not be used to sort it. This became an issue
with the new implementation of qsort() in glibc 2.39 that is not
guaranteed to be a stable sort, causing Headers to be re-ordered and
corrupted.

Replace the usage of llvm::array_pod_sort() with std::stable_sort() in
order to fix this issue. The signature of compareModuleHeaders() has to
be modified.

Fixes #73145.
@EugeneZelenko EugeneZelenko reopened this Nov 24, 2023
@nikic
Copy link
Contributor

nikic commented Nov 25, 2023

/cherry-pick cf1bde3

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2023

/branch llvm/llvm-project-release-prs/issue73145

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2023

/pull-request llvm/llvm-project-release-prs#788

@nikic nikic moved this from Needs Triage to Needs Review in LLVM Release Status Nov 26, 2023
tru pushed a commit that referenced this issue Nov 27, 2023
Struct Module::Header is not a POD type. As such, qsort() and
llvm::array_pod_sort() must not be used to sort it. This became an issue
with the new implementation of qsort() in glibc 2.39 that is not
guaranteed to be a stable sort, causing Headers to be re-ordered and
corrupted.

Replace the usage of llvm::array_pod_sort() with std::stable_sort() in
order to fix this issue. The signature of compareModuleHeaders() has to
be modified.

Fixes #73145.

(cherry picked from commit cf1bde3)
@tru tru moved this from Needs Review to Done in LLVM Release Status Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules release:backport test-suite
Projects
4 participants