Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embinded class export missing (by dead code elimination?) #5537

Closed
kwonoj opened this issue Aug 28, 2017 · 3 comments
Closed

embinded class export missing (by dead code elimination?) #5537

kwonoj opened this issue Aug 28, 2017 · 3 comments

Comments

@kwonoj
Copy link

kwonoj commented Aug 28, 2017

I maybe doing something stupid but couldn't figure out myself, so would like to ask some help.

I've exported one class via embind, as below:

  EMSCRIPTEN_BINDINGS(cld3) {
    class_<chrome_lang_id::NNetLanguageIdentifier>("NNetLanguageIdentifier")
      .constructor<int, int>()
      .class_property("kMinNumBytesToConsider", &chrome_lang_id::NNetLanguageIdentifier::kMinNumBytesToConsider)
      .class_property("kMaxNumBytesToConsider", &chrome_lang_id::NNetLanguageIdentifier::kMaxNumBytesToConsider)
      .class_property("kMaxNumInputBytesToConsider", &chrome_lang_id::NNetLanguageIdentifier::kMaxNumInputBytesToConsider)
      .class_property("kReliabilityThreshold", &chrome_lang_id::NNetLanguageIdentifier::kReliabilityThreshold)
      .class_property("kReliabilityHrBsThreshold", &chrome_lang_id::NNetLanguageIdentifier::kReliabilityHrBsThreshold)
      .function("FindLanguage", &chrome_lang_id::NNetLanguageIdentifier::FindLanguage)
      .function("FindTopNMostFreqLangs", &chrome_lang_id::NNetLanguageIdentifier::FindTopNMostFreqLangs)
      ;
}

and build it via emcc,

em++ \
-O3 \
-Oz \
--llvm-lto 1 \
-s MODULARIZE=1 \
-s NO_EXIT_RUNTIME=1 \
-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
--bind \
./.libs/libprotobuf.bc \
./libcld3.a \
--pre-js ./preprocessor.js \

and output does not contains exported class in module.

If I created dummy fn to hold reference of class only

  void dummy() {
    chrome_lang_id::NNetLanguageIdentifier* dummy;
    throw "should not be called";
  }

and export it explicitly via -s EXPORTED_FUNCTIONS="['_dummy']" , then embinded class also exported as well. This makes me guess if this is somehow related with dead code elimination, but couldn't figure out how to prevent this. Am I missing some configurations? Repo I've used for this is at https://github.com/kwonoj/docker-cld3-wasm/tree/master/build, specifically https://github.com/kwonoj/docker-cld3-wasm/blob/master/build/build.sh / https://github.com/kwonoj/docker-cld3-wasm/blob/master/build/embind.patch .

@kripken kripken added the embind label Aug 28, 2017
@AlexPerrot
Copy link
Contributor

I've had a similar issue.
Based on the repository you linked, I assume your binding are in libcld3.a.
IIRC, linking .a archives only links used symbols, so bindings should be defined in a .bc file, since by definition they are not used in the compiled code.

@bzz
Copy link

bzz commented Apr 2, 2018

It might be a different case of binding a class vs a single function, but

by building \w -s MODULARIZE=1 -s 'EXPORT_NAME="CLD3"', an example of `

CLD3().langId(utf.encode(text))

works for me.

@stale
Copy link

stale bot commented Sep 19, 2019

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Sep 19, 2019
@stale stale bot closed this as completed Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants