4 echo "Path to clang required!"
5 echo "Usage: update_memprof_inputs.sh /path/to/updated/clang"
11 # Allows the script to be invoked from other directories.
12 OUTDIR
=$
(dirname $
(realpath
-s $0))
14 read -r -d '' BASIC
<< EOF
17 int main(int argc, char **argv) {
18 char *x = (char *)malloc(10);
21 x = (char *)malloc(10);
28 read -r -d '' INLINE
<< EOF
32 __attribute__((always_inline))
34 char *ptr = (char*) malloc(x);
39 __attribute__((noinline))
40 void foo(int x){ qux(x); }
42 __attribute__((noinline))
43 void bar(int x) { foo(x); }
45 int main(int argc, char **argv) {
51 read -r -d '' MULTI
<< EOF
52 #include <sanitizer/memprof_interface.h>
55 int main(int argc, char **argv) {
56 char *x = (char *)malloc(10);
59 __memprof_profile_dump();
60 x = (char *)malloc(10);
67 read -r -d '' BASIC_HISTOGRAM
<< EOF
136 int main(int argc, char **argv) {
193 for (int i = 0; i < 21; ++i) {
198 for (int i = 0; i < 21; ++i) {
207 read -r -d '' PADDING_HISTOGRAM
<< EOF
230 int main(int argc, char **argv) {
251 DEFAULT_MEMPROF_FLAGS
="-fuse-ld=lld -Wl,--no-rosegment -gmlt -fdebug-info-for-profiling -fmemory-profile -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id -no-pie"
253 # Map each test to their source and any additional flags separated by ;
255 INPUTS
["basic"]="BASIC"
256 INPUTS
["inline"]="INLINE"
257 INPUTS
["multi"]="MULTI"
258 INPUTS
["pic"]="BASIC;-pie"
259 INPUTS
["buildid"]="BASIC;-Wl,-build-id=sha1"
261 for name
in "${!INPUTS[@]}"; do
262 IFS
=";" read -r src flags
<<< "${INPUTS[$name]}"
263 echo "${!src}" > ${OUTDIR}/${name}.c
264 ${CLANG} ${DEFAULT_MEMPROF_FLAGS} ${flags} ${OUTDIR}/${name}.c -o ${OUTDIR}/${name}.memprofexe
265 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/${name}.memprofexe > ${OUTDIR}/${name}.memprofraw
266 rm ${OUTDIR}/${name}.c
270 DEFAULT_HIST_FLAGS="${DEFAULT_MEMPROF_FLAGS} -mllvm -memprof-use-callbacks=true
-mllvm -memprof-histogram"
273 # Map each test to their source and any additional flags separated by ;
274 declare -A HISTOGRAM_INPUTS
275 HISTOGRAM_INPUTS["basic-histogram
"]="BASIC_HISTOGRAM
"
276 HISTOGRAM_INPUTS["padding-histogram
"]="PADDING_HISTOGRAM
"
278 for name in "${!HISTOGRAM_INPUTS[@]}"; do
279 IFS=";" read -r src flags <<< "${HISTOGRAM_INPUTS[$name]}"
280 echo "${!src}" > ${OUTDIR}/${name}.c
281 ${CLANG} ${DEFAULT_HIST_FLAGS} ${flags} ${OUTDIR}/${name}.c -o ${OUTDIR}/${name}.memprofexe
282 env MEMPROF_OPTIONS
=log_path
=stdout
${OUTDIR}/${name}.memprofexe > ${OUTDIR}/${name}.memprofraw
283 rm ${OUTDIR}/${name}.c