Skip to content

build: fixup unity builds with MUSL - #16428

Closed
vszakats wants to merge 23 commits into
curl:masterfrom
vszakats:aresrr
Closed

vszakats wants to merge 23 commits into
curl:masterfrom
vszakats:aresrr

Conversation

@vszakats

Copy link
Copy Markdown
Member

No description provided.

@bagder

This comment was marked as outdated.

@vszakats

vszakats commented Feb 21, 2025 •

Copy link
Copy Markdown
Member Author

Yep, sorry, realized that a bit late (though I could not spot the difference in meaning myself).
Recycling this PR for unity tests, which may become a fix.

MUSL also fixed the sched.h collision in this recent commit (not yet released):
https://git.musl-libc.org/cgit/musl/commit/?id=1a98576401ff604ff06a030a3644e2780b2a837d

@vszakats vszakats reopened this Feb 21, 2025
@github-actions github-actions Bot added the CI Continuous Integration label Feb 21, 2025
@vszakats vszakats changed the title merge ares/rr macros, define in one place build: fixup unity builds with MUSL Feb 21, 2025
@vszakats
vszakats marked this pull request as draft February 21, 2025 17:31
@vszakats vszakats added build and removed HTTPS-RR labels Feb 21, 2025
@testclutch

This comment was marked as outdated.

@vszakats
vszakats force-pushed the aresrr branch 4 times, most recently from 8784fe6 to 3b6bf5f Compare February 22, 2025 00:16
@vszakats

Copy link
Copy Markdown
Member Author

Non-debug builds are also affected. Same root cause, different compiler errors. It most likely affects curl-for-win MUSL builds too in this combination (once RR is enabled there).

@vszakats

vszakats commented Jul 6, 2025

Copy link
Copy Markdown
Member Author

Closing this attempt in favor of #17827.

@vszakats vszakats closed this Jul 6, 2025
@vszakats
vszakats deleted the aresrr branch July 6, 2025 11:02
vszakats added a commit that referenced this pull request Jul 28, 2025
Fixing:
- HTTPS-RR builds with c-ares and Linux MUSL.
- curl-for-win minimal builds with Linux MUSL.

It should fix all other kinds of entaglement between curl's redefintions
of system symbols and system (or 3rd-party) headers sensitive to that.

It also syncs memory override behavior between unity & non-unity builds,
thus reducing build variations.

The idea is to define and declare everything once in `curl_setup.h`,
without overriding any system symbols with curl ones yet. Then, like
before this patch, override them, if necessary, in each source file via
`curl_memory.h` and `memdebug.h`, after including system headers.
To ensure a clean slate with no overrides at the beginning of each
source file, reset all of them unconditionally at the end of
`curl_setup.h`, by including `curl_mem_undef.h`. (This assumes
`curl_setup.h` is always included first, which is already the case
throughout the codebase.)

`curl_mem_undef.h` can also be included explicitly wherever overrides
are causing problems. E.g. in tests which use unity-style builds and
a previously included `curl_memory.h`/`memdebug.h` can be spilling into
other source files.

The simplified role of the two override headers:
- `curl_memory.h`: overrides system memory allocator functions to
  libcurl ones, when memory tracing (aka `CURLDEBUG`) is disabled.
- `memdebug.h`: overrides system memory allocator and some other
  functions to curl debug functions, when memory tracing is enabled.

Changed made in this patch, step-by-step:
- curl_memory.h: move allocator typedefs and protos to `curl_setup.h`.
- memdebug.h: move `ALLOC_*` macros to `curl_setup.h`.
- memdebug.h: move allocator protos to `curl_setup.h`.
- memdebug.h: move `Curl_safefree()` macro to `curl_setup.h`.
  (it's a regular macro, with a one-time, global, definition.)
- curl_memory.h: move system symbol undefs to a new, separate header:
  `curl_mem_undef.h`.
- curl_setup.h: include `curl_mem_undef.h` at the end, unconditionally,
  to reset system symbol macros after each inclusion.
- handle `sclose()` and `fake_sclose()` in `curl_setup.h`. They are not
  system symbols, a one-time definition does the job.

Also:
- GHA/linux: enable unity mode for the HTTP-RR c-ares MUSL job.
  Follow-up to 17ab4d6 #16413

That said, I'd still find it better to avoid redefining system macros.
To communicate clearly the fact that they are not the original system
calls and they do behave differently. And, it would allow dropping the
undef/redef dance in each source file, and maintaining the logic with
it. The "last #include files should be in this order" comments in each
source would also become unnecessary. Also the trick of using
`(func)` (or interim macros) to call the non-overridden function where
required. This method works for printf and most everything else already.
For `_tcsdup`, socket and fopen functions this could work without
disturbing the codebase much.

Ref: #16428 (clean reboot of)

Closes #17827
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CI Continuous Integration tidy-up

Development

Successfully merging this pull request may close these issues.

3 participants