Skip to content

Conversation

arunetm-zz
Copy link
Contributor

Enabling Webassembly to build with Linux

Enabling Webassembly to build with Linux
Copy link
Collaborator

@obastemur obastemur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any place, this module is part of resulting binary. Is that intended?

@arunetm-zz
Copy link
Contributor Author

@Cellule @MikeHolman please review.

mbstowcs_s(&convertedChars, buf, idSize + 1, sectionName, _TRUNCATE);
buf[idSize] = 0;
TRACE_WASM_SECTION(_u("Section Header: %s, length = %u (0x%x)"), buf, sectionSize, sectionSize);
TRACE_WASM_SECTION(_u("Section Header: %s, length = %u (0x%x)"), sectionName, sectionSize, sectionSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sectionName is a char* does it work in with a printf function using a char16 format string ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if %S will work here to print char string. If that doesn't, try use utf8::NarrowToWide

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had changed sectionName to wchar_t to avoid the use of mbstowcs_s in linux to get around a method not defined error. Will change this back to char16* and look for another workaround to make it compile in xplat.

@@ -27,8 +27,8 @@ namespace Wasm
{
SectionFlag flag;
SectionCode precedent;
char16* name;
char* id;
const wchar_t* name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the point of char16 was for cross plat

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Please try avoid wchar_t.


In reply to: 83068286 [](ancestors = 83068286)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this back. The use of "mbstowcs_s" was giving pain in Linux, will look for a workaround.

@Cellule
Copy link
Contributor

Cellule commented Oct 12, 2016

@dotnet-bot test linux tests please

@Cellule
Copy link
Contributor

Cellule commented Oct 12, 2016

@obastemur I'm sorry for my ignorance, but what does it mean for a module to be part of the resulting binary or not?

@@ -0,0 +1,20 @@
add_library (Chakra.WasmReader OBJECT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unneeded extra blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove.

#define LAYOUT_TYPE_WMS_REG2(layout, t0, t1) \
template <typename SizePolicy> struct OpLayoutT_##layout\
{\
t0##LayoutType LAYOUT_PREFIX_##t0()0;\
t1##LayoutType LAYOUT_PREFIX_##t1()1;\
t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
Copy link

@jianchun jianchun Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\ [](start = 23, length = 44)

Is this to have () in a field name (weird, why do we want that)? From the change I assume directly ##0 doesn't work, right? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

() is part of the macro name and it is not going to be part of the actual field name. The tricky part was to have the number to be appended to the end of the filed name to avoid naming conflicts.
##0 does not work as ## expects strings as operands.

@jianchun
Copy link

#ifdef ENABLE_WASM

Is ENABLE_WASM turned on Linux?


Refers to: lib/WasmReader/WasmSection.h:8 in de4503e. [](commit_id = de4503e, deletion_comment = False)

@jianchun
Copy link

    if (!memcmp(SectionInfo::All[i].id, sectionName, idSize))

Does "sectionId" sound a better name for this variable (I was confused and thought this was the same as sectionInfo.name)?


Refers to: lib/WasmReader/WasmBinaryReader.cpp:167 in de4503e. [](commit_id = de4503e, deletion_comment = False)

@jianchun
Copy link

@obastemur I'm sorry for my ignorance, but what does it mean for a module to be part of the resulting binary or not?

The new Chakra.WasmReader lib is not linked to anything. Kind of related to my other question -- is it enabled on Linux? Suppose it would link to ch and Jsrt.lib?

@arunetm-zz
Copy link
Contributor Author

@jianchun, ENABLE_WASM is turned on for Linux. Its on for all debug/test builds.
@Cellule, can you please verify whether this is the right thing to do?

@arunetm-zz
Copy link
Contributor Author

@obastemur, @jianchun Forgive my ignorance, I missed the step to link Cahkra.WasmReader lib for Linux. Will make this change and update the PR.
Thanks!

@Cellule
Copy link
Contributor

Cellule commented Oct 12, 2016

@arunetm We don't need to enable WebAssembly on Linux right now. I don't see the harm, but regardless it is intended to be enable only in debug and test builds at the moment since it is still a WIP

@MikeHolman
Copy link
Contributor

@Cellule I think it is useful to have on Linux, if for no other reason than to be able to fuzz with AFL.

@Cellule
Copy link
Contributor

Cellule commented Oct 13, 2016

@MikeHolman Yes I believe it would be good to have, but what I am wondering is, does it have to be a blocker to merge WebAssembly to master ?

@Cellule
Copy link
Contributor

Cellule commented Oct 13, 2016

Any update on this ?

@arunetm-zz
Copy link
Contributor Author

@Cellule Currently fixing a linker error and looking for a workaround for mbstowcs_s.
Will update the PR soon I get to a solution.

@arunetm-zz
Copy link
Contributor Author

The linker fails to find WasmLibrary::WasmDeferredParseExternalThunk defined in Language/amd64/amd64_Thunks.asm (called from Library/WasmLibrary.cpp). CMakeLists.txt includes only Language/amd64/amd64_Thunks.S and we don't have the WasmDeferredParseExternalThunk defined in it (hence this issue)
Forgive my ignorance of cmake, but adding amd64_Thunks.asm to CMakeLists.txt doesn't seem to recognize the format and it leads to many failures.

@jianchun. This is a long shot question but, is it possible to allow CMake to recognize the .asm format and include Language/amd64/amd64_Thunks.asm for the build?

@Cellule Is there a reason why we have WasmDeferredParseExternalThunk defined in Languages/amd64/amd64_Thunks.asm instead of Library/amd64/JavaScriptFunction.asm since its being called from Library/WasmLibrary.cpp only? Should we move it?
Also to have amd64_Thunks.S (gnu compliant) implement WasmDeferredParseExternalThunk, does it need to be written again from scratch?
thanks in advance.

@jianchun
Copy link

@arunetm WasmDeferredParseExternalThunk needs to be rewritten in amd64_Thunks.S. You can see that by comparing amd64_Thunks.asm and amd64_Thunks.S.

@arunetm-zz
Copy link
Contributor Author

@Cellule @MikeHolman. I'm starting to rewrite the WasmDeferredParseExternalThunk inside amd64_Thunks.S (or any other possible missing pieces) to make it available for xplat builds. Is this path beneficial to do this at this point or should we disable WebAssembly in Linux in preparation to the master integration?

@MikeHolman
Copy link
Contributor

@arunetm I think it's beneficial to do, but for the merge to master let's just disable on x-plat.

@Cellule Cellule mentioned this pull request Oct 15, 2016
@Cellule Cellule merged commit de4503e into chakra-core:WebAssembly_Stage Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants