https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664
Bug ID: 91664 Summary: Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: element at elementsofsound dot org Target Milestone: --- Created attachment 46826 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46826&action=edit Preprocessed file for fmv-test.c Target: x86_64-linux-gnu gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1) Creating a static library archive with publicly declared functions with target_clones attribute, causes undefined reference errors to the function clones when linking the archive into the final application. I created a test build on github which illustrates this: https://github.com/elementgreen/fmv-test Also a stackoverflow question: https://stackoverflow.com/questions/57798005/how-to-fix-undefined-reference-linker-errors-when-static-linking-archive-with-gc This test build has 3 different make targets "works", "also_works", and "borken". The first just builds the executable in one go with .c source files and -o for the target executable. The second compiles each .c into .o object files and then links them with gcc -o and the object files. The final make target compiles each .c into .o files, then creates an archive with ar, and then links the .a archive into the final executable with gcc -o. The first 2 targets work, the 3rd does not, with the errors: gcc -c fmv-test.c gcc -c main.c ar cr fmv-test.a fmv-test.o main.o gcc -o fmv-test-borken fmv-test.a /usr/bin/ld: fmv-test.a(main.o): in function `fmv_test': main.c:(.text.fmv_test.resolver[fmv_test.resolver]+0x1f): undefined reference to `fmv_test.avx2.0' /usr/bin/ld: main.c:(.text.fmv_test.resolver[fmv_test.resolver]+0x3b): undefined reference to `fmv_test.avx.1' /usr/bin/ld: main.c:(.text.fmv_test.resolver[fmv_test.resolver]+0x57): undefined reference to `fmv_test.sse4_1.2' /usr/bin/ld: main.c:(.text.fmv_test.resolver[fmv_test.resolver]+0x71): undefined reference to `fmv_test.sse2.3' /usr/bin/ld: main.c:(.text.fmv_test.resolver[fmv_test.resolver]+0x7a): undefined reference to `fmv_test.default.4' collect2: error: ld returned 1 exit status