| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
# or more contributor license agreements. See the NOTICE file |
| 5 |
# distributed with this work for additional information |
| 6 |
# regarding copyright ownership. The ASF licenses this file |
| 7 |
# to you under the Apache License, Version 2.0 (the |
| 8 |
# "License"); you may not use this file except in compliance |
| 9 |
# with the License. You may obtain a copy of the License at |
| 10 |
# |
| 11 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
# |
| 13 |
# Unless required by applicable law or agreed to in writing, |
| 14 |
# software distributed under the License is distributed on an |
| 15 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
# KIND, either express or implied. See the License for the |
| 17 |
# specific language governing permissions and limitations |
| 18 |
# under the License. |
| 19 |
# |
| 20 |
|
| 21 |
if test $# -lt 2; then |
| 22 |
echo <<EOF |
| 23 |
usage: $0 LIB EXE [args ...] |
| 24 |
Get the libasan linked to LIB and preload it to run `EXE args ...` |
| 25 |
EOF |
| 26 |
fi |
| 27 |
|
| 28 |
LIB=$1; shift |
| 29 |
EXE=$2 |
| 30 |
|
| 31 |
case $EXE in |
| 32 |
*ruby*|*.rb) |
| 33 |
# ruby has spurious leaks and causes asan errors. |
| 34 |
|
| 35 |
# Disable link order check to run with limited sanitizing |
| 36 |
# Still seeing problems. |
| 37 |
|
| 38 |
# https://github.com/google/sanitizers/issues/1066 |
| 39 |
# asan on Ubuntu Trusty does not recognize verify_asan_link_order=0 option |
| 40 |
ASAN_OPTIONS=verify_asan_link_order=0 |
| 41 |
export ASAN_OPTIONS |
| 42 |
;; |
| 43 |
*) |
| 44 |
# Preload the asan library linked to LIB. Note we need to |
| 45 |
# check the actual linkage, there may be multiple asan lib |
| 46 |
# versions installed and we must use the same one. |
| 47 |
|
| 48 |
# ldd prints something like this (proton compiled with clang) |
| 49 |
# libclang_rt.asan-x86_64.so => /lib64/.../libclang_rt.asan-x86_64.so (0x00007f3d7fdad000) |
| 50 |
libasan=$(ldd "$LIB" | awk "/(asan.*\\.so[.0-9]*)/ { print \$3 }") |
| 51 |
LD_PRELOAD="$libasan:$LD_PRELOAD" |
| 52 |
export LD_PRELOAD |
| 53 |
;; |
| 54 |
esac |
| 55 |
|
| 56 |
exec "$@" |