Skip to content

treewide: fix 64-bit printk format mismatches and an LTO strcpy link failure - #127

Merged
FengHeting merged 2 commits into
ViudiraTech:developfrom
FengHeting:fix/format-specifiers
Nov 4, 2026
Merged

FengHeting merged 2 commits into
ViudiraTech:developfrom
FengHeting:fix/format-specifiers

Conversation

@FengHeting

Copy link
Copy Markdown
Contributor

Summary

Two build fixes for compiler-dependent behavior.

64-bit printk format specifiers

int64_t, size_t and pointer-sized constants do not have a stable
underlying type across toolchains, so the same %lld / %llu / %zd call
sites trip -Wformat on some hosts while building cleanly on others, which
makes the failure move between machines.

Pass every argument at the type its specifier reads:

  • kernel/arch/cpu/smp.c: print the size_t CPU count with %zu instead
    of %zd.
  • fs/ntfs/ntfs_runlist.c: cast the int64_t byte offset and cluster count
    to unsigned long long where the format uses %llu.
  • fs/proc/procfs.c: cast pid_t fields to unsigned long long for
    %llu, use %llu for resident_pages, and use %llu for the user stack
    top instead of %lu.
  • include/process/process.h: give PROCESS_USER_STACK_TOP an ULL
    suffix so its type matches the %llu in procfs.

Rendered output is unchanged for the value ranges these fields can take.

LTO strcpy link failure

GCC can expand strcat() into a strcpy() call during LTO after the
strcpy() definition has been pruned as unused, leaving an undefined reference to 'strcpy' at link time. Mark the definition
__attribute__((used)) so it survives to the final link.

Testing

  • make -j$(nproc) (GCC): clean build, no warnings.
  • clang-tidy (make <file>.tidy) clean on all touched C files.

Values of typedef types (int64_t, size_t) and pointer-sized constants do not have a stable underlying type across compilers, so the same %lld, %llu and %zd call sites fail -Wformat on some hosts and pass on others.

Pass each argument at the type its specifier reads: cast int64_t values printed with %llu to unsigned long long, print size_t with %zu, and give PROCESS_USER_STACK_TOP an ULL suffix so /proc/<pid>/stat keeps printing it with %llu.  The rendered text is unchanged.

Signed-off-by: FengHeting <2609948707@qq.com>
GCC can expand strcat() into a strcpy() call during LTO after the definition was already pruned, leaving an undefined reference to strcpy at link time.  Mark the definition as used so it survives to the final link.

Signed-off-by: FengHeting <2609948707@qq.com>
@FengHeting
FengHeting merged commit 763570b into ViudiraTech:develop Nov 4, 2026
2 checks passed
@FengHeting
FengHeting deleted the fix/format-specifiers branch November 4, 2026 17:53
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.

1 participant