-
Notifications
You must be signed in to change notification settings - Fork 88
Fix #570: Honor #![no_builtins] attribute by passing -fno-builtin to GCC #854
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
harin-ramesh
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
harin-ramesh:issue-570-fix
base: master
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.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
290e465
Fix #570: Honor #![no_builtins] attribute by passing -fno-builtin to GCC
harin-ramesh 118f663
Add test to verify #![no_builtins] prevents GCC loop-to-memset optimi…
harin-ramesh 7b582f1
Moved builtins test to a seperate folder
harin-ramesh 92f028d
Code refactor and comment update
harin-ramesh 9246f9b
updated comments
harin-ramesh 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Test that the #![no_builtins] attribute is honored. | ||
| // When this attribute is present, GCC should not replace code patterns | ||
| // (like loops) with calls to builtins (like memset). | ||
| // See https://github.com/rust-lang/rustc_codegen_gcc/issues/570 | ||
| // | ||
| // This test is verified by the build system test `--no-builtins-tests` which | ||
| // compiles this file and checks that `memset` is not referenced in the object file. | ||
|
|
||
| #![no_std] | ||
| #![no_builtins] | ||
| #![crate_type = "lib"] | ||
|
|
||
| // This function implements a byte-setting loop that GCC would typically | ||
| // optimize into a memset call. With #![no_builtins], GCC should preserve | ||
| // the loop instead of replacing it with a builtin call. | ||
| #[no_mangle] | ||
| #[inline(never)] | ||
| pub unsafe fn set_bytes(mut s: *mut u8, c: u8, n: usize) { | ||
| let end = s.add(n); | ||
| while s < end { | ||
| *s = c; | ||
| s = s.add(1); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Test that without #![no_builtins], GCC DOES replace code patterns with builtins. | ||
| // This is the counterpart to no_builtins.rs - we verify that memset IS emitted | ||
| // when the no_builtins attribute is NOT present. | ||
| // | ||
| // This test is verified by the build system test `--no-builtins-tests` which | ||
| // compiles this file and checks that `memset` IS referenced in the object file. | ||
|
|
||
| #![no_std] | ||
| #![crate_type = "lib"] | ||
|
|
||
| // This function implements a byte-setting loop that GCC should optimize | ||
| // into a memset call when no_builtins is NOT set. | ||
| #[no_mangle] | ||
| #[inline(never)] | ||
| pub unsafe fn set_bytes(mut s: *mut u8, c: u8, n: usize) { | ||
| let end = s.add(n); | ||
| while s < end { | ||
| *s = c; | ||
| s = s.add(1); | ||
| } | ||
| } |
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.
Please add a comment explaining why we use this specific flag and link to GCC's source code.
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 do not see a new link to GCC's source code.
Did you add a link to this code as requested?
Thanks.
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 missed adding the link earlier, added now, please review.