From 6e1d0ca236c97f89af0a9816e0e9c53ae0f83052 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Tue, 15 Aug 2023 08:09:46 -0400 Subject: [PATCH] build_scripts: set the page size Otherwise lld seems to assume 0x10000 sized pages and tries to align the output segments to 0x10000. This often causes elfs with large padding regions before the first segment we actually want to load on the board. --- build_scripts/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build_scripts/src/lib.rs b/build_scripts/src/lib.rs index f7581e77..74bf682d 100644 --- a/build_scripts/src/lib.rs +++ b/build_scripts/src/lib.rs @@ -175,6 +175,11 @@ pub fn auto_layout() { // Tell rustc which linker script to use and where to find it. println!("cargo:rustc-link-arg=-T{}", layout_path.display()); println!("cargo:rustc-link-search={}", out_dir); + + // Configure the alignment size for the linker. This prevents the linker + // from assuming very large pages (i.e. 65536 bytes) and unnecessarily + // inserting additional padding into the output ELF. + println!("cargo:rustc-link-arg=-zmax-page-size=4096"); } // Retrieves an environment variable as a String. Returns None if the variable