wasm-ld: error: initial memory too small, 18317952 bytes needed - cmake

I want to compile ffmpeg to wasm.After downloading FFMPEG and emsdk source code,I used command below to build.
emconfigure ./configure --cc="emcc" --enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic \
--disable-ffplay --disable-ffprobe --disable-asm --disable-doc --disable-devices --disable-pthreads --disable-w32threads --disable-network \
--disable-hwaccels --disable-parsers --disable-bsfs --disable-debug --disable-protocols --disable-indevs --disable-outdevs --enable-protocol=file --ranlib="emranlib"
emmake make
then I got such error:
emcc: warning: ignoring unsupported linker flag: `-rpath-
link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavfo
rmat:libavcodec:libavutil:libavresample` [-Wlinkflags]
wasm-ld: error: initial memory too small, 18317952 bytes needed
emcc: error: '/home/ubuntu/emsdk/upstream/bin/wasm-ld -o
/tmp/emscripten_temp_t3l4sg_k/ffmpeg_g.wasm -Llibavcodec -Llibavdevice
-Llibavfilter -Llibavformat -L/home/ubuntu/emsdk/upstream/emscripten
/system/local/lib -Llibavresample -L/home/ubuntu/emsdk/upstream/emscripten
/system/lib -Llibavutil -L/home/ubuntu/emsdk/upstream/emscripten
/cache/wasm -Llibpostproc -Llibswscale -Llibswresample -z noexecstack
fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
fftools/cmdutils.o fftools/ffmpeg.o libavdevice/libavdevice.a
libavfilter/libavfilter.a libavformat/libavformat.a
libavcodec/libavcodec.a libswresample/libswresample.a
libswscale/libswscale.a libavutil/libavutil.a /home/ubuntu/emsdk/upstream
/emscripten/cache/wasm/libc.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libcompiler_rt.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc++-noexcept.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc++abi-noexcept.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libdlmalloc.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libpthread_stub.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc_rt_wasm.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm
-enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --import-
memory --import-table --strip-debug --export main --export malloc --export
free --export stackSave --export stackRestore --export stackAlloc --export
__data_end --export __wasm_call_ctors --export fflush --export
__errno_location --export _get_tzname --export _get_daylight --export
_get_timezone --export memalign --export memset -z stack-size=5242880
--initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed
How can I change the default emcc initial-memory setting?

There is an answer here in this github issue.
The quickest fix has been to set the total memory flag to -s TOTAL_MEMORY=num_bytes. Just make sure the number you pass is a multiple of 64kb or it won't compile.
Also if you intend to alter the codebase I would round up as this size for "bytes needed" may change , in my case it was bound by 60MB (for code unrelated to this).

Related

sse2 instruction set not enabled

