Skip to content

SctPkg: Replace global -mabi=ms with EFIAPI macro for GCC IA32/X64 - #358

Open
r1chard-lyu wants to merge 3 commits into
tianocore:masterfrom
r1chard-lyu:sctpkg-efiapi-macro
Open

r1chard-lyu wants to merge 3 commits into
tianocore:masterfrom
r1chard-lyu:sctpkg-efiapi-macro

Conversation

@r1chard-lyu

@r1chard-lyu r1chard-lyu commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

REF: #285

The edk2 community prefers annotating public interfaces with EFIAPI
over forcing the Microsoft x64 calling convention globally via
-mabi=ms. The global flag obscures which symbols actually cross the
UEFI ABI boundary and silently changes the calling convention of
internal helpers that should follow the host System V ABI.

This series replaces the global -mabi=ms flag for GCC IA32/X64 with
an explicit EFIAPI macro, then annotates the SctLib print pipeline
so the va_list ABI stays consistent end-to-end.

Changes

  1. SctPkg/UEFI — Replace -mabi=ms with
    -DEFIAPI=__attribute__((ms_abi)) for the GCC IA32/X64 toolchains
    in UEFI_SCT.dsc.
  2. SctPkg/Include — Add EFIAPI to the public print function
    declarations (SctPrint, SctSPrint, SctVSPrint, etc.) so call
    sites pick up the correct calling convention.
  3. SctPkg/Library/SctLib — Add EFIAPI to print function
    definitions, internal helpers, and VA_LIST consumers so the
    va_list ABI is consistent through the entire print pipeline.

REF: tianocore#285

The edk2 community prefers adding the missing EFIAPI annotation to each
public interface over using '-mabi=ms' as a global declaration, so that
only functions that genuinely cross the UEFI ABI boundary carry the
Microsoft calling convention, while the rest of the code stays on the
host System V ABI.

Following that direction, replace the global '-mabi=ms' compiler flag
with an explicit EFIAPI macro definition
'-DEFIAPI=__attribute__((ms_abi))' for GCC IA32 and X64 toolchains.
This makes the ABI boundary explicit at the declaration site instead
of implicit at the build-system level.

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
Annotate the public print function declarations (SctPrintAt, SctPrint,
SctAPrint, SctSPrint, SctVSPrint, SctAVSPrint, SctASPrint, SctPoolPrint,
SctCatPrint) with EFIAPI to match their definitions in SctLib/Print.c,
ensuring a consistent calling convention across the call sites once
EFIAPI is explicitly defined for GCC IA32/X64.

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
With -mabi=ms removed and EFIAPI explicitly defined for GCC IA32/X64,
the va_list calling chain in SctLib/Print.c requires careful handling
to keep a consistent ABI across the entire print pipeline:

- SCT_PRINT_STATE.Output and .SetAttr changed to EFIAPI function
  pointer types to match UEFI EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
- Type casts for OutputString and SetAttribute updated to include EFIAPI
- All variadic functions (SctPrint, SctSPrint, SctPoolPrint, etc.) and
  VA_LIST consumers (SctVSPrint, _IPrint, _PoolCatPrint, etc.) annotated
  with EFIAPI to ensure consistent va_list ABI throughout the call chain
- All static internal helpers that participate in the print pipeline
  (_Print, PFLUSH, PPUTC, PITEM, PGETC, PSETATTR, etc.) annotated
  with EFIAPI accordingly

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
@r1chard-lyu
r1chard-lyu force-pushed the sctpkg-efiapi-macro branch from 7057674 to c9279cb Compare June 12, 2026 12:54

@edhay edhay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the updates.


# GCC:*_*_IA32_CC_FLAGS = -D EFI32 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error -mno-red-zone -Wno-address -mno-stack-arg-probe "-DEFIAPI=__attribute__((ms_abi))" -m32 -mabi=ms -D MDE_CPU_X32
GCC:*_*_IA32_CC_FLAGS = -D EFIX64 $(GCC_VER_MACRO) -Wno-error -mabi=ms
GCC:*_*_IA32_CC_FLAGS = -D EFIX64 $(GCC_VER_MACRO) -Wno-error "-DEFIAPI=__attribute__((ms_abi))"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this change tested for all functions in a edk2-test run?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I ran a full SCT run. All test suites were executed, 7079 cases total, on
OVMF/QEMU, and the results are identical before and after the patch. This change
is expected to affect the x86 platform only.

without patch with patch
Total 7079 7079
Passed 7047 7047
Failed 32 32

@r1chard-lyu

Copy link
Copy Markdown
Contributor Author

@edhay When can we expect this to be merged? Currently, this should only affect IA32/X64 GCC builds.

@anncheng-arm anncheng-arm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me

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.

3 participants