Skip to content
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

Compile fixes for building with musl libc #201

Merged
merged 5 commits into from
Oct 17, 2014

Conversation

mthuurne
Copy link
Contributor

The musl libc library is an embedded libc that is gaining popularity. The following cleanups fix compile errors where musl does things differently from glibc, but within the specs. They should be safer on all platforms.

The timer_t type is not used anywhere in the code. The fallback typedef
can break builds though on systems where timer_t exists but is not an
alias for __timer_t, such as systems using the musl libc.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
There is no guarantee that <sys/param.h> defines HZ. And in musl libc,
it doesn't. Since this is a Linux-specific constant, include the
Linux-specific header for it.

Note that HZ as defined by the system headers is the default value of
HZ (100), which might differ from the actual value of HZ in the kernel
config. Ideally userland would not use HZ at all and do all timing in
milliseconds instead.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
This looks like a sanity check that 64-bit file offset definitions were
indeed provided by the included headers. But __USE_FILE_OFFSET64 is an
internal define of glibc, so don't perform this check when compiling
with a different libc.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
The type of "st_mode" in "struct stat" is "mode_t", not "__mode_t".

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Previously, "-D__STDC_VERSION__=199901L" was used to request C99
functionality from the system headers, but this does not tell the
compiler to provide C99 language features, so for example the
"restrict" keyword is not available then. This mismatch breaks the
build when using musl libc.

Instead we use "-std=c99" to select C99, but this has the side effect
of disabling non-standard APIs. So we have to manually re-select those.
The simplest way of doing so is "-D_DEFAULT_SOURCE", but that is not
universally supported yet by libcs, so for now I opted for the more
portable "-D_POSIX_C_SOURCE=199309L" to get access to clock_gettime()
and maybe other functionality not in the C99 standard.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
@mthuurne
Copy link
Contributor Author

Today I rebased on the current master and added one commit to fix new compile errors (the C99 one). It now builds fine with musl 1.1.5.

popcornmix added a commit that referenced this pull request Oct 17, 2014
Compile fixes for building with musl libc
@popcornmix popcornmix merged commit 4333d6d into raspberrypi:master Oct 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants