Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address binskim flag for compiler in driver build #99

Open
wants to merge 1 commit into
base: npu/release/18.x
Choose a base branch
from

Conversation

ShaojieZhuIntel
Copy link

@ShaojieZhuIntel ShaojieZhuIntel commented Feb 11, 2025

Summary

Since the compiler in the driver build cannot pass the Binskim scan and shows [Explicitly disabled warnings: 4146;4244;4267], it is necessary to remove the suppression of these three warnings. LLVM code like:

-wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'

     -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
     -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
     -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'

-wd4146 means disable the /w4146 warning
-wd4244 means disable the /w4244 warning
-wd4267 means disable the /w4267 warning

So we need enable these three warnings to pass the Binskim

Since it is not possible to directly enable specific warnings for the LLVM repo within the compiler repo, we use an option here to control whether the specified warnings are suppressed.

JIRA ticket

Related PR in NPU Compiler and/or OpenVINO repository with sub-module update

Other related tickets

List tickets for additional work, eg, something was found during review but you agreed to address it in another Jira

  • E-xxxxx

@ShaojieZhuIntel ShaojieZhuIntel force-pushed the address-cid-binskim-patch branch from 0dbede6 to c5b379a Compare February 13, 2025 02:10
@ShaojieZhuIntel ShaojieZhuIntel marked this pull request as ready for review February 13, 2025 05:23
@ShaojieZhuIntel ShaojieZhuIntel requested a review from a team as a code owner February 13, 2025 05:23
@ShaojieZhuIntel
Copy link
Author

ShaojieZhuIntel commented Feb 13, 2025

Apply the current changes from PR99 in PR15919, and perform compiler in driver build with PR205. The build was successful and passed the binskim scan.
The CiD build job is recorded in PR15919.

https://github.com/intel-innersource/applications.ai.vpu-accelerators.vpux-plugin/pull/15919 PR-checker passed

@AlexandruLorinti
Copy link

I confirm there are no errors regarding suppressed warnings in BinSkim scan

