security/nss/coreconf/sanitizers.py
author Franziskus Kiefer <franziskuskiefer@gmail.com>
Wed, 16 Nov 2016 14:06:23 +0100
changeset 322860 f296d03423848da45f1839b946b103047834b459
child 323912 ecb49ac1035745fe2c0efc76ec7c65096a34ab89
permissions -rw-r--r--
Bug 1317947 - land NSS 0x5b7a40ced8c5, r=me

#!/usr/bin/env python2

from __future__ import print_function
import sys

def main():
    if len(sys.argv) < 2:
        raise Exception('Specify either "ld", asan", "sancov" or "ubsan" as argument.')

    sanitizer = sys.argv[1]
    if sanitizer == "ubsan":
        print('-fsanitize=undefined -fno-sanitize-recover=undefined ', end='')
        return
    if sanitizer == "asan":
        print('-fsanitize=address ', end='')
        print('-fno-omit-frame-pointer -fno-optimize-sibling-calls ', end='')
        return
    if sanitizer == "sancov":
        if len(sys.argv) < 3:
            raise Exception('sancov requires another argument (edge|bb|func).')
        print('-fsanitize-coverage='+sys.argv[2]+' ', end='')
        return

    # We have to remove this from the ld flags when building asan.
    if sanitizer == "ld":
        print('-Wl,-z,defs ', end='')
        return

    raise Exception('Specify either "ld", asan", "sancov" or "ubsan" as argument.')

if __name__ == '__main__':
    main()