Skip to content

clang -O produces references to memset even with -fno-builtin -ffreestanding -nostdlib #147401

@attila-lendvai

Description

@attila-lendvai

i'm compiling a static linux binary that talks directly to the kernel, i.e. without libc:

clang -O3 -nostdlib -nostartfiles -ffreestanding -fno-builtin-memset -Wl,-Bstatic -Qunused-arguments --target=x86_64-linux-gnu eval2.ll

if i delete the -O then it works as expected.

i think some of the optimizations emits calls to memset regardless of the command line arguments.

$ clang --version
clang version 20.1.7
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gnu/store/hvi2iz7n4zk4pyxvibrxa6j43hkv4wn2-clang-20.1.7/bin
$ uname -a
Linux lelap 6.14.11 #1 SMP PREEMPT_DYNAMIC 1 x86_64 GNU/Linux
$ guix describe
Generation 231	Jul 06 2025 13:09:57	(current)
  guix 50b7528
    repository URL: https://codeberg.org/guix/guix.git
    branch: master
    commit: 50b75285883623ee244d0a71a225807c0672ac33

eval2.ll.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:optimizationsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions