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

Error building building example WASM filter #161

Closed
bravenut opened this issue Jan 15, 2024 · 3 comments
Closed

Error building building example WASM filter #161

bravenut opened this issue Jan 15, 2024 · 3 comments

Comments

@bravenut
Copy link

bravenut commented Jan 15, 2024

Hi,

when I follow the steps outlined in the README for the example on how to compile a C++ WASM filter, on running

docker run -v $PWD:/work -w /work wasmsdk:v2 /build_wasm.sh

The process exits with unsuccessfully because of some linker error. The full output of above docker run execution is:

Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
Adding directories to PATH:
PATH += /root/emsdk
PATH += /root/emsdk/upstream/emscripten
PATH += /root/emsdk/node/16.20.0_64bit/bin

Setting environment variables:
PATH = /root/emsdk:/root/emsdk/upstream/emscripten:/root/emsdk/node/16.20.0_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
EMSDK = /root/emsdk
EMSDK_NODE = /root/emsdk/node/16.20.0_64bit/bin/node
em++ --no-entry -s EXPORTED_FUNCTIONS=['_malloc'] --std=c++17 -O3 -flto -DPROXY_WASM_PROTOBUF_LITE=1 -I/sdk -I/usr/local/include --js-library /sdk/proxy_wasm_intrinsics.js myproject.cc /sdk/proxy_wasm_intrinsics_lite.pb.cc /sdk/struct_lite.pb.cc /sdk/proxy_wasm_intrinsics.cc /sdk/libprotobuf-lite.a -o myproject.wasm
cache:INFO: generating system asset: sysroot/lib/wasm32-emscripten/lto/crt1_reactor.o... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/crt1_reactor.o" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libGL.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libGL.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libal.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libal.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libhtml5.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libhtml5.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libstandalonewasm.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libstandalonewasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libstubs.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libstubs.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libnoexit.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libnoexit.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libdlmalloc.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libdlmalloc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libcompiler_rt.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libcompiler_rt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc++-noexcept.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc++-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc++abi-noexcept.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc++abi-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libsockets.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libsockets.a" for subsequent builds)
cache:INFO:  - ok
wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(common.o at 148324)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(int128.o at 215264)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(status.o at 255880)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(stringpiece.o at 288944)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(arena.o at 536568)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(generated_enum_util.o at 1047244)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(extension_set.o at 569832)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(generated_message_util.o at 1058004)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(strutil.o at 341272)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(message_lite.o at 1793592)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(implicit_weak_message.o at 1772184)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(repeated_field.o at 1973296)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(stringprintf.o at 312408)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(structurally_valid.o at 324240)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(wire_format_lite.o at 2351556)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(coded_stream.o at 2437540)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(strtod.o at 2498396)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(zero_copy_stream.o at 2512840)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(zero_copy_stream_impl.o at 2519904)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'


wasm-ld: warning: Linking two modules of different data layouts: '/sdk/libprotobuf-lite.a(zero_copy_stream_impl_lite.o at 2562216)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'

error: undefined symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_ (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_ may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/root/emsdk/node/16.20.0_64bit/bin/node /root/emsdk/upstream/emscripten/src/compiler.js /tmp/tmp9fxi9a7g.json' failed (returned 1)
/sdk/Makefile.base_lite:8: recipe for target 'myproject.wasm' failed
make: *** [myproject.wasm] Error 1
@krinkinmu
Copy link
Contributor

I've seen a very similar looking error when building an extension (though not from the example) with prebuilt protobuf libraries. In my case, it was ultimately resolved by rebuilding those libraries. I took provided Dockerfile to build the image and modified sdk_container.sh by adding the following at the end of the script:

git clone https://github.com/protocolbuffers/protobuf
cd protobuf
git checkout v3.9.1
git submodule update --init --recursive
./autogen.sh
emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto"
emmake make
cp src/.libs/libprotobuf-lite.a /sdk
cp src/.libs/libprotobuf.a /sdk
cd
rm -rf protobuf

This should build WASM version of the protobuf libraries and puts them into the /sdk directory inside the docker image instead of precompiled versions.

Note, I didn't test it extensively, but in the simple WASM filter I used it I didn't see any problems.

krinkinmu added a commit to krinkinmu/proxy-wasm-cpp-sdk that referenced this issue Oct 1, 2024
The way the script is currently it does not work (anymore). I'm aware
of two issues with the current setup:

1. emsdk underneath installs and uses Node JS and the version of Node JS
   is not pinned by the script and isn't tied to the version of the SDK
   used.

   As a result, emsdk moved to a newer version of Node JS than the one
   that was probably used when the scripts were created. This new
   version (it seems, the version currently being used is 18.20.3)
   requires a relatively fresh version of glibc which just isn't
   available in Ubuntu Bionic used as a base image. That results in
   obscure errors from CMake (see
   proxy-wasm#170)
2. for whatever reason, the version of the protobuf static libraries
   currently in the repo, don't seem to work. I don't really know
   how the issue happened, but there were at least 2 users that faced
   the problem (see
   proxy-wasm#161).

To resolve the first issue, we have a bunch of options:

1. Fix the version of emsdk
2. Fix the version of Node JS
3. Update the version of glibc

I figured I can combine options 1 and 3 together for the following
reasons:

1. Fixing the version of emsdk fixes the problem
2. The problem arised from the fact that the versions of software
   used in the build script are a bit old, so an update might be
   in order, even though we have other solutions to the problem.

> NOTE: It's my understanding that fixing emsdk version should also
> pin Node JS version, so if we deploy option 1, option 2 seem
> redundant.

For the second problem, I think there is only one ultimate solution
- not store binary artifacts in the repository and instead build
them from the sources in the repo.

It seems that in the past there was a concern that building protobuf
libraries takes a long time - it's still certainly the case. However,
I think we can compensate for that in two ways:

1. Drop WAVM - it does not seem like WAVM is still needed (the project
   itself appears to be dead and hasn't had any updates for at least 2
   years), but also one of the comments in
   proxy-wasm#158, that
   removed the WAVM from the docs, also suggests that three doesn't
   seem to be a good reason to keep WAVM in the SDK build script.
2. Take advantage of potential hardware threads in the system when
   calling make - most laptops or servers these days have multiple
   cores, so if we have to build protobuf libraries twice, we can
   speed it up by using more cores.

With all those changes made, the build time adds up to something like
32 minutes on my laptop, compared to the 48m without building
protobuf libraries from sources (and without adding -j option to make).
So I think the additional time spent on building protobuf library is
compensated by other changes.

Signed-off-by: Mikhail Krinkin <[email protected]>
krinkinmu added a commit to krinkinmu/proxy-wasm-cpp-sdk that referenced this issue Oct 7, 2024
The way the script is currently it does not work (anymore). I'm aware
of two issues with the current setup:

1. emsdk underneath installs and uses Node JS and the version of Node JS
   is not pinned by the script and isn't tied to the version of the SDK
   used.

   As a result, emsdk moved to a newer version of Node JS than the one
   that was probably used when the scripts were created. This new
   version (it seems, the version currently being used is 18.20.3)
   requires a relatively fresh version of glibc which just isn't
   available in Ubuntu Bionic used as a base image. That results in
   obscure errors from CMake (see
   proxy-wasm#170)
2. for whatever reason, the version of the protobuf static libraries
   currently in the repo, don't seem to work. I don't really know
   how the issue happened, but there were at least 2 users that faced
   the problem (see
   proxy-wasm#161).

To resolve the first issue, we have a bunch of options:

1. Fix the version of emsdk
2. Fix the version of Node JS
3. Update the version of glibc

I figured I can combine options 1 and 3 together for the following
reasons:

1. Fixing the version of emsdk fixes the problem
2. The problem arised from the fact that the versions of software
   used in the build script are a bit old, so an update might be
   in order, even though we have other solutions to the problem.

> NOTE: It's my understanding that fixing emsdk version should also
> pin Node JS version, so if we deploy option 1, option 2 seem
> redundant.

For the second problem, I think there is only one ultimate solution
- not store binary artifacts in the repository and instead build
them from the sources in the repo.

It seems that in the past there was a concern that building protobuf
libraries takes a long time - it's still certainly the case. However,
I think we can compensate for that in two ways:

1. Drop WAVM - it does not seem like WAVM is still needed (the project
   itself appears to be dead and hasn't had any updates for at least 2
   years), but also one of the comments in
   proxy-wasm#158, that
   removed the WAVM from the docs, also suggests that three doesn't
   seem to be a good reason to keep WAVM in the SDK build script.
2. Take advantage of potential hardware threads in the system when
   calling make - most laptops or servers these days have multiple
   cores, so if we have to build protobuf libraries twice, we can
   speed it up by using more cores.

With all those changes made, the build time adds up to something like
32 minutes on my laptop, compared to the 48m without building
protobuf libraries from sources (and without adding -j option to make).
So I think the additional time spent on building protobuf library is
compensated by other changes.

Signed-off-by: Mikhail Krinkin <[email protected]>
martijneken pushed a commit that referenced this issue Oct 10, 2024
* Refresh and fix SDK Docker image build scripts

The way the script is currently it does not work (anymore). I'm aware
of two issues with the current setup:

1. emsdk underneath installs and uses Node JS and the version of Node JS
   is not pinned by the script and isn't tied to the version of the SDK
   used.

   As a result, emsdk moved to a newer version of Node JS than the one
   that was probably used when the scripts were created. This new
   version (it seems, the version currently being used is 18.20.3)
   requires a relatively fresh version of glibc which just isn't
   available in Ubuntu Bionic used as a base image. That results in
   obscure errors from CMake (see
   #170)
2. for whatever reason, the version of the protobuf static libraries
   currently in the repo, don't seem to work. I don't really know
   how the issue happened, but there were at least 2 users that faced
   the problem (see
   #161).

To resolve the first issue, we have a bunch of options:

1. Fix the version of emsdk
2. Fix the version of Node JS
3. Update the version of glibc

I figured I can combine options 1 and 3 together for the following
reasons:

1. Fixing the version of emsdk fixes the problem
2. The problem arised from the fact that the versions of software
   used in the build script are a bit old, so an update might be
   in order, even though we have other solutions to the problem.

> NOTE: It's my understanding that fixing emsdk version should also
> pin Node JS version, so if we deploy option 1, option 2 seem
> redundant.

For the second problem, I think there is only one ultimate solution
- not store binary artifacts in the repository and instead build
them from the sources in the repo.

It seems that in the past there was a concern that building protobuf
libraries takes a long time - it's still certainly the case. However,
I think we can compensate for that in two ways:

1. Drop WAVM - it does not seem like WAVM is still needed (the project
   itself appears to be dead and hasn't had any updates for at least 2
   years), but also one of the comments in
   #158, that
   removed the WAVM from the docs, also suggests that three doesn't
   seem to be a good reason to keep WAVM in the SDK build script.
2. Take advantage of potential hardware threads in the system when
   calling make - most laptops or servers these days have multiple
   cores, so if we have to build protobuf libraries twice, we can
   speed it up by using more cores.

With all those changes made, the build time adds up to something like
32 minutes on my laptop, compared to the 48m without building
protobuf libraries from sources (and without adding -j option to make).
So I think the additional time spent on building protobuf library is
compensated by other changes.

Signed-off-by: Mikhail Krinkin <[email protected]>

* Update emsdk version to 3.1.67 in Bazel configuration

This CL mostly follows the instructions in
https://github.com/emscripten-core/emsdk/blob/main/bazel/README.md.
Even so, there are a few things that are worth mentioning:

1. I tested the changes locally and in my tests
   incompatible_enable_cc_toolchain_resolution bazel flag made no
   difference (e.g. everything builds with or without the flag);
   I still keep it though because instructions say that it should
   be there and it does not cause any harm.
2. I don't think that we still need to patch emsdk to exclude npm
   modules from the toolchain, because it appears that upstream
   already removed those as a toolchain dependency in
   emscripten-core/emsdk#1045.

It's worth noting, that even though I don't think that emsdk patch
is still needed, I actually wasn't able to reproduce the problem
reported in #149
locally without the emsdk.patch even with the current version of
emsdk used by C++ SDK.

Signed-off-by: Mikhail Krinkin <[email protected]>

* Update building.md to match updated sdk_container.sh

This is a followup to the previous commits that refreshed the build
scripts and emsdk. This change reconciles the docs with the current
state of the build scripts.

Signed-off-by: Mikhail Krinkin <[email protected]>

---------

Signed-off-by: Mikhail Krinkin <[email protected]>
@krinkinmu
Copy link
Contributor

I think this issue is addressed by #172.

@martijneken @mpwarres it does not seem that I can close this bug (since I didn't open it), but I faced the same issue and it was addressed for my be rebuilding libprotobuf, so I think the PR fixes it.

@mpwarres
Copy link
Contributor

Closing per previous comment. Thanks @krinkinmu !

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

No branches or pull requests

3 participants