@@ -767,6 +767,15 @@ if (MSVC)
foreach(flag ${msvc_warning_flags})
append("${flag}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endforeach(flag)

if (BUILD_COMPILER_FOR_DRIVER)
string(REPLACE "-wd4146" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'm not quite familiar with LLVM CMake code involved here, but I'd consider updating global CMAKE variables, especially CMAKE_C/CXX_* not the best practice, reason is there's a chance it'd affect other targets you didn't intended to change
I saw that case in our project already, when OpenVINO did this and then propagated not always desired compilation options to our targets

If you stick with modifying these variables for some reason, could you please clarify why and confirm no unintended target is changed (presumably nothing outside of llvm-project folder)?

Alternative would be just working with target properties, you can specify compilation options per target such it's not intrusive

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to modify and test based on your suggestion.

Comment on lines 295 to 296
if(MSVC)
if(BUILD_COMPILER_FOR_DRIVER)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: if (MSVC AND BUILD_COMPILER_FOR_DRIVER)
Also, since we have to modified LLVM's codebase, I suppose we should have some kind tracker of all such changes

@nikita-kud do we have anything like this already?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thank you!

Copy link
Contributor

@nikita-kud nikita-kud Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikita-kud do we have anything like this already?

Yes, we have: E-101222
But I think it can't be upstreamed. This change looks sad. Why we can't suppress these warnings scanner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikita-kud do we have anything like this already?

Yes, we have: E-101222 But I think it can't be upstreamed. This change looks sad. Why we can't suppress these warnings scanner?

Because we need to pass binskim. @AlexandruLorinti We are currently fix the binskim scan failures by applying a patch during the CiD build. Since it cannot be upstreamed, can we continue using this method?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikita-kud do we have anything like this already?

Yes, we have: E-101222 But I think it can't be upstreamed. This change looks sad. Why we can't suppress these warnings scanner?

Because we need to pass binskim. @AlexandruLorinti We are currently fix the binskim scan failures by applying a patch during the CiD build. Since it cannot be upstreamed, can we continue using this method?

any method would be ok, you can keep the patch in CiD build

@ShaojieZhuIntel ShaojieZhuIntel force-pushed the address-cid-binskim-patch branch from 85abebf to cb1282d Compare February 20, 2025 11:57
Copy link

@ggladilo ggladilo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to each modification of compile options
Maybe makes sense to create a CMake function that accepts target and silences all needed warnings, then you could add explanation to just function implementation
In this case all the logic for making binskim happy is reused


if(MSVC AND BUILD_COMPILER_FOR_DRIVER)
target_compile_options(LLVMAnalysis PRIVATE
/w34146 /w34244 /w34267

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to do the same in NPU Cmake which includes LLVM, avoiding a patch.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I guess it's true, we could write CMake code/function in our project that processes pre-defined set of targets (from LLVM repo that we know are problematic to one our jobs/processes) and for each given target modifies a property of it that corresponds to compile options used to build the target accordingly
This way we get clean separation - this warnings disablement is not a problem of LLVM (since they can build their targets they probably just do not provide support for these-warnings-clean-build), but our problem since we seem to place more requirements on LLVM codebase than its authors/maintainers

Comment on lines 165 to 167
# Due to this target cannot pass the binskim scan after the compiler in the driver build,
# it is necessary to remove the suppression of these three warnings(/wd4146 /wd4244 /wd4267).
enable_msvc_warnings_on_compiler_for_driver(LLVMAnalysis /w3 4146 4244 4267)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comments to the function implementation, no need to repeat every time you call the function
Function name is confusing, do you disable or enable warnings here? From the values looks like you disable them
Also, I'd keep function specific to your use case, instead of accepting warnings as arguments, just "hardcode" them internally and name the function something along the lines as fix_binksim or something (choose better name than mine!)
Also consider @lmielick's comment to implement solution in compiler repo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for your suggestions! Here we are enabling warnings, and I will modify the function according to your advice. Additionally, I am trying to modify only the compiler repo to make it pass binskim.

@ShaojieZhuIntel ShaojieZhuIntel force-pushed the address-cid-binskim-patch branch from 26236fc to 5ce36b2 Compare March 27, 2025 03:53
@ShaojieZhuIntel
Copy link
Author

Firstly, can not directly enable warnings for LLVM within the compiler repo. Secondly, I tried creating a function in the compiler repo and calling this function for each target in LLVM that fails the binskim check. This approach reduces the binskim errors, but it involves modifying many targets. Additionally, if the same errors appear in other targets in the future, further modifications to the LLVM code will be necessary. Therefore, I believe it is more appropriate to add an option in LLVM that allows controlling the enabling of relevant warnings from the compiler repo.

@ShaojieZhuIntel
Copy link
Author

Test job: https://jenkins-npu-compiler.ir.intel.com/job/pub/job/IE-Packages/job/Release/job/CiD-Windows10/15966/ passed
binskim passed
Hi @ggladilo @lmielick @nikita-kud @AlexandruLorinti Could you please help to review this change?

@andrey-golubev
Copy link
Contributor

andrey-golubev commented Mar 27, 2025

Why do we need it in LLVM? Can we instead do it at the compiler's side around add_subdirectory(LLVM)?
Then the change is local to our stack and doesn't have to be forever cherry-picked between LLVM releases.

Also, removing warnings doesn't look good to me. Are there issues in LLVM otherwise? Can we fix them instead and push that to upstream?

@lmielick
Copy link

lmielick commented Mar 27, 2025

This approach reduces the binskim errors, but it involves modifying many targets.

@ShaojieZhuIntel did you try using directory level CMAKE variables? I would presume we can append these flags into CFLAGS on directory level. Even if this is applied eagerly for all LLVM targets it should be fine:
a) there is no incentive to fix warnings on LLVM side
b) if it's contingent on BINSKIM flag we can still keep the LLVM warnings on in developer build or so

@ShaojieZhuIntel
Copy link
Author

Why do we need it in LLVM? Can we instead do it at the compiler's side around add_subdirectory(LLVM)? Then the change is local to our stack and doesn't have to be forever cherry-picked between LLVM releases.

Also, removing warnings doesn't look good to me. Are there issues in LLVM otherwise? Can we fix them instead and push that to upstream?

We are not removing warnings; we are enabling warnings because some warnings are suppressed in LLVM, which is not allowed by binskim. Like:

  AliasAnalysis.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  AliasSetTracker.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  AssumeBundleQueries.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  AssumptionCache.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  BasicAliasAnalysis.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  BlockFrequencyInfo.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  BlockFrequencyInfoImpl.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]
  BranchProbabilityInfo.cpp.obj (LLVMAnalysis.lib) [Explicitly disabled warnings: 4146;4244;4267]

Even if we handle this around add_subdirectory(LLVM), it will be overridden by the actions in LLVM that disable warnings.

-wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'

      -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
      -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
      -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'

@ShaojieZhuIntel
Copy link
Author

This approach reduces the binskim errors, but it involves modifying many targets.

@ShaojieZhuIntel did you try using directory level CMAKE variables? I would presume we can append these flags into CFLAGS on directory level. Even if this is applied eagerly for all LLVM targets it should be fine: a) there is no incentive to fix warnings on LLVM side b) if it's contingent on BINSKIM flag we can still keep the LLVM warnings on in developer build or so

Yes, I have tried enabling warnings around add_subdirectory(LLVM), but LLVM suppresses some warnings again, causing the enabling of warnings to be ineffective. Like:

-wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'

      -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
      -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
      -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'

@XinWangIntel
Copy link
Contributor

@ggladilo @lmielick @andrey-golubev @AlexandruLorinti , could you help to review this again? The PR is to open suppressed warnings by remove some compiler flags (which make we can not see warnings in log). And we tried on vpux-plugin repo side, append cmake flag on that level can not work since llvm append flag after that again and invalid our new added flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants