Skip to content

Crypto: use VC_INLINE for the ARM CPU_Query helpers - #1886

Merged
idrassi merged 1 commit into
veracrypt:masterfrom
flatstik:cpu-query-static-inline
Sep 30, 2026
Merged

idrassi merged 1 commit into
veracrypt:masterfrom
flatstik:cpu-query-static-inline

Conversation

@flatstik

@flatstik flatstik commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

C99 inline without static does not emit a function body. On aarch64 at -O0/-Os, DetectArmFeatures() then fails to link:

undefined reference to CPU_QueryAES
undefined reference to CPU_QuerySHA2

This showed up building VeraCrypt 1.26.29 as an OpenWrt package for aarch64_generic (OpenWrt builds with -Os). The helpers now use VC_INLINE, like the other helpers in cpu.c (IsIntel, IsAMD, IsHygon).

Signed-off-by: Ville Takio ville+git@takio.fi

@BKPepe

BKPepe commented Sep 29, 2026

Copy link
Copy Markdown

@idrassi sorry to bother you, but would you mind to take a look?

@flatstik
flatstik force-pushed the cpu-query-static-inline branch from 3dbee95 to 151b246 Compare September 30, 2026 08:55
@flatstik

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (after #1896); still a one-line-per-function change in src/Crypto/cpu.c.

Reproduction on master a15c996 with the OpenWrt aarch64 toolchain (gcc 14.4, musl):

aarch64-openwrt-linux-musl-gcc -Os -std=gnu99 -I.. -I../Common -c cpu.c
aarch64-openwrt-linux-musl-nm cpu.o | grep ' U CPU_Query'
                 U CPU_QueryAES
                 U CPU_QuerySHA2

Same at -O0; at -O2 gcc happens to inline both calls, which is why it doesn't show up in the usual builds. With this change, cpu.o has no undefined CPU_Query* references at any of those levels.

Comment thread src/Crypto/cpu.c Outdated
volatile int g_hasSHA256ARM = 0;

inline int CPU_QueryAES()
static inline int CPU_QueryAES()

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.

Please use VC_INLINE for both CPU_QueryAES and CPU_QuerySHA2, following the existing helpers in cpu.c. This resolves the linkage problem while preserving our established portability macro.

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.

Done, both now use VC_INLINE (c06d745, rebased on current master). Checked with the OpenWrt aarch64 toolchain at -O0, -Os and -O2: no undefined CPU_Query* references and no warnings.

@idrassi

idrassi commented Sep 30, 2026

Copy link
Copy Markdown
Member

@flatstik After the VC_INLINE adjustment, I will approve this PR.

C99 inline without static does not emit a function body, so aarch64
builds at -O0/-Os fail to link DetectArmFeatures (undefined reference
to CPU_QueryAES / CPU_QuerySHA2). Use VC_INLINE like the other helpers
in cpu.c.

Signed-off-by: Ville Takio <ville+git@takio.fi>
@flatstik
flatstik force-pushed the cpu-query-static-inline branch from 151b246 to c06d745 Compare September 30, 2026 11:41
@flatstik flatstik changed the title Crypto: make ARM CPU_Query helpers static inline Crypto: use VC_INLINE for the ARM CPU_Query helpers Sep 30, 2026

@idrassi idrassi 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.

Thank you for your contribution.

@idrassi
idrassi merged commit 5c7f60d into veracrypt:master Sep 30, 2026
1 check 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.

3 participants