GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — permission: move PrintTree into unnamed namespace by tniessen · Pull Request #48874 · nodejs/node

Conversation

@tniessen

@tniessen tniessen commented Jul 21, 2023

Copy link
Copy Markdown
Member

This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@tniessen
permission: move PrintTree into unnamed namespace
1515ca7
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.
@nodejs-github-bot

nodejs-github-bot commented Jul 21, 2023

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jul 21, 2023
RafaelGSS
RafaelGSS approved these changes Jul 21, 2023
View reviewed changes

@RafaelGSS RafaelGSS left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. Would you mind explaining the current problem? Just to not make the same mistake again

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tniessen reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@tniessen

tniessen commented Jul 21, 2023

Copy link
Copy Markdown
Member Author

@RafaelGSS Of course :)

When building a C++ application, each compilation unit (e.g., fs_permission.cc) is compiled separately. Then, the linker combines the resulting object files (such as fs_permission.o) into a single executable file (or static/shared library).

As a rule of thumb, the visibility of symbols during the compilation phase should match the visibility of symbols during the linking phase. In this case, for example, PrintTree is not declared in any header files, so during the compilation phase, it is only visible within a single compilation unit (i.e., within fs_permission.cc). However, during the linking phase, the PrintTree symbol will be visible regardless of where it was defined, and regardless of whether it has been declared elsewhere.

This can lead to subtle bugs. (I'll ignore name mangling in this section.)

  • For example, if someone defined another function PrintTree in child_process_permission.cc, it would not result in a compiler error because the compiler only considers one compilation unit at a time, but it would lead to an error during the linking phase. And linker errors tend to be difficult to analyze, so a compiler error is almost always preferable.
  • A worse scenario arises when someone declares a function by the same name PrintTree elsewhere but does not define it properly (e.g., because the definition contains a typo in the function name, such as PrinTre). It again won't lead to a compiler error because the compiler has seen a valid declaration of PrintTree, and it also won't lead to an error during the linking phase because the linker finds a definition of the function. The linker does not care what compilation unit the definition came from, it only cares about the name of the symbol. This might lead one compilation unit to accidentally refer to a function that was never supposed to be visible outside of another compilation unit.

Moving a function into an anonymous namespace within a compilation unit ensures that it will not be visible outside of the compilation unit during the linking phase. (In most cases, the same can be accomplished by marking the function as static, but in modern C++, we have a slight preference towards anonymous namespaces.)

Properly managing visibility has other benefits, too. For example, you might want to get a compiler warning if a function is unused. However, if a function is not in an anonymous namespace and not marked as static, the compiler has to assume that it may be referenced by other compilation units, and thus cannot detect if it is unused. Making the compiler aware of the intended visibility allows better analysis of the source code.

RafaelGSS, anonrig, and debadree25 reacted with heart emoji
All reactions
  • ❤️ 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RafaelGSS

RafaelGSS commented Jul 21, 2023

Copy link
Copy Markdown
Member

Thank you!

tniessen, anonrig, and debadree25 reacted with heart emoji
All reactions
  • ❤️ 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@debadree25 debadree25 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Jul 23, 2023
debadree25
debadree25 approved these changes Jul 23, 2023
View reviewed changes

@debadree25 debadree25 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you much for explaining so well @tniessen :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tniessen reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jul 23, 2023
@nodejs-github-bot

nodejs-github-bot commented Jul 23, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/52905/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Jul 23, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/52906/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Jul 23, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/52907/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RafaelGSS RafaelGSS added the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 23, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 23, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 88ab2e7 into nodejs:main Jul 23, 2023
@nodejs-github-bot

nodejs-github-bot commented Jul 23, 2023

Copy link
Copy Markdown
Collaborator

Landed in 88ab2e7

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jul 24, 2023
CI Reliability 2023-07-24 nodejs/reliability#622
Open
CI Reliability 2023-07-25 nodejs/reliability#623
Open
CI Reliability 2023-07-26 nodejs/reliability#624
Open
CI Reliability 2023-07-27 nodejs/reliability#625
Open
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Jul 27, 2023
@tniessen @Ceres6
permission: move PrintTree into unnamed namespace
8fd1490
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: nodejs#48874
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
This was referenced Jul 28, 2023
CI Reliability 2023-07-28 nodejs/reliability#626
Open
CI Reliability 2023-07-29 nodejs/reliability#627
Open
CI Reliability 2023-07-30 nodejs/reliability#628
Open
CI Reliability 2023-07-31 nodejs/reliability#629
Open
@tniessen tniessen added the permission Issues and PRs related to the Permission Model. label Aug 10, 2023
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
@tniessen @Ceres6
permission: move PrintTree into unnamed namespace
2ed30b3
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: nodejs#48874
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
@tniessen @Ceres6
permission: move PrintTree into unnamed namespace
9dee421
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: nodejs#48874
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this pull request Aug 14, 2023
@tniessen @UlisesGascon
permission: move PrintTree into unnamed namespace
a5e8fc7
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: nodejs#48874
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Aug 15, 2023
@tniessen @RafaelGSS
permission: move PrintTree into unnamed namespace
53ee985
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: #48874
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
v20.6.0 proposal #49185
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@RafaelGSS RafaelGSS RafaelGSS approved these changes
+1 more reviewer
@debadree25 debadree25 debadree25 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. permission Issues and PRs related to the Permission Model.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@tniessen @nodejs-github-bot @RafaelGSS @debadree25
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.