core: fix build on musl libc (Alpine) - stray #undef _GNU_SOURCE in lib/url.c#4119
Open
Lt-Flash wants to merge 1 commit into
Open
core: fix build on musl libc (Alpine) - stray #undef _GNU_SOURCE in lib/url.c#4119Lt-Flash wants to merge 1 commit into
Lt-Flash wants to merge 1 commit into
Conversation
url.c defined _GNU_SOURCE only around <stdio.h>/<string.h> and then
undefined it again before including ut.h. On musl libc the feature-test
macros are re-evaluated by every system header, so once _GNU_SOURCE is
removed the later <time.h> (pulled in through ut.h and dprint.h) no
longer exposes clock_gettime(), CLOCK_REALTIME or ctime_r(). The core
then fails to compile on Alpine/musl with gcc 15:
lib/../mem/../dprint.h:204: implicit declaration of 'ctime_r'
lib/../ut.h:1401: implicit declaration of 'clock_gettime'
lib/../ut.h:1401: 'CLOCK_REALTIME' undeclared
glibc is unaffected: it latches internal __USE_* macros at the first
header inclusion, which the later #undef does not clear.
Keep _GNU_SOURCE defined for the whole translation unit, matching how
other core files (io_wait.h, transformations.c) enable it.
Lt-Flash
marked this pull request as ready for review
July 25, 2026 00:54
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the OpenSIPS core failing to compile on musl libc (Alpine Linux) with a modern GCC. A single stray
#undef _GNU_SOURCEinlib/url.chides the POSIX time prototypes on musl, so the very first core object (lib/url.o) never builds.Symptom
Building
masterin a stock Alpine 3.24 container (musl 1.2.x, gcc 15.2.0) dies immediately:With gcc 14+,
-Wimplicit-function-declarationis an error by default, so this is a hard build failure, not a warning. The same tree builds fine on glibc.Root cause
lib/url.copens with:The difference between the two libcs is when the feature-test macros are evaluated:
musl re-checks the feature-test macros in every system header. Its
features.honly turns on the permissive default set (_BSD_SOURCE+_XOPEN_SOURCE 700, which is what exposesclock_gettime/ctime_r) when no source macro is defined:When
<stdio.h>first includesfeatures.h,_GNU_SOURCEis defined, so that default block is skipped andfeatures.hlatches (include guard). The following#undef _GNU_SOURCEthen leaves the translation unit with no feature-test macro at all. Whenut.hlater includes<time.h>,features.his guard-skipped and never re-derives the defaults, sotime.h's guarded prototypes (clock_gettime,ctime_r,CLOCK_REALTIME) are all absent -> implicit declarations -> build error.glibc latches internal
__USE_POSIX*/__USE_GNUmacros at the first header inclusion. The later#undef _GNU_SOURCEdoes not clear those, so the prototypes stay visible and the build succeeds. That is why this has gone unnoticed.A one-line reproducer confirms the mechanism on musl:
The fix
Drop the
#undefand keep_GNU_SOURCEdefined for the whole translation unit (with a comment explaining why). This matches how other core sources already enable it unconditionally (io_wait.h,transformations.c), and is a no-op on glibc.Testing
make opensipsfails atlib/url.obefore this change; builds to completion after it. Full core binary produced, modules build and load, runtime verified.#undefwas already a no-op there).lib/url.cis the only core file that uses this#define/#undef _GNU_SOURCEbracket, so this one file is the whole fix for the core.Opening as a draft for maintainer review of the approach (per-file fix here vs. defining
_GNU_SOURCEtree-wide in the build).