public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: T P <prog13579@gmail.com>, Libc-help <libc-help@sourceware.org>
Subject: Re: Failed to build glibc with clang for aarch64
Date: Fri, 29 Apr 2022 11:24:15 -0300	[thread overview]
Message-ID: <be1d7ac9-8420-1a2e-0170-b2811749e8fc@linaro.org> (raw)
In-Reply-To: <CAFEmNk18LN5aUWQo2hQ7OZQXLEigRzqKz-A_w-Q5ieLH8fHD3Q@mail.gmail.com>



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

  reply	other threads:[~2022-04-29 14:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29  4:23 T P
2022-04-29 14:24 ` Adhemerval Zanella [this message]
2022-04-30 13:58   ` Zhu Simon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be1d7ac9-8420-1a2e-0170-b2811749e8fc@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-help@sourceware.org \
    --cc=prog13579@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).