This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] [sanitizers] [windows] Use a linker directive pragma for psapi
ClosedPublic

Authored by mstorsjo on Oct 9 2018, 1:15 AM.

Details

Summary

This allows users of static libraries (such as ubsan) to link without knowing about this transitive dependency, if using the psapi functions that require linking to a separate psapi library. Since Windows 7, these functions (EnumProcessModules, GetModuleInformation, GetProcessMemoryInfo) are remapped to K32- prefixed ones, available in kernel32.dll.

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 9 2018, 1:15 AM
Herald added subscribers: Restricted Project, mgorny, dberris, kubamracek. · View Herald TranscriptOct 9 2018, 1:15 AM
mstorsjo added inline comments.Oct 9 2018, 1:17 AM
lib/sanitizer_common/sanitizer_win.cc
34

This distinction between library names (psapi.lib vs libpsapi.a) needs to be taken care of at some level; either here, in clang or in lld. I'm including it in all patches, to easier compare where the logic fits the best.

For MinGW, this pragma/directive requires compiling with -fms-extensions, and ld.bfd doesn't support defaultlib in embedded directives (but the sanitizers in general require a number of other features missing in ld.bfd already).

rnk added inline comments.Oct 9 2018, 10:06 AM
lib/sanitizer_common/sanitizer_win.cc
34

If this is only targeting LLD, then I'd prefer to just use the basename "psapi" version and continue forward with making LLD search for .a files in addition to .lib files.

mstorsjo updated this revision to Diff 168844.Oct 9 2018, 11:47 AM

Assuming mingw library name logic elsewhere.

rnk accepted this revision.Oct 9 2018, 1:59 PM

lgtm

This revision is now accepted and ready to land.Oct 9 2018, 1:59 PM
This revision was automatically updated to reflect the committed changes.