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.  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:  And on mobile:  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:  Mobile view: 
7958: Avoid double text edits when renaming mod declaration r=matklad a=Veykril Closes rust-lang/rust-analyzer#7916 See microsoft/vscode-languageserver-node#752 for context Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
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.