CC=g++
CFLAGS=-O3 -c -Wall
DFLAGS=-g -Wall
LDFLAGS= -lz -lm -lpthread
KSWSOURCE=ksw.c
ALGNSOURCES=main.cpp aligner.cpp graph.cpp readfl.cpp hash.cpp form.cpp btree.cpp conLSH.cpp
INDSOURCES=whash.cpp genhash.cpp formh.cpp conLSH.cpp
INDOBJECTS=$(INDSOURCES:.cpp=.o) $(KSWSOURCE:.c=.o)
ALGNOBJECTS=$(ALGNSOURCES:.cpp=.o) $(KSWSOURCE:.c=.o)
INDEXER=conLSH-indexer
ALIGNER=conLSH-aligner
all: $(INDSOURCES) $(ALGNSOURCES) $(KSWSOURCE) $(ALIGNER) $(INDEXER)
$(ALIGNER): $(ALGNOBJECTS)
$(CC) $(ALGNOBJECTS) -o $# $(LDFLAGS)
$(INDEXER): $(INDOBJECTS)
$(CC) $(INDOBJECTS) readfl.o -o $# $(LDFLAGS)
debug:
$(CC) $(DFLAGS) $(ALGNSOURCES) $(KSWSOURCE) $(LDFLAGS)
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
.c.o:
$(CC) $(CFLAGS) $< -o $#
clean:
rm -rf *.o $(ALIGNER) $(INDEXER) a.out
I have the above makefile but I am getting an error
/usr/lib/gcc/i686-linux-gnu/4.8/include/emmintrin.h:31:3: error: #error "SSE2 instruction set not enabled"
# error "SSE2 instruction set not enabled"
From what I understand and googled this is a flag for parallel computation.
I tried from other posts with the same problem to either include:
CXXFLAGS=-03 -c Wall -mfpmath=sse
OR:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3")
but without any success. Can you help?
I am not sure a CXX flags is necessary because a lot of (probably) cascading errors are shown in ksw like,
ksw.c:49:2: error: ‘__m128i’ does not name a type
__m128i *qp, *H0, *H1, *E, *Hmax;
-msse2 is the specific option, so passing that to GCC will work, if you get your build scripts set up to actually do that. https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#x86-Options
Or better, use -march=native to enable everything your CPU has, if you're building for local use, not for distributing a binary that might have to work on an old-but-not-ancient CPU. (Of course, if you care about performance, it's weird to be building for 32-bit mode. SSE2 is baseline for x86-64. Unless your CPU is too old to support SSE2, e.g. a Pentium III. Or for example, there are embedded x86 CPUs without SSE, like AMD Geode. In that case, a binary built (successfully) with -msse2 will probably crash with an illegal instruction on such a CPU.)
-mfpmath=sse just tells GCC to use SSE for scalar FP math assuming that SSE is available; unrelated to telling GCC to assume the target CPU does support SSE2. It can be good to use it as well for performance, but it's not going to matter in getting your code to compile.
And yes, SSE1/2 intrinsic types like __m128i will only get defined when SSE is enabled, so error: ‘__m128i’ does not name a type is a clear sign that -msse wasn't enabled
If using autoconf or something, maybe use this:
./configure CPPFLAGS="-O3 -march=native -fno-math-errno"
If you have .c files as well as .cpp, set CFLAGS as well as CPPFLAGS. More options like -flto can be helpful for optimization (cross-file inlining at link time), if you get those added to your LD options. As well as any other optimization options like -ffast-math if you want to use it. Or at least -fno-trapping-math helps some, and GCC already did optimizations that violated the semantics trapping-math was supposed to provide. See this Q&A re: -fno-trapping-math -fno-math-errno being safe to use basically everywhere, even in code that depends on strict FP like Kahan summation.
This worked for me also:
./configure CPPFLAGS="-march=native"

Checkpoint Resuming Throwing Assertion - ARM Arch

