This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Do not include sysctl.h when building with musl libc
AbandonedPublic

Authored by ldionne on Nov 24 2020, 1:48 PM.

Details

Reviewers
bcain
pzheng
Group Reviewers
Restricted Project
Summary

The header file sysctl.h uses BEGIN_DECLS/END_DECLS which are not defined by musl.

Diff Detail

Event Timeline

pzheng created this revision.Nov 24 2020, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2020, 1:48 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
pzheng requested review of this revision.Nov 24 2020, 1:48 PM
ldionne requested changes to this revision.Nov 25 2020, 12:06 PM

The header file sysctl.h uses BEGIN_DECLS/END_DECLS which are not defined by musl.

I don't understand. What's the issue?

This revision now requires changes to proceed.Nov 25 2020, 12:06 PM

The issue here is that the header file "sysctl.h" uses some macros (BEGIN_DECLS/END_DECLS) which are only defined by glibc and not by musl libc (refer to https://wiki.musl-libc.org/faq.html). Therefore, when we build with musl libc, we are seeing the following build failures.

usr/include/sys/sysctl.h:65:1: error: unknown type name '__BEGIN_DECLS'
__BEGIN_DECLS
^

This patch tries to guard the include of sysctl.h with !defined(_LIBCPP_HAS_MUSL_LIBC) so that the header file is not included when musl libc is used. We started to see the libcxx build failure above after 477a687 landed. 477a687 removed some #if guards which seem to have exposed the issue. Before 477a687, those guards actually prevented sysctl.h from being included in our build. However, I think the root cause is not 477a687, but the unconditional include of sysctl.h. I hope this gives a little bit more background on what this patch is trying to fix.

Can you please let me know if https://reviews.llvm.org/D92135 solves your issue? I believe https://reviews.llvm.org/D92135 is superior, since it also simplifies our implementation to use POSIX functionality.

Thanks, @ldionne! D92135 does also fix the issue.

ldionne commandeered this revision.Nov 26 2020, 9:16 AM
ldionne edited reviewers, added: pzheng; removed: ldionne.

Great!

ldionne abandoned this revision.Nov 26 2020, 9:17 AM

Resolved by D92135 instead.