DevHeads.net

Issue with undefined reference with assembler in rr

I was working on packaging rr [1] and one of the tests [2] fails to build
when optimizations are turned on. I've reduced it to the following and
still been able to reproduce the issue:

static const float xmm0 = 10;

int main() {
__asm__ __volatile__(
#if __i386__
"movss xmm0, %xmm0\n\t"
#elif __x86_64__
"movss xmm0(%rip), %xmm0\n\t"
#else
#error unexpected architecture
#endif
);

return 0;
}

Here's the output on F23 x86_64:
$ gcc fxregs.c -O0
$ gcc fxregs.c -O1
/tmp/cccdze3O.o: In function `main':
fxregs.c:(.text+0x4): undefined reference to `xmm0'
collect2: error: ld returned 1 exit status

Is this a gcc bug or is there something that I need to do in the build to
get the tests to build without error?

Thanks,
Dave

[1]: <a href="https://github.com/mozilla/rr" title="https://github.com/mozilla/rr">https://github.com/mozilla/rr</a>
[2]:
<a href="https://github.com/mozilla/rr/blob/9a532fd786f6378d6b8c2cd70a04731341cf0609/src/test/fxregs.c" title="https://github.com/mozilla/rr/blob/9a532fd786f6378d6b8c2cd70a04731341cf0609/src/test/fxregs.c">https://github.com/mozilla/rr/blob/9a532fd786f6378d6b8c2cd70a04731341cf0...</a>

Comments

Re: Issue with undefined reference with assembler in rr

By Richard W.M. Jones at 01/14/2016 - 08:39

On Wed, Jan 13, 2016 at 10:00:08PM -0700, Dave Johansen wrote:
I think it's a bug in your test. GCC is just optimizing away the xmm0
variable because it cannot see "inside" the asm to know that it is
being used.

This works for me. I believe you don't need the #if conditional
either since this should work on any x86 machine:

__asm__ __volatile__ ("movss %0, %%xmm0\n\t" : : "m" (xmm0) : "%xmm0");

Rich.

Re: Issue with undefined reference with assembler in rr

By Dave Johansen at 01/14/2016 - 23:21

On Thu, Jan 14, 2016 at 5:39 AM, Richard W.M. Jones < ... at redhat dot com>
wrote:

Yes, it appears that you're right. Removing the static fixes the
compilation issue when optimizations are enabled. I'll submit a patch
upstream.
Thanks,
Dave