Skip to content

Commit

Permalink
[CLIENT-2512] Add option to build client with sanitizer (#494)
Browse files Browse the repository at this point in the history
* Compile and link with libasan
* Stop sanitizer from exiting after first error
  • Loading branch information
juliannguyen4 authored Aug 23, 2023
1 parent e752217 commit 4d9d413
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ python3 -m build
DEBUG=1 python3 -m build
``` -->

### Building with sanitizer enabled

You can build the Python client with sanitizer to find memory errors and memory leaks. To do this, pass in an environment variable:
```bash
SANITIZER=1 python3 -m build
```

Then once you install the build with sanitizer, you may run a Python script using the Python client with this environment variable:

```bash
# Replace this file path with your actual libasan shared library path
# You can find the path using this command:
# ldconfig -p | grep libasan.so
LD_PRELOAD=/lib/x86_64-linux-gnu/libasan.so.6 python3 -c "import aerospike"
```

### Troubleshooting macOS

In some versions of macOS, Python 2.7 is installed as ``python`` with
Expand Down
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@
'-DMARCH_' + machine,
'-Wno-implicit-function-declaration'
]

if machine == 'x86_64':
extra_compile_args.append('-march=nocona')
extra_objects = []

extra_link_args = []

SANITIZER=os.getenv('SANITIZER')
if SANITIZER:
sanitizer_flags = [
'-fsanitize=address',
'-fsanitize-recover=all'
]
extra_compile_args.extend(sanitizer_flags)

extra_link_args.append("-static-libasan")
extra_link_args.extend(sanitizer_flags)

library_dirs = ['/usr/local/opt/openssl/lib', '/usr/local/lib']
libraries = [
'ssl',
Expand Down

0 comments on commit 4d9d413

Please sign in to comment.