-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc][bazel] Add bazel targets for libc/include/... tests. #141150
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
Open
jtstogel
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jtstogel:add-include-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+368
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
What would happen if you try to link in this library to a test which already has
main()
before this change?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.
It'll fail to link with
duplicate symbol: main
. In the case that a test has it's ownmain()
, I figured it's least surprising to be explicit about whichmain()
a program is using rather than falling back to the unit test framework'smain()
if there's e.g. a typo somewhere in the test or the test'smain()
is namespaced or something.Happy to revert if you think it's unnecessary or there's another reason to avoid it!
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.
So, both with and without this change the link would fail with
duplicate symbol: main
if the unit test which has its own main() would depend on//libc/test/UnitTest:LibcUnitTest
. Could you clarify which behavior are you trying to change?E.g. if a unit test accidentally has its
int main()
wrapped in a namespace, then both with and without this change the test will instead pick up the main() from the framework, won't it?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.
I could be misconfigured on my machine, but AFAICT this isn't true?
Here's some code examples: main...jtstogel:llvm-project:linker-opt-example. My understanding (which may be incorrect) is that the linker won't include the object file unless a symbol is used, so if the test has it's own
main()
, the unit test framework main will just be ignored.Sorry that example wasn't well formed. I think a better argument for why files like these should set
alwayslink=True
is that the program's semantics falls down to link order. In the following example, what does the test do? I would expect it to immediately fail withduplicate symbol: main
, but on my machine the test either fails or passes based on the ordering of[":main1", ":main2"]
.main1.cc
main2.cc
example_test.cc
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.
At the end of the day, this line of the change doesn't matter so much -- I only included it here since it seemed marginally better and non-controvertial. Happy to remove it if you feel it's worse for whatever reason.
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.
Thanks for the detailed explanation, I agree that this change is reasonable. Would you mind adding a comment above
alwayslink = True
to specify that we deliberately force linking in library to ensure the test case doesn't provide their ownmain()
?