From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id 05DB3385803E for ; Fri, 29 Apr 2022 14:24:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05DB3385803E Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-e922e68b0fso8301540fac.1 for ; Fri, 29 Apr 2022 07:24:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=zqfToV7UZi8NOV0VkZyVwOApQ4WiwDqN2Gzg6KF5FAc=; b=TT2J6lmys7YCA3405EokA6bezd3M7MldyCnvMA6qwpyI2JcFMrfP30UVUzRQzPNsJf 2o7ElFpfZ0RMMngw7Ssy8bD0QBWppIMQEwcX4KNEE67t9vKS5TtsYBWbU/cMGbx0ep4L J5XLVrL8rZwSm5BSCkcI2ww0G9KpQ2eZO+kAtcD/2DXFY+DS+rG4rXY2QwZtOP8e49Sw YneoJ8y+YvfGr48NYbZKtT/63t5I024hlnIrbIPznSwVslk9G18OD5SCsaWXicNvEeBE OaAsVRvUfN8HK5I4i0kT6BVoGsj9t6tg5iVtQZ9ynD7vJlwnwdlAxn0Kkm6FSs5wZpTH AOqQ== X-Gm-Message-State: AOAM5318nnd8CgQTYalYwFE4EPNZyFIwMdWqAHdQNuBPlPRoWHG0k/y4 cLMWZV9D2jUs3RB1ICX0FB+Nxg== X-Google-Smtp-Source: ABdhPJxjdsOMJtPSjxYHWWo17WimsQZ5nWwHFl8twFIC8saomJDLoKhvCY7H9RqMpNk6vuQCVhXDpQ== X-Received: by 2002:a05:6870:560b:b0:ec:90dd:2de8 with SMTP id m11-20020a056870560b00b000ec90dd2de8mr103561oao.134.1651242258044; Fri, 29 Apr 2022 07:24:18 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:726:ddb4:c7ad:9b4b:dfd6? ([2804:431:c7cb:726:ddb4:c7ad:9b4b:dfd6]) by smtp.gmail.com with ESMTPSA id t28-20020a056808159c00b00325361c4fbesm1119909oiw.5.2022.04.29.07.24.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Apr 2022 07:24:17 -0700 (PDT) Message-ID: Date: Fri, 29 Apr 2022 11:24:15 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: Failed to build glibc with clang for aarch64 Content-Language: en-US To: T P , Libc-help References: From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: Fri, 29 Apr 2022 14:24:21 -0000 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=glibc.git;a=commitdiff;h=c8b0172687a7b862fdd5229d95c513b9d0b64dcb), > 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="clang --target=aarch64" CXX="clang++ --target=aarch64" > --target=aarch64 --host=aarch64-linux-gnu --disable-werror --prefix=/usr I have updated my branch with a master rebase, so it should not be in sync 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=aarch64 -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="clang --target=aarch64" CXX="clang++ --target=aarch64" > --target=aarch64 --host=aarch64-linux-gnu --disable-werror --prefix=/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-clang-nostartfiles“ > show that this flag is supported by clang? Although lld is currently support for build with gcc (at least for x86 and 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=/usr \ --build=x86_64-linux-gnu \ --host=aarch64-linux-gnu \ --target=aarch64-linux-gnu \ CC="clang --target=aarch64-linux" \ CXX="clang++ --target=aarch64-linux" \ --with-default-link=yes 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