error compiling on gcc/x64 with address sanitizer

Recommended Posts

Is this the right place to report errors in AngelScript?

I have found a compile error that affects both v2.31.2 and the latest svn.  I am using gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 running on Lubuntu 16.04.3 LTS.  The error is in as_callfunc_x64_gcc.cpp.  Without address sanitizer, the file compiles correctly, but with address sanitizer, I get the following error message:

angelscript/source/as_callfunc_x64_gcc.cpp: In function ‘asQWORD X64_CallFunction(const asQWORD*, int, funcptr_t, asQWORD&, bool)’:
angelscript/source/as_callfunc_x64_gcc.cpp:162:82: error: ‘asm’ operand has impossible constraints
  "%rdi", "%rsi", "%rax", "%rdx", "%rcx", "%r8", "%r9", "%r10", "%r11", "%r15");

The root cause appears to be register exhaustion due to address sanitizer reserving some registers for its own use.  Changing the "r" constraints on the input parameters to "g" constraints appears to fix the problem:

Index: angelscript/source/as_callfunc_x64_gcc.cpp
--- angelscript/source/as_callfunc_x64_gcc.cpp	(revision 2407)
+++ angelscript/source/as_callfunc_x64_gcc.cpp	(working copy)
@@ -157,7 +157,7 @@
 		"  movq %%rdx, %4 \n"
 		"endcall: \n"
-		: : "r" ((asQWORD)cnt), "r" (args), "r" (func), "m" (retQW1), "m" (retQW2), "m" (returnFloat)
+		: : "g" ((asQWORD)cnt), "g" (args), "g" (func), "m" (retQW1), "m" (retQW2), "m" (returnFloat)
 		: "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", 
 		  "%rdi", "%rsi", "%rax", "%rdx", "%rcx", "%r8", "%r9", "%r10", "%r11", "%r15");


Share this post

Link to post
Share on other sites

Yes, this is the correct place for reporting problems on AngelScript :)

Thanks for letting me know about the problem and the potential solution. I'll be sure to check it out and if it is correct make the changes as you suggested it.

I'll report back when the problem is fixed.


Share this post

Link to post
Share on other sites

I didn't encounter any problem compiling the library using address sanitizer with GNUC and Ubuntu 64bit.

What other compiler options are you using? Perhaps it is a specific combination of compiler options that causes the problem you reported.

I used the following:

g++ -m64 -std=c++11 -fsanitize=address -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_x64_gcc.o -c ../../source/as_callfunc_x64_gcc.cpp




Share this post

Link to post
Share on other sites

I used the bare minimum to compile the file, i.e. "g++ -fsanitize=address -c angelscript/source/as_callfunc_x64_gcc.cpp". However, I am getting the same error when I use your command line. Maybe you're testing on a different version of gcc? Like I wrote in my original post, I'm running gcc 5.4.0 on Lubuntu 16.4 LTS (Xenial Xerus).

Edited by a light breeze

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now