Trouble building package with Msan

84 views
Skip to first unread message

nolo...@gmail.com

unread,
May 6, 2019, 11:25:36 PM5/6/19
to memory-sanitizer
I'm trying to instrument a third party library being built from sources. I'm using Clang 7.0.1 on Fedora 29. Clang takes -fsanitize=memory. The link step is driven through the compiler and uses the following command:

clang -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -g2 -O2 -fsanitize=memory -fno-omit-frame-pointer -march=native -fPIC -pthread -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o libz.so.1.2.11 adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo  -lc -L/var/sanitize/lib64 -fsanitize=memory -Wl,-R,/var/sanitize/lib64 -Wl,--enable-new-dtags

Later, I build OpenSSL with the Sanitizer:

gmake[2]: Entering directory '/home/build/openssl-1.0.2r'
[ -z "" ] || clang -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -g2 -O2 -I/var/sanitize/include -DNDEBUG -g2 -O2 -fsanitize=memory -fno-omit-frame-pointer -march=native -fPIC -pthread -fsanitize=memory -DPEDANTIC -m64 -DL_ENDIAN -O3 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-language-extension-token   -Qunused-arguments -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -Iinclude \
        -DFINGERPRINT_PREMAIN_DSO_LOAD -o fips_premain_dso  \
        fips_premain.c fipscanister.o \
        libcrypto.a -lmsan -ldl -lpthread -L/var/sanitize/lib64 -Wl,-R,/var/sanitize/lib64 -Wl,--enable-new-dtags -Wl,-R,/var/sanitize/lib64 -Wl,--enable-new-dtags -ldl

And then attempt to run the 'make check':

gmake[3]: Entering directory '/home/build/openssl-1.0.2r'
gmake[4]: Entering directory '/home/build/openssl-1.0.2r'
clang: symbol lookup error: /var/sanitize/lib64/libz.so.1: undefined symbol: __msan_va_arg_overflow_size_tls

When I check libz.so.1 dependencies I don't see msan:

$ ls /var/sanitize/lib64
libbz2.a  libz.a  libz.so  libz.so.1  libz.so.1.2.11  pkgconfig
$ ldd /var/sanitize/lib64/libz.so.1
        linux-vdso.so.1 (0x00007ffd495db000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f52e6aff000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f52e6add000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f52e6d25000)

I don't see a reference to the Msan library.

The MemorySanitizer page is at https://github.com/google/sanitizers/wiki/MemorySanitizer, but it is missing detailed info on compile and link. I'm guessing I am missing an option somewhere.

What am I doing wrong?

Evgenii Stepanov

unread,
May 8, 2019, 4:20:22 PM5/8/19
to memory-s...@googlegroups.com
MSan runtime library is statically linked to the executable, and its
symbols are re-exported. There is a requirement that a sanitized
library may only be loaded into a sanitized executable (same as ASan).
It appears that your "clang" binary is not built with MSan. Did you
set LD_LIBRARY_PATH to /var/sanitize/lib64?

Another reason for such failure could be a linker script (or a version
script) that breaks msan symbols re-export.
> --
> You received this message because you are subscribed to the Google Groups "memory-sanitizer" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to memory-sanitiz...@googlegroups.com.
> To post to this group, send email to memory-s...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/memory-sanitizer/c9a39660-3e7e-41b7-9cd3-cb2109e5acfc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages