From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by sourceware.org (Postfix) with ESMTPS id E6DD63858D28 for ; Sat, 30 Apr 2022 13:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6DD63858D28 Received: by mail-ua1-x933.google.com with SMTP id s1so1444648uac.6 for ; Sat, 30 Apr 2022 06:58:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z3r29kDpGQN3Gozg9cmpw4Mzto4/zITn7huDZDP0c3g=; b=ylm2ZDnAAgNLMqIoaHoObeGsOSqmICIbA39p5NcHop9AdLAN649CQzp/27/RXPWtpR 9EPIHJqjfSrPVi5/DPcZdx4CFLikCx6ngtokBLM6+ZMnHR/sMzZiT27VEnEjp+Hv9ydC bb/JUCeqy920LwN2CAAB51I+WZrtAhwgDBgwjlgurgVMSPhRfu2/20ZnlkmwKrd1tw0/ I5P0pTua+ur2UFtvnhizLS3tbJI77WfaKtyNSZT3iUOGD+9QwnIXFccpx1N7MEC17PdI r3aDD9xapd82FsG9K4KtW5Q9c1fTORj7QuOiOVId/qYmHnJ1dWD3B/1CCI5BatJ5lOCp sF6w== X-Gm-Message-State: AOAM532NO/y1mbG9Ww6w8V/jpGyI5//Ek+Jyzi8YfpU2WbvbFQrfMwOS GpvDZbI7Yi7CuWkfronJLksrwSVaDnlRYbeAwuthheYRGAf/Qo2l X-Google-Smtp-Source: ABdhPJwRbtwojG4jXRDvjQlYfPPJ0iebYTcCOct3JtxuR6Oi4ZwNEJ0sOVzbjJF2SeCzRJ9ksB8CpDfcoKlXDzKt960= X-Received: by 2002:ab0:2505:0:b0:362:7789:fec5 with SMTP id j5-20020ab02505000000b003627789fec5mr1053384uan.54.1651327102935; Sat, 30 Apr 2022 06:58:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Zhu Simon Date: Sat, 30 Apr 2022 21:58:10 +0800 Message-ID: Subject: Re: Failed to build glibc with clang for aarch64 To: Adhemerval Zanella Cc: Libc-help X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Apr 2022 13:58:26 -0000 Hello Adhemerval, Thanks for you kind help, it can work on my system (Ubuntu 20.04 and llvm 13.0.0) now with your latest commit, thanks! Best Regards, Simon Adhemerval Zanella =E4=BA=8E2022=E5=B9=B44= =E6=9C=8829=E6=97=A5=E5=91=A8=E4=BA=94 22:24=E5=86=99=E9=81=93=EF=BC=9A > > > On 29/04/2022 01:23, T P via Libc-help wrote: > > Hello Adhemerval and all, > > > > I checkout your branch azanella/clang and use the below commit ( > > > https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommitdiff;h=3Dc8b0172687a7= b862fdd5229d95c513b9d0b64dcb > ), > > I build glibc with clang for x86 successfully, that's great. Then I try > to > > build it for aarch64 using the below config: > > ../configure CC=3D"clang --target=3Daarch64" CXX=3D"clang++ --target=3D= aarch64" > > --target=3Daarch64 --host=3Daarch64-linux-gnu --disable-werror --prefix= =3D/usr > > I have updated my branch with a master rebase, so it should not be in syn= c > the my current work (I was not sure how old sourceware one was). > > On the system I use (ubuntu 22.04) it requires you install the default > aarc64 > sysroot, done by install aarch64-linux-gnu-gcc pacakge (iy might vary > depending > of the distribution). > > I also noted that triplet used for clang, 'aarch64', is not suffice. You > will > need to use 'aarch64-linux' because: > > 1. clang won't find the correct sysroot, at least on my system (it > complains > that asm/errno.h can't no be founded). > > 2. It won't define __linux or __linux__ macros, which is used in some > places > in the code. > > With my updated branch I could build to aarch64-linux with current llvm > master > (3c2a74a3ae02d16e899e280953c055f92aa6cdaa). > > > > > The below error is reported: > > > > *make[2]: Entering directory '/home/glibc/glibc/csu'* > > *clang --target=3Daarch64 -nostdlib -nostartfiles -r -o > > /home/glibc/glibc/build/csu/crt1.o /home/glibc/glibc/build/csu/start.o > > /home/glibc/glibc/build/csu/abi-note.o /home/glibc/glibc/build/csu/init= .o > > /home/glibc/glibc/build/csu/static-reloc.o* > > *ld: error: /home/glibc/glibc/build/csu/start.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/abi-note.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/init.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/static-reloc.o is incompatible > with > > elf_x86_64* > > *collect2: error: ld returned 1 exit status* > > *clang-13: error: linker (via gcc) command failed with exit code 1 (use > -v > > to see invocation)* > > *make[2]: *** [Makefile:134: /home/glibc/glibc/build/csu/crt1.o] Error = 1* > > *make[2]: Leaving directory '/home/glibc/glibc/csu'* > > *make[1]: *** [Makefile:483: csu/subdir_lib] Error 2* > > *make[1]: Leaving directory '/home/glibc/glibc'* > > *make: *** [Makefile:9: all] Error 2* > > I am almost sure this similar to error I saw trying to use just 'aarch64' > triple. > > > > > Then I run the above command manually by use -v, it reports as below: > > *clang version 13.0.0* > > *Target: aarch64* > > *Thread model: posix* > > *InstalledDir: /usr/local/bin* > > * "/usr/bin/gcc" -nostdlib -nostartfiles -o > > /home/glibc/glibc/build/csu/crt1.o -r /home/glibc/glibc/build/csu/start= .o > > /home/glibc/glibc/build/csu/abi-note.o /home/glibc/glibc/build/csu/init= .o > > /home/glibc/glibc/build/csu/static-reloc.o* > > *ld: error: /home/glibc/glibc/build/csu/start.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/abi-note.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/init.o is incompatible with > > elf_x86_64* > > *ld: error: /home/glibc/glibc/build/csu/static-reloc.o is incompatible > with > > elf_x86_64* > > *collect2: error: ld returned 1 exit status* > > *clang-13: error: linker (via gcc) command failed with exit code 1 (use > -v > > to see invocation)* > > > > I think it's an issue on my computer that clang will not invoke ld.lld > > correctly, it always run "/usr/bin/gcc" which I still can't fix. Then I > try > > this command by manually invoking the ld.lld directly but it still > reports > > error: > > *root@6ab3fca322b6:/home/glibc/glibc/build# ld.lld -nostdlib > -nostartfiles > > -o /home/glibc/glibc/build/csu/crt1.o -r > > /home/glibc/glibc/build/csu/start.o > /home/glibc/glibc/build/csu/abi-note.o > > /home/glibc/glibc/build/csu/init.o > > /home/glibc/glibc/build/csu/static-reloc.o* > > *ld.lld: error: unknown argument '-nostartfiles'* > > > > I think the issue is the flag'-nostartfiles', then I remove it and try > the > > below command it works: > > *root@6ab3fca322b6:/home/glibc/glibc/build# ld.lld -nostdlib -o > > /home/glibc/glibc/build/csu/crt1.o -r /home/glibc/glibc/build/csu/start= .o > > /home/glibc/glibc/b* > > *uild/csu/abi-note.o /home/glibc/glibc/build/csu/init.o > > /home/glibc/glibc/build/csu/static-reloc.o* > > *root@6ab3fca322b6:/home/glibc/glibc/build#* > > > > My questions are as below: > > 1. Is the below command correct to build the branch with clang for > aarch64: > > ../configure CC=3D"clang --target=3Daarch64" CXX=3D"clang++ --target=3D= aarch64" > > --target=3Daarch64 --host=3Daarch64-linux-gnu --disable-werror --prefix= =3D/usr > > > > 2. Why clang failed to invoke ld.lld? I am using clang and ld.lld 13.0.= 0 > > and I build the llvm from source code. > > > > 3. Why the flag '-nostartfiles' is not supported by ld.lld? I find the > > webpage " > > > https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clan= g-nostartfiles > =E2=80=9C > > show that this flag is supported by clang? > > Although lld is currently support for build with gcc (at least for x86 an= d > ARM), > the issue seems related on recent --with-default-link [1]. So you will > need to > use 'yes' to build with lld: > > # Assuming 'ld' points to 'ld.lld' in you path > $ configure --prefix=3D/usr \ > --build=3Dx86_64-linux-gnu \ > --host=3Daarch64-linux-gnu \ > --target=3Daarch64-linux-gnu \ > CC=3D"clang --target=3Daarch64-linux" \ > CXX=3D"clang++ --target=3Daarch64-linux" \ > --with-default-link=3Dyes > > It should build. I have not yet tested if build all tests and the make > check > result, I only have done it with binutils. > > > Btw, thanks for taking interest in this work. I hope to get something > 'upstreamable' in near future. > > [1] https://sourceware.org/pipermail/libc-alpha/2022-April/138260.html >