Hello,

I am trying to cross compile musl 1.2.2 by using the following configure:
./configure CC="clang --target=aarch64" --target=aarch64 CFLAGS="--rtlib=compiler-rt" AR=/usr/local/bin/llvm-ar LDFLAGS="-fuse-ld=/usr/local/bin/ld.lld" RANLIB=/usr/local/bin/llvm-ranlib --syslibdir=/usr/local/lib LIBCC=-L/usr/local/lib/clang/13.0.0/lib/linux

The linking phase failed, it reported the below error:
gcc: error: unrecognized command-line option ‘--noexecstack’
clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:162: lib/libc.so] Error 1
make: *** Waiting for unfinished jobs....

Finally, I find the reason is on my computer clang -fuse-ld=/usr/local/bin/ld.lld can't force clang to use ld.lld, while it still will invoke gcc ld, below is my testing:
simon@LAPTOP-JH2M71LG:~/workspace/musl-1.2.2$ clang -fuse-ld=/usr/local/bin/ld.lld -v -nostdlib -shared -Wl,-e,_dlstart
-o lib/libc.so obj/src/aio/aio.lo
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
 "/usr/local/bin/ld.lld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -shared -o lib/libc.so -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/local/bin/../lib -L/lib -L/usr/lib -e _dlstart obj/src/aio/aio.lo
ld.lld: error: obj/src/aio/aio.lo is incompatible with elf_x86_64
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

Then I modified the Makefile (line 162 and 163) from:
lib/libc.so: $(LOBJS) $(LDSO_OBJS)
    $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
        -Wl,-e,_dlstart -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)
to 
lib/libc.so: $(LOBJS) $(LDSO_OBJS)
    /usr/local/bin/ld.lld -nostdlib -shared \
    -e _dlstart -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)

It works now! I am using clang 13.0.0. Is it the problem caused by my computer setting? And I also have a question why $(CFLAGS_ALL) is needed to build libc.so? Thanks!

Best Regards,
Simon