Skip to content

Commit

Permalink
Create a separate entry point for the ELF file, instead of using the …
Browse files Browse the repository at this point in the history
…SGX entry point
  • Loading branch information
Pagten committed Dec 4, 2019
1 parent 5f1d6c4 commit 3ee0f48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs
Expand Up @@ -7,7 +7,7 @@ pub fn target() -> Result<Target, String> {
"--as-needed",
"--eh-frame-hdr",
"-z" , "noexecstack",
"-e","sgx_entry",
"-e","elf_entry",
"-Bstatic",
"--gc-sections",
"-z","text",
Expand All @@ -29,6 +29,7 @@ pub fn target() -> Result<Target, String> {
];

const EXPORT_SYMBOLS: &[&str] = &[
"elf_entry",
"sgx_entry",
"HEAP_BASE",
"HEAP_SIZE",
Expand Down
20 changes: 20 additions & 0 deletions src/libstd/sys/sgx/abi/entry.S
Expand Up @@ -104,6 +104,26 @@ IMAGE_BASE:
and %gs:tcsls_flags,%\reg
.endm

/* We place the ELF entry point in a separate section so it can be removed by
elf2sgxs */
.section .text_no_sgx, "ax"
.Lelf_entry_error_msg:
.ascii "Error: This file is an SGX enclave which cannot be executed as a standard Linux binary.\nSee the installation guide at https://edp.fortanix.com/docs/installation/guide/ on how to use 'cargo run' or follow the steps at https://edp.fortanix.com/docs/tasks/deployment/ for manual deployment.\n"
.global elf_entry
.type elf_entry,function
elf_entry:
/* print error message */
movq $1, %rax /* write() syscall */
movq $2, %rdi /* write to stderr */
lea .Lelf_entry_error_msg(%rip), %rsi
movq $288, %rdx /* num chars to write */
syscall

movq $60, %rax /* exit() syscall */
movq $0, %rdi /* error code */
syscall
/* end elf_entry */

.text
.global sgx_entry
.type sgx_entry,function
Expand Down

0 comments on commit 3ee0f48

Please sign in to comment.