From dfe3b4999f6d369f6446254b142c0dc4d3754351 Mon Sep 17 00:00:00 2001 From: Sumit Garg Date: Thu, 21 Dec 2023 13:57:05 +0530 Subject: [PATCH] examples: Reuse TA linker script provided via TA devkit Having copies of TA linker scripts for every TA written in rust isn't scalable and prone to version skews with the linker script provided by TA devkit. And we would like to build and run TAs with different OP-TEE versions. So lets reuse linker script provided by TA devkit and therby drop copies from every TA direcetory. Signed-off-by: Sumit Garg --- examples/acipher-rs/ta/build.rs | 31 ++++++- examples/acipher-rs/ta/dyn_list | 6 ++ examples/acipher-rs/ta/ta_aarch64.lds | 92 ------------------- examples/acipher-rs/ta/ta_arm.lds | 91 ------------------ examples/aes-rs/ta/build.rs | 31 ++++++- examples/aes-rs/ta/dyn_list | 6 ++ examples/aes-rs/ta/ta_aarch64.lds | 92 ------------------- examples/aes-rs/ta/ta_arm.lds | 91 ------------------ examples/authentication-rs/ta/build.rs | 31 ++++++- examples/authentication-rs/ta/dyn_list | 6 ++ examples/authentication-rs/ta/ta_aarch64.lds | 92 ------------------- examples/authentication-rs/ta/ta_arm.lds | 91 ------------------ examples/big_int-rs/ta/build.rs | 31 ++++++- examples/big_int-rs/ta/dyn_list | 6 ++ examples/big_int-rs/ta/ta_aarch64.lds | 92 ------------------- examples/big_int-rs/ta/ta_arm.lds | 91 ------------------ examples/diffie_hellman-rs/ta/build.rs | 31 ++++++- examples/diffie_hellman-rs/ta/dyn_list | 6 ++ examples/diffie_hellman-rs/ta/ta_aarch64.lds | 92 ------------------- examples/diffie_hellman-rs/ta/ta_arm.lds | 91 ------------------ examples/digest-rs/ta/build.rs | 31 ++++++- examples/digest-rs/ta/dyn_list | 6 ++ examples/digest-rs/ta/ta_aarch64.lds | 92 ------------------- examples/digest-rs/ta/ta_arm.lds | 91 ------------------ examples/hello_world-rs/ta/build.rs | 31 ++++++- examples/hello_world-rs/ta/dyn_list | 6 ++ examples/hello_world-rs/ta/ta_aarch64.lds | 92 ------------------- examples/hello_world-rs/ta/ta_arm.lds | 91 ------------------ examples/hotp-rs/ta/build.rs | 31 ++++++- examples/hotp-rs/ta/dyn_list | 6 ++ examples/hotp-rs/ta/ta_aarch64.lds | 92 ------------------- examples/hotp-rs/ta/ta_arm.lds | 91 ------------------ examples/random-rs/ta/build.rs | 31 ++++++- examples/random-rs/ta/dyn_list | 6 ++ examples/random-rs/ta/ta_aarch64.lds | 92 ------------------- examples/random-rs/ta/ta_arm.lds | 91 ------------------ examples/secure_storage-rs/ta/build.rs | 31 ++++++- examples/secure_storage-rs/ta/dyn_list | 6 ++ examples/secure_storage-rs/ta/ta_aarch64.lds | 92 ------------------- examples/secure_storage-rs/ta/ta_arm.lds | 91 ------------------ .../signature_verification-rs/ta/build.rs | 31 ++++++- .../signature_verification-rs/ta/dyn_list | 6 ++ .../ta/ta_aarch64.lds | 92 ------------------- .../signature_verification-rs/ta/ta_arm.lds | 91 ------------------ examples/supp_plugin-rs/ta/build.rs | 31 ++++++- examples/supp_plugin-rs/ta/dyn_list | 6 ++ examples/supp_plugin-rs/ta/ta_aarch64.lds | 92 ------------------- examples/supp_plugin-rs/ta/ta_arm.lds | 91 ------------------ examples/time-rs/ta/build.rs | 31 ++++++- examples/time-rs/ta/dyn_list | 6 ++ examples/time-rs/ta/ta_aarch64.lds | 92 ------------------- examples/time-rs/ta/ta_arm.lds | 91 ------------------ 52 files changed, 442 insertions(+), 2418 deletions(-) create mode 100644 examples/acipher-rs/ta/dyn_list delete mode 100644 examples/acipher-rs/ta/ta_aarch64.lds delete mode 100644 examples/acipher-rs/ta/ta_arm.lds create mode 100644 examples/aes-rs/ta/dyn_list delete mode 100644 examples/aes-rs/ta/ta_aarch64.lds delete mode 100644 examples/aes-rs/ta/ta_arm.lds create mode 100644 examples/authentication-rs/ta/dyn_list delete mode 100644 examples/authentication-rs/ta/ta_aarch64.lds delete mode 100644 examples/authentication-rs/ta/ta_arm.lds create mode 100644 examples/big_int-rs/ta/dyn_list delete mode 100644 examples/big_int-rs/ta/ta_aarch64.lds delete mode 100644 examples/big_int-rs/ta/ta_arm.lds create mode 100644 examples/diffie_hellman-rs/ta/dyn_list delete mode 100644 examples/diffie_hellman-rs/ta/ta_aarch64.lds delete mode 100644 examples/diffie_hellman-rs/ta/ta_arm.lds create mode 100644 examples/digest-rs/ta/dyn_list delete mode 100644 examples/digest-rs/ta/ta_aarch64.lds delete mode 100644 examples/digest-rs/ta/ta_arm.lds create mode 100644 examples/hello_world-rs/ta/dyn_list delete mode 100644 examples/hello_world-rs/ta/ta_aarch64.lds delete mode 100644 examples/hello_world-rs/ta/ta_arm.lds create mode 100644 examples/hotp-rs/ta/dyn_list delete mode 100644 examples/hotp-rs/ta/ta_aarch64.lds delete mode 100644 examples/hotp-rs/ta/ta_arm.lds create mode 100644 examples/random-rs/ta/dyn_list delete mode 100644 examples/random-rs/ta/ta_aarch64.lds delete mode 100644 examples/random-rs/ta/ta_arm.lds create mode 100644 examples/secure_storage-rs/ta/dyn_list delete mode 100644 examples/secure_storage-rs/ta/ta_aarch64.lds delete mode 100644 examples/secure_storage-rs/ta/ta_arm.lds create mode 100644 examples/signature_verification-rs/ta/dyn_list delete mode 100644 examples/signature_verification-rs/ta/ta_aarch64.lds delete mode 100644 examples/signature_verification-rs/ta/ta_arm.lds create mode 100644 examples/supp_plugin-rs/ta/dyn_list delete mode 100644 examples/supp_plugin-rs/ta/ta_aarch64.lds delete mode 100644 examples/supp_plugin-rs/ta/ta_arm.lds create mode 100644 examples/time-rs/ta/dyn_list delete mode 100644 examples/time-rs/ta/ta_aarch64.lds delete mode 100644 examples/time-rs/ta/ta_arm.lds diff --git a/examples/acipher-rs/ta/build.rs b/examples/acipher-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/acipher-rs/ta/build.rs +++ b/examples/acipher-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/acipher-rs/ta/dyn_list b/examples/acipher-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/acipher-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/acipher-rs/ta/ta_aarch64.lds b/examples/acipher-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/acipher-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/acipher-rs/ta/ta_arm.lds b/examples/acipher-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/acipher-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/aes-rs/ta/build.rs b/examples/aes-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/aes-rs/ta/build.rs +++ b/examples/aes-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/aes-rs/ta/dyn_list b/examples/aes-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/aes-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/aes-rs/ta/ta_aarch64.lds b/examples/aes-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/aes-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/aes-rs/ta/ta_arm.lds b/examples/aes-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/aes-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/authentication-rs/ta/build.rs b/examples/authentication-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/authentication-rs/ta/build.rs +++ b/examples/authentication-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/authentication-rs/ta/dyn_list b/examples/authentication-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/authentication-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/authentication-rs/ta/ta_aarch64.lds b/examples/authentication-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/authentication-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/authentication-rs/ta/ta_arm.lds b/examples/authentication-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/authentication-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/big_int-rs/ta/build.rs b/examples/big_int-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/big_int-rs/ta/build.rs +++ b/examples/big_int-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/big_int-rs/ta/dyn_list b/examples/big_int-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/big_int-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/big_int-rs/ta/ta_aarch64.lds b/examples/big_int-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/big_int-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/big_int-rs/ta/ta_arm.lds b/examples/big_int-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/big_int-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/diffie_hellman-rs/ta/build.rs b/examples/diffie_hellman-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/diffie_hellman-rs/ta/build.rs +++ b/examples/diffie_hellman-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/diffie_hellman-rs/ta/dyn_list b/examples/diffie_hellman-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/diffie_hellman-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/diffie_hellman-rs/ta/ta_aarch64.lds b/examples/diffie_hellman-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/diffie_hellman-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/diffie_hellman-rs/ta/ta_arm.lds b/examples/diffie_hellman-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/diffie_hellman-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/digest-rs/ta/build.rs b/examples/digest-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/digest-rs/ta/build.rs +++ b/examples/digest-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/digest-rs/ta/dyn_list b/examples/digest-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/digest-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/digest-rs/ta/ta_aarch64.lds b/examples/digest-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/digest-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/digest-rs/ta/ta_arm.lds b/examples/digest-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/digest-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/hello_world-rs/ta/build.rs b/examples/hello_world-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/hello_world-rs/ta/build.rs +++ b/examples/hello_world-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/hello_world-rs/ta/dyn_list b/examples/hello_world-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/hello_world-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/hello_world-rs/ta/ta_aarch64.lds b/examples/hello_world-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/hello_world-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/hello_world-rs/ta/ta_arm.lds b/examples/hello_world-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/hello_world-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/hotp-rs/ta/build.rs b/examples/hotp-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/hotp-rs/ta/build.rs +++ b/examples/hotp-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/hotp-rs/ta/dyn_list b/examples/hotp-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/hotp-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/hotp-rs/ta/ta_aarch64.lds b/examples/hotp-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/hotp-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/hotp-rs/ta/ta_arm.lds b/examples/hotp-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/hotp-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/random-rs/ta/build.rs b/examples/random-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/random-rs/ta/build.rs +++ b/examples/random-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/random-rs/ta/dyn_list b/examples/random-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/random-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/random-rs/ta/ta_aarch64.lds b/examples/random-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/random-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/random-rs/ta/ta_arm.lds b/examples/random-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/random-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/secure_storage-rs/ta/build.rs b/examples/secure_storage-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/secure_storage-rs/ta/build.rs +++ b/examples/secure_storage-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/secure_storage-rs/ta/dyn_list b/examples/secure_storage-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/secure_storage-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/secure_storage-rs/ta/ta_aarch64.lds b/examples/secure_storage-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/secure_storage-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/secure_storage-rs/ta/ta_arm.lds b/examples/secure_storage-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/secure_storage-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/signature_verification-rs/ta/build.rs b/examples/signature_verification-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/signature_verification-rs/ta/build.rs +++ b/examples/signature_verification-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/signature_verification-rs/ta/dyn_list b/examples/signature_verification-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/signature_verification-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/signature_verification-rs/ta/ta_aarch64.lds b/examples/signature_verification-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/signature_verification-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/signature_verification-rs/ta/ta_arm.lds b/examples/signature_verification-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/signature_verification-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/supp_plugin-rs/ta/build.rs b/examples/supp_plugin-rs/ta/build.rs index 75c36c3c..5c6df3ae 100644 --- a/examples/supp_plugin-rs/ta/build.rs +++ b/examples/supp_plugin-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/supp_plugin-rs/ta/dyn_list b/examples/supp_plugin-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/supp_plugin-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/supp_plugin-rs/ta/ta_aarch64.lds b/examples/supp_plugin-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/supp_plugin-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/supp_plugin-rs/ta/ta_arm.lds b/examples/supp_plugin-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/supp_plugin-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} diff --git a/examples/time-rs/ta/build.rs b/examples/time-rs/ta/build.rs index fb1e5dc6..c19c6eaa 100644 --- a/examples/time-rs/ta/build.rs +++ b/examples/time-rs/ta/build.rs @@ -18,7 +18,7 @@ use proto; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use uuid::Uuid; @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> { }};", time_low, time_mid, time_hi_and_version, clock_seq_and_node )?; + let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string()); + let optee_os_path = &PathBuf::from(optee_os_dir.clone()); let search_path = match env::var("ARCH") { Ok(ref v) if v == "arm" => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(arm)\n")?; + for line in f.lines() { + write!(ta_lds, "{}\n", line?)?; + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib") }, _ => { - File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?; + let mut ta_lds = File::create(out.join("ta.lds"))?; + let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?; + let f = BufReader::new(f); + + write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?; + write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?; + for line in f.lines() { + let l = line?; + + if l == "\t. = ALIGN(4096);" { + write!(ta_lds, "\t. = ALIGN(65536);\n")?; + } else { + write!(ta_lds, "{}\n", l)?; + } + } Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib") } }; @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-link-arg=-pie"); println!("cargo:rustc-link-arg=-Os"); println!("cargo:rustc-link-arg=--sort-section=alignment"); + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/time-rs/ta/dyn_list b/examples/time-rs/ta/dyn_list new file mode 100644 index 00000000..70e001ea --- /dev/null +++ b/examples/time-rs/ta/dyn_list @@ -0,0 +1,6 @@ +{ +__elf_phdr_info; +trace_ext_prefix; +trace_level; +ta_head; +}; diff --git a/examples/time-rs/ta/ta_aarch64.lds b/examples/time-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603f..00000000 --- a/examples/time-rs/ta/ta_aarch64.lds +++ /dev/null @@ -1,92 +0,0 @@ -OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") -OUTPUT_ARCH(aarch64) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -} - diff --git a/examples/time-rs/ta/ta_arm.lds b/examples/time-rs/ta/ta_arm.lds deleted file mode 100644 index 764ea257..00000000 --- a/examples/time-rs/ta/ta_arm.lds +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm") -OUTPUT_ARCH(arm) - -PHDRS { - /* - * Exec and rodata headers are hard coded to RX and RO - * respectively. This is needed because the binary is relocatable - * and the linker would automatically make any header writeable - * that need to be updated during relocation. - */ - exec PT_LOAD FLAGS (5); /* RX */ - rodata PT_LOAD FLAGS (4); /* RO */ - rwdata PT_LOAD; - dyn PT_DYNAMIC; -} - -SECTIONS { - .ta_head : {*(.ta_head)} :exec - .text : { - __text_start = .; - *(.text .text.*) - *(.stub) - *(.glue_7) - *(.glue_7t) - *(.gnu.linkonce.t.*) - /* Workaround for an erratum in ARM's VFP11 coprocessor */ - *(.vfp11_veneer) - PROVIDE(__gnu_mcount_nc = __utee_mcount); - __text_end = .; - } - .plt : { *(.plt) } - - .eh_frame : { *(.eh_frame) } :rodata - .rodata : { - *(.gnu.linkonce.r.*) - *(.rodata .rodata.*) - } - /* .ARM.exidx is sorted, so has to go in its own output section. */ - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.dyn : { *(.rel.dyn) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .dynamic : { *(.dynamic) } :dyn :rodata - .dynsym : { *(.dynsym) } :rodata - .dynstr : { *(.dynstr) } - .hash : { *(.hash) } - - /* Page align to allow dropping execute bit for RW data */ - . = ALIGN(4096); - - .data : { *(.data .data.* .gnu.linkonce.d.*) } :rwdata - .got : { *(.got.plt) *(.got) } - .bss : { - *(.bss .bss.* .gnu.linkonce.b.* COMMON) - - /* - * TA profiling with gprof - * Reserve some space for the profiling buffer, only if the - * TA is instrumented (i.e., some files were built with -pg). - * Note that PROVIDE() above defines a symbol only if it is - * referenced in the object files. - * This also provides a way to detect at runtime if the TA is - * instrumented or not. - */ - . = ALIGN(8); - __gprof_buf_start = .; - __gprof_buf_end = .; - } - - /DISCARD/ : { *(.interp) } -}