I am trying to create and resume from a checkpoint for an ARM compiled binary (LLVM Test Suite).
I cross compiled the LLVM Test Suite with the following command in a Makefile:
./arm-linux-gnueabihf-gcc -O0 -ggdb3 -std=c99 -static $< -o $#
(basically using the arm-linux-gnueabihf-gcc cross compiler version 7.4)
I created the checkpoints using the following command:
./build/ARM/gem5.opt --outdir=chkpt_only/ configs/example/se.py --checkpoint-dir chkpt_only/ --take-checkpoints=0,20000000000 --cpu-type=AtomicSimpleCPU --cmd=../../../Benchmarks/LLVM_Test_Suite/SingleSource/Benchmarks/Stanford/Towers
I tried to resume from the checkpoint with the following command:
./build/ARM/gem5.opt --outdir=chkpt_only/ configs/example/se.py -r 1 --checkpoint-dir chkpt_only/ --cpu-type=O3_ARM_v7a_3 --caches --cmd=../../../Benchmarks/LLVM_Test_Suite/SingleSource/Benchmarks/Stanford/Towers
The above seems to work when the --cpu-type is In-order but for any O3 CPU I get the following assertion:
gem5.opt: build/ARM/cpu/o3/rename_map.hh:282: const PhysRegId* UnifiedRenameMap::lookup(const RegId&) const: Assertion `vecMode == Enums::Elem' failed.
Can someone please help me to understand/fix this assertion?
PS: The git commit is 2775f55447edb344d99f30273ad93fea515d7e2b

Tensorflow Serving Compile Error Using Docker on OSX

I'm trying to install TensorFlow serving on OSX El Capitan using Docker but keep running into an error. Here is the tutorial I'm following:
https://tensorflow.github.io/serving/docker.html
Here is the command causing the error:
bazel test tensorflow_serving/...
Here's the error I'm getting:
for (int i = 0; i < suffix.size(); ++i) {
^
ERROR: /root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/tf/tensorflow/core/kernels/BUILD:212:1: C++ compilation of rule '#tf//tensorflow/core/kernels:mirror_pad_op' failed: gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -iquote external/tf -iquote ... (remaining 65 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 4.
gcc: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
Solved! Looks like the issues was with running out of memory in the VM.
Here's how I fixed it:
1) When creating the machine, make sure it has more memory (mine was only 1GB). Here is how you create a docker machine with 4GB:
docker-machine create -d virtualbox --virtualbox-memory 4096 default
2) When running the bazel command pass in a parameter limiting the amount of memory to use. Here I'm running the command using only 2GB:
bazel build -c opt --copt=-mavx --verbose_failures --local_resources 2048,2.0,1.0 -j 1 //tensorflow_serving/example:mnist_export
Where the original command was:
bazel build //tensorflow_serving/example:mnist_export

Compile Apache 2.4.6 in Solaris 10 in a SPARC machine (64bits) errors

I've been compiling Httpd 2.4.6 in Solaris 10 in a SPARC machine from last Monday. I get some errors that I have no idea how to fix.
I've successfully compile the Httpd 2.4.6 in Solaris 10 x86, according this article:
Compile Apache 2.4.2 in Solaris 10 in a x86 machine (64bits) errors
I tried several compiler flags, which failed with different errors.
Here is the steps how I did the build:
export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/xpg4/bin:/usr/sfw/bin:/usr/sfw/sbin:/usr/ccs/bin
#export LDFLAGS=" -L/usr/sfw/lib -R/usr/sfw/lib -L/usr/X/lib -R/usr/X/lib -L/usr/X11/lib -R/usr/X11/lib -L/usr/ccs/lib -R/usr/ccs/lib "
#export LDFLAGS="-L/usr/sfw/lib/sparcv9 -L/usr/lib/sparcv9 -L/usr/sfw/lib -R/usr/sfw/lib -L/usr/X/lib -R/usr/X/lib -L/usr/X11/lib -R/usr/X11/lib -L/usr/ccs/lib -R/usr/ccs/lib "
#export LDFLAGS="-L/usr/local/lib -R/usr/local/lib -R/usr/lib -L/usr/lib -R/usr/openwin/lib -L/usr/openwin/lib -L/usr/local/ssl/lib -R/usr/local/ssl/lib -L/usr/local/BerkeleyDB.4.2/lib -R/usr/local/BerkeleyDB.4.2/lib -L/usr/sfw/lib/sparcv9 -L/usr/lib/sparcv9 -L/usr/sfw/lib -R/usr/sfw/lib -L/usr/X/lib -R/usr/X/lib -L/usr/X11/lib -R/usr/X11/lib -L/usr/ccs/lib -R/usr/ccs/lib "
#export LD_LIBRARY_PATH=/usr/lib:/usr/sfw/lib
#export LD_LIBRARY_PATH_64=/usr/lib/64:/usr/sfw/lib/64
#Dont use CC, use GCC! This is VERY important. It wont work otherwise!!
export CC=gcc
#export CFLAGS="-m64 -O3"
export CFLAGS="-m64 -O2 -L/usr/local/lib -R/usr/local/lib -L/usr/local/ssl/lib -R/usr/local/ssl/lib -L/usr/openwin/lib -R/usr/openwin/lib -I/usr/local/rrdtool-1.2.19/include -I/usr/local/BerkeleyDB.4.7/include -I/usr/local/include/cairo"
export CPPFLAGS="-m64 -I/usr/local/include -I/usr/local/ssl/include -I/usr/local/include/ncurses -I/usr/openwin/include -I/usr/local/rrdtool-1.2.19/include -I/usr/local/BerkeleyDB.4.7/include -I/usr/local/include/lzo"
export LDFLAGS="-L/usr/local/lib -R/usr/local/lib -R/usr/lib -L/usr/lib -R/usr/openwin/lib -L/usr/openwin/lib -L/usr/local/ssl/lib -R/usr/local/ssl/lib -L/usr/X11R6/lib -R/usr/X11R6/lib -L/usr/local/BerkeleyDB.4.7/lib -R/usr/local/BerkeleyDB.4.7/lib"
#export CFLAGS=” -O2 -mcpu=v9 -m64″
#export CPP_FLAGS="-m64 -O3"
#export CPP_FLAGS="-m64 -O3 -I/usr/sfw/include -I/usr/local/include -I/usr/local/ssl/include -I/usr/local/include/ncurses -I/usr/local/BerkeleyDB.4.2/include -I/usr/openwin/include"
#export CPP_FLAGS="-I/usr/sfw/include"
#export CXX_FLAGS="-m64 -O3"
bzip2 -dc apr-1.4.8.tar.bz2 | tar xf -
bzip2 -dc apr-util-1.5.2.tar.bz2 | tar xf -
bzip2 -dc httpd-2.4.6.tar.bz2.tar.bz2.tar.bz2 | tar xf -
mv apr-util-1.5.2/ httpd-2.4.6/srclib/apr-util
mv apr-1.4.8/ httpd-2.4.6/srclib/apr
gzip -dc m4-1.4.17.tar.gz | tar xf -
cd m4-1.4.17
./configure --prefix=/opt/cmtools/m4-1.4.17
gmake
gmake install
gmake clean
gzip -dc autoconf-2.69.tar.gz | tar xf -
cd autoconf-2.69
./configure --prefix=/opt/cmtools/autoconf-2.69 M4=/opt/cmtools/m4-1.4.17/bin/m4
gmake
gmake install
gmake clean
gzip -dc automake-1.13.2.tar.gz | tar xf -
cd automake-1.13.2
./configure --prefix=/opt/cmtools/automake-1.13.2 PATH=/opt/cmtools/autoconf-2.69/bin:$PATH
gmake
gmake install
gmake clean
bzip2 -dc pcre-8.33.tar.bz2 | tar xf -
cd pcre-8.33/
./configure --disable-cpp CFLAGS="-g -O3" CC="gcc -m64" --prefix=/usr/local/pcre
gmake
gmake install
gmake clean
gzip -dc openssl-1.0.1e.tar.gz | tar xf -
cd openssl-1.0.1e
./config --prefix=/usr/local/ssl shared -m32
gmake
gmake install
gmake clean
bzip2 -dc binutils-2.23.2.tar.bz2.tar.bz2.tar.bz2 | tar xf -
cd binutils-2.23.2
./configure --prefix=/opt/cmtools/binutils-2.23.2
gmake
gmake install
gmake clean
cd httpd-2.4.6
./configure --prefix=/usr/local/apache2 \
--enable-mods-shared=all \
--enable-proxy \
--enable-proxy-connect \
--enable-proxy-ftp \
--enable-proxy-http \
--enable-ssl=shared \
--enable-ssl \
--with-ssl=/usr/local/ssl \
--with-mpm=prefork --with-pcre=/usr/local/pcre \
-with-included-apr
gmake
gmake install
gmake clean
The main error that I encountered when tried with different compile flags are:
ld: fatal: file /usr/local/lib/libpcre.so: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to .libs/httpd
collect2: ld returned 1 exit status
gmake[1]: *** [httpd] Error 1
gmake[1]: Leaving directory `/opt/cmtools/soft/httpd-2.4.6'
gmake: *** [all-recursive] Error 1
ld: fatal: file /usr/local/ssl/lib/libssl.so: wrong ELF class: ELFCLASS32
ld: fatal: file /usr/local/ssl/lib/libcrypto.so: wrong ELF class: ELFCLASS32
ld: fatal: File processing errors. No output written to .libs/ab
collect2: ld returned 1 exit status
gmake[2]: *** [ab] Error 1
gmake[2]: Leaving directory `/opt/cmtools/soft/httpd-2.4.6/support'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/opt/cmtools/soft/httpd-2.4.6/support'
gmake: *** [all-recursive] Error 1
Undefined first referenced
symbol in file
TLSv1_2_client_method ab.o
TLSv1_1_client_method ab.o
BIO_set_callback ab.o
BIO_set_callback_arg ab.o
BIO_get_callback_arg ab.o
SSL_CTX_set_info_callback ab.o
ld: fatal: Symbol referencing errors. No output written to .libs/ab
collect2: ld returned 1 exit status
gmake[2]: *** [ab] Error 1
gmake[2]: Leaving directory `/opt/cmtools/soft/httpd-2.4.6/support'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/opt/cmtools/soft/httpd-2.4.6/support'
gmake: *** [all-recursive] Error 1
Here is the system info:
bash-3.00# uname -a
SunOS hegel 5.10 Generic_142909-17 sun4v sparc SUNW,SPARC-Enterprise-T5120
bash-3.00# cat /etc/release
Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Assembled 11 August 2010
bash-3.00# isainfo -b
64
Appreciated for any thread for this.
Thanks.
You're building PCRE as a 64-bit library ("-m64"), but trying to build OpenSSL as a 32-bit library ("-m32") and link against that PCRE. That won't work.
Try building OpenSSL as 64-bit.
You may find that you need to edit the OpenSSL "Configure" file to adjust the compiler flags used for your hardware and compiler combination. For instance, if building on Solaris x86 using the Sun Studio compiler, the Configure script includes the "-fast" compiler flag. I found out the hard way that this hurts you when you build on a box with an AMD processor, but plan to use the code on boxes with Intel processors: the "-fast" flag enables all applicable optimizations for your compile box, including things like AMD 3DNow! extensions. Better to edit the Configure file before running it, and substitute "-fast" with architecture optimizations that are sensible for your lowest-common-denominator Intel systems in that case. OpenSSL uses an unusual Configure script that ignores the usual environment variables like CFLAGS, so editing Configure is occasionally necessary.
Also, don't be tempted to do a parallel make ("gmake -j n") with OpenSSL. The Makefile generated by OpenSSL's Configure isn't parallel-safe, and it won't build.

g++ 4.4 "error while loading shared libraries"

I'm following the C++ Cookbook tutorial on static and dynamic library linking with g++. I can build the binary fine, but when I run it I get the error
./hellobeatles: error while loading shared libraries: libjohnpaul.so: cannot open shared object file: No such file or directory
I used the command
: g++ -o hellobeatles hellobeatles.cpp -L ../johnpaul/ -L ../georgeringo/ -ljohnpaul -lgeorgeringo
The program builds and runs fine if I explicitly list the path like
: g++ -o hellobeatles hellobeatles.cpp ../johnpaul/libjohnpaul.so ../georgeringo/libgeorgeringo.so
Am I linking to the libaries incorrectly in the first command? Or is there some configuration setting I need to muck with?
I'm running an Ubuntu 9.10 guest vm in VirtualBox if that matters, and here's the -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
The dynamic linker expects to find shared libraries in /usr/lib, /lib, /usr/local/lib, and possibly a few other places. It will certainly not look for them in ../johnpaul/.
If the libraries are intended to be installed into a global location, then just install them there.
Otherwise, you must tell the dynamic linker where to find them.
A better approach is to add them to RPATH encoded into the executable:
g++ -o hellobeatles hellobeatles.cpp \
-L ../johnpaul/ -L ../georgeringo/ -ljohnpaul -lgeorgeringo \
-Wl,-rpath=/path/to/johnpaul:/path/to/georgeringo
Alternative (and less preferred) approach is to:
export LD_LIBRARY_PATH=/path/to/johnpaul:/path/to/georgeringo