add profile flag when linking to fix apiscan errors#1567
Conversation
| copy run_code_on_dllmain_x86.dll ..\run_code_on_dllmain_x86.dll /Y | ||
| copy run_code_on_dllmain_x86.pdb ..\run_code_on_dllmain_x86.pdb /Y | ||
|
|
||
| cl /EHsc /Zi /O1 /W3 /Qspectre inject_dll.cpp /link /DEBUG /OPT:REF /OPT:ICF /GUARD:CF /out:inject_dll_x86.exe |
There was a problem hiding this comment.
Did you remove these flags on purpose? I believe these flags generate a DEBUG dll. Did we need/want a release mode DLL now?
There was a problem hiding this comment.
Yeah you're right. I guess I need both /DEBUG and /PROFILE
There was a problem hiding this comment.
Oh nevermind. I guess /PROFILE implies this:
https://learn.microsoft.com/en-us/cpp/build/reference/profile-performance-tools-profiler?view=msvc-170#remarks
There was a problem hiding this comment.
https://learn.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info?view=msvc-170
without /DEBUG it won't generate pdb so you won't be able to debug the dll once it generated. I mean at least on source level.
There was a problem hiding this comment.
/OPT:REF and /OPT:ICF seems optimization options to reduce dll file size. so I guess it could be removed if that doesn't work as expected?
There was a problem hiding this comment.
Oh nevermind. I guess /PROFILE implies this: learn.microsoft.com/en-us/cpp/build/reference/profile-performance-tools-profiler?view=msvc-170#remarks
Yes! I remember reading that and I forgot why I removed debug, that's why!
| copy run_code_on_dllmain_x86.pdb ..\run_code_on_dllmain_x86.pdb /Y | ||
|
|
||
| cl /EHsc /Zi /O1 /W3 /Qspectre inject_dll.cpp /link /DEBUG /OPT:REF /OPT:ICF /GUARD:CF /out:inject_dll_x86.exe | ||
| cl /EHsc /Zi /O1 /W3 /Qspectre inject_dll.cpp /link /PROFILE /GUARD:CF /out:inject_dll_x86.exe |
There was a problem hiding this comment.
isn't /PROFILE for profiling? I mean when you want to inject profiling stub on each symbols to gather profiling info. I thought those are usually not used unless dll is specificallly built for profiling.
There was a problem hiding this comment.
According to https://eng.ms/docs/products/apiscan/howto/preparinginput/binaries/creating_vulcan_ready_files, we have two options for APIScan to work:
Linking/link.exe
/profile (https://learn.microsoft.com/en-us/cpp/build/reference/profile-performance-tools-profiler)
This informs the linker to emit full fixup information so that Vulcancompletely identifies code and data cross-references. Be aware thatthis implies the following linker switches that affect codegeneration: /incremental:no /opt:ref /opt:noicf. The /opt switchescan be overridden on the command-line after /profile is used.
Optionally for non public source bases the following switches can be used instead of /profile:
/debug:full (https://learn.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info)
/debugtype:cv,fixup (https://learn.microsoft.com/en-us/cpp/build/reference/debugtype-debug-info-options)
/incremental:no (https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally)
So I can use the three debug switches instead of profile, It doesn't matter to me. 😄
There was a problem hiding this comment.
No read this:
https://learn.microsoft.com/en-us/cpp/build/reference/profile-performance-tools-profiler?view=msvc-170#remarks
/PROFILE implies /DEBUG:full
There was a problem hiding this comment.
surprised that /PROFILE flag is recommended to be enabled by default. I guess now it generates fast enough code to okay to be enabled by default.
|
@AdamYoblick To test this you can run some python script in a loop with a timer. Then use the process ID of that process and attach to it from VS Code. You can set the |
|
We have |
Thanks Pavel. How can I ensure that the inject* dlls that I built are used? Are they always used in the attach scenario? |
|
Ok I tested this by writing an infinite loop with a timer, then using the following attach configuration in launch.json in vscode: I was able to attach (with python 3.11 as 3.12 is not supported in the attach code yet) and set breakpoints and everything worked as expected. |
|
The next step after merging this in is to run the debugpy compliance pipeline to see if apiscan still reports errors on these binaries. |
Fixes #1547
APIScan logs are reporting that the following two files are invalid binaries:
Reading the docs at https://eng.ms/docs/products/apiscan/howto/preparinginput/binaries/creating_vulcan_ready_files, we are supposed to link with the
/PROFILEflag (or a combination of three other flags). I've modified the flags for the two failing binaries, and created this PR. The PR checks perform a compile of the binaries, so I downloaded the windows artifacts from https://github.com/microsoft/debugpy/actions/runs/8729118226?pr=1567. Then I committed those binaries back into the repo.I'm not entire sure how to test these changes yet. Need to investigate that before merging. @int19h Do you know how I can test these re-compiled "inject" binaries?
@rchiodo @debonte - I'm not a C++ expert, but I read through the docs. Do either of you see any issues with the flag changes I made?