This is an archive of the discontinued LLVM Phabricator instance.

[ASan] [MinGW] Avoid including headers for functions that will be redefined
AbandonedPublic

Authored by mstorsjo on Sep 10 2018, 12:26 PM.

Details

Reviewers
rnk
timurrrr
Summary

With mingw-w64 headers, including windows.h ends up including stdlib.h and malloc.h implicitly, with the following path:

compiler-rt/lib/asan/asan_malloc_win.cc
x86_64-w64-mingw32/include/windows.h
x86_64-w64-mingw32/include/windef.h
x86_64-w64-mingw32/include/minwindef.h
x86_64-w64-mingw32/include/winnt.h
lib/clang/8.0.0/include/x86intrin.h
lib/clang/8.0.0/include/immintrin.h
lib/clang/8.0.0/include/xmmintrin.h
lib/clang/8.0.0/include/mm_malloc.h
x86_64-w64-mingw32/include/c++/v1/stdlib.h
x86_64-w64-mingw32/include/stdlib.h

These headers include declarations of functions like e.g. free(), without the dllexport attribute, but other included headers also include inline functions that reference free().

If these functions have been declared before (either with or without dllimport), we can still redeclare them with dllexport, this only yields a warning. However, if they have been declared without dllimport and referenced by an inline function in the headers, it has already been emitted to IR and we can't add the dllexport attribute afterwards.

By undefining STDC_HOSTED, we avoid xmmintrin.h including mm_malloc.h.

Diff Detail

Event Timeline

mstorsjo created this revision.Sep 10 2018, 12:26 PM
Herald added subscribers: Restricted Project, kubamracek. · View Herald TranscriptSep 10 2018, 12:26 PM
rnk added a comment.Sep 10 2018, 4:40 PM

ಠ_ಠ mm_malloc.h, you are a source of much complexity.

lib/asan/asan_malloc_win.cc
28

How badly do we need this include? It looks like we only get it for a few typedefs like HANDLE, LPVOID, and some other stuff that we could avoid without too much work. This file is intentionally isolated to avoid these kinds of conflicts. Should we just isolate it from windows.h too?

mstorsjo added inline comments.Sep 10 2018, 11:39 PM
lib/asan/asan_malloc_win.cc
28

That's probably a much less fragile approach - I'll see if I can make it build without it.

mstorsjo abandoned this revision.Sep 11 2018, 1:33 PM

Going with D51914 instead.