]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/link-section.rs
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
[rust.git] / src / test / run-pass / link-section.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #[cfg(not(target_os = "macos"))]
12 #[link_section=".moretext"]
13 fn i_live_in_more_text() -> &'static str {
14     "knock knock"
15 }
16
17 #[cfg(not(target_os = "macos"))]
18 #[link_section=".imm"]
19 static magic: usize = 42;
20
21 #[cfg(not(target_os = "macos"))]
22 #[link_section=".mut"]
23 static mut frobulator: usize = 0xdeadbeef;
24
25 #[cfg(target_os = "macos")]
26 #[link_section="__TEXT,__moretext"]
27 fn i_live_in_more_text() -> &'static str {
28     "knock knock"
29 }
30
31 #[cfg(target_os = "macos")]
32 #[link_section="__RODATA,__imm"]
33 static magic: usize = 42;
34
35 #[cfg(target_os = "macos")]
36 #[link_section="__DATA,__mut"]
37 static mut frobulator: usize = 0xdeadbeef;
38
39 pub fn main() {
40     unsafe {
41         frobulator = 0xcafebabe;
42         println!("{} {} {}", i_live_in_more_text(), magic, frobulator);
43     }
44 }