Skip to content

Commit 12307b3

Browse files
committed
Auto merge of #67084 - Pagten:feature/print-msg-from-elf-entrypoint, r=Amanieu
SGX: Change ELF entrypoint This fixes [rust-sgx issue #148](fortanix/rust-sgx#148). A new entry point is created for the ELF file generated by `rustc`, separate from the enclave entry point. When the ELF file is executed as a Linux binary, the error message below is written to stderr. > Error: This file is an SGX enclave which cannot be executed as a standard Linux binary. > See 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. When the ELF file is converted to an SGXS using `elf2sgxs`, the old entry point is still set as the enclave entry point. In a future pull request in the rust-sgx repository, `elf2sgxs` will be modified to remove the code in the ELF entry point, since this code is not needed in the enclave.
2 parents 8843b28 + f02ffb8 commit 12307b3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs

+1-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",

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

+30
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ 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+
.Lelf_entry_error_msg_end:
113+
114+
.global elf_entry
115+
.type elf_entry,function
116+
elf_entry:
117+
/* print error message */
118+
movq $2,%rdi /* write to stderr (fd 2) */
119+
lea .Lelf_entry_error_msg(%rip),%rsi
120+
movq $.Lelf_entry_error_msg_end-.Lelf_entry_error_msg,%rdx
121+
.Lelf_entry_call:
122+
movq $1,%rax /* write() syscall */
123+
syscall
124+
test %rax,%rax
125+
jle .Lelf_exit /* exit on error */
126+
add %rax,%rsi
127+
sub %rax,%rdx /* all chars written? */
128+
jnz .Lelf_entry_call
129+
130+
.Lelf_exit:
131+
movq $60,%rax /* exit() syscall */
132+
movq $1,%rdi /* exit code 1 */
133+
syscall
134+
ud2 /* should not be reached */
135+
/* end elf_entry */
136+
107137
.text
108138
.global sgx_entry
109139
.type sgx_entry,function

0 commit comments

Comments
 (0)