Skip to content

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

Closed

Description

@andrewrk
[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

Activity

  1. added this to the 0.6.0 milestone on Sep 29, 2019
  2. andrewrk commented on Feb 17, 2020

    @andrewrk
    MemberAuthor

    Related: #4459

  3. modified the milestones: 0.6.0, 0.7.0 on Mar 31, 2020
  4. daurnimator commented on Mar 31, 2020

    @daurnimator
    Contributor

    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
    
  5. andrewrk commented on Mar 31, 2020

    @andrewrk
    MemberAuthor

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

  6. modified the milestones: 0.7.0, 0.8.0 on Oct 17, 2020
  7. modified the milestones: 0.8.0, 0.9.0 on Nov 6, 2020
  8. modified the milestones: 0.9.0, 0.10.0 on May 19, 2021
  9. andrewrk commented on Dec 16, 2021

    @andrewrk
    MemberAuthor

    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)
  10. 47 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-riscv64os-linux

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions