-
Notifications
You must be signed in to change notification settings - Fork 431
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
Respect #[global_allocator]
in cc_common.link
builds
#1926
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c029987
Respect #[global_allocator] in cc_common.link builds
scentini c975e7c
Fix CI flags and add public visibility to test toolchain to make Baze…
scentini 0a306b1
Regenerate documentation
scentini c00b610
Exclude global alloc tests from cc_common.link task
scentini 3c38a0a
Exclude with_global_alloc directory from tests too
scentini 14f84fc
Address review comment
scentini 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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,52 @@ | ||
#include <stdint.h> | ||
|
||
// This file has some exciting magic to get Rust code linking in a cc_binary. | ||
// The Rust compiler generates some similar symbol aliases when it links, so we | ||
// have to do it manually. We mark all our symbols as weak so that linking this | ||
// via Rust tooling to produce a binary with a Rust main works. | ||
// | ||
// It is intended to be used in rust_toolchain.allocator_library. | ||
// | ||
// https://github.com/rust-lang/rust/blob/master/library/alloc/src/alloc.rs | ||
// and https://github.com/rust-lang/rust/blob/master/library/std/src/alloc.rs | ||
// are the best source of docs I've found on these functions and variables. | ||
// https://doc.rust-lang.org/std/alloc/index.html talks about how this is | ||
// intended to be used. | ||
// | ||
// Also note | ||
// https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html for | ||
// the sizes of the various integer types. | ||
// | ||
// This file strongly assumes that the default allocator is used. It will | ||
// not work with any other allocated switched in via `#[global_allocator]`. | ||
|
||
// New feature as of https://github.com/rust-lang/rust/pull/88098. | ||
__attribute__((weak)) uint8_t __rust_alloc_error_handler_should_panic = 0; | ||
|
||
extern "C" uint8_t *__rg_alloc(uintptr_t size, uintptr_t align); | ||
extern "C" __attribute__((weak)) | ||
uint8_t *__rust_alloc(uintptr_t size, uintptr_t align) { | ||
return __rg_alloc(size, align); | ||
} | ||
extern "C" void __rg_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align); | ||
extern "C" __attribute__((weak)) | ||
void __rust_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align) { | ||
__rg_dealloc(ptr, size, align); | ||
} | ||
extern "C" uint8_t *__rg_realloc(uint8_t *ptr, uintptr_t old_size, uintptr_t align, | ||
uintptr_t new_size); | ||
extern "C" __attribute__((weak)) | ||
uint8_t *__rust_realloc(uint8_t *ptr, uintptr_t old_size, uintptr_t align, | ||
uintptr_t new_size) { | ||
return __rg_realloc(ptr, old_size, align, new_size); | ||
} | ||
extern "C" uint8_t *__rg_alloc_zeroed(uintptr_t size, uintptr_t align); | ||
extern "C" __attribute__((weak)) | ||
uint8_t *__rust_alloc_zeroed(uintptr_t size, uintptr_t align) { | ||
return __rg_alloc_zeroed(size, align); | ||
} | ||
extern "C" void __rg_oom(uintptr_t size, uintptr_t align); | ||
extern "C" __attribute__((weak)) | ||
void __rust_alloc_error_handler(uintptr_t size, uintptr_t align) { | ||
__rg_oom(size, align); | ||
} |
This file contains 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,17 @@ | ||
load( | ||
"@rules_rust//rust:defs.bzl", | ||
"rust_binary", | ||
"rust_test", | ||
) | ||
|
||
rust_binary( | ||
name = "main", | ||
srcs = ["main.rs"], | ||
edition = "2021", | ||
) | ||
|
||
rust_test( | ||
name = "global_alloc_test", | ||
crate = ":main", | ||
edition = "2021", | ||
) |
This file contains 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,25 @@ | ||
workspace(name = "test_cc_common_link_with_global_alloc") | ||
|
||
local_repository( | ||
name = "rules_rust", | ||
path = "../../../", | ||
) | ||
|
||
local_repository( | ||
name = "test_cc_common_link", | ||
path = "../", | ||
) | ||
|
||
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") | ||
|
||
rules_rust_dependencies() | ||
|
||
rust_register_toolchains( | ||
allocator_library = "@test_cc_common_link//:allocator_library", | ||
edition = "2018", | ||
global_allocator_library = "@test_cc_common_link//:global_allocator_library", | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
bazel_skylib_workspace() |
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.
nit: Target that provides allocator functions when ...
nit: could you clarify that this applies only to non-exec mode
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.
Done!