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

Add missing library header guards #181

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

makubacki
Copy link
Member

Description

All header files should include header guards.

Some header files, such as those which define structures,
cannot be included more than once within a translation unit, as doing
so would cause a redefinition error. Such headers must be guarded to
prevent ill-effects from multiple inclusion. Similarly, if header
files include other header files, and this inclusion graph contains
a cycle, then at least one file within the cycle must contain header
guards in order to break the cycle. Because of cases like these, all
headers should be guarded as a matter of good practice, even if they
do not strictly need to be.

Furthermore, most modern compilers contain optimizations which are
triggered by header guards. If the header guard strictly conforms
to the pattern that compilers expect, then inclusions of that
header other than the first have absolutely no effect: the file
isn't re-read from disk, nor is it re-tokenised or re-preprocessed.
This can result in a noticeable, albeit minor, improvement to
compilation time.

  • Impacts functionality?
    • Functionality - Does the change ultimately impact how firmware functions?
    • Examples: Add a new library, publish a new PPI, update an algorithm, ...
  • Impacts security?
    • Security - Does the change have a direct security impact on an application,
      flow, or firmware?
    • Examples: Crypto algorithm change, buffer overflow fix, parameter
      validation improvement, ...
  • Breaking change?
    • Breaking change - Will anyone consuming this change experience a break
      in build or boot behavior?
    • Examples: Add a new library class, move a module to a different repo, call
      a function in a new library class in a pre-existing module, ...
  • Includes tests?
    • Tests - Does the change include any explicit test code?
    • Examples: Unit tests, integration tests, robot tests, ...
  • Includes documentation?
    • Documentation - Does the change contain explicit documentation additions
      outside direct code modifications (and comments)?
    • Examples: Update readme file, add feature readme file, link to documentation
      on an a separate Web page, ...

How This Was Tested

  • Compilation
  • CodeQL

Integration Instructions

N/A

All header files should include header guards.

Some header files, such as those which define structures,
cannot be included more than once within a translation unit, as doing
so would cause a redefinition error. Such headers must be guarded to
prevent ill-effects from multiple inclusion. Similarly, if header
files include other header files, and this inclusion graph contains
a cycle, then at least one file within the cycle must contain header
guards in order to break the cycle. Because of cases like these, all
headers should be guarded as a matter of good practice, even if they
do not strictly need to be.

Furthermore, most modern compilers contain optimizations which are
triggered by header guards. If the header guard strictly conforms
to the pattern that compilers expect, then inclusions of that
header other than the first have absolutely no effect: the file
isn't re-read from disk, nor is it re-tokenised or re-preprocessed.
This can result in a noticeable, albeit minor, improvement to
compilation time.

Signed-off-by: Michael Kubacki <[email protected]>
@makubacki makubacki self-assigned this Jan 6, 2024
@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Jan 6, 2024
@makubacki makubacki merged commit 6d9f164 into microsoft:main Jan 11, 2024
14 checks passed
ProjectMuBot referenced this pull request in microsoft/mu_tiano_platforms Feb 7, 2024
Introduces 16 new commits in [Features/DFCI](https://github.com/microsoft/mu_feature_dfci).

<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/7ebaafe21c424484bd54fcc14b8621512fcfd1a7">7ebaaf</a> GitHub Action: Bump actions/setup-python from 4 to 5 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/171">#171</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/dad287af53ee6d46e3c2d1bbe871e2d6f8ac6f3f">dad287</a> pip: bump edk2-pytool-extensions from 0.26.2 to 0.26.3 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/174">#174</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/74f99d60d65a6ec5943aaba53e63db325485aaef">74f99d</a> pip: bump edk2-pytool-library from 0.19.7 to 0.19.8 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/173">#173</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/f4f8b31d278c32fd4bba941c07e98de9c2d3f755">f4f8b3</a> Repo File Sync: Update GitHub actions in CodeQL workflow (<a href="https://github.com/microsoft/mu_feature_dfci/pull/177">#177</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/4f61f15818ccbc6c273e28bf5e3746798ba8f013">4f61f1</a> pip: bump edk2-pytool-extensions from 0.26.3 to 0.26.4 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/178">#178</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/94fab9ca7f7d3dd97344903f028b1684fbb5cf13">94fab9</a> pip: bump regex from 2023.10.3 to 2023.12.25 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/179">#179</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/6d9f1641a550cce0d3a5a2db9e329d95f92e74fb">6d9f16</a> Add missing library header guards (<a href="https://github.com/microsoft/mu_feature_dfci/pull/181">#181</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/bcf129cb557b9edb09f7420af7984d6d1e95a3b5">bcf129</a> .git-blame-ignore-revs: Ignore Line Ending and Uncrustify only commits (<a href="https://github.com/microsoft/mu_feature_dfci/pull/182">#182</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/c8011291657bcc49cceaf1f9425baad39642bfdc">c80112</a> pip: bump edk2-pytool-library from 0.19.8 to 0.19.9 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/183">#183</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/d7eaaea27899e7cd5db3593b99ff9813873a4f9c">d7eaae</a> DfciPkg: Drop IntrinsicLib (<a href="https://github.com/microsoft/mu_feature_dfci/pull/185">#185</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/d8533821ba56a525ae10dd8f6f4458374aa9471d">d85338</a> Repo File Sync: Support CodeQL Plugin in BaseTools (<a href="https://github.com/microsoft/mu_feature_dfci/pull/186">#186</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/d07069b5d0ae74855b22f11172611a2fc8aad9b9">d07069</a> Update pip-requirements.txt (<a href="https://github.com/microsoft/mu_feature_dfci/pull/190">#190</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/5dbc7025dcc55873871cc71cac2cce18c01e6482">5dbc70</a> Repo File Sync: synced file(s) with microsoft/mu_devops (<a href="https://github.com/microsoft/mu_feature_dfci/pull/187">#187</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/202abc76a903193e0736fd29c72f52816d89db0a">202abc</a> GitHub Action: Bump robinraju/release-downloader from 1.8 to 1.9 (<a href="https://github.com/microsoft/mu_feature_dfci/pull/191">#191</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/85bebf6a5a3d79d3e3df198726f20e018eb44f0b">85bebf</a> Repo File Sync: synced file(s) with microsoft/mu_devops (<a href="https://github.com/microsoft/mu_feature_dfci/pull/192">#192</a>)</li>
<li><a href="https://github.com/microsoft/mu_feature_dfci/commit/ae7a47ff6682bf50d116d5dd3edb8d1e4596cfb7">ae7a47</a> Repo File Sync: synced file(s) with microsoft/mu_devops (<a href="https://github.com/microsoft/mu_feature_dfci/pull/193">#193</a>)</li>
</ul>
</details>

Signed-off-by: Project Mu Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact:non-functional Does not have a functional impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants