Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Sep 19, 2023

When Python is configured to use ASAN, MSAN or UBSAN sanitizer, with "./configure --with-address-sanitizer" for example, compiler and linker flags for sanitizers are no longer exported to third party C extensions. Add flags to CFLAGS_NODIST and LDFLAGS_NODIST, instead of BASECFLAGS and LDFLAGS.

Makefile.pre.in: PY_LDFLAGS_NOLTO now uses PY_LDFLAGS_NODIST, instead of LDFLAGS_NODIST, and add CONFIGURE_LDFLAGS_NOLTO after PY_LDFLAGS_NODIST.

@vstinner
Copy link
MemberAuthor

On the main branch, with the bug:

$ ./configure --with-pydebug --with-address-sanitizer CC=clang $ grep fsanitize Makefile BASECFLAGS= -fsanitize=address -fno-omit-frame-pointer -fno-strict-overflow -Wsign-compare -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer CONFIGURE_LDFLAGS= -fsanitize=address 

With the fix, the flags are not longer exported:

$ ./configure --with-pydebug --with-address-sanitizer CC=clang $ grep fsanitize Makefile CONFIGURE_CFLAGS_NODIST= -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -fsanitize=address -fno-omit-frame-pointer CONFIGURE_LDFLAGS_NODIST= -fsanitize=address 

@vstinner
Copy link
MemberAuthor

cc @gpshead@erlend-aasland

When Python is configured to use ASAN, MSAN or UBSAN sanitizer, with "./configure --with-address-sanitizer" for example, compiler and linker flags for sanitizers are no longer exported to third party C extensions. Add flags to CFLAGS_NODIST and LDFLAGS_NODIST, instead of BASECFLAGS and LDFLAGS. Makefile.pre.in: PY_LDFLAGS_NOLTO now uses PY_LDFLAGS_NODIST, instead of LDFLAGS_NODIST, and add CONFIGURE_LDFLAGS_NOLTO after PY_LDFLAGS_NODIST.
@vstinner
Copy link
MemberAuthor

Test PY_LDFLAGS_NOLTO on building _bootstrap_python:

./configure --with-address-sanitizer --with-lto make 

Logs:

gcc -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -fsanitize=address -fno-lto -o _bootstrap_python (...) 

-fno-lto option is passed as expected.

@gpshead
Copy link
Member

this change makes sense if we want to do this. it wasn't clear what "right" behavior was to me for this, see my comment on the Issue. (i'm happy either way myself)

@vstinner
Copy link
MemberAuthor

I thought that it was a mistake, but apparently, some people actually want this behavior. I'm mostly using ASAN, but for ASAN, it seems to be the expected behavior. So I just close my PR :-)

If someone wants to adjust the code for other sanitizers, please go ahead!

@vstinnervstinner closed this Oct 2, 2023
@vstinnervstinner deleted the configure_asan branch October 2, 2023 17:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@gpshead