Skip to content

GHA: add a build with c-ares + HTTP-RR on Alpine - #16413

Closed
bagder wants to merge 3 commits into
masterfrom
bagder/gha-alpine-cares
Closed

bagder wants to merge 3 commits into
masterfrom
bagder/gha-alpine-cares

Conversation

@bagder

@bagder bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member

No description provided.

@bagder bagder added CI Continuous Integration HTTPS-RR labels Feb 21, 2025
@bagder bagder mentioned this pull request Feb 21, 2025
@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

These errors look disturbing:

/usr/include/sched.h: At top level:
memdebug.h:120:59: error: expected declaration specifiers or '...' before numeric constant
  120 | #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
      |                                                           ^~~~~~~~
memdebug.h:120:69: error: expected declaration specifiers or '...' before string constant
  120 | #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
      |                                                                     ^~~~~~~~
memdebug.h:124:38: error: expected declaration specifiers or '...' before numeric constant
  124 | #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
      |                                      ^~~~~~~~
memdebug.h:124:48: error: expected declaration specifiers or '...' before string constant
  124 | #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
      |                                                ^~~~~~~~
/usr/include/sched.h: At top level:
memdebug.h:120:59: error: expected declaration specifiers or '...' before numeric constant
  120 | #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
      |                                                           ^~~~~~~~
memdebug.h:120:69: error: expected declaration specifiers or '...' before string constant
  120 | #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
      |                                                                     ^~~~~~~~
memdebug.h:124:38: error: expected declaration specifiers or '...' before numeric constant
  124 | #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
      |                                      ^~~~~~~~
memdebug.h:124:48: error: expected declaration specifiers or '...' before string constant
  124 | #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
      |                                                ^~~~~~~~

@bagder
bagder force-pushed the bagder/gha-alpine-cares branch from 46cc033 to 8ba7ed1 Compare February 21, 2025 07:38
@vszakats

vszakats commented Feb 21, 2025 •

Copy link
Copy Markdown
Member

These errors look disturbing:

/usr/include/sched.h: At top level:
[...]
memdebug.h:124:48: error: expected declaration specifiers or '...' before string constant
  124 | #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
      |                                                ^~~~~~~~

It's caused by redefining 3rd-party symbols and those redefinitions applied to
external headers and messing them up.

In this case the solution might be to ensure that we include sched.h before
memdebug.h, e.g. by moving its include from easy_lock.h to curl_setup.h.

(The ultimate solution would be replacing these redefinitions with curl-specific
macros, e.g. to use CURL_FREE() in place of free(). These can be redefined
at will without side-effects.)

@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

(The ultimate solution would be replacing these redefinitions with curl-specific macros, e.g. to use CURL_FREE() in place of free(). These can be redefined at will without side-effects.)

It would however change the code significantly. One of the nice parts of the current setup is that we can keep using the standard memory functions, no magic necessary. Switching away from using the standard function names takes away a portion of the beauty of this setup I think.

@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

In this case the solution might be to ensure that we include sched.h before memdebug.h, .e.g. by moving its include from easy_lock.h to curl_setup.h.

It seems this happens in unity builds only, which makes depending on include order much more complicated...

@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

I'm fine with just not using unity build together with memdebug.

@testclutch

Copy link
Copy Markdown

Analysis of PR #16413 at 0d68e6eb:

Test 3023 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Generated by Testclutch

@vszakats

vszakats commented Feb 21, 2025 •

Copy link
Copy Markdown
Member

In this case the solution might be to ensure that we include sched.h before memdebug.h, .e.g. by moving its include from easy_lock.h to curl_setup.h.

It seems this happens in unity builds only, which makes depending on include order much more complicated...

Yes, this issue is normally avoided by the comment /* The last 3 #include files should be in this order */ to include "memdebug.h" last. It works when the PP state is reset between source files, but in unity it's not a solution. Well,
in most cases it is, but there may be outlier cases like this one.

Have you tried moving (or copying) #include <shed.h> to curl_setup.h or curl_setup_once.h?

(I think losing unity for all debug builds would be a big loss and would complicate thinking about builds.)

