ivila commented on code in PR #156: URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897749388
########## examples/hello_world-rs/ta/Makefile: ########## @@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt") TARGET ?= aarch64-unknown-linux-gnu CROSS_COMPILE ?= aarch64-linux-gnu- OBJCOPY := $(CROSS_COMPILE)objcopy -LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\" +LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\" Review Comment: > > Using the `ld.bfd` works as well, right? > > Yes, it did on cross_compiling, but not working if you compile on arm host machine, as ld.bfd defaultly trying to link to libgcc_s.so instead of libgcc.a if not cross compile(and the argument is `-lgcc_s`).  and with `-Bstatic` provided, it tries to find `libgcc_s.a`, but this is not valid as it should be in the name of `libgcc.a` @DemesneGH sorry for my previous misleading response, actually when using `ld.bfd` as linker, its argument is `-Bdynamic -lgcc_s`, the problem of `cannot find -lgcc_s` is that ld.bfd defaultly do not know how to find the libgcc_s.so in host machine (actually gcc has a bunch of undocument configs in it). Here is how it happens: 1. we have a build.rs, so cargo will need to build a `build script binary` first, the target is the same as host machine, in x64 is **x86_64-unknown-linux-gnu**, in aarch64 is **aarch64-unknown-linux-gnu**. 2. we set linker config by `target.aarch64-unknown-linux-gnu="aarch64-linux-gnu-ld.bfd"`, please keep in mind this change the linker of target **aarch64-unknown-linux-gnu**. 3. then run `make` to build ta, it tries to build a `build script binary` first and then use it to build our source codes, and things going bad starts from here. When building the `build script binary` it requires libunwind for backtrace, adds the requirement of `gcc_s` (yes, this is not added by our source codes but the `build.rs`), but we change the linker (and yes, the target of build script is **aarch64-unknown-linux-gnu** when your host is aarch64 host), so everything fuckup, you will get a link error as you cannot find libgcc_s.so(only gcc knows how to find it, for example, on my coolpi4B with ubuntu23, it is /lib/aarch64-linux-gnu/libgcc_s.so.1). So my answer is, never use ld.bfd as default linker in if your target is the same as your host machine(aka not cross compiling) > ### Why it works on x64 host? > as what I described above, the target of build script is **x86_64-unknown-linux-gnu**, and the target of our source codes is **aarch64-unknown-linux-gnu**, we just change the linker of **aarch64-unknown-linux-gnu**, the build script is fine here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org For additional commands, e-mail: dev-h...@teaclave.apache.org