apache / incubator-teaclave-sgx-sdk

Apache Teaclave (incubating) SGX SDK helps developers to write Intel SGX applications in the Rust programming language, and also known as Rust SGX SDK.
https://teaclave.apache.org
Apache License 2.0
1.17k stars 259 forks source link

Rust errors #14

Closed yhechaichi closed 6 years ago

yhechaichi commented 6 years ago

Hello,

I'm trying to run the sample codes examples but I have the 3 following errors :

error[E0470]: re-exported macro not found
   --> /home/.../sgx_tstd/src/lib.rs:117:18
    |
117 | #[macro_reexport(assert, assert_eq, assert_ne, debug_assert, debug_assert_eq,
    |                  ^^^^^^

error[E0412]: cannot find type `Infallible` in module `convert`
   --> /home/.../sgx_tstd/src/error.rs:236:25
    |
236 | impl Error for convert::Infallible {
    |                         ^^^^^^^^^^ not found in `convert`

error[E0277]: the trait bound `usize: core::convert::From<u64>` is not satisfied
   --> /home/.../sgx_tstd/src/io/cursor.rs:142:33
    |
142 |     let pos: usize = (*pos_mut).try_into().map_err(|_| {
    |                                 ^^^^^^^^ the trait `core::convert::From<u64>` is not implemented for `usize`
    |
    = help: the following implementations were found:
              <usize as core::convert::From<u16>>
              <usize as core::convert::From<u8>>
    = note: required because of the requirements on the impl of `core::convert::TryFrom<u64>` for `usize`
    = note: required because of the requirements on the impl of `core::convert::TryInto<usize>` for `u64`

error: aborting due to 3 previous errors

Some errors occurred: E0277, E0412, E0470.
For more information about an error, try `rustc --explain E0277`.
error: Could not compile `sgx_tstd`.

I tried to find a workaround but I'm not that experimented and I don't want to break anything. Any help would be greatly appreciated.

dingelish commented 6 years ago

Hi @yhechaichi , did you do this in the provided docker? what's the output of rustc --version on your machine? Thanks!

yhechaichi commented 6 years ago

I didn't do this in the provided docker indeed, as I couldn't make it work... My computer has no sgx-compatible processor, I wanted to run the whole thing in simulation mode, is it possible to use rust-sgx in this way ? My rust version is the following : rustc 1.26.0-nightly (9c9424de5 2018-03-27)

dingelish commented 6 years ago

Rust's std is changing rapidly. So our sgx_tstd always pins to a certain version of rust compiler. For now it's nightly-2018-03-16. Please set up your rust toolchain as follows: rustup default nightly-2018-03-16 and rustup component add rust-src

dingelish commented 6 years ago

if you need xargo, please do cargo install xargo

yhechaichi commented 6 years ago

Thank you for your help, I still have the same errors unfortunately... Can I use the docker without having an intel-sgx enabled processor ? My end goal would just be to write some algorithms and run them in simulation mode

dingelish commented 6 years ago

that's weird.

for simulation mode, you can always specify SGX_MODE=SIM before make to build/run sgx enclaves in simulation mode, no matter if you're in docker or not.

dingelish commented 6 years ago

what's your current rustc --version outputs?

yhechaichi commented 6 years ago

Yes, it seems like a rust specific problem Here's my output : rustc 1.26.0-nightly (9c9424de5 2018-03-27)

dingelish commented 6 years ago

if rustup works correctly, after rustup default nightly-2018-03-16, the output should be rustc 1.26.0-nightly (392645394 2018-03-15) what's your output of rustup toolchain list?

yhechaichi commented 6 years ago

Yeah that's weird, I executed rustup default nightly-2018-03-16 again but it still gives me the same result. The output is : stable-x86_64-unknown-linux-gnu nightly-2018-03-16-x86_64-unknown-linux-gnu (default) nightly-x86_64-unknown-linux-gnu

dingelish commented 6 years ago

So now it's clear. The rustc you installed is not coming from rustup. What's your output of which rustc?

yhechaichi commented 6 years ago

Oh ok ! It's /root/.cargo/bin/rustc

dingelish commented 6 years ago

so are you always log in as root? or did you sudo rustup?

dingelish commented 6 years ago

can you try rustup self uninstall and see if your rustc still exists?

yhechaichi commented 6 years ago

I did sudo su for the install and stayed logged as root afterwards. As it is my personal computer I can log in as root if needed. Ok, I'm uninstalling now

yhechaichi commented 6 years ago

rustc --help bash: /root/.cargo/bin/rustc: No such file or directory

dingelish commented 6 years ago

got it. rustup never requires root privilege. so please do the following and report your results:

  1. sudo su and completely uninstall rustup, remove /root/.cargo, /root/.rustup
  2. log out from root privilege. check if ~/.rustup and ~/.cargo exists
dingelish commented 6 years ago
  1. completely log out and then log back in. check if rustc command reports No command 'rustc' found, did you mean: ....

It should not report anything like No such file or directory.

yhechaichi commented 6 years ago

Ok I logged out and it put : Program not yet installed, you can install it with : sudo apt install rustc

dingelish commented 6 years ago

Great! so now please install rust by curl https://sh.rustup.rs -sSf | sh

customize the default host triple as x86_64-unknown-linux-gnu and default toolchain as nightly-2018-03-16 and modify PATH variable. at last, run source $HOME/.cargo/env as instructed

dingelish commented 6 years ago
ding@ubuntu:~$ curl https://sh.rustup.rs -sSf | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust programming
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin
directory, located at:

  /home/ding/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile file located at:

  /home/ding/.profile

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
2

I'm going to ask you the value of each these installation options.
You may simply press the Enter key to leave unchanged.

Default host triple?
x86_64-unknown-linux-gnu

Default toolchain? (stable/beta/nightly/none)
nightly-2018-03-16

Modify PATH variable? (y/n)
y

Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: nightly-2018-03-16
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
1

info: syncing channel updates for 'nightly-2018-03-16-x86_64-unknown-linux-gnu'
info: latest update on 2018-03-16, rust version 1.26.0-nightly (392645394 2018-03-15)
info: downloading component 'rustc'
 66.4 MiB /  66.4 MiB (100 %)  19.3 MiB/s ETA:   0 s
info: downloading component 'rust-std'
 48.8 MiB /  48.8 MiB (100 %)  16.6 MiB/s ETA:   0 s
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: default toolchain set to 'nightly-2018-03-16'

  nightly-2018-03-16 installed - rustc 1.26.0-nightly (392645394 2018-03-15)

Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done automatically.

To configure your current shell run source $HOME/.cargo/env
ding@ubuntu:~$ source $HOME/.cargo/env
ding@ubuntu:~$ rustc --version
rustc 1.26.0-nightly (392645394 2018-03-15)
yhechaichi commented 6 years ago

Ok nice, I tried the --version command again and the output is : rustc 1.26.0-nightly (392645394 2018-03-15) !

dingelish commented 6 years ago

:) try the sdk samples again!

dingelish commented 6 years ago

i guess you'll encounter a linking problem :) but don't worry

yhechaichi commented 6 years ago

Ok I don't have the previous erros anymore, thank you really much ! :) I have some different errors though:

dimensio@Dimy-VirtualBox:~/Téléchargements/rust-sgx-sdk-master/third_party/rusty
-machine/examples$ cargo run --example k-means_generating_cluster
 Downloading syn v0.7.1
 Downloading quote v0.1.4                                                       
 Downloading filetime v0.1.15                                                   
 Downloading cfg-if v0.1.2                                                      
 Downloading libc v0.2.40                                                       
   Compiling libc v0.2.40                                                       
   Compiling cfg-if v0.1.2
   Compiling unwind v0.0.0 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/libunwind)
   Compiling sgx_types v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_types)
   Compiling quote v0.1.4
   Compiling matrixmultiply v0.1.14 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/matrixmultiply)
   Compiling rawpointer v0.1.0 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/rawpointer)
   Compiling filetime v0.1.15
   Compiling sgx_trts v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_trts)
   Compiling syn v0.7.1
   Compiling build_helper v0.1.0 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/build_helper)
   Compiling sgx_alloc v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_alloc)
   Compiling sgx_tprotected_fs v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_tprotected_fs)
   Compiling num-derive v0.1.41 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/num/derive)
   Compiling sgx_tstd v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_tstd)