@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

Have you tried moving (or copying) #include <shed.h> to curl_setup.h or curl_setup_once.h?

I have not. It is also an unfortunate change because that header file is only needed for easy_lock.c so including it universally for every C file seems like a... non-ideal fix.

(I think losing unity for all debug builds would be a big loss and would complicate thinking about builds.)

Not to be that guy, but the unity builds are actually what complicate the builds, not the other way around...

@vszakats

Copy link
Copy Markdown
Member

Have you tried moving (or copying) #include <shed.h> to curl_setup.h or curl_setup_once.h?

I have not. It is also an unfortunate change because that header file is only needed for easy_lock.c so including it universally for every C file seems like a... non-ideal fix.

(I think losing unity for all debug builds would be a big loss and would complicate thinking about builds.)

Not to be that guy, but the unity builds are actually what complicate the builds, not the other way around...

That's disappointing to hear, given how much time it saves in CI
(for me also locally, but I guess that's my problem entirely.)

I believe the free() redefinition is fundamentally wrong.

It can not only break in unity builds, but any non-unity build
where the system defines free as a macro, or maps free to
its own macro. It's the latter case with Alpine's sched.h:

#define CPU_FREE(set) free(set)

The redefinition solution caused a whole bunch of ugly workarounds
due to this for freeaddreinfo()/getaddrinfo(). While I agree
that free() looks nicer than CURL_FREE() (or whatever other
local macro.), it solves this class of problems cleanly with or without
unity.

I still think that unity actually helped finding and dropping a whole
bunch of inconsistency issues, hacks and trickery, especially around
macro use. If speed is of no concern, these probably should be.

Redefining system symbols is brittle and should not be done unless
absolutely unavoidable. It's already fragile and depends on include
order "enforced" by comments.

@bagder

bagder commented Feb 21, 2025 •

Copy link
Copy Markdown
Member Author

That's disappointing to hear, given how much time it saves in CI

I know they do, and that's the reason we tolerate all the little hacks we need to do to deal with it.

I believe the free() redefinition is fundamentally wrong.

I don't. They are fragile though.

I still think that unity actually helped finding and dropping a whole bunch of inconsistency issues, hacks and trickery, especially around macro use

Yeah, it has forced us clean up some things.

Redefining system symbols is brittle and should not be done unless absolutely unavoidable

Well, we need to come back and think of the reason for doing them: we want to allow users to keep using the plain normal C functions for memory allocations but yet provide a system that can detect a certain set of mistakes involving them. I think there is a strong reason to stick to the common functions: to allow developers to know them, feel familiar with them and to not hesitate which functions to use when the they come writing new code.

I think those advantages of sticking to the "real" functions are benefits that outweigh the obstacles and challenges we need to overcome in the build systems.

Not too unlike to how we like to keep the unity builds in spite of the friction they cause.

@bagder
bagder force-pushed the bagder/gha-alpine-cares branch from 0d68e6e to 99296c0 Compare February 21, 2025 13:50
@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

speaking of quirks... 😀

To avoid warnings if it gets done again - like in unity builds.
Comment thread lib/asyn-ares.c Resolved
@bagder

bagder commented Feb 21, 2025

Copy link
Copy Markdown
Member Author

✔️

@bagder bagder closed this in 17ab4d6 Feb 21, 2025
@bagder
bagder deleted the bagder/gha-alpine-cares branch February 21, 2025 15:44
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Jul 6, 2025
- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 6, 2025
- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 6, 2025
- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 7, 2025
- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 7, 2025
finalize Alpine configs

- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 7, 2025
finalize Alpine configs

- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 7, 2025
finalize Alpine configs

- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 8, 2025
finalize Alpine configs

- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
vszakats added a commit to vszakats/curl that referenced this pull request Jul 9, 2025
finalize Alpine configs

- formatting: tidy-up option order and job name.
- enable unity mode again for the RR c-ares job.
  Follow-up to 17ab4d6 curl#16413
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

CI Continuous Integration HTTPS-RR

Development

Successfully merging this pull request may close these issues.

3 participants