Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

AVX extensions required for bindings on win32-x64 #1854

Closed
algol-fi opened this issue Jan 11, 2017 · 9 comments
Closed

AVX extensions required for bindings on win32-x64 #1854

algol-fi opened this issue Jan 11, 2017 · 9 comments

Comments

@algol-fi
Copy link

Installing node-sass via npm install on Windows Server 2012:

npm install node-sass

downloads a native bindings library for win32-x64. This library, when node-sass is run on a box that does not have AVX enabled, exits with a STATUS_ILLEGAL_INSTRUCTION (0xC000001D). Is it possible to have a different version (compiled without AVX instructions) of the bindings installed if the platform does not support them?

System information:

npm -v
3.10.10
node -v
v6.9.3
node -p process.versions
{ http_parser: '2.7.0',
node: '6.9.3',
v8: '5.1.281.89',
uv: '1.9.1',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '57.1',
modules: '48',
openssl: '1.0.2j' }
node -p process.platform
win32
node -p process.arch
x64
node -p "require('node-sass').info"
node-sass 4.2.0 (Wrapper) [JavaScript]
libsass 3.4.3 (Sass Compiler) [C/C++]
npm ls node-sass
`-- [email protected]

@algol-fi algol-fi changed the title AVX extensions required for bindings AVX extensions required for bindings on win32-x64 Jan 11, 2017
@xzyfer
Copy link
Contributor

xzyfer commented Jan 18, 2017

@am11 are you able to translate this for the non-windows folk?

@am11
Copy link
Contributor

am11 commented Jan 18, 2017

@algol-fi, some questions:

  • how did you determine that it's faulting at the AVX instructions?
    • one way to be sure is to recompile with /mapinfo:exports linker flag, enable coredumps and execute the app. When crash happens, lookup the address in map file to get the name of function where crash happened. http://www.codeproject.com/KB/debug/mapfile.aspx.
    • another way is to run node in cmd, attach the VS debugger to this running node.exe process, once attached, run require('node-sass').info in the REPL and see where in our code it throws.
  • do you get this failure with other / older versions of node-sass: npm install [email protected] for example?

@algol-fi
Copy link
Author

I determined where the fault is happening by running

node.exe node-sass mystyle.sass

under windbg. The content of mystyle.sass is probably not very relevant, but I can try to reproduce the effect with a minimal example.

The stack trace is the following:

 # Child-SP          RetAddr           Call Site
00 00000069`6423db50 00007ff9`2ca12fc4 binding!pow+0xba1 [f:\dd\vctools\crt\fpw32\tran\amd64\pow.asm @ 1616]
01 00000069`6423dc20 00007ff9`2cae86e7 binding!Sass::round+0x54 [s:\node_modules\node-sass\src\libsass\src\util.cpp @ 18]
02 00000069`6423dc70 00007ff9`2ca662be binding!Sass::Inspect::operator()+0x227 [s:\node_modules\node-sass\src\libsass\src\inspect.cpp @ 606]
03 00000069`6423dfc0 00007ff9`2ca2b27c binding!Sass::AST_Node::to_string+0xfe [s:\node_modules\node-sass\src\libsass\src\ast.cpp @ 2301]
04 00000069`6423e2d0 00007ff9`2ca2afdb binding!Sass::Eval::interpolation+0x8ec [s:\node_modules\node-sass\src\libsass\src\eval.cpp @ 1139]
05 00000069`6423e530 00007ff9`2ca2b923 binding!Sass::Eval::interpolation+0x64b [s:\node_modules\node-sass\src\libsass\src\eval.cpp @ 1112]
06 00000069`6423e790 00007ff9`2ca23b49 binding!Sass::Eval::operator()+0x483 [s:\node_modules\node-sass\src\libsass\src\eval.cpp @ 1168]
07 00000069`6423e910 00007ff9`2caae100 binding!Sass::Eval::operator()+0xf9 [s:\node_modules\node-sass\src\libsass\src\eval.cpp @ 447]
08 00000069`6423ead0 00007ff9`2cab3e3a binding!Sass::Expand::operator()+0x6f0 [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 321]
09 00000069`6423ebb0 00007ff9`2caae84b binding!Sass::Expand::append_block+0x11a [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 783]
0a 00000069`6423ec10 00007ff9`2cab3e3a binding!Sass::Expand::operator()+0x2eb [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 357]
0b 00000069`6423ed80 00007ff9`2caae84b binding!Sass::Expand::append_block+0x11a [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 783]
0c 00000069`6423ede0 00007ff9`2cab3e3a binding!Sass::Expand::operator()+0x2eb [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 357]
0d 00000069`6423ef50 00007ff9`2caae84b binding!Sass::Expand::append_block+0x11a [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 783]
0e 00000069`6423efb0 00007ff9`2cab3e3a binding!Sass::Expand::operator()+0x2eb [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 357]
0f 00000069`6423f120 00007ff9`2caae84b binding!Sass::Expand::append_block+0x11a [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 783]
10 00000069`6423f180 00007ff9`2cab3e3a binding!Sass::Expand::operator()+0x2eb [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 357]
11 00000069`6423f2f0 00007ff9`2caabaa6 binding!Sass::Expand::append_block+0x11a [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 783]
12 00000069`6423f350 00007ff9`2ca09e19 binding!Sass::Expand::operator()+0x216 [s:\node_modules\node-sass\src\libsass\src\expand.cpp @ 87]
13 00000069`6423f430 00007ff9`2ca0938b binding!Sass::Context::compile+0x349 [s:\node_modules\node-sass\src\libsass\src\context.cpp @ 655]
14 00000069`6423f760 00007ff9`2c9f94f6 binding!Sass::File_Context::parse+0x55b [s:\node_modules\node-sass\src\libsass\src\context.cpp @ 584]
15 00000069`6423f980 00007ff9`2c9f9cf1 binding!Sass::sass_parse_block+0x156 [s:\node_modules\node-sass\src\libsass\src\sass_context.cpp @ 228]
16 00000069`6423fa70 00007ff9`2c9f98c0 binding!sass_compiler_parse+0x61 [s:\node_modules\node-sass\src\libsass\src\sass_context.cpp @ 471]
17 00000069`6423faa0 00007ff9`2c9f9c72 binding!sass_compile_context+0x30 [s:\node_modules\node-sass\src\libsass\src\sass_context.cpp @ 360]
18 00000069`6423fae0 00007ff6`c5831c57 binding!sass_compile_file_context+0xd2 [s:\node_modules\node-sass\src\libsass\src\sass_context.cpp @ 458]
19 00000069`6423fb40 00007ff6`c581de14 node!uv_fs_poll_getpath+0x627
1a 00000069`6423fb80 00007ff6`c5f92211 node!uv_once+0x114
1b 00000069`6423fbd0 00007ff9`4ab713d2 node!uncompress+0x1db41
1c 00000069`6423fc00 00007ff9`4bf754e4 KERNEL32!BaseThreadInitThunk+0x22
1d 00000069`6423fc30 00000000`00000000 ntdll!RtlUserThreadStart+0x34

The referenced pow.asm is using AVX, since the current executing instruction is

00007ff9`2cb3d691 c5fb11442410    vmovsd  qword ptr [rsp+10h],xmm0 ss:00000069`6423db60=0000000000000008

and c5 is the 2-byte VEX prefix used for AVX instructions.

@am11
Copy link
Contributor

am11 commented Jan 18, 2017

Thanks for the details and stack trace @algol-fi, it does look like the case. The exception site (std:pow call) is: https://github.com/sass/libsass/blob/b28de0/src/util.cpp#L18.

Can you please try rebuilding the source locally, to see if this issue is still reproducible (i.e. confirming our compiler/linker flags are all set correctly and that we only need a build machine for non-SSE128 binaries). Instructions to build are available here: https://github.com/sass/node-sass#rebuilding-binaries (you will need VC build tools or VS2013+).

@algol-fi
Copy link
Author

I rebuilt the source locally, replaced the binding.node in the package with the built one and everything seems to be working fine. No illegal instruction and a correct CSS file in output.

@am11
Copy link
Contributor

am11 commented Jan 23, 2017

Thanks for the confirmation @algol-fi!

@xzyfer, this was a bug in VS2013, that was fixed in VS2015 https://connect.microsoft.com/VisualStudio/Feedback/Details/981479 (see last comment from Microsoft team)

Solution:

// in LibSass -> util.cpp, after #include<cmath> statement:
#if defined(_MSC_VER) && _MSC_VER >= 1800 && _MSC_VER < 1900 && defined(_M_X64) || defined(__x86_64__)
  // FIXME: Remove this workaround when we switch to VS2015+.
  _set_FMA3_enable(0);
#endif

FTR, the AVX instructions were also causing issues in node.js (when it is turned off in Boot Configuration Data by the user/admin: bcdedit tweaking), and was fixed after they moved to VS2015 nodejs/node#7261 (without _set_FMA3_enable hack). Perhaps, we should reconsider our stance about VS2013 and move forward? Even Chromimum guys are building with VS2015 Update 3 [ref] (since September 8, 2016). :)

@saper
Copy link
Member

saper commented Jan 26, 2017

@am11 thank you for your analysis. I believe the stacktrace is correct and identifies the problem. We should switch to VS2015 for all nodes starting from I believe v6.2.0 - this is when node itself switched to VS2015.

The next workaround I would try is to use msvcr120.dll from vs2015, if that works at all.

@xzyfer
Copy link
Contributor

xzyfer commented Jan 27, 2017

Nice work @am11. I've just read through those links and I agree with @saper that we should try to build v6+ with VS2015.

xzyfer added a commit to xzyfer/node-sass that referenced this issue Jan 27, 2017
Node change to Visual Studio 2015 when Node 6 went to LTS.

See nodejs/node#7989
Fixes sass#1854
xzyfer added a commit to xzyfer/node-sass that referenced this issue Jan 27, 2017
Node change to Visual Studio 2015 when Node 6 went to LTS.

See nodejs/node#7989
Fixes sass#1854
xzyfer added a commit to xzyfer/node-sass that referenced this issue Jan 27, 2017
Node change to Visual Studio 2015 when Node 6 went to LTS.

See nodejs/node#7989
Fixes sass#1854
@mgreter
Copy link
Contributor

mgreter commented Jan 29, 2017

@am11 can you create a PR for libsass to include the hotfix? I guess it doesn't hurt to include it if it fixes a possible bug. I guess there are no real side effects from this change? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants