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

glibc: add changes to make riscv64-linux-gnu works #18803

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/libc/glibc/csu/elf-init-2.33.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<https://www.gnu.org/licenses/>. */

#include <stddef.h>
#include <elf-initfini.h>


/* These magic symbols are provided by the linker. */
Expand Down
1 change: 1 addition & 0 deletions lib/libc/glibc/sysdeps/generic/elf-initfini.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define NO_INITFINI 0
6 changes: 6 additions & 0 deletions lib/libc/glibc/sysdeps/generic/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
# define cfi_personality(enc, exp) .cfi_personality enc, exp
# define cfi_lsda(enc, exp) .cfi_lsda enc, exp

# ifndef __clang__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this in upstream glibc. Should a patch be submitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? Idk if we've ever sent a patch to glibc before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, something is weird here:

clang --version
Ubuntu clang version 16.0.6 (15)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/binclang -target riscv test.s -cclang -target riscv64 test.s -c
test.s:5:1: error: unknown directive
.cfi_label .Ldummy
^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang doesn't support the directive which is why we have this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang doesn't support the directive which is why we have this.

It's definitely an oversight. The MCStreamer code in LLVM has an API for emitting CFI labels, it's just that the MCParser hasn't been taught to parse them. Honestly a bit a surprised no one has run into this before as it affects ARC, C-SKY, and LoongArch too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to drop this workaround in LLVM 19: llvm/llvm-project#97922

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, amazing getting that done. Would that mean this PR will have to wait for the next LLVM version bump in Zig?

# define cfi_label(label) .cfi_label label
# else
# define cfi_label(label)
# endif

#else /* ! ASSEMBLER */

# define CFI_STRINGIFY(Name) CFI_STRINGIFY2 (Name)
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/glibc/sysdeps/riscv/start-2.33.S
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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_label (.Ldummy)
cfi_undefined (ra)
call load_gp
mv a5, a0 /* rtld_fini. */
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/glibc/sysdeps/riscv/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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_label (.Ldummy)
cfi_undefined (ra)
call load_gp
mv a5, a0 /* rtld_fini. */
Expand Down
24 changes: 24 additions & 0 deletions lib/libc/include/riscv64-linux-gnu/gnu/stubs-lp64d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This file is automatically generated.
It defines a symbol `__stub_FUNCTION' for each function
in the C library which is a stub, meaning it will fail
every time called, usually setting errno to ENOSYS. */

#ifdef _LIBC
# error Applications may not define the macro _LIBC
#endif

#define __stub___compat_bdflush
#define __stub___compat_create_module
#define __stub___compat_get_kernel_syms
#define __stub___compat_query_module
#define __stub___compat_uselib
#define __stub_chflags
#define __stub_fchflags
#define __stub_fedisableexcept
#define __stub_feenableexcept
#define __stub_fegetexcept
#define __stub_gtty
#define __stub_revoke
#define __stub_setlogin
#define __stub_sigreturn
#define __stub_stty
Loading