about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJavier Blazquez <jblazquez@riotgames.com>2021-10-11 12:09:32 -0700
committerJavier Blazquez <jblazquez@riotgames.com>2021-10-11 12:09:32 -0700
commit4ed846ad4d4e0be96efc4837fa416aabce1882db (patch)
tree6e7b9ea268fc26c35e3c3da2071e2b63e158bb1f /src
parent25ec8273855fde2d72ae877b397e054de5300e10 (diff)
downloadrust-4ed846ad4d4e0be96efc4837fa416aabce1882db.tar.gz
rust-4ed846ad4d4e0be96efc4837fa416aabce1882db.zip
Add -Z no-unique-section-names to reduce ELF header bloat.
This change adds a new compiler flag that can help reduce the size of
ELF binaries that contain many functions.

By default, when enabling function sections (which is the default for most
targets), the LLVM backend will generate different section names for each
function. For example, a function "func" would generate a section called
".text.func". Normally this is fine because the linker will merge all those
sections into a single one in the binary. However, starting with LLVM 12
(llvm/llvm-project@ee5d1a0), the backend will
also generate unique section names for exception handling, resulting in
thousands of ".gcc_except_table.*" sections ending up in the final binary
because some linkers don't currently merge or strip these EH sections.
This can bloat the ELF headers and string table significantly in
binaries that contain many functions.

The new option is analogous to Clang's -fno-unique-section-names, and
instructs LLVM to generate the same ".text" and ".gcc_except_table"
section for each function, resulting in smaller object files and
potentially a smaller final binary.
Diffstat (limited to 'src')
-rw-r--r--src/doc/unstable-book/src/compiler-flags/no-unique-section-names.md9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/compiler-flags/no-unique-section-names.md b/src/doc/unstable-book/src/compiler-flags/no-unique-section-names.md
new file mode 100644
index 00000000000..5c1c7cda701
--- /dev/null
+++ b/src/doc/unstable-book/src/compiler-flags/no-unique-section-names.md
@@ -0,0 +1,9 @@
+# `no-unique-section-names`
+
+------------------------
+
+This flag currently applies only to ELF-based targets using the LLVM codegen backend. It prevents the generation of unique ELF section names for each separate code and data item when `-Z function-sections` is also in use, which is the default for most targets. This option can reduce the size of object files, and depending on the linker, the final ELF binary as well.
+
+For example, a function `func` will by default generate a code section called `.text.func`. Normally this is fine because the linker will merge all those `.text.*` sections into a single one in the binary. However, starting with [LLVM 12](https://github.com/llvm/llvm-project/commit/ee5d1a04), the backend will also generate unique section names for exception handling, so you would see a section name of `.gcc_except_table.func` in the object file and potentially in the final ELF binary, which could add significant bloat to programs that contain many functions.
+
+This flag instructs LLVM to use the same `.text` and `.gcc_except_table` section name for each function, and it is analogous to Clang's `-fno-unique-section-names` option.