Skip to content

Commit eccaa01

Browse files
committed
rustc_target: Add a target spec option for static-pie support
1 parent f182c4a commit eccaa01

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/librustc_codegen_ssa/back/link.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,10 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
11431143
};
11441144

11451145
// Adjust the output kind to target capabilities.
1146-
let pic_exe_supported = sess.target.target.options.position_independent_executables;
1147-
let static_pic_exe_supported = false; // FIXME: Add this option to target specs.
1148-
let static_dylib_supported = sess.target.target.options.crt_static_allows_dylibs;
1146+
let opts = &sess.target.target.options;
1147+
let pic_exe_supported = opts.position_independent_executables;
1148+
let static_pic_exe_supported = opts.static_position_independent_executables;
1149+
let static_dylib_supported = opts.crt_static_allows_dylibs;
11491150
match kind {
11501151
LinkOutputKind::DynamicPicExe if !pic_exe_supported => LinkOutputKind::DynamicNoPicExe,
11511152
LinkOutputKind::StaticPicExe if !static_pic_exe_supported => LinkOutputKind::StaticNoPicExe,

src/librustc_target/spec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,8 @@ pub struct TargetOptions {
855855
/// the functions in the executable are not randomized and can be used
856856
/// during an exploit of a vulnerability in any code.
857857
pub position_independent_executables: bool,
858+
/// Executables that are both statically linked and position-independent are supported.
859+
pub static_position_independent_executables: bool,
858860
/// Determines if the target always requires using the PLT for indirect
859861
/// library calls or not. This controls the default value of the `-Z plt` flag.
860862
pub needs_plt: bool,
@@ -1028,6 +1030,7 @@ impl Default for TargetOptions {
10281030
has_rpath: false,
10291031
no_default_libraries: true,
10301032
position_independent_executables: false,
1033+
static_position_independent_executables: false,
10311034
needs_plt: false,
10321035
relro_level: RelroLevel::None,
10331036
pre_link_objects: Default::default(),
@@ -1432,6 +1435,7 @@ impl Target {
14321435
key!(has_rpath, bool);
14331436
key!(no_default_libraries, bool);
14341437
key!(position_independent_executables, bool);
1438+
key!(static_position_independent_executables, bool);
14351439
key!(needs_plt, bool);
14361440
key!(relro_level, RelroLevel)?;
14371441
key!(archive_format);
@@ -1663,6 +1667,7 @@ impl ToJson for Target {
16631667
target_option_val!(has_rpath);
16641668
target_option_val!(no_default_libraries);
16651669
target_option_val!(position_independent_executables);
1670+
target_option_val!(static_position_independent_executables);
16661671
target_option_val!(needs_plt);
16671672
target_option_val!(relro_level);
16681673
target_option_val!(archive_format);

0 commit comments

Comments
 (0)