[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-09 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

Martin Liška  changed:

   What|Removed |Added

 Status|ASSIGNED|WAITING

--- Comment #9 from Martin Liška  ---
(In reply to Richard Biener from comment #7)
> The issue is that with a declaration like
> 
> double fmv_test (double *dArray, int size) __attribute__ ((__target_clones__
> ("avx2","avx","sse4.1","sse2","default")));
> 
> we're creating a resolver even if there's no definition of fmv_test visible.
> We shouldn't do that.  We should only emit resolvers for definitions.

Are you sure we want to generate resolver only for definitions?
Similarly to normal declarations, it's linkers job to resolve symbols and
eventually print errors.

I don't see why the linker bails out when the archive is used.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-05 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

Martin Liška  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |marxin at gcc dot 
gnu.org

--- Comment #8 from Martin Liška  ---
I'll take a look.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-05 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-code
 Status|WAITING |NEW
 CC||marxin at gcc dot gnu.org
  Known to fail||10.0, 8.3.1, 9.2.1

--- Comment #7 from Richard Biener  ---
The issue is that with a declaration like

double fmv_test (double *dArray, int size) __attribute__ ((__target_clones__
("avx2","avx","sse4.1","sse2","default")));

we're creating a resolver even if there's no definition of fmv_test visible.
We shouldn't do that.  We should only emit resolvers for definitions.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-05 Thread element at elementsofsound dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

--- Comment #6 from element at elementsofsound dot org  ---
I removed the internal_func() with the target_clones attribute, which caused
the last number digit of the symbols for fmv_test clones to match up between
object files, but errors still occur. I ran nm on the resulting archive and got
the below output, which may provide a clue. Note that the fmv_test target clone
functions have lower case 't' for local Text and don't end up in the archive
index. I removed the target_clones attribute and fmv_test ends up being a
global Text symbol (also pasted below), which builds fine:

nm -s fmv-test.a
Archive index:
main in main.o
fmv_test in main.o
fmv_test.resolver in main.o
fmv_normal_function in fmv-test.o
fmv_test.resolver in fmv-test.o
fmv_test in fmv-test.o

main.o:
 U __cpu_indicator_init
 U __cpu_model
 i fmv_test
 U fmv_test.avx.1
 U fmv_test.avx2.0
 U fmv_test.default.4
 W fmv_test.resolver
 U fmv_test.sse2.3
 U fmv_test.sse4_1.2
 U _GLOBAL_OFFSET_TABLE_
 T main
 U malloc
 U memset

fmv-test.o:
 U __cpu_indicator_init
 U __cpu_model
004d T fmv_normal_function
 i fmv_test
00a8 t fmv_test.avx.1
005b t fmv_test.avx2.0
 t fmv_test.default.4
 W fmv_test.resolver
0142 t fmv_test.sse2.3
00f5 t fmv_test.sse4_1.2
 U _GLOBAL_OFFSET_TABLE_




This is when fmv_test is defined without target_clones attribute:
Archive index:
main in main.o
fmv_test in fmv-test.o
fmv_normal_function in fmv-test.o

main.o:
 U fmv_test
 U _GLOBAL_OFFSET_TABLE_
 T main
 U malloc
 U memset

fmv-test.o:
004d T fmv_normal_function
 T fmv_test

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-04 Thread element at elementsofsound dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

--- Comment #5 from element at elementsofsound dot org  ---
(In reply to Andrew Pinski from comment #3)
> Maybe it is not clear but target_clones is only supposed to be on the
> definition rather just declarations too.

I'm not sure if I understood you exactly. The target_clones attribute is
defined in the header file for the definition of the function (for use by other
.c files). If I add it to the actual function, GCC complains, so I only have it
on the definition. I think that is what you meant.

One thing I have noticed is that when the .c files are compiled as individual
object files, objdump shows that the number at the end of the symbols for the
target clones do not match. However, when linking these object files with gcc
they somehow are resolved. If instead they are placed in an archive, then they
don't resolve. Not sure if this is related. It seems like this has something to
do more with the linking than gcc compilation of the C code. So perhaps my lack
of knowledge led me to file the bug for the wrong component?

See below:
objdump -t fmv-test.o | grep fmv_test
 l F .text  0062 fmv_test.default.9
0239 l F .text  0062 fmv_test.avx2.4
029b l F .text  0062 fmv_test.avx.5
02fd l F .text  0062 fmv_test.sse4_1.6
035f l F .text  0062 fmv_test.sse2.7
 ld  .text.fmv_test.resolver
.text.fmv_test.resolver
03c1 g   i   .text  0080
internal_func._GLOBAL___fmv_test.ifunc
  wF .text.fmv_test.resolver0080
fmv_test.resolver
 g   i   .text.fmv_test.resolver0080 fmv_test

objdump -t main.o | grep fmv_test
 ld  .text.fmv_test.resolver
.text.fmv_test.resolver
 g   i   .text.fmv_test.resolver0080 fmv_test
  wF .text.fmv_test.resolver0080
fmv_test.resolver
 *UND*   fmv_test.avx2.0
 *UND*   fmv_test.avx.1
 *UND*   fmv_test.sse4_1.2
 *UND*   fmv_test.sse2.3
 *UND*   fmv_test.default.4

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-04 Thread element at elementsofsound dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

--- Comment #4 from element at elementsofsound dot org  ---
(In reply to Andrew Pinski from comment #2)
> Try this:
> gcc -c fmv-test.c
> gcc -c main.c
> ar cr fmv-test.a  main.o fmv-test.o
> gcc -o fmv-test-borken fmv-test.a
> 
> It might be because the way linker processes archives and most likely not a
> bug.

I tried changing the order of the .o files in the ar command as shown, but same
errors occurred.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-04 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

--- Comment #3 from Andrew Pinski  ---
Maybe it is not clear but target_clones is only supposed to be on the
definition rather just declarations too.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-04 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2019-09-05
 Ever confirmed|0   |1

--- Comment #2 from Andrew Pinski  ---
Try this:
gcc -c fmv-test.c
gcc -c main.c
ar cr fmv-test.a  main.o fmv-test.o
gcc -o fmv-test-borken fmv-test.a

It might be because the way linker processes archives and most likely not a
bug.

[Bug c/91664] Undefined reference linker errors when static linking archive with gcc target_clones function multi-versioning

2019-09-04 Thread element at elementsofsound dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91664

--- Comment #1 from element at elementsofsound dot org  ---
Created attachment 46827
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46827=edit
Preprocessed file for main.c