-
Notifications
You must be signed in to change notification settings - Fork 13k
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 link_section attribute for static and fn items #7958
Conversation
That seems odd that the program crashes as a result of that. Could you detect this to generate a lint/error? That definitely seems like non-obvious behavior which might bite some people. |
This allows for control over the section placement of static, static mut, and fn items. One caveat is that if a static and a static mut are placed in the same section, the static is declared first, and the static mut is assigned to, the generated program crashes. For example: #[link_section=".boot"] static foo : uint = 0xdeadbeef; #[link_section=".boot"] static mut bar : uint = 0xcafebabe; Declaring bar first would mark .bootdata as writable, preventing the crash when bar is written to.
@alexcrichton: This seems expected to me. By defualt, rustc tells LLVM to emit static items in a read-only section (typically .rodata), and static mut items in a writable section (.data). Whatever new section gets defined takes the mode of the first thing that goes in it. The equivalent code in C is: const unsigned foo attribute ((section ("boot"))) = 10; GCC will throw an error on that, saying there's a section type mismatch. Clang, on the other hand, accepts it and segfaults if you assign to bar. This makes me think it's LLVM's problem. |
Looking at the LLVM source:
added with
I think that assigning into the |
@kemurphy Is there a reason to call it |
@alexcrichton: Not really, it was arbitrary; "section" just seemed a little bare and there's already another attribute prefixed with "link_" somewhere. Is "section" preferred? #rust didn't seem to have a preference when I asked about it. |
Hmm... I'd be fine with |
dbaupp suggested to let it land and then ask graydon what the test is capable of doing, but yeah I can add a test to just exercise the path. |
@huonw: Ah, cool. :) I did think of one failing test idea: put a static mut in .rodata and make sure writing to it causes a segfault. Also, putting a function in .data might have an interesting failure mode. |
This allows for control over the section placement of static, static mut, and fn items. One caveat is that if a static and a static mut are placed in the same section, the static is declared first, and the static mut is assigned to, the generated program crashes. For example: #[link_section=".boot"] static foo : uint = 0xdeadbeef; #[link_section=".boot"] static mut bar : uint = 0xcafebabe; Declaring bar first would mark .bootdata as writable, preventing the crash when bar is written to.
…les, r=camsteffen Improve styles of filtering options for Clippy's lint list Partially solves rust-lang#7958 Updated styles for filtering options. It now uses dropdown menus. ![image](https://user-images.githubusercontent.com/19844144/144608479-cdd9de0b-f101-4d49-a135-0969efb01a11.png) changelog: none
Add version filtering option to the lint list I'm no web dev, so I don't know if this is the best execution 😄. Here's how it looks: ![Desktop](https://user-images.githubusercontent.com/69764315/165403602-9e39fe0f-6a96-46cb-ba51-8b035e74cce4.gif) And on mobile: ![Mobile](https://user-images.githubusercontent.com/69764315/165403908-fc4a0051-2ed4-48a3-b45b-b261f49ce259.png) I've split this into two commits, in the second one I moved the JS into its own file to make it easier to work on. Is that alright? And if so, could the same thing be done to the css? changelog: none cc: rust-lang#7958, `@repi` r? `@xFrednet`
…=xFrednet Add Default to Clippy Lints Lint groups - related to rust-lang#7958 This PR adds a default (reset) button to Clippy Lints Lint groups. (change for website) [The page](https://rust-lang.github.io/rust-clippy/master/index.html) sets only `Deprecated` to false by default. Certainly it is easy to set only `deprecated` to false, but it may be a bit lazy for beginners. https://user-images.githubusercontent.com/38400669/194831117-3ade7e0d-c4de-4189-9daf-3be8ea3cdd18.mov changelog: none
…, r=xFrednet Add applicability filter to lint list page changelog: Add applicability filter to lint list website. Fixes rust-lang#7958 Desktop view: ![image](https://github.com/rust-lang/rust-clippy/assets/43732866/ef16dff1-c1c5-48a7-aa5c-ddd504280c90) Mobile view: ![image](https://github.com/rust-lang/rust-clippy/assets/43732866/9e6f54d9-b079-443f-a6b0-ca8ee4ed1eed)
This allows for control over the section placement of static, static
mut, and fn items. One caveat is that if a static and a static mut are
placed in the same section, the static is declared first, and the static
mut is assigned to, the generated program crashes. For example:
[link_section=".boot"]
static foo : uint = 0xdeadbeef;
[link_section=".boot"]
static mut bar : uint = 0xcafebabe;
Declaring bar first would mark .bootdata as writable, preventing the
crash when bar is written to.