warning: unused attribute
  --> /home/dimensio/Téléchargements/rust-sgx-sdk-master/sgx_tstd/src/io/cursor.rs:29:1
   |
29 | #![feature(hashmap_internals)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_attributes)] on by default

warning: crate-level attribute should be in the root module
  --> /home/dimensio/Téléchargements/rust-sgx-sdk-master/sgx_tstd/src/io/cursor.rs:29:1
   |
29 | #![feature(hashmap_internals)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Compiling num-traits v0.1.40 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/num/traits)
   Compiling sgx_rand v0.9.8 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/sgx_rand)
   Compiling num-integer v0.1.35 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/num/integer)
   Compiling num-iter v0.1.34 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/num/iter)
   Compiling num v0.1.40 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/num)
   Compiling rulinalg v0.4.2 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/rulinalg)
   Compiling rusty-machine v0.5.4 (file:///home/dimensio/T%C3%A9l%C3%A9chargements/rust-sgx-sdk-master/third_party/rusty-machine)
error[E0464]: multiple matching crates for `rand`
 --> examples/k-means_generating_cluster.rs:2:1
  |
2 | extern crate rand;
  | ^^^^^^^^^^^^^^^^^^
  |
  = note: candidates:
          crate `rand`: /home/dimensio/.rustup/toolchains/nightly-2018-03-16-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-2779eabb5c756457.rlib
          crate `rand`: /home/dimensio/.rustup/toolchains/nightly-2018-03-16-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-be60682438d3a539.rlib

error[E0463]: can't find crate for `rand`
 --> examples/k-means_generating_cluster.rs:2:1
  |
2 | extern crate rand;
  | ^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 2 previous errors

Some errors occurred: E0463, E0464.
For more information about an error, try `rustc --explain E0463`.
error: Could not compile `rusty-machine`.

To learn more, run the command again with --verbose.
dingelish commented 6 years ago

Please don’t use cargo run. It’s not supported. Please do SGX_MODE=SIM make at sample root (samplecode/machine-learning) and cd bin and ./app

Remember this is a sgx project, not a cargo crate

yhechaichi commented 6 years ago

Yes you're right ! I tried to make the hello world example instead then to begin with, here is an error during the process :

cp ../../compiler-rt/libcompiler-rt-patch.a ./lib
./lib/libenclave.a(sgx_tstd-227b34267c1a8a61.sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs.rcgu.o) : in function « __rg_alloc » :
sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs:(.text.__rg_alloc+0x41) : undefined reference to « posix_memalign »
./lib/libenclave.a(sgx_tstd-227b34267c1a8a61.sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs.rcgu.o) : in function « __rg_realloc » :
sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs:(.text.__rg_realloc+0x83) : Undefined reference to « posix_memalign »
collect2: error: ld returned 1 exit status
dingelish commented 6 years ago

This is expected in your setup :) You need to re-build the Intel SGX SDK with my patch Please refer to the Dockerfile, line 35, and 60-65 for the setup. Get the version of Intel SGX SDK (e.g. 2.1.2), and then download the source codes at Intel's release. Uncompress, and patch sdk/tlibc/Makefile, and then make the whole project. At last, sudo copy libsgx_tstdc.a to /opt/sgxsdk/lib64/libsgx_tstdc.a

