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`). 
![image](https://private-user-images.githubusercontent.com/11420684/398629399-b4a0e6fa-64c8-4b33-bb91-5ea2f2a248b6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzUxOTgwMzksIm5iZiI6MTczNTE5NzczOSwicGF0aCI6Ii8xMTQyMDY4NC8zOTg2MjkzOTktYjRhMGU2ZmEtNjRjOC00YjMzLWJiOTEtNWVhMmYyYTI0OGI2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDEyMjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMjI2VDA3MjIxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThjNTVhNWZlMjU1OGM3Mzk3MTZlYTdlYWE0MjNlNGVhYzE1NGY3MjAxNTVhMjdkM2JjMDdkZTQyNjkzNTQ2YWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.5paANYW1Tl-BYJXDmKPBXjojhMzFr8dcWaPJsJtAlw
 4) 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

Reply via email to