]> git.lizzy.rs Git - rust.git/commitdiff
rustc-book: Document `-C relocation-model`
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 23 Apr 2020 21:53:25 +0000 (00:53 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 26 Apr 2020 08:37:16 +0000 (11:37 +0300)
src/doc/rustc/src/codegen-options/index.md
src/librustc_session/options.rs

index a503679f19bf74e039cbecb0b82ee6dd1b95bb87..dc5d797ebbcd191dbf5bf10652729c9a18bf7552 100644 (file)
@@ -319,11 +319,46 @@ to a valid `.profdata` file. See the chapter on
 
 ## relocation-model
 
-This option lets you choose which
-[relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to
-use.
+This option controls generation of
+[position-independent code (PIC)](https://en.wikipedia.org/wiki/Position-independent_code).
 
-To find the valid options for this flag, run `rustc --print relocation-models`.
+Supported values for this option are:
+
+#### Primary relocation models
+
+- `static` - non-relocatable code, machine instructions may use absolute addressing modes.
+
+- `pic` - fully relocatable position independent code,
+machine instructions need to use relative addressing modes.  
+Equivalent to the "uppercase" `-fPIC` or `-fPIE` options in other compilers,
+depending on the produced crate types.  
+This is the default model for majority of supported targets.
+
+#### Special relocation models
+
+- `dynamic-no-pic` - relocatable external references, non-relocatable code.  
+Only makes sense on Darwin and is rarely used.  
+If StackOverflow tells you to use this as an opt-out of PIC or PIE, don't believe it,
+use `-C relocation-model=static` instead.
+- `ropi`, `rwpi` and `ropi-rwpi` - relocatable code and read-only data, relocatable read-write data,
+and combination of both, respectively.  
+Only makes sense for certain embedded ARM targets.
+- `default` - relocation model default to the current target.  
+Only makes sense as an override for some other explicitly specified relocation model
+previously set on the command line.
+
+Supported values can also be discovered by running `rustc --print relocation-models`.
+
+#### Linking effects
+
+In addition to codegen effects, `relocation-model` has effects during linking.
+
+If the relocation model is `pic` and the current target supports position-independent executables
+(PIE), the linker will be instructed (`-pie`) to produce one.  
+If the target doesn't support both position-independent and statically linked executables,
+then `-C target-feature=+crt-static` "wins" over `-C relocation-model=pic`,
+and the linker is instructed (`-static`) to produce a statically linked
+but not position-independent executable.
 
 ## remark
 
index 804e929bc812fc42702bc21b012bb0d777c2040c..2279c16748c12fc4b87cb5fb6e9af17ce85c9422 100644 (file)
@@ -706,7 +706,8 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
     profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
         "use the given `.profdata` file for profile-guided optimization"),
     relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
-        "choose the relocation model to use (`rustc --print relocation-models` for details)"),
+        "control generation of position-independent code (PIC) \
+        (`rustc --print relocation-models` for details)"),
     remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
         "print remarks for these optimization passes (space separated, or \"all\")"),
     rpath: bool = (false, parse_bool, [UNTRACKED],