Skip to content

Hotfix: Fix RHEL patch for C11 non-RHEL builds#97

Merged
quetric merged 1 commit into
Xilinx:mainfrom
amd-vserbu:hotfix/ami-patch-c11
May 26, 2026
Merged

Hotfix: Fix RHEL patch for C11 non-RHEL builds#97
quetric merged 1 commit into
Xilinx:mainfrom
amd-vserbu:hotfix/ami-patch-c11

Conversation

@amd-vserbu
Copy link
Copy Markdown
Collaborator

Summary

scripts/package-ami.sh rewrites the eventfd_signal() version gate in submodules/AVED/sw/AMI/driver/ami_program.c so the void-arg form is also selected on RHEL 9.5+, where Red Hat backported the upstream 6.8 simplification into the 5.14-based kernel.

The current rewrite uses a single composite #if:

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0) \
 || (defined(RHEL_RELEASE_CODE) \
     && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 5))

This works on RHEL but breaks the build on other distros with kernel >= 5.18 (Ubuntu 24.04, Ubuntu 22.04 HWE), if the kernel is compiled under C11 (-std=gnu11, the default since v5.18).

Why it breaks

Per C11, in a #if controlling expression all identifiers remaining after macro expansion (other than the operand of defined) are replaced with the pp-number 0, including function-like macro names. On a non-RHEL kernel RHEL_RELEASE_VERSION is undefined, so the preprocessor ends up parsing:

... || (0 && 0 >= 0(9, 5))
                   ^^^^^^^ syntax error

i.e. MACRO(a, b) becomes 0(a, b), which is not a valid constant expression. The defined(RHEL_RELEASE_CODE) short-circuit doesn't help, the rule applies during expression parsing, before evaluation.

Fix

Replace the sed rewrite with a patch that guards the RHEL check behind #ifdef RHEL_RELEASE_CODE, so non-RHEL translation units never tokenize RHEL_RELEASE_VERSION in a #if at all:

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0)
    eventfd_signal(efd_ctx);
#else
# ifdef RHEL_RELEASE_CODE
#  if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 5)
    eventfd_signal(efd_ctx);
#  else
    eventfd_signal(efd_ctx, <count>);
#  endif
# else
    eventfd_signal(efd_ctx, <count>);
# endif
#endif

Applied via patch --no-backup-if-mismatch -p1 -d "${AVED_DIR}"; the existing trap already git checkouts ami_program.c on exit, so revert semantics are unchanged.

Signed-off-by: Vlad-Gabriel Serbu <Vlad-Gabriel.Serbu@amd.com>
@quetric quetric merged commit 472e565 into Xilinx:main May 26, 2026
3 checks passed
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.

2 participants