dingelish commented 6 years ago

The dockerfile is self-contained and I think you should read it to build your environment.

yhechaichi commented 6 years ago

Thank you so much for your help, I'll try this and let you know the results ! :) Once again thank you really much !

dingelish commented 6 years ago

You're welcome :)

yhechaichi commented 6 years ago

Hello sir, I'm finally back home !

So I just tried to do what you mentionned above but applying the patch gives me an error when I make the whole project. When I don't use the patch, the making process works but when I replace this :

include ../../buildenv.mk

CFLAGS   += $(ENCLAVE_CFLAGS)
ASFLAGS  := $(CFLAGS)
CFLAGS   += -std=c99
CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti

CPPFLAGS += -I.                          \
            -I$(COMMON_DIR)/inc          \
            -I$(COMMON_DIR)/inc/tlibc    \
            -I$(COMMON_DIR)/inc/internal \
            -I$(LINUX_SDK_DIR)/trts      \
            -I./gdtoa

ifneq ($(USE_OPT_LIBS), 0)
CFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
CXXFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c math/*.c stdlib/*.c string/*.c stdio/*.c time/*.c) 
else
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c stdlib/*.c string/*.c stdio/*.c time/*.c)
endif

LIBC_CPP_SRCS := $(wildcard gen/*.cpp) tstdc_version.cpp
LIBC_ASM_SRCS := $(wildcard gen/*.S)

LIBC_OBJS := $(LIBC_C_SRCS:.c=.o)
LIBC_OBJS += $(LIBC_CPP_SRCS:.cpp=.o)
LIBC_OBJS += $(LIBC_ASM_SRCS:.S=.o)
LIBC_OBJS := $(sort $(LIBC_OBJS))

LIBC_NAME    := libtlibc.a

.PHONY: all
all: $(LIBC_NAME)

$(LIBC_NAME): $(LIBC_OBJS)
    $(AR) rcs $@ $^

string/consttime_memequal.o: string/consttime_memequal.c
    $(CC)  $(filter-out -O2,$(CFLAGS)) -O1 $(CPPFLAGS) -c $< -o $@

%.o: %.c
    $(CC)  $(CFLAGS)   $(CPPFLAGS) -c $< -o $@

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.S
    $(CC)  $(ASFLAGS)  $(CPPFLAGS) -c $< -o $@

.PHONY: clean
clean:
    @$(RM) $(LIBC_NAME) $(LIBC_OBJS)

by this, according to the patch,


include ../../buildenv.mk

CFLAGS   += $(ENCLAVE_CFLAGS)
ASFLAGS  := $(CFLAGS)
CFLAGS   += -std=c99 -D USE_MALLOC_DEPRECATED
CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti

CPPFLAGS += -I. \
ifneq ($(USE_OPT_LIBS), 0)
CFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
CXXFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c math/*.c stdlib/*.c string/*.c stdio/*.c time/*.c) 
else
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c stdlib/*.c string/*.c stdio/*.c time/*.c)
endif

LIBC_CPP_SRCS := $(wildcard gen/*.cpp) tstdc_version.cpp
LIBC_ASM_SRCS := $(wildcard gen/*.S)

LIBC_OBJS := $(LIBC_C_SRCS:.c=.o)
LIBC_OBJS += $(LIBC_CPP_SRCS:.cpp=.o)
LIBC_OBJS += $(LIBC_ASM_SRCS:.S=.o)
LIBC_OBJS := $(sort $(LIBC_OBJS))

LIBC_NAME    := libtlibc.a

.PHONY: all
all: $(LIBC_NAME)

$(LIBC_NAME): $(LIBC_OBJS)
    $(AR) rcs $@ $^

string/consttime_memequal.o: string/consttime_memequal.c
    $(CC)  $(filter-out -O2,$(CFLAGS)) -O1 $(CPPFLAGS) -c $< -o $@

%.o: %.c
    $(CC)  $(CFLAGS)   $(CPPFLAGS) -c $< -o $@

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.S
    $(CC)  $(ASFLAGS)  $(CPPFLAGS) -c $< -o $@

.PHONY: clean
clean:
    @$(RM) $(LIBC_NAME) $(LIBC_OBJS)

It gives me the following error :

cc  -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -UDEBUG -DNDEBUG -ffunction-sections -fdata-sections -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type -Waddress -Wsequence-point -Wformat-security -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow -Wcast-align -Wconversion -Wredundant-decls -DITT_ARCH_IA64 -ffreestanding -nostdinc -fvisibility=hidden -fpie -D_TLIBC_USE_INTEL_FAST_STRING_   -I.  -c gdtoa/dmisc.c -o gdtoa/dmisc.o
In file included from gdtoa/gdtoaimp.h:181:0,
                 from gdtoa/dmisc.c:32:
gdtoa/gdtoa.h:36:37: fatal error: stddef.h: No such file or directory
compilation terminated.
Makefile:70 : recipe for target « gdtoa/dmisc.o » failed
make: *** [gdtoa/dmisc.o] Error 1

(I translated the error messages in English, they were in French)

dingelish commented 6 years ago

Hey bro, glad you back again!

Could you please check (1) you've installed all dependencies and (2) you can make the original Intel SDK?

在 2018年4月4日,14:32,yhechaichi notifications@github.com 写道:

Hello sir, I'm finally back home !

So I just tried to do what you mentionned above but applying the patch gives me an error when I make a whole project. When I don't the making process works but when I replace this :

include ../../buildenv.mk

CFLAGS += $(ENCLAVE_CFLAGS) ASFLAGS := $(CFLAGS) CFLAGS += -std=c99 CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti

CPPFLAGS += -I. \ -I$(COMMON_DIR)/inc \ -I$(COMMON_DIR)/inc/tlibc \ -I$(COMMON_DIR)/inc/internal \ -I$(LINUX_SDK_DIR)/trts \ -I./gdtoa

ifneq ($(USE_OPT_LIBS), 0) CFLAGS += -D_TLIBC_USE_INTEL_FASTSTRING CXXFLAGS += -D_TLIBC_USE_INTEL_FASTSTRING LIBC_C_SRCS := $(wildcard gen/.c gdtoa/.c locale/.c math/.c stdlib/.c string/.c stdio/.c time/.c) else LIBC_C_SRCS := $(wildcard gen/.c gdtoa/.c locale/.c stdlib/.c string/.c stdio/.c time/*.c) endif

LIBC_CPP_SRCS := $(wildcard gen/.cpp) tstdc_version.cpp LIBC_ASM_SRCS := $(wildcard gen/.S)

LIBC_OBJS := $(LIBC_C_SRCS:.c=.o) LIBC_OBJS += $(LIBC_CPP_SRCS:.cpp=.o) LIBC_OBJS += $(LIBC_ASM_SRCS:.S=.o) LIBC_OBJS := $(sort $(LIBC_OBJS))

LIBC_NAME := libtlibc.a

.PHONY: all all: $(LIBC_NAME)

$(LIBC_NAME): $(LIBC_OBJS) $(AR) rcs $@ $^

string/consttime_memequal.o: string/consttime_memequal.c $(CC) $(filter-out -O2,$(CFLAGS)) -O1 $(CPPFLAGS) -c $< -o $@

%.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.cpp $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.S $(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@

.PHONY: clean clean: @$(RM) $(LIBC_NAME) $(LIBC_OBJS) by this, according to the patch,

include ../../buildenv.mk

CFLAGS += $(ENCLAVE_CFLAGS) ASFLAGS := $(CFLAGS) -CFLAGS += -std=c99 +CFLAGS += -std=c99 -D USE_MALLOC_DEPRECATED CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti

CPPFLAGS += -I. \ ifneq ($(USE_OPT_LIBS), 0) CFLAGS += -D_TLIBC_USE_INTEL_FASTSTRING CXXFLAGS += -D_TLIBC_USE_INTEL_FASTSTRING LIBC_C_SRCS := $(wildcard gen/.c gdtoa/.c locale/.c math/.c stdlib/.c string/.c stdio/.c time/.c) else LIBC_C_SRCS := $(wildcard gen/.c gdtoa/.c locale/.c stdlib/.c string/.c stdio/.c time/*.c) endif

LIBC_CPP_SRCS := $(wildcard gen/.cpp) tstdc_version.cpp LIBC_ASM_SRCS := $(wildcard gen/.S)

LIBC_OBJS := $(LIBC_C_SRCS:.c=.o) LIBC_OBJS += $(LIBC_CPP_SRCS:.cpp=.o) LIBC_OBJS += $(LIBC_ASM_SRCS:.S=.o) LIBC_OBJS := $(sort $(LIBC_OBJS))

LIBC_NAME := libtlibc.a

.PHONY: all all: $(LIBC_NAME)

$(LIBC_NAME): $(LIBC_OBJS) $(AR) rcs $@ $^

string/consttime_memequal.o: string/consttime_memequal.c $(CC) $(filter-out -O2,$(CFLAGS)) -O1 $(CPPFLAGS) -c $< -o $@

%.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.cpp $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.S $(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@

.PHONY: clean clean: @$(RM) $(LIBC_NAME) $(LIBC_OBJS) It gives me the following error :

cc -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -UDEBUG -DNDEBUG -ffunction-sections -fdata-sections -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type -Waddress -Wsequence-point -Wformat-security -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow -Wcast-align -Wconversion -Wredundant-decls -DITT_ARCH_IA64 -ffreestanding -nostdinc -fvisibility=hidden -fpie -D_TLIBC_USE_INTEL_FASTSTRING -I. -c gdtoa/dmisc.c -o gdtoa/dmisc.o In file included from gdtoa/gdtoaimp.h:181:0, from gdtoa/dmisc.c:32: gdtoa/gdtoa.h:36:37: fatal error: stddef.h: No such file or directory compilation terminated. Makefile:70 : recipe for target « gdtoa/dmisc.o » failed make: *** [gdtoa/dmisc.o] Error 1 (I translated the error messages in English, they were in French)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/baidu/rust-sgx-sdk/issues/14#issuecomment-378752256, or mute the thread https://github.com/notifications/unsubscribe-auth/AByKZOQw4eY3muNm1wnBS45pEWg59fhTks5tlTv8gaJpZM4S_hjO.

yhechaichi commented 6 years ago

Thank you really much for the quick reply ! :)

Yeah I just ran the following lines before without errors, following the dockerfile : apt-get update && apt-get install -y build-essential ocaml automake autoconf libtool wget python libssl-dev libcurl4-openssl-dev protobuf-compiler libprotobuf-dev sudo kmod vim curl git-core libprotobuf-c0-dev libboost-thread-dev libboost-system-dev liblog4cpp5-dev libjsoncpp-dev alien uuid-dev libxml2-dev cmake pkg-config

and then

mkdir /root/sgx && \
    wget -O /root/sgx/sgx_linux_x64_sdk_2.1.102.43402.bin https://download.01.org/intel-sgx/linux-2.1.2/ubuntu64-desktop/sgx_linux_x64_sdk_2.1.102.43402.bin && \
    cd /root/sgx && \
    chmod +x /root/sgx/sgx_linux_x64_sdk_2.1.102.43402.bin && \
    echo -e 'no\n/opt' | /root/sgx/sgx_linux_x64_sdk_2.1.102.43402.bin && \
echo 'source /opt/sgxsdk/environment' >> /root/.bashrc

Yeah I can make the original Intel sdk !

dingelish commented 6 years ago

oops. Please make your makefile look like this following

CFLAGS   += $(ENCLAVE_CFLAGS)
ASFLAGS  := $(CFLAGS)
CFLAGS   += -std=c99 -D USE_MALLOC_DEPRECATED
CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti
yhechaichi commented 6 years ago

So this is the makefile that I use :

include ../../buildenv.mk

CFLAGS   += $(ENCLAVE_CFLAGS)
ASFLAGS  := $(CFLAGS)
CFLAGS   += -std=c99 -D USE_MALLOC_DEPRECATED
CXXFLAGS += $(ENCLAVE_CXXFLAGS) -fno-exceptions -fno-rtti

ifneq ($(USE_OPT_LIBS), 0)
CFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
CXXFLAGS += -D_TLIBC_USE_INTEL_FAST_STRING_
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c math/*.c stdlib/*.c string/*.c stdio/*.c time/*.c) 
else
LIBC_C_SRCS := $(wildcard gen/*.c gdtoa/*.c locale/*.c stdlib/*.c string/*.c stdio/*.c time/*.c)
endif

LIBC_CPP_SRCS := $(wildcard gen/*.cpp) tstdc_version.cpp
LIBC_ASM_SRCS := $(wildcard gen/*.S)

LIBC_OBJS := $(LIBC_C_SRCS:.c=.o)
LIBC_OBJS += $(LIBC_CPP_SRCS:.cpp=.o)
LIBC_OBJS += $(LIBC_ASM_SRCS:.S=.o)
LIBC_OBJS := $(sort $(LIBC_OBJS))

LIBC_NAME    := libtlibc.a

.PHONY: all
all: $(LIBC_NAME)

$(LIBC_NAME): $(LIBC_OBJS)
    $(AR) rcs $@ $^

string/consttime_memequal.o: string/consttime_memequal.c
    $(CC)  $(filter-out -O2,$(CFLAGS)) -O1 $(CPPFLAGS) -c $< -o $@

%.o: %.c
    $(CC)  $(CFLAGS)   $(CPPFLAGS) -c $< -o $@

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@

%.o: %.S
    $(CC)  $(ASFLAGS)  $(CPPFLAGS) -c $< -o $@

.PHONY: clean
clean:
    @$(RM) $(LIBC_NAME) $(LIBC_OBJS)

It now gives me :

In file included from gdtoa/gdtoaimp.h:181:0,
                 from gdtoa/dmisc.c:32:
gdtoa/gdtoa.h:36:37: error: no include path in which to search for stddef.h
In file included from gdtoa/dmisc.c:32:0:
gdtoa/gdtoaimp.h:192:20: fatal error: stdlib.h: No such file or directory
compilation terminated.
Makefile:67 : recipe for target « gdtoa/dmisc.o » failed
make: *** [gdtoa/dmisc.o] Error1
yhechaichi commented 6 years ago

Also if I try to apply the patch with the following line as in the dockerfile cd /root/linux-sgx-sgx_2.1.2 && git apply ../patch && \

It tells me that the patch is corrupted at line 13

dingelish commented 6 years ago

In your makefile, the definition of CPPFLAGS is lost. Add them and you'll be fine.

dingelish commented 6 years ago
CPPFLAGS += -I.                          \
            -I$(COMMON_DIR)/inc          \
            -I$(COMMON_DIR)/inc/tlibc    \
            -I$(COMMON_DIR)/inc/internal \
            -I$(LINUX_SDK_DIR)/trts      \
            -I./gdtoa
yhechaichi commented 6 years ago

Ok I could make it !

yhechaichi commented 6 years ago

I'm looking for the linux-sgx-sgx_2.1.2/build/linux/libsgx_tstdc.a file in order to copy it to /opt/sgxsdk/lib64/libsgx_tstdc.a but I don't even have a build folder. I downloaded the linux_sgx-sgx_2.1.2 from the link you gave me above so that's weird...

EDIT : Solved, I remade the whole thing

yhechaichi commented 6 years ago

I still have the same error as above, I feel so close though... :(

cp ../../compiler-rt/libcompiler-rt-patch.a ./lib
./lib/libenclave.a(sgx_tstd-227b34267c1a8a61.sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs.rcgu.o) : in function « __rg_alloc » :
sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs:(.text.__rg_alloc+0x41) : undefined reference to « posix_memalign »
./lib/libenclave.a(sgx_tstd-227b34267c1a8a61.sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs.rcgu.o) : in function « __rg_realloc » :
sgx_tstd2-c9c4492fed60e20121d4f0ce742b6db7.rs:(.text.__rg_realloc+0x83) : Undefined reference to « posix_memalign »
collect2: error: ld returned 1 exit status

It seems like my changes weren't taken into account,but I copied the libsgx_tstdc.a at the right place and tried to redownload and remake the linuxsgx but it didn't work too...

dingelish commented 6 years ago

That's weird. would you please check build/linux/libsgx_tstdc.a and /opt/sgxsdk/lib64/libsgx_tstdc.a are the same?

yhechaichi commented 6 years ago

I deleted the /opt/sgxsdk/lib64/libsgx_tstdc.a file and replaced it by build/linux/libsgx_tstdc.a and it doesn't work unfortunately

dingelish commented 6 years ago

can you provide your output of ls -l /opt/sgxsdk/lib64/

dingelish commented 6 years ago

and, what's your output of find /opt -iname libsgx_tstdc.a

yhechaichi commented 6 years ago

Here it is, once again thank you really much for your help !

total 39016
drwxr-xr-x 2 root root     4096 avril  4 22:59 gdb-sgx-plugin
-rw-r--r-- 1 root root      943 avril  4 22:59 libc++_Changes_SGX.txt
-rw-r--r-- 1 root root     8402 avril  4 22:59 libsgx_capable.a
-rwxr-xr-x 1 root root    12632 avril  4 22:59 libsgx_capable.so
-rwxr-xr-x 1 root root    18072 avril  4 22:59 libsgx_ptrace.so
-rw-r--r-- 1 root root  2864020 avril  4 22:59 libsgx_tcmalloc.a
-rw-r--r-- 1 root root  3710194 avril  4 22:59 libsgx_tcrypto.a
-rw-r--r-- 1 root root   995000 avril  4 22:59 libsgx_tcxx.a
-rw-r--r-- 1 root root    24658 avril  4 22:59 libsgx_tkey_exchange.a
-rw-r--r-- 1 root root   100304 avril  4 22:59 libsgx_tprotected_fs.a
-rw-r--r-- 1 root root   106606 avril  4 22:59 libsgx_trts.a
-rw-r--r-- 1 root root   112908 avril  4 22:59 libsgx_trts_sim.a
-rw-r--r-- 1 root root    67556 avril  4 22:59 libsgx_tservice.a
-rw-r--r-- 1 root root    59316 avril  4 22:59 libsgx_tservice_sim.a
-rw-r--r-- 1 root root 31102890 avril  5 01:17 libsgx_tstdc.a
-rw-r--r-- 1 root root   448966 avril  4 22:59 libsgx_tstdcxx.a
-rwxr-xr-x 1 root root    30064 avril  4 22:59 libsgx_uae_service_sim.so
-rwxr-xr-x 1 root root     8584 avril  4 22:59 libsgx_uae_service.so
-rw-r--r-- 1 root root    17564 avril  4 22:59 libsgx_ukey_exchange.a
-rw-r--r-- 1 root root    10390 avril  4 22:59 libsgx_uprotected_fs.a
-rwxr-xr-x 1 root root   183624 avril  4 22:59 libsgx_urts_sim.so
-rwxr-xr-x 1 root root     8664 avril  4 22:59 libsgx_urts.so
-rw-r--r-- 1 root root     1146 avril  4 22:59 STLport_Changes_SGX.txt
/opt/intel/sgxsdk/lib64/libsgx_tstdc.a
/opt/sgxsdk/lib64/libsgx_tstdc.a
dingelish commented 6 years ago

it seems you have two installations of intel sdk. replace both of

/opt/intel/sgxsdk/lib64/libsgx_tstdc.a
/opt/sgxsdk/lib64/libsgx_tstdc.a

with the one you made

yhechaichi commented 6 years ago

Ok I can make the sample files now ! I have one last error when I execute the ./app command after that : ./app: error while loading shared libraries: libsgx_urts_sim.so: cannot open shared object file: No such file or directory

dingelish commented 6 years ago

reinstall sgx_linux_x64_psw and everything should be fine