Skip to content

plat/*/pal: Add extern "C" guard to ectx.h for C++ compatibility - #1832

Open
RaduAndreiTudorica wants to merge 1 commit into
unikraft:stagingfrom
RaduAndreiTudorica:fix-plat-pal-ectx-extern-c
Open

RaduAndreiTudorica wants to merge 1 commit into
unikraft:stagingfrom
RaduAndreiTudorica:fix-plat-pal-ectx-extern-c

Conversation

@RaduAndreiTudorica

@RaduAndreiTudorica RaduAndreiTudorica commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Description of Changes

The plat/native/pal/include/uk/plat/pal/ectx.h and
plat/xen/pal/include/uk/plat/pal/ectx.h headers define
uk_pal_ectx_* functions as static inline without an extern "C"
guard. When these headers are included from C++ code (e.g., via
libcxxabi's cxa_guard.cpp -> uk/syscall.h -> uk/arch/ctx.h ->
uk/lcpu/ectx.h), the functions get C++ language linkage, conflicting
with the extern "C" declarations in ukpal/include/uk/pal/ectx.h.

This causes a build failure for any C++ application on both stable and
staging:

ukpal/include/uk/pal/ectx.h:63: error: conflicting declaration of
'void uk_pal_ectx_sanitize(uk_pal_ectx*)' with 'C' linkage
plat/native/pal/include/uk/plat/pal/ectx.h:28: note: previous
declaration with 'C++' linkage

Tested by applying the fix locally and building helloworld-cpp on both stable and staging both build successfully after this change.

Related Work

N/A

PR Checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes C++ compatibility issues in the platform PAL ECTX headers by ensuring the uk_pal_ectx_* inline definitions use C linkage, preventing conflicts with the extern "C" declarations in lib/ukpal/include/uk/pal/ectx.h.

Changes:

  • Add extern "C" guards to plat/native/pal/include/uk/plat/pal/ectx.h.
  • Add extern "C" guards to plat/xen/pal/include/uk/plat/pal/ectx.h.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
plat/xen/pal/include/uk/plat/pal/ectx.h Wraps PAL ECTX inline definitions in extern "C" to align linkage with the public PAL header.
plat/native/pal/include/uk/plat/pal/ectx.h Wraps PAL ECTX inline definitions in extern "C" to align linkage with the public PAL header.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 34
static inline void uk_pal_ectx_sanitize(struct uk_pal_ectx *state)
{
uk_plat_native_ectx_sanitize((struct uk_plat_native_ectx *)state);
RaduAndreiTudorica added a commit to RaduAndreiTudorica/lib-redis that referenced this pull request Jul 30, 2026
Bump Redis from 7.0.11 to 8.0.2.

Redis 8 introduces fast_float, a C++ implementation of strtod used by
util.c. Rather than pulling a full C++ toolchain into the unikernel,
provide a strtod() based implementation of fast_float_strtod(). Redis
already falls back to strtod() for inputs fast_float does not handle,
so behaviour is unchanged.

Add a patch leaving HAVE_POPCNT and HAVE_AVX2 undefined: bitops.c and
hyperloglog.c call __builtin_cpu_supports() when they are defined, which
requires __cpu_model from libgcc. libgcc is not linked into the
unikernel, so the generic implementations are used instead.

Add the compiler's own include directory to the C include path, which
Redis 8 needs for immintrin.h.

Tested on qemu/x86_64 with catalog-core/redis: PING, SET and GET work
and INFO reports redis_version:8.0.2.

Depends on unikraft/unikraft#1832 for the extern "C" guard in ectx.h,
needed by the C++ dependency check.

Signed-off-by: Radu Andrei Tudorica <raduandreitudorica3@gmail.com>

@StefanJum StefanJum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine @RaduAndreiTudorica , thank you. Please leave a commit message that shortly describes the issue that the missing guard can lead to (the PR description can do fine)

The uk_pal_ectx_* functions in plat/native/pal and plat/xen/pal are
defined as static inline without an extern "C" guard. When these
headers are pulled into C++ code, the functions get C++ language
linkage, which conflicts with the extern "C" declarations in
ukpal/include/uk/pal/ectx.h and breaks the build for any C++
application:

  ukpal/include/uk/pal/ectx.h:63: error: conflicting declaration of
  'void uk_pal_ectx_sanitize(uk_pal_ectx*)' with 'C' linkage
  plat/native/pal/include/uk/plat/pal/ectx.h:28: note: previous
  declaration with 'C++' linkage

One path that reaches it is libcxxabi's cxa_guard.cpp, through
uk/syscall.h, uk/arch/ctx.h and uk/lcpu/ectx.h.

Tested by building helloworld-cpp on both stable and staging.

Signed-off-by: Radu Andrei Tudorica <raduandreitudorica3@gmail.com>
@RaduAndreiTudorica
RaduAndreiTudorica force-pushed the fix-plat-pal-ectx-extern-c branch from 4de07be to ce24b44 Compare August 11, 2026 14:28
@RaduAndreiTudorica

Copy link
Copy Markdown
Contributor Author

This is fine @RaduAndreiTudorica , thank you. Please leave a commit message that shortly describes the issue that the missing guard can lead to (the PR description can do fine)

Done, thanks!
I moved the explanation into the commit message.

@StefanJum StefanJum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks.
Reviewed-by: Stefan Jumarea stefanjumarea02@gmail.com

@RaduAndreiTudorica

Copy link
Copy Markdown
Contributor Author

The libc-test job failed on a transient network error, not on this change:

WGET libmusl: https://www.musl-libc.org/releases/musl-1.2.3.tar.gz
tar (child): .../libmusl/musl-1.2.3.tar.gz: Cannot open: No such file or directory

musl-libc.org didn't serve the tarball. Could someone re-run the job?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plat Unikraft Patform plat/xen Unikraft for Xen

Projects

Status: 🧊 Icebox

Development

Successfully merging this pull request may close these issues.

4 participants