Bug 35025 - clang++6: fatal error: 'stdlib.h' file not found
Summary: clang++6: fatal error: 'stdlib.h' file not found
Status: CLOSED NOTABUG
Alias: None
Product: Sisyphus
Classification: Development
Component: clang6.0 (show other bugs)
Version: unstable
Hardware: x86_64 Linux
: P3 normal
Assignee: Konstantin A Lepikhov (L.A. Kostis)
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-13 01:15 MSK by Vitaly Chikunov
Modified: 2019-04-17 16:39 MSK (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Chikunov 2018-06-13 01:15:35 MSK
При сборке bcc под clang:

[  7%] Building CXX object src/cc/CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o
cd /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc && /usr/bin/clang++   -I/usr/include/../tools/clang/include -I/usr/src/RPM/BUILD/bcc-v0.5.0/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat  -pipe -Wall -g -O2 -Wall  -isystem /usr/include -fno-rtti -fPIC -DBCC_PROG_TAG_DIR='"/var/tmp/bcc"' -DLLVM_MAJOR_VERSION=6 -O2 -g -DNDEBUG   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=gnu++11 -o CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o -c /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc
Can't read /proc/cpuinfo: No such file or directory
Can't read /proc/cpuinfo: No such file or directory
In file included from /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc:21:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/string:52:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/bits/basic_string.h:6349:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/ext/string_conversions.h:41:
/usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/cstdlib:75:15: fatal error: 'stdlib.h' file not found
#include_next <stdlib.h>
              ^~~~~~~~~~
1 error generated.

При этом запуск с -v дает (запуск заодно со strace):

[builder@localhost cc]$ strace -v -o a -f -e file  /usr/bin/clang++   -I/usr/include/../tools/clang/include -I/usr/src/RPM/BUILD/bcc-v0.5.0/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat  -pipe -Wall -g -O2 -Wall  -isystem /usr/include -fno-rtti -fPIC -DBCC_PROG_TAG_DIR='"/var/tmp/bcc"' -DLLVM_MAJOR_VERSION=6 -O2 -g -DNDEBUG   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=gnu++11 -o CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o -c /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc  -v
Can't read /proc/cpuinfo: No such file or directory
clang version 6.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i586-alt-linux/7
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-alt-linux/7
Found candidate GCC installation: /usr/lib/gcc/i586-alt-linux/7
Found candidate GCC installation: /usr/lib64/gcc/x86_64-alt-linux/7
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-alt-linux/7
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/clang-6.0" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ns_guard.cc -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/CMakeFiles/bcc-loader-static.dir/ns_guard.cc.gcno -resource-dir /usr/lib64/clang/6.0.0 -isystem /usr/include -I /usr/include/../tools/clang/include -I /usr/src/RPM/BUILD/bcc-v0.5.0/src -I /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src -I /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -I /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc -I /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b -I /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b -I /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang -I /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat -D "BCC_PROG_TAG_DIR=\"/var/tmp/bcc\"" -D LLVM_MAJOR_VERSION=6 -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -internal-isystem /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7 -internal-isystem /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/x86_64-alt-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/6.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -Wall -std=gnu++11 -fdeprecated-macro -fdebug-compilation-dir /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -ferror-limit 19 -fmessage-length 159 -fno-rtti -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o -x c++ /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc
Can't read /proc/cpuinfo: No such file or directory
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/include/../tools/clang/include"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/src/RPM/BUILD/bcc-v0.5.0/src
 /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src
 /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc
 /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc
 /usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b
 /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b
 /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang
 /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat
 /usr/include
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/x86_64-alt-linux
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/backward
 /usr/local/include
 /usr/lib64/clang/6.0.0/include
End of search list.
In file included from /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc:21:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/string:52:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/bits/basic_string.h:6349:
In file included from /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/ext/string_conversions.h:41:
/usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/cstdlib:75:15: fatal error: 'stdlib.h' file not found
#include_next <stdlib.h>
              ^~~~~~~~~~
1 error generated.


[builder@localhost cc]$ find /usr/include -name stdlib.h
/usr/include/c++/7/tr1/stdlib.h
/usr/include/c++/7/stdlib.h
/usr/include/bits/stdlib.h
/usr/include/stdlib.h

То есть stdlib.h есть в /usr/include, а /usr/include есть в списке поиска для #include  <...>. Но оно даже не пытается читать /usr/include/stdlib.h:

[builder@localhost cc]$ grep stdlib.h a
1780  openat(AT_FDCWD, "/usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/x86_64-alt-linux/stdlib.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1780  openat(AT_FDCWD, "/usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/backward/stdlib.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1780  openat(AT_FDCWD, "/usr/local/include/stdlib.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1780  openat(AT_FDCWD, "/usr/lib64/clang/6.0.0/include/stdlib.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

Если в командной строке clang++ удалить `-isystem /usr/include` или заменить на `-I-/usr/include` то ошибки нет:


[builder@localhost cc]$ /usr/bin/clang++   -I/usr/include/../tools/clang/include -I/usr/src/RPM/BUILD/bcc-v0.5.0/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat  -pipe -Wall -g -O2 -Wall  -I/usr/include -fno-rtti -fPIC -DBCC_PROG_TAG_DIR='"/var/tmp/bcc"' -DLLVM_MAJOR_VERSION=6 -O2 -g -DNDEBUG   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=gnu++11 -o CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o -c /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc          Can't read /proc/cpuinfo: No such file or directory
Can't read /proc/cpuinfo: No such file or directory
[builder@localhost cc]$ /usr/bin/clang++   -I/usr/include/../tools/clang/include -I/usr/src/RPM/BUILD/bcc-v0.5.0/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc -I/usr/src/RPM/BUILD/bcc-v0.5.0/BUILD/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/b -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/frontends/clang -I/usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/compat  -pipe -Wall -g -O2 -Wall  -fno-rtti -fPIC -DBCC_PROG_TAG_DIR='"/var/tmp/bcc"' -DLLVM_MAJOR_VERSION=6 -O2 -g -DNDEBUG   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=gnu++11 -o CMakeFiles/bcc-loader-static.dir/ns_guard.cc.o -c /usr/src/RPM/BUILD/bcc-v0.5.0/src/cc/ns_guard.cc
Can't read /proc/cpuinfo: No such file or directory
Can't read /proc/cpuinfo: No such file or directory
[builder@localhost cc]$


Гугинг дал похожий баг без решения https://forum.qt.io/topic/87190/clang-code-model-fails-to-find-header-files/3
Comment 1 Ivan A. Melnikov 2018-06-13 10:51:06 MSK
ИМХО clang работает as designed. Директива #include_next ищет файл *дальше* по списку include directories. Когда компиляция завершается ошибкой, порядок инклюдов такой:

#include <...> search starts here:
 /usr/include
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/x86_64-alt-linux
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/backward
 /usr/local/include
 /usr/lib64/clang/6.0.0/include


Если удалить из коммандной строкии `-isystem /usr/include`, то порядок такой:

#include <...> search starts here:
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/x86_64-alt-linux
 /usr/bin/../lib64/gcc/x86_64-alt-linux/7/../../../../include/c++/7/backward
 /usr/local/include
 /usr/lib64/clang/6.0.0/include
 /usr/include

Здесь /usr/include находится после /usr/include/c++/7/, и #include_next проходит.

Так что похоже тут неправ cmake, собирающий bcc.
Comment 2 Vitaly Chikunov 2018-06-13 12:23:14 MSK
Скорее всего "ошибка" в clang связанная с `"ignoring duplicate directory "/usr/include"` - удалился второй, который должен был обработаться после `include/c++/7`, а когда я удалил `-isystem /usr/include` остался только второй стоящий позже в путях.
Comment 3 Konstantin A Lepikhov (L.A. Kostis) 2018-06-20 00:22:50 MSK
(In reply to comment #2)
> Скорее всего "ошибка" в clang связанная с `"ignoring duplicate directory
> "/usr/include"` - удалился второй, который должен был обработаться после
> `include/c++/7`, а когда я удалил `-isystem /usr/include` остался только второй
> стоящий позже в путях.

У вас есть простой пример как это воспроизвести?
Comment 4 Vitaly Chikunov 2018-06-20 00:26:44 MSK
Нет.
Comment 5 Maxim Okhotskiy 2019-04-17 16:39:14 MSK
I've found the root cause of this issue. I'll describe my setup:
* libyaml-cpp-dev
* package1
* package2
Those three packages are dependent on each other, in other words package1 needs headers of libyaml and package2 needs package1 and therefore libyaml headers as well.

libyaml:
/usr/lib/x86_64-linux-gnu/cmake/yaml-cpp/yaml-cpp-config-version.cmake : set(PACKAGE_VERSION "0.5.2")

Then for, some reason, I used ${YAML_CPP_INCLUDE_DIR} in package1, that is set in yaml-cpp-config.cmake:
set(YAML_CPP_INCLUDE_DIR "${YAML_CPP_CMAKE_DIR}/../../../../include")

And it was like:
target_include_directories(package1_target PUBLIC ${YAML_CPP_INCLUDE_DIR})

In package2 I used target_link_libraries(package2_target package1_target)

And now we have the described problem with missing stdlib.h when we try to build package2

From now on I'll be talking about package2.
If we take a look at compile_commands.json we can see:
"command": "/usr/bin/clang++-6.0   -DBOOST_CB_DISABLE_DEBUG -isystem /usr/lib/x86_64-linux-gnu/cmake/yaml-cpp/../../../../include    -std=gnu++14 -o CMakeFiles/main.cpp.o -c /home/user/package1/src/main.cpp"

And this is the problem. If we try to run clang++-6.0 with the same parameters, we'll get the same result. Removing this -isystem does the job.

So the solution was to replace include of ${YAML_CPP_INCLUDE_DIR} in package1 with just target_link_libraries(package1_target PUBLIC yaml-cpp)

Hope it helps.