2015-03-25 04:17:33 -05:00
|
|
|
//@ ignore-aarch64
|
2018-01-03 12:24:25 -06:00
|
|
|
//@ ignore-gdb // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
|
2014-10-09 09:31:03 -05:00
|
|
|
//@ min-lldb-version: 310
|
2013-11-04 00:53:01 -06:00
|
|
|
|
2014-02-06 21:57:09 -06:00
|
|
|
//@ compile-flags:-g
|
2014-07-09 07:46:09 -05:00
|
|
|
|
|
|
|
// === GDB TESTS ===================================================================================
|
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::SINGLE_VARIANT'
|
|
|
|
// gdbr-command:print c_style_enum::SINGLE_VARIANT
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$1 = TheOnlyVariant
|
|
|
|
// gdbr-check:$1 = c_style_enum::SingleVariant::TheOnlyVariant
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::AUTO_ONE'
|
|
|
|
// gdbr-command:print c_style_enum::AUTO_ONE
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$2 = One
|
|
|
|
// gdbr-check:$2 = c_style_enum::AutoDiscriminant::One
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::AUTO_TWO'
|
|
|
|
// gdbr-command:print c_style_enum::AUTO_TWO
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$3 = One
|
|
|
|
// gdbr-check:$3 = c_style_enum::AutoDiscriminant::One
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::AUTO_THREE'
|
|
|
|
// gdbr-command:print c_style_enum::AUTO_THREE
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$4 = One
|
|
|
|
// gdbr-check:$4 = c_style_enum::AutoDiscriminant::One
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::MANUAL_ONE'
|
|
|
|
// gdbr-command:print c_style_enum::MANUAL_ONE
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$5 = OneHundred
|
|
|
|
// gdbr-check:$5 = c_style_enum::ManualDiscriminant::OneHundred
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::MANUAL_TWO'
|
|
|
|
// gdbr-command:print c_style_enum::MANUAL_TWO
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$6 = OneHundred
|
|
|
|
// gdbr-check:$6 = c_style_enum::ManualDiscriminant::OneHundred
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2017-03-09 15:11:23 -06:00
|
|
|
// gdbg-command:print 'c_style_enum::MANUAL_THREE'
|
|
|
|
// gdbr-command:print c_style_enum::MANUAL_THREE
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$7 = OneHundred
|
|
|
|
// gdbr-check:$7 = c_style_enum::ManualDiscriminant::OneHundred
|
2014-02-20 19:44:29 -06:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:run
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print auto_one
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$8 = One
|
|
|
|
// gdbr-check:$8 = c_style_enum::AutoDiscriminant::One
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print auto_two
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$9 = Two
|
|
|
|
// gdbr-check:$9 = c_style_enum::AutoDiscriminant::Two
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print auto_three
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$10 = Three
|
|
|
|
// gdbr-check:$10 = c_style_enum::AutoDiscriminant::Three
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print manual_one_hundred
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$11 = OneHundred
|
|
|
|
// gdbr-check:$11 = c_style_enum::ManualDiscriminant::OneHundred
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print manual_one_thousand
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$12 = OneThousand
|
|
|
|
// gdbr-check:$12 = c_style_enum::ManualDiscriminant::OneThousand
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print manual_one_million
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$13 = OneMillion
|
|
|
|
// gdbr-check:$13 = c_style_enum::ManualDiscriminant::OneMillion
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-04-24 04:35:48 -05:00
|
|
|
// gdb-command:print single_variant
|
2016-10-25 16:32:04 -05:00
|
|
|
// gdbg-check:$14 = TheOnlyVariant
|
|
|
|
// gdbr-check:$14 = c_style_enum::SingleVariant::TheOnlyVariant
|
|
|
|
|
|
|
|
// gdbg-command:print 'c_style_enum::AUTO_TWO'
|
|
|
|
// gdbr-command:print AUTO_TWO
|
|
|
|
// gdbg-check:$15 = Two
|
|
|
|
// gdbr-check:$15 = c_style_enum::AutoDiscriminant::Two
|
|
|
|
|
|
|
|
// gdbg-command:print 'c_style_enum::AUTO_THREE'
|
|
|
|
// gdbr-command:print AUTO_THREE
|
|
|
|
// gdbg-check:$16 = Three
|
|
|
|
// gdbr-check:$16 = c_style_enum::AutoDiscriminant::Three
|
|
|
|
|
|
|
|
// gdbg-command:print 'c_style_enum::MANUAL_TWO'
|
|
|
|
// gdbr-command:print MANUAL_TWO
|
|
|
|
// gdbg-check:$17 = OneThousand
|
|
|
|
// gdbr-check:$17 = c_style_enum::ManualDiscriminant::OneThousand
|
|
|
|
|
|
|
|
// gdbg-command:print 'c_style_enum::MANUAL_THREE'
|
|
|
|
// gdbr-command:print MANUAL_THREE
|
|
|
|
// gdbg-check:$18 = OneMillion
|
|
|
|
// gdbr-check:$18 = c_style_enum::ManualDiscriminant::OneMillion
|
2013-07-02 03:33:51 -05:00
|
|
|
|
2014-07-09 07:46:09 -05:00
|
|
|
|
|
|
|
// === LLDB TESTS ==================================================================================
|
|
|
|
|
|
|
|
// lldb-command:run
|
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v auto_one
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] One
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::AutoDiscriminant) auto_one = c_style_enum::AutoDiscriminant::One
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v auto_two
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] Two
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::AutoDiscriminant) auto_two = c_style_enum::AutoDiscriminant::Two
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v auto_three
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] Three
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::AutoDiscriminant) auto_three = c_style_enum::AutoDiscriminant::Three
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v manual_one_hundred
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] OneHundred
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_hundred = c_style_enum::ManualDiscriminant::OneHundred
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v manual_one_thousand
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] OneThousand
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_thousand = c_style_enum::ManualDiscriminant::OneThousand
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v manual_one_million
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] OneMillion
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_million = c_style_enum::ManualDiscriminant::OneMillion
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2024-03-15 09:05:57 -05:00
|
|
|
// lldb-command:v single_variant
|
2024-03-10 08:55:58 -05:00
|
|
|
// lldbg-check:[...] TheOnlyVariant
|
2018-10-02 11:13:30 -05:00
|
|
|
// lldbr-check:(c_style_enum::SingleVariant) single_variant = c_style_enum::SingleVariant::TheOnlyVariant
|
2014-07-09 07:46:09 -05:00
|
|
|
|
2014-10-27 17:37:07 -05:00
|
|
|
#![allow(unused_variables)]
|
2014-04-02 22:18:58 -05:00
|
|
|
#![allow(dead_code)]
|
2015-09-19 15:33:47 -05:00
|
|
|
#![feature(omit_gdb_pretty_printer_section)]
|
2014-12-03 16:48:18 -06:00
|
|
|
#![omit_gdb_pretty_printer_section]
|
2013-08-17 10:37:42 -05:00
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
use self::AutoDiscriminant::{One, Two, Three};
|
|
|
|
use self::ManualDiscriminant::{OneHundred, OneThousand, OneMillion};
|
|
|
|
use self::SingleVariant::TheOnlyVariant;
|
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2013-07-02 11:10:24 -05:00
|
|
|
enum AutoDiscriminant {
|
2013-07-02 03:33:51 -05:00
|
|
|
One,
|
|
|
|
Two,
|
|
|
|
Three
|
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2013-07-02 11:10:24 -05:00
|
|
|
enum ManualDiscriminant {
|
2013-07-02 03:33:51 -05:00
|
|
|
OneHundred = 100,
|
|
|
|
OneThousand = 1000,
|
|
|
|
OneMillion = 1000000
|
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2018-04-25 03:33:02 -05:00
|
|
|
#[repr(u8)]
|
2013-07-02 11:10:24 -05:00
|
|
|
enum SingleVariant {
|
|
|
|
TheOnlyVariant
|
|
|
|
}
|
|
|
|
|
2014-02-20 19:44:29 -06:00
|
|
|
static SINGLE_VARIANT: SingleVariant = TheOnlyVariant;
|
|
|
|
|
|
|
|
static mut AUTO_ONE: AutoDiscriminant = One;
|
|
|
|
static mut AUTO_TWO: AutoDiscriminant = One;
|
|
|
|
static mut AUTO_THREE: AutoDiscriminant = One;
|
|
|
|
|
|
|
|
static mut MANUAL_ONE: ManualDiscriminant = OneHundred;
|
|
|
|
static mut MANUAL_TWO: ManualDiscriminant = OneHundred;
|
|
|
|
static mut MANUAL_THREE: ManualDiscriminant = OneHundred;
|
|
|
|
|
2013-07-02 03:33:51 -05:00
|
|
|
fn main() {
|
|
|
|
|
|
|
|
let auto_one = One;
|
|
|
|
let auto_two = Two;
|
|
|
|
let auto_three = Three;
|
|
|
|
|
|
|
|
let manual_one_hundred = OneHundred;
|
|
|
|
let manual_one_thousand = OneThousand;
|
|
|
|
let manual_one_million = OneMillion;
|
|
|
|
|
2013-07-02 11:10:24 -05:00
|
|
|
let single_variant = TheOnlyVariant;
|
|
|
|
|
2014-02-20 19:44:29 -06:00
|
|
|
unsafe {
|
|
|
|
AUTO_TWO = Two;
|
|
|
|
AUTO_THREE = Three;
|
|
|
|
|
|
|
|
MANUAL_TWO = OneThousand;
|
|
|
|
MANUAL_THREE = OneMillion;
|
|
|
|
};
|
|
|
|
|
2014-07-09 07:46:09 -05:00
|
|
|
zzz(); // #break
|
rustc: Enable -f{function,data}-sections
The compiler has previously been producing binaries on the order of 1.8MB for
hello world programs "fn main() {}". This is largely a result of the compilation
model used by compiling entire libraries into a single object file and because
static linking is favored by default.
When linking, linkers will pull in the entire contents of an object file if any
symbol from the object file is used. This means that if any symbol from a rust
library is used, the entire library is pulled in unconditionally, regardless of
whether the library is used or not.
Traditional C/C++ projects do not normally encounter these large executable
problems because their archives (rust's rlibs) are composed of many objects.
Because of this, linkers can eliminate entire objects from being in the final
executable. With rustc, however, the linker does not have the opportunity to
leave out entire object files.
In order to get similar benefits from dead code stripping at link time, this
commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as
well as passing --gc-sections to the linker *by default*. This means that each
function and each global will be placed into its own section, allowing the
linker to GC all unused functions and data symbols.
By enabling these flags, rust is able to generate much smaller binaries default.
On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in
size). The output size of dynamic libraries remained constant, but the output
size of rlibs increased, as seen below:
libarena - 2.27% bigger ( 292872 => 299508)
libcollections - 0.64% bigger ( 6765884 => 6809076)
libflate - 0.83% bigger ( 186516 => 188060)
libfourcc - 14.71% bigger ( 307290 => 352498)
libgetopts - 4.42% bigger ( 761468 => 795102)
libglob - 2.73% bigger ( 899932 => 924542)
libgreen - 9.63% bigger ( 1281718 => 1405124)
libhexfloat - 13.88% bigger ( 333738 => 380060)
liblibc - 10.79% bigger ( 551280 => 610736)
liblog - 10.93% bigger ( 218208 => 242060)
libnative - 8.26% bigger ( 1362096 => 1474658)
libnum - 2.34% bigger ( 2583400 => 2643916)
librand - 1.72% bigger ( 1608684 => 1636394)
libregex - 6.50% bigger ( 1747768 => 1861398)
librustc - 4.21% bigger (151820192 => 158218924)
librustdoc - 8.96% bigger ( 13142604 => 14320544)
librustuv - 4.13% bigger ( 4366896 => 4547304)
libsemver - 2.66% bigger ( 396166 => 406686)
libserialize - 1.91% bigger ( 6878396 => 7009822)
libstd - 3.59% bigger ( 39485286 => 40902218)
libsync - 3.95% bigger ( 1386390 => 1441204)
libsyntax - 4.96% bigger ( 35757202 => 37530798)
libterm - 13.99% bigger ( 924580 => 1053902)
libtest - 6.04% bigger ( 2455720 => 2604092)
libtime - 2.84% bigger ( 1075708 => 1106242)
liburl - 6.53% bigger ( 590458 => 629004)
libuuid - 4.63% bigger ( 326350 => 341466)
libworkcache - 8.45% bigger ( 1230702 => 1334750)
This increase in size is a result of encoding many more section names into each
object file (rlib). These increases are moderate enough that this change seems
worthwhile to me, due to the drastic improvements seen in the final artifacts.
The overall increase of the stage2 target folder (not the size of an install)
went from 337MB to 348MB (3% increase).
Additionally, linking is generally slower when executed with all these new
sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the
`rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three
megabytes are shaved off the binary. I found this increase in link time to be
acceptable relative to the benefits of code size gained.
This commit only enables --gc-sections for *executables*, not dynamic libraries.
LLVM does all the heavy lifting when producing an object file for a dynamic
library, so there is little else for the linker to do (remember that we only
have one object file).
I conducted similar experiments by putting a *module's* functions and data
symbols into its own section (granularity moved to a module level instead of a
function/static level). The size benefits of a hello world were seen to be on
the order of 400K rather than 1.2MB. It seemed that enough benefit was gained
using ffunction-sections that this route was less desirable, despite the lesser
increases in binary rlib size.
2014-04-28 19:17:18 -05:00
|
|
|
|
2016-04-07 14:43:46 -05:00
|
|
|
// Borrow to avoid an eager load of the constant value in the static.
|
|
|
|
let a = &SINGLE_VARIANT;
|
rustc: Enable -f{function,data}-sections
The compiler has previously been producing binaries on the order of 1.8MB for
hello world programs "fn main() {}". This is largely a result of the compilation
model used by compiling entire libraries into a single object file and because
static linking is favored by default.
When linking, linkers will pull in the entire contents of an object file if any
symbol from the object file is used. This means that if any symbol from a rust
library is used, the entire library is pulled in unconditionally, regardless of
whether the library is used or not.
Traditional C/C++ projects do not normally encounter these large executable
problems because their archives (rust's rlibs) are composed of many objects.
Because of this, linkers can eliminate entire objects from being in the final
executable. With rustc, however, the linker does not have the opportunity to
leave out entire object files.
In order to get similar benefits from dead code stripping at link time, this
commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as
well as passing --gc-sections to the linker *by default*. This means that each
function and each global will be placed into its own section, allowing the
linker to GC all unused functions and data symbols.
By enabling these flags, rust is able to generate much smaller binaries default.
On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in
size). The output size of dynamic libraries remained constant, but the output
size of rlibs increased, as seen below:
libarena - 2.27% bigger ( 292872 => 299508)
libcollections - 0.64% bigger ( 6765884 => 6809076)
libflate - 0.83% bigger ( 186516 => 188060)
libfourcc - 14.71% bigger ( 307290 => 352498)
libgetopts - 4.42% bigger ( 761468 => 795102)
libglob - 2.73% bigger ( 899932 => 924542)
libgreen - 9.63% bigger ( 1281718 => 1405124)
libhexfloat - 13.88% bigger ( 333738 => 380060)
liblibc - 10.79% bigger ( 551280 => 610736)
liblog - 10.93% bigger ( 218208 => 242060)
libnative - 8.26% bigger ( 1362096 => 1474658)
libnum - 2.34% bigger ( 2583400 => 2643916)
librand - 1.72% bigger ( 1608684 => 1636394)
libregex - 6.50% bigger ( 1747768 => 1861398)
librustc - 4.21% bigger (151820192 => 158218924)
librustdoc - 8.96% bigger ( 13142604 => 14320544)
librustuv - 4.13% bigger ( 4366896 => 4547304)
libsemver - 2.66% bigger ( 396166 => 406686)
libserialize - 1.91% bigger ( 6878396 => 7009822)
libstd - 3.59% bigger ( 39485286 => 40902218)
libsync - 3.95% bigger ( 1386390 => 1441204)
libsyntax - 4.96% bigger ( 35757202 => 37530798)
libterm - 13.99% bigger ( 924580 => 1053902)
libtest - 6.04% bigger ( 2455720 => 2604092)
libtime - 2.84% bigger ( 1075708 => 1106242)
liburl - 6.53% bigger ( 590458 => 629004)
libuuid - 4.63% bigger ( 326350 => 341466)
libworkcache - 8.45% bigger ( 1230702 => 1334750)
This increase in size is a result of encoding many more section names into each
object file (rlib). These increases are moderate enough that this change seems
worthwhile to me, due to the drastic improvements seen in the final artifacts.
The overall increase of the stage2 target folder (not the size of an install)
went from 337MB to 348MB (3% increase).
Additionally, linking is generally slower when executed with all these new
sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the
`rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three
megabytes are shaved off the binary. I found this increase in link time to be
acceptable relative to the benefits of code size gained.
This commit only enables --gc-sections for *executables*, not dynamic libraries.
LLVM does all the heavy lifting when producing an object file for a dynamic
library, so there is little else for the linker to do (remember that we only
have one object file).
I conducted similar experiments by putting a *module's* functions and data
symbols into its own section (granularity moved to a module level instead of a
function/static level). The size benefits of a hello world were seen to be on
the order of 400K rather than 1.2MB. It seemed that enough benefit was gained
using ffunction-sections that this route was less desirable, despite the lesser
increases in binary rlib size.
2014-04-28 19:17:18 -05:00
|
|
|
let a = unsafe { AUTO_ONE };
|
|
|
|
let a = unsafe { MANUAL_ONE };
|
2013-07-02 03:33:51 -05:00
|
|
|
}
|
|
|
|
|
2014-07-09 07:46:09 -05:00
|
|
|
fn zzz() { () }
|