Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to build glibc for target riscv64-linux-gnu #3340

Open
andrewrk opened this issue Sep 29, 2019 · 10 comments · May be fixed by #18803
Open

unable to build glibc for target riscv64-linux-gnu #3340

andrewrk opened this issue Sep 29, 2019 · 10 comments · May be fixed by #18803
Labels
arch-riscv RISCV-32 and RISCV-64 os-linux
Milestone

Comments

@andrewrk
Copy link
Member

[nix-shell:~/dev/zig/build]$ ./zig build-exe --c-source hello.c -target riscv64-linux-gnu -lc
/home/andy/dev/zig/lib/libc/glibc/sysdeps/riscv/start.S:37:10: fatal error: 'entry.h' file not found
#include <entry.h>
         ^~~~~~~~~
1 error generated.

The following command failed:
/home/andy/dev/zig/build/zig cc -MD -MV -MF /home/andy/.local/share/zig/stage1/tmp/jy58t2gTUqIE-start.o.d -nostdinc -fno-spell-checking -isystem /home/andy/dev/zig/lib/include -target riscv64-unknown-linux-gnu -g -fno-omit-frame-pointer -D_DEBUG -fno-stack-protector -fPIC -o /home/andy/.local/share/zig/stage1/tmp/jy58t2gTUqIE-start.o -c /home/andy/dev/zig/lib/libc/glibc/sysdeps/riscv/start.S -I /home/andy/dev/zig/lib/libc/glibc/include -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/sysv/linux/riscv -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/riscv/nptl -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/sysv/linux/generic -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/sysv/linux/include -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/sysv/linux -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/nptl -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/pthread -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/sysv -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix/riscv -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/unix -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/riscv -I /home/andy/dev/zig/lib/libc/glibc/sysdeps/generic -I /home/andy/dev/zig/lib/libc/glibc -I /home/andy/dev/zig/lib/libc/include/riscv64-linux-gnu -I /home/andy/dev/zig/lib/libc/include/generic-glibc -I /home/andy/dev/zig/lib/libc/include/riscv64-linux-any -I /home/andy/dev/zig/lib/libc/include/any-linux-any -D_LIBC_REENTRANT -include /home/andy/dev/zig/lib/libc/glibc/include/libc-modules.h -DMODULE_NAME=libc -Wno-nonportable-include-path -include /home/andy/dev/zig/lib/libc/glibc/include/libc-symbols.h -DPIC -DSHARED -DTOP_NAMESPACE=glibc -DASSEMBLER -g -Wa,--noexecstack
@andrewrk andrewrk added the arch-riscv RISCV-32 and RISCV-64 label Sep 29, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 29, 2019
@andrewrk
Copy link
Member Author

Related: #4459

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 31, 2020
@daurnimator
Copy link
Collaborator

This now seems to fail with:

$ zig build-exe --c-source hello.c -target riscv64-linux-gnu -lc
In file included from hello.c:1:
In file included from /home/daurnimator/src/zig/lib/libc/include/generic-glibc/stdio.h:27:
In file included from /home/daurnimator/src/zig/lib/libc/include/generic-glibc/bits/libc-header-start.h:33:
In file included from /home/daurnimator/src/zig/lib/libc/include/generic-glibc/features.h:489:
/home/daurnimator/src/zig/lib/libc/include/riscv64-linux-gnu/gnu/stubs.h:11:11: fatal error: 'gnu/stubs-lp64d.h' file not found
# include <gnu/stubs-lp64d.h>
          ^~~~~~~~~~~~~~~~~~~
1 error generated.

The following command failed:
/home/daurnimator/src/zig/build/zig clang -c -MD -MV -MF zig-cache/tmp/uZEbEh5O-XWK-hello.o.d -nostdinc -fno-spell-checking -isystem /home/daurnimator/src/zig/lib/include -isystem /home/daurnimator/src/zig/lib/libc/include/riscv64-linux-gnu -isystem /home/daurnimator/src/zig/lib/libc/include/generic-glibc -isystem /home/daurnimator/src/zig/lib/libc/include/riscv64-linux-any -isystem /home/daurnimator/src/zig/lib/libc/include/any-linux-any -target riscv64-unknown-linux-gnu -Xclang -target-feature -Xclang +64bit,+a,+c,+d,-e,+f,+m,-relax,-reserve-x1,-reserve-x10,-reserve-x11,-reserve-x12,-reserve-x13,-reserve-x14,-reserve-x15,-reserve-x16,-reserve-x17,-reserve-x18,-reserve-x19,-reserve-x2,-reserve-x20,-reserve-x21,-reserve-x22,-reserve-x23,-reserve-x24,-reserve-x25,-reserve-x26,-reserve-x27,-reserve-x28,-reserve-x29,-reserve-x3,-reserve-x30,-reserve-x31,-reserve-x4,-reserve-x5,-reserve-x6,-reserve-x7,-reserve-x8,-reserve-x9,-rvc-hints -mno-relax -g -fno-omit-frame-pointer -fsanitize=undefined -fsanitize-trap=undefined -D_DEBUG -Og -fstack-protector-strong --param ssp-buffer-size=4 -fPIC -o zig-cache/tmp/uZEbEh5O-XWK-hello.o hello.c

@andrewrk
Copy link
Member Author

The fix for this issue is likely just copying a few files over from glibc 2.31 into zig's source repo.

@andrewrk
Copy link
Member Author

andrewrk commented Dec 16, 2021

After #10339, the next problem:

$ ./zig build-exe hello.c -lc -target riscv64-linux-gnu
error(compilation): clang failed with stderr: /home/andy/Downloads/zig/lib/libc/glibc/sysdeps/riscv/start.S:48:2: error: unknown directive
 .cfi_label .Ldummy
 ^

error(compilation): /home/andy/Downloads/zig/lib/libc/glibc/sysdeps/riscv/start.S:1:1: unable to build C object: clang exited with code 1
error: unable to build glibc CRT file: BuildingLibCObjectFailed

.cfi_label seems to be an undocumented feature of GAS that clang does not support.

Not sure how to work around that:

ENTRY (ENTRY_POINT)
	/* Terminate call stack by noting ra is undefined.  Use a dummy
	   .cfi_label to force starting the FDE.  */
	.cfi_label .Ldummy
	cfi_undefined (ra)
	call  load_gp
	mv    a5, a0  /* rtld_fini.  */
	/* main may be in a shared library.  */
	la   a0, main
	REG_L a1, 0(sp)      /* argc.  */
	addi  a2, sp, SZREG  /* argv.  */
	andi  sp, sp, ALMASK /* Align stack. */
	li    a3, 0	     /* Used to be init.  */
	li    a4, 0	     /* Used to be fini.  */
	mv    a6, sp  /* stack_end.  */

	call  __libc_start_main@plt
	ebreak
END (ENTRY_POINT)

@alexfanqi
Copy link

alexfanqi commented Sep 21, 2022

Digging into old glibc mail archive, I found https://sourceware.org/pipermail/libc-alpha/2019-January/100734.html

Using a pair of cfi_startproc and cfi_endproc should work equivalently like cfi_label. aarch64 also uses this way https://github.com/bminor/glibc/blob/b92a49359f33a461db080a33940d73f47c756126/sysdeps/unix/sysv/linux/aarch64/clone.S#L72

@joonas-fi
Copy link

I just hit this problem, while trying to cross-compile Go code (with C dependencies) to target riscv64-linux-gnu:

/usr/local/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
/zig/lib/libc/glibc/sysdeps/riscv/start-2.33.S:48:2: error: unknown directive
 .cfi_label .Ldummy

Is is possible to give a "for dummies" instruction on how to ad-hoc fix this? I need to change some file under /zig/lib/libc/glibc/sysdeps/riscv/ ?

@kassane
Copy link
Contributor

kassane commented Nov 3, 2022

@alexfanqi
Copy link

alexfanqi commented Nov 23, 2022

From my understanding of upstream issue linked in, the cfi_label is there to push the cfi_undefined ra into FDE of the entry function instead of leaving it in CIE that is shared for many FDE s. As shown in https://sourceware.org/bugzilla/show_bug.cgi?id=29749#c2, without cfi_label, gas puts cfi_undefined ra in CIE. And I found that llvm-mc puts it in FDE. So I think for llvm, the cfi_label line can be simply removed.

@Beyley
Copy link

Beyley commented Apr 12, 2023

From my understanding of upstream issue linked in, the cfi_label is there to push the cfi_undefined ra into FDE of the entry function instead of leaving it in CIE that is shared for many FDE s. As shown in https://sourceware.org/bugzilla/show_bug.cgi?id=29749#c2, without cfi_label, gas puts cfi_undefined ra in CIE. And I found that llvm-mc puts it in FDE. So I think for llvm, the cfi_label line can be simply removed.

Just hit this problem too, removing that directive and compiling with zig build -Dtarget=riscv64-linux-gnu.2.34 makes it work

zatrazz added a commit to zatrazz/glibc that referenced this issue Sep 28, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Nov 17, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Nov 28, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
saagarjha pushed a commit to ahjragaas/glibc that referenced this issue Dec 21, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Dec 22, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Dec 26, 2023
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Jan 5, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Jan 8, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Jan 25, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
saagarjha pushed a commit to ahjragaas/glibc that referenced this issue Jan 29, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
@RossComputerGuy
Copy link
Sponsor Contributor

RossComputerGuy commented Feb 4, 2024

Wanted to try this out myself but I ran into this on aarch64-linux:

$ zig build-exe hello.c -lc -target riscv64-linux-gnu
thread 30581 panic: access of union field 'success' while field 'failure' is active

Copying the command out with --verbose-cc set gave me this:

In file included from hello.c:1:
In file included from zig/lib/zig/libc/include/generic-glibc/stdio.h:27:
In file included from zig/lib/zig/libc/include/generic-glibc/bits/libc-header-start.h:33:
In file included from zig/lib/zig/libc/include/generic-glibc/features.h:539:
zig/lib/zig/libc/include/riscv64-linux-gnu/gnu/stubs.h:17:11: fatal error: 'gnu/stubs-lp64d.h' file not found
zig/lib/zig/libc/glibc/sysdeps/riscv/start-2.33.S:48:2: error: unknown directive
 .cfi_label .Ldummy
 ^

riscv64-linux-gnu.2.34 hits the same issue and this is with a master build of Zig.

saagarjha pushed a commit to ahjragaas/glibc that referenced this issue Feb 7, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Feb 8, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Feb 9, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Feb 14, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Feb 16, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
zatrazz added a commit to zatrazz/glibc that referenced this issue Feb 21, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
saagarjha pushed a commit to ahjragaas/glibc that referenced this issue Apr 2, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
saagarjha pushed a commit to ahjragaas/glibc that referenced this issue Apr 17, 2024
The .cfi_label is a gas extension not supported by clang.  From a
ziglang discussion [1], it seems that it is not really required.

[1] ziglang/zig#3340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv RISCV-32 and RISCV-64 os-linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants