Skip to content

Commit 3ee0f48

Browse files
committed
Create a separate entry point for the ELF file, instead of using the SGX entry point
1 parent 5f1d6c4 commit 3ee0f48

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn target() -> Result<Target, String> {
77
"--as-needed",
88
"--eh-frame-hdr",
99
"-z" , "noexecstack",
10-
"-e","sgx_entry",
10+
"-e","elf_entry",
1111
"-Bstatic",
1212
"--gc-sections",
1313
"-z","text",
@@ -29,6 +29,7 @@ pub fn target() -> Result<Target, String> {
2929
];
3030

3131
const EXPORT_SYMBOLS: &[&str] = &[
32+
"elf_entry",
3233
"sgx_entry",
3334
"HEAP_BASE",
3435
"HEAP_SIZE",

src/libstd/sys/sgx/abi/entry.S

+20
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ IMAGE_BASE:
104104
and %gs:tcsls_flags,%\reg
105105
.endm
106106

107+
/* We place the ELF entry point in a separate section so it can be removed by
108+
elf2sgxs */
109+
.section .text_no_sgx, "ax"
110+
.Lelf_entry_error_msg:
111+
.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"
112+
.global elf_entry
113+
.type elf_entry,function
114+
elf_entry:
115+
/* print error message */
116+
movq $1, %rax /* write() syscall */
117+
movq $2, %rdi /* write to stderr */
118+
lea .Lelf_entry_error_msg(%rip), %rsi
119+
movq $288, %rdx /* num chars to write */
120+
syscall
121+
122+
movq $60, %rax /* exit() syscall */
123+
movq $0, %rdi /* error code */
124+
syscall
125+
/* end elf_entry */
126+
107127
.text
108128
.global sgx_entry
109129
.type sgx_entry,function

0 commit comments

Comments
 (0)