Issue 928 in include-what-you-use: IWYU doesn't support glibc

2 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Jun 23, 2021, 9:16:34 AMJun 23
to include-wh...@googlegroups.com
New issue 928 by alejandro-colomar: IWYU doesn't support glibc
https://github.com/include-what-you-use/include-what-you-use/issues/928

System (glibc) headers use headerrs in <bits/...> or <asm/...> to implement the functionality that standard headers provide to the user.

IWYU should never recommend those headers, which BTW have warning messages so that the user doesn't include them directly.

I'd like to use IWYU to check if my includes are correct, but I have a noise of about 99% of the reports, and most of them are about this, so I can't use IWYU at all.


Example:

```
/home/user/src/alx/libalx/include/alx/base/time/gettime.h should add these lines:
#include <bits/types/clockid_t.h> // for clockid_t

/home/user/src/alx/libalx/include/alx/base/time/gettime.h should remove these lines:
- #include <alx/base/compiler/attribute.h> // lines 26-26

The full include-list for /home/user/src/alx/libalx/include/alx/base/time/gettime.h:
#include <bits/types/clockid_t.h> // for clockid_t
#include <stdint.h> // for int64_t
#include <time.h> // for timespec
---
```

It's recommending me to include <bits/types/clockid_t.h> directly, as I make use of clockid_t, which is defined there. That would make sense, if POSIX didn't make clear that `clockid_t` is provided by `<sys/types.h>` or `<time.h>`; see <https://man7.org/linux/man-pages/man3/clockid_t.3.html>.

Of course, glibc doesn't provide IWYU pragmas to export all of those, because glibc doesn't use IWYU. And I don't think they should. glibc is the main library, apart from libstdc++, that a C++ program uses in Linux. Not supporting it from IWYU is a big bug.

And of course filling my code with pragmas to keep all of the glibc headers doesn't solve any problem, because now IWYU is completely useless (how do I know if a header could be removed if I basically made IWYU ignore all of them???).

notifi...@include-what-you-use.org

unread,
Jun 23, 2021, 2:32:39 PMJun 23
to include-wh...@googlegroups.com
Comment #1 on issue 928 by kimgr: IWYU doesn't support glibc
https://github.com/include-what-you-use/include-what-you-use/issues/928

Welcome to IWYU! Which version are you running? I think something was recently fixed wrt `clockid_t`.

In general, this kind of problem is solved with mappings in IWYU, declarations to describe the relationship between private and public headers.

There are builtin mappings in IWYU for glibc, so I'm surprised this doesn't just work. But you can also provide external mappings in json-like format. Search the docs for mappings and I think you'll find some more information.

notifi...@include-what-you-use.org

unread,
Jun 24, 2021, 7:51:32 AMJun 24
to include-wh...@googlegroups.com
Comment #2 on issue 928 by alejandro-colomar: IWYU doesn't support glibc
https://github.com/include-what-you-use/include-what-you-use/issues/928

```
$ iwyu --version
include-what-you-use 0.15 based on Debian clang version 11.0.1-2
$ dpkg -l iwyu
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-===========================================
ii iwyu 8.15-2 amd64 Analyze #includes in C and C++ source files

```

notifi...@include-what-you-use.org

unread,
Jun 27, 2021, 5:15:04 AMJun 27
to include-wh...@googlegroups.com
Comment #3 on issue 928 by kimgr: IWYU doesn't support glibc
https://github.com/include-what-you-use/include-what-you-use/issues/928

I was thinking of this change: https://github.com/include-what-you-use/include-what-you-use/commit/e2e69bf914e39f2b09a3d4403ecf89872566301f. You should be able to make a similar change to add mappings for `clockid_t`.

notifi...@include-what-you-use.org

unread,
Jun 27, 2021, 5:19:02 AMJun 27
to include-wh...@googlegroups.com
Comment #4 on issue 928 by alejandro-colomar: IWYU doesn't support glibc
https://github.com/include-what-you-use/include-what-you-use/issues/928

Okay, I will! Thanks! :-)

notifi...@include-what-you-use.org

unread,
Jun 27, 2021, 8:03:07 AMJun 27
to include-wh...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages