This is an automated email from the ASF dual-hosted git repository. yuanz pushed a commit to branch no-std in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-trustzone-sdk.git
commit 13aba14ce5d90e053f1add4471f8014f56a02f78 Author: Sumit Garg <[email protected]> AuthorDate: Thu Dec 21 13:57:05 2023 +0530 examples: no_std: 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 <[email protected]> --- examples/acipher-rs/ta/build.rs | 34 +++++++- examples/acipher-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/acipher-rs/ta/ta_arm.lds | 91 --------------------- examples/aes-rs/ta/build.rs | 34 +++++++- examples/aes-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/aes-rs/ta/ta_arm.lds | 91 --------------------- examples/authentication-rs/ta/build.rs | 34 +++++++- examples/authentication-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/authentication-rs/ta/ta_arm.lds | 91 --------------------- examples/big_int-rs/ta/build.rs | 34 +++++++- 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 | 34 +++++++- examples/diffie_hellman-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/diffie_hellman-rs/ta/ta_arm.lds | 91 --------------------- examples/digest-rs/ta/build.rs | 34 +++++++- examples/digest-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/digest-rs/ta/ta_arm.lds | 91 --------------------- examples/hello_world-rs/ta/build.rs | 34 +++++++- examples/hello_world-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/hello_world-rs/ta/ta_arm.lds | 91 --------------------- examples/hotp-rs/ta/build.rs | 34 +++++++- examples/hotp-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/hotp-rs/ta/ta_arm.lds | 91 --------------------- examples/random-rs/ta/build.rs | 34 +++++++- examples/random-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/random-rs/ta/ta_arm.lds | 91 --------------------- examples/secure_storage-rs/ta/build.rs | 34 +++++++- examples/secure_storage-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/secure_storage-rs/ta/ta_arm.lds | 91 --------------------- examples/signature_verification-rs/ta/build.rs | 34 +++++++- .../signature_verification-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/signature_verification-rs/ta/ta_arm.lds | 91 --------------------- examples/supp_plugin-rs/ta/build.rs | 34 +++++++- examples/supp_plugin-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/supp_plugin-rs/ta/ta_arm.lds | 91 --------------------- examples/time-rs/ta/build.rs | 34 +++++++- examples/time-rs/ta/ta_aarch64.lds | 92 ---------------------- examples/time-rs/ta/ta_arm.lds | 91 --------------------- 39 files changed, 403 insertions(+), 2418 deletions(-) diff --git a/examples/acipher-rs/ta/build.rs b/examples/acipher-rs/ta/build.rs index fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/acipher-rs/ta/ta_aarch64.lds b/examples/acipher-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/aes-rs/ta/ta_aarch64.lds b/examples/aes-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/authentication-rs/ta/ta_aarch64.lds b/examples/authentication-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/digest-rs/ta/ta_aarch64.lds b/examples/digest-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/hotp-rs/ta/ta_aarch64.lds b/examples/hotp-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/random-rs/ta/ta_aarch64.lds b/examples/random-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 75c36c3..d63e893 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } 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 adb7603..0000000 --- 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 764ea25..0000000 --- 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 fb1e5dc..d7f9b44 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,9 @@ 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"); + + let mut dyn_list = File::create(out.join("dyn_list"))?; + write!(dyn_list, "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n")?; + println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"); Ok(()) } diff --git a/examples/time-rs/ta/ta_aarch64.lds b/examples/time-rs/ta/ta_aarch64.lds deleted file mode 100644 index adb7603..0000000 --- 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 764ea25..0000000 --- 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) } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
