Support for -static-libasan

Dimitrios Apostolou <[email protected]>
Newsgroups gmane.comp.gnu.libtool.general
Message-ID <alpine.DEB.2.20.1701140129370.7791@localhost>
Hello list,

I was getting the following error message after building with
CFLAGS='-fsanitize=address -static-libasan' LDFLAGS=-static-libasan
and trying to run the generated executable.

==5331==Your application is linked against incompatible ASan runtimes.


Please note that the project also contains a shared library, which libtool 
was always linking while ignoring the "-static-libasan" flag. So the 
library was linking to "libasan.so" while the binaries were linked with 
the static runtime.

The attached patch on the generated libtool script solved the issue to me. 
Feel free to use it upstream, if it makes sense.

Thanks,
Dimitris

_______________________________________________
https://lists.gnu.org/mailman/listinfo/libtool
libtool-link-static-libasan.diff (text/x-diff, 1.5 KB)
--- libtool.orig	2017-01-14 01:23:44.996640378 +0100
+++ libtool	2017-01-14 01:25:59.264414122 +0100
@@ -7766,24 +7766,25 @@
       # -F/path              path to uninstalled frameworks, gcc on darwin
       # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
       # -fstack-protector*   stack protector flags for GCC
       # @file                GCC response files
       # -tp=*                Portland pgcc target processor selection
       # --sysroot=*          for sysroot support
       # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
       # -specs=*             GCC specs files
       # -stdlib=*            select c++ std lib with clang
       # -fsanitize=*         Clang/GCC memory and address sanitizer
+      # -static-lib*san      Do not require libasan.so in runtime, link statically instead
       -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
       -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
       -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
-      -specs=*|-fsanitize=*)
+      -specs=*|-fsanitize=*|-static-lib*san)
         func_quote_for_eval "$arg"
 	arg=$func_quote_for_eval_result
         func_append compile_command " $arg"
         func_append finalize_command " $arg"
         func_append compiler_flags " $arg"
         continue
         ;;
 
       -Z*)
         if test os2 = "`expr $host : '.*\(os2\)'`"; then
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.