Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing __cpu_indicator_init and __cpu_model in compiler-rt #18074

Open
lacc97 opened this issue Nov 22, 2023 · 6 comments · May be fixed by #20081
Open

Missing __cpu_indicator_init and __cpu_model in compiler-rt #18074

lacc97 opened this issue Nov 22, 2023 · 6 comments · May be fixed by #20081
Labels
compiler-rt enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@lacc97
Copy link
Contributor

lacc97 commented Nov 22, 2023

Zig Version

0.12.0-dev.1685+994e19164

Steps to Reproduce and Observed Behavior

Trying to compile a C file where a function has target_clone attribute fails. e.g. for targets.c:

#include <stdio.h>

int foo(void) __attribute__ ((__target_clones__("default,avx2")));

int main() {
    return foo();
}

int __attribute__ ((__target_clones__("default,avx2"))) foo(void) {
    return 0;
}

Running

zig cc -march=baseline -o targets targets.c

fails with

ld.lld: error: undefined symbol: __cpu_indicator_init
>>> referenced by targets.c
>>>               /home/luisc/.cache/zig/o/15708c62c5fddecc0c537adadb7a1a1b/targets.o:(foo.ifunc)

ld.lld: error: undefined symbol: __cpu_model
>>> referenced by targets.c
>>>               /home/luisc/.cache/zig/o/15708c62c5fddecc0c537adadb7a1a1b/targets.o:(foo.ifunc)

Expected Behavior

This should compile successfully.

@lacc97 lacc97 added the bug Observed behavior contradicts documented or intended behavior label Nov 22, 2023
@lacc97
Copy link
Contributor Author

lacc97 commented Nov 22, 2023

These symbols are defined in compiler-rt in LLVM: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/cpu_model.c

Also, maybe related to #4591.

@matu3ba
Copy link
Contributor

matu3ba commented Nov 24, 2023

These symbols are defined in compiler-rt in LLVM: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/cpu_model.c

only for those targets:

#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) ||           \
     defined(_M_X64)) &&                                                       \
    (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER))

aarch64 and other platforms use different symbols/strategies.

@matu3ba
Copy link
Contributor

matu3ba commented Dec 2, 2023

Exporting the symbols should be rather straightforward, since the x86 and x86_64 feature detection is already implemented. See #4591 (comment).

@matu3ba
Copy link
Contributor

matu3ba commented Dec 2, 2023

@lacc97 Do you want to take a shot at it?

@lacc97
Copy link
Contributor Author

lacc97 commented Dec 3, 2023

Sure I'll give it a shot.

@lacc97
Copy link
Contributor Author

lacc97 commented Dec 3, 2023

@matu3ba PR here :) #18193

@Vexu Vexu added enhancement Solving this issue will likely involve adding new logic or components to the codebase. and removed bug Observed behavior contradicts documented or intended behavior labels Mar 26, 2024
@Vexu Vexu added this to the 0.13.0 milestone Mar 26, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
5 participants