Hello,

I made a change to the Makefile of musl 1.2.2 at line 162, just remove the CFLAGS_ALL. 

Note: The reason why I remove the CFLAGS_ALL, because I find on my computer when "clang --target=aarch64 -fuse-ld=/usr/local/bin/ld.lld -Wl,....." is used, gcc linker will be invoked, but when  --target=aarch64 is removed, ld.lld will be invoked as expect. Since CFLAGS_ALL contains the option --target=aarch64, so I modify the Makefile.

And use the below configuration:
./configure CC=clang --target=aarch64 CFLAGS="--target=aarch64 --rtlib=compiler-rt" AR=/usr/local/bin/llvm-ar LDFLAGS="-fuse-ld=/usr/local/bin/ld.lld -Wl,-z,noexecstack -m elf64-littleaarch64" RANLIB=/usr/local/bin/llvm-ranlib LIBCC=  --syslibdir=/usr/local/lib

Then ld.lld is invoked but still report the below error, does anyone have encounter the same problem?


Thanks,
Simon

From: Jeffrey Walton <noloader@gmail.com>
Sent: Saturday, October 30, 2021 12:25
To: musl@lists.openwall.com <musl@lists.openwall.com>
Subject: Re: [musl] Failed to build musl 1.2.2 by using clang cross compiler
 


On Fri, Oct 29, 2021 at 11:46 PM Chunlin Zhu <simon_0214@hotmail.com> wrote:
Hello, 

On my computer I have built and install the llvm toolchain from the source code by using the below configuration, the llvm lib is installed in the /usr/local/lib folder.
cmake -S llvm -B build -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;compiler-rt;lld" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" 

And I am trying to build musl libc 1.2.2 for aarch64 by using llvm/clang, and I use the below configure:
./configure CC=clang --target=aarch64 CFLAGS="-v --target=aarch64 --rtlib=compiler-rt" AR=/usr/local/bin/llvm-ar RANLIB=/usr/local/bin/llvm-ranlib LIBCC=-lcompiler_rt --syslibdir=/usr/local/lib

It report the error as below:


And I find the compile phase is OK, the problem occurs during the link phase, I don't understand why finally gcc is invoked.


By the way, the below configure works on my computer:

./configure CC=clang 

make -j4 


Set LD to clang, too. It sounds like GCC is creeping in because it is a default.

For the link error with --noexecstack, the linker needs -z,noexecstack. So add -Wl,-z,noexecstack to LDFLAGS. See the ld(1) man page at https://www.man7.org/linux/man-pages/man1/ld.1.html.

ASFLAGS should continue to use --noexecstack.

Jeff