edk2-basetools icon indicating copy to clipboard operation
edk2-basetools copied to clipboard

[Feature]: Verify library INF implements specified library class from the DSC

Open Javagedes opened this issue 2 years ago • 7 comments

What does the feature solve?

This feature will resolve hard to detect linking errors due to libraries not being properly linked to components due to a quiet mismatch of library classes

Describe the solution

A check can take place inside of BaseTools/Source/Workspace/DscBuildData.py that, when parsing library class lines in a DSC's [LibraryClasses.*] section or library override of the [Components.*] section, will verify that the library instance actually implements the library by checking which LIBRARY_CLASS definitions exist in the INF [Defines] section.

That is to say, for the following example: TestLib|Path/To/BaseTestLib.inf, that BaseTestLib.inf has LIBRARY_CLASS = TestLib defined in the [Defines] section.

The following commit shows a possible implementation that has been verified to catch invalid linking in the two scenarios above: https://github.com/tianocore/edk2/compare/master...Javagedes:edk2:verify-library-class

Attached is a diff: diff.txt

@mdkinney @makubacki @YuweiChen1110

Have you considered any alternatives?

No response

Additional context

No response

Javagedes avatar Jul 18 '23 19:07 Javagedes

@YuweiChen1110, can you please advise on next steps?

makubacki avatar Jul 18 '23 22:07 makubacki

It is valuable to add this feature. The feature's quality is under testing. After testing, will reply with the result. And then we can submit the formal PR in edk2-basetools repo and send out the patch with email for edk2 repo.

YuweiChen1110 avatar Jul 21 '23 03:07 YuweiChen1110

Hi @YuweiChen1110, I found an issue in the diff I previously sent you. In larger builds the same DSC is parsed multiple times, thus each mismatch is reported multiple times also, which is not preferred. I spent some time getting a fix to only report each mismatch once. Below is the diff. Here is also a link to the two commits: https://github.com/microsoft/mu_basecore/compare/release/202302...Javagedes:mu_basecore:library-check

diff.txt

Javagedes avatar Jul 21 '23 04:07 Javagedes

Thanks for the contribution and clarify!

YuweiChen1110 avatar Jul 21 '23 05:07 YuweiChen1110

When I tested this feature in my local build env, I encountered some errors and currently finding the root cause. Will update this issue with the error info after collection.

Thanks for your patience.

YuweiChen1110 avatar Jul 31 '23 11:07 YuweiChen1110

What issue are you seeing? I can debug tomorrow

Javagedes avatar Jul 31 '23 14:07 Javagedes

Hi, the situation I encountered is shown below. It seems like not this feature's issue but with adding this feature a previously existing but undiscovered bug is exposed.

The situation is: a PCD in INF file is not defined in DEC file. The expected behavior of build system should be: raise the error "PCD [%s.%s] in [%s] is not found in dependent packages:"

However in some strange case, when we do not add this feature, the error will not be raised, after we add this feature, the error is raised correctly. It is very strange, and I am checking on the root cause.

From my side, we need to fix the bug firstly then merge this feature. Or it will block build system current use.

Will update the PR with debugging status.

YuweiChen1110 avatar Aug 04 '23 09:08 YuweiChen1110