1. 06 4月, 2017 5 次提交
    • J
      don't test for the absence of BAR in the rmake test · ecddad69
      Jorge Aparicio 提交于
      it's not related to this feature
      ecddad69
    • J
      cast the #[used] static to *i8 · c1635d7e
      Jorge Aparicio 提交于
      to match the type signature of the llvm.used variable
      c1635d7e
    • J
      fix location of the emitted object file · c759eea7
      Jorge Aparicio 提交于
      c759eea7
    • J
      bc1bd8a6
    • J
      add an #[used] attribute · 4c7e2773
      Jorge Aparicio 提交于
      similar to GCC's __attribute((used))__. This attribute prevents LLVM from
      optimizing away a non-exported symbol, within a compilation unit (object file),
      when there are no references to it.
      
      This is better explained with an example:
      
      ```
      #[used]
      static LIVE: i32 = 0;
      
      static REFERENCED: i32 = 0;
      
      static DEAD: i32 = 0;
      
      fn internal() {}
      
      pub fn exported() -> &'static i32 {
          &REFERENCED
      }
      ```
      
      Without optimizations, LLVM pretty much preserves all the static variables and
      functions within the compilation unit.
      
      ```
      $ rustc --crate-type=lib --emit=obj symbols.rs && nm -C symbols.o
      0000000000000000 t drop::h1be0f8f27a2ba94a
      0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c
      0000000000000000 r symbols::DEAD::hc2ea8f9bd06f380b
      0000000000000000 r symbols::LIVE::h0970cf9889edb56e
      0000000000000000 T symbols::exported::h6f096c2b1fc292b2
      0000000000000000 t symbols::internal::h0ac1aadbc1e3a494
      ```
      
      With optimizations, LLVM will drop dead code. Here `internal` is dropped because
      it's not a exported function/symbol (i.e. not `pub`lic). `DEAD` is dropped for
      the same reason. `REFERENCED` is preserved, even though it's not exported,
      because it's referenced by the `exported` function. Finally, `LIVE` survives
      because of the `#[used]` attribute even though it's not exported or referenced.
      
      ```
      $ rustc --crate-type=lib -C opt-level=3 --emit=obj symbols.rs && nm -C symbols.o
      0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c
      0000000000000000 r symbols::LIVE::h0970cf9889edb56e
      0000000000000000 T symbols::exported::h6f096c2b1fc292b2
      ```
      
      Note that the linker knows nothing about `#[used]` and will drop `LIVE`
      because no other object references to it.
      
      ```
      $ echo 'fn main() {}' >> symbols.rs
      $ rustc symbols.rs && nm -C symbols | grep LIVE
      ```
      
      At this time, `#[used]` only works on `static` variables.
      4c7e2773
  2. 05 4月, 2017 2 次提交
  3. 04 4月, 2017 6 次提交
  4. 03 4月, 2017 2 次提交
  5. 01 4月, 2017 13 次提交
  6. 31 3月, 2017 12 次提交