For a simple Rust program
fn main() {
println!("Hello, world!");
}
with Cargo.toml
as:
[package]
name = "got-test"
version = "0.1.0"
edition = "2021"
[dependencies]
[profile.release]
lto = true
codegen-units = 1
And we compile it as
cargo build --release --target x86_64-unknown-linux-musl
with rustc version 1.84.0 on Ubuntu 22.04.
We can see many libc functions are called via static GOT table in the generated binary:
These GOT entries lead to many indirect calls across the whole binary, which may potentially decrease the performance (one more memory access and less opportunity for inline optimization).
I know little about LTO, while I guess it may be LTO's job to do those things? Why LTO has no effect on those static GOT entries? Since they are only read but never written across the whole binary, can these entries be eliminated?
P.S. Found this SO question which may be relevant, which I don't know if the bug described in it has been fixed or not.