proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
140 stars 68 forks source link

Error building building example WASM filter #161

Closed bravenut closed 1 week ago

bravenut commented 9 months ago

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 commented 1 month ago

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 commented 1 week ago

I think this issue is addressed by https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/pull/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 commented 1 week ago

Closing per previous comment. Thanks @krinkinmu !