public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Failed to build glibc with clang for aarch64
@ 2022-04-29  4:23 T P
  2022-04-29 14:24 ` Adhemerval Zanella
  0 siblings, 1 reply; 3+ messages in thread
From: T P @ 2022-04-29  4:23 UTC (permalink / raw)
  To: libc-help

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

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*

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?

Thanks!

Best Regards,
Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Failed to build glibc with clang for aarch64
  2022-04-29  4:23 Failed to build glibc with clang for aarch64 T P
@ 2022-04-29 14:24 ` Adhemerval Zanella
  2022-04-30 13:58   ` Zhu Simon
  0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2022-04-29 14:24 UTC (permalink / raw)
  To: T P, Libc-help



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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Failed to build glibc with clang for aarch64
  2022-04-29 14:24 ` Adhemerval Zanella
@ 2022-04-30 13:58   ` Zhu Simon
  0 siblings, 0 replies; 3+ messages in thread
From: Zhu Simon @ 2022-04-30 13:58 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: Libc-help

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 <adhemerval.zanella@linaro.org> 于2022年4月29日周五 22:24写道:

>
>
> 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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-30 13:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  4:23 Failed to build glibc with clang for aarch64 T P
2022-04-29 14:24 ` Adhemerval Zanella
2022-04-30 13:58   ` Zhu Simon

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).