]> git.proxmox.com Git - rustc.git/blame - src/rtstartup/rsbegin.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / rtstartup / rsbegin.rs
CommitLineData
92a42be0
SL
1// Copyright 2015 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// rsbegin.o and rsend.o are the so called "compiler runtime startup objects".
12// They contain code needed to correctly initialize the compiler runtime.
13//
14// When an executable or dylib image is linked, all user code and libraries are
15// "sandwiched" between these two object files, so code or data from rsbegin.o
16// become first in the respective sections of the image, whereas code and data
17// from rsend.o become the last ones. This effect can be used to place symbols
18// at the beginning or at the end of a section, as well as to insert any required
19// headers or footers.
20//
21// Note that the actual module entry point is located in the C runtime startup
22// object (usually called `crtX.o), which then invokes initialization callbacks
23// of other runtime components (registered via yet another special image section).
24
cc61c64b 25#![feature(no_core, lang_items, optin_builtin_traits)]
92a42be0 26#![crate_type="rlib"]
9e0c209e 27#![no_core]
92a42be0
SL
28#![allow(non_camel_case_types)]
29
9e0c209e
SL
30#[lang = "sized"]
31trait Sized {}
32#[lang = "sync"]
33trait Sync {}
cc61c64b 34impl Sync for .. {}
9e0c209e
SL
35#[lang = "copy"]
36trait Copy {}
7cac9316 37#[lang = "freeze"]
cc61c64b
XL
38trait Freeze {}
39impl Freeze for .. {}
9e0c209e 40
7cac9316
XL
41#[lang="drop_in_place"]
42#[inline]
43#[allow(unconditional_recursion)]
44pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
45 drop_in_place(to_drop);
46}
47
92a42be0 48#[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
3157f602 49pub mod eh_frames {
92a42be0
SL
50 #[no_mangle]
51 #[link_section = ".eh_frame"]
52 // Marks beginning of the stack frame unwind info section
53 pub static __EH_FRAME_BEGIN__: [u8; 0] = [];
54
55 // Scratch space for unwinder's internal book-keeping.
56 // This is defined as `struct object` in $GCC/libgcc/unwind-dw2-fde.h.
c30ab7b3 57 static mut OBJ: [isize; 6] = [0; 6];
92a42be0
SL
58
59 // Unwind info registration/deregistration routines.
60 // See the docs of `unwind` module in libstd.
3157f602 61 extern "C" {
92a42be0
SL
62 fn rust_eh_register_frames(eh_frame_begin: *const u8, object: *mut u8);
63 fn rust_eh_unregister_frames(eh_frame_begin: *const u8, object: *mut u8);
64 }
65
66 unsafe fn init() {
67 // register unwind info on module startup
68 rust_eh_register_frames(&__EH_FRAME_BEGIN__ as *const u8,
c30ab7b3 69 &mut OBJ as *mut _ as *mut u8);
92a42be0
SL
70 }
71
72 unsafe fn uninit() {
73 // unregister on shutdown
74 rust_eh_unregister_frames(&__EH_FRAME_BEGIN__ as *const u8,
c30ab7b3 75 &mut OBJ as *mut _ as *mut u8);
92a42be0
SL
76 }
77
78 // MSVC-specific init/uninit routine registration
3157f602 79 pub mod ms_init {
92a42be0
SL
80 // .CRT$X?? sections are roughly analogous to ELF's .init_array and .fini_array,
81 // except that they exploit the fact that linker will sort them alphabitically,
82 // so e.g. sections with names between .CRT$XIA and .CRT$XIZ are guaranteed to be
83 // placed between those two, without requiring any ordering of objects on the linker
84 // command line.
85 // Note that ordering of same-named sections from different objects is not guaranteed.
86 // Since .CRT$XIA contains init array's header symbol, which must always come first,
87 // we place our initialization callback into .CRT$XIB.
88
89 #[link_section = ".CRT$XIB"] // .CRT$XI? : C initialization callbacks
90 pub static P_INIT: unsafe fn() = super::init;
91
92 #[link_section = ".CRT$XTY"] // .CRT$XT? : C termination callbacks
93 pub static P_UNINIT: unsafe fn() = super::uninit;
94 }
95}