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

Relocation trunacted to fit error R_RISCV_JAL while compiling kernel #738

Closed
atishp04 opened this issue Oct 14, 2020 · 18 comments
Closed

Relocation trunacted to fit error R_RISCV_JAL while compiling kernel #738

atishp04 opened this issue Oct 14, 2020 · 18 comments
Labels

Comments

@atishp04
Copy link

atishp04 commented Oct 14, 2020

Hi,
I am making some changes in linux kernel to improve kernel protection. I tried to move .init.text below .text both being in a different 2MB sections. This is done to apply different permissions to these areas. Kernel uses 2MB(PMD) mappings to improve kernel performance.

Here is the branch with the required changes.
https://github.com/atishp04/linux/tree/relocation_jal_issue

It works most of the time except when CONFIG_HARDENED_USERCOPY is enabled.
I see the following linker error in that case.

net/ipv4/ipconfig.o: in function ic_setup_routes': /home/atish/workspace/linux/net/ipv4/ipconfig.c:400:(.init.text+0x1c4): relocation truncated to fit: R_RISCV_JAL against symbol ip_rt_ioctl' defined in .text section in net/ipv4/fib_frontend.o
make: *** [Makefile:1162: vmlinux] Error 1

This happens only when copy_from_user is called from function that is annotated with __init.
The relocation id seems to be RISCV_CALL from the objdump. I am not sure why linker converts it to JAL.
I further narrowed down the issue to a __builtin_constant_p

Here is the code path:
ip_rt_ioctl->rtentry_to_fib_config->copy_from_user->check_copy_size->check_object_size

#ifdef CONFIG_HARDENED_USERCOPY
112 extern void __check_object_size(const void *ptr, unsigned long n,
113                                         bool to_user);
114
115 static __always_inline void check_object_size(const void *ptr,
unsigned long n,
116                                               bool to_user)
117 {
118         if (!__builtin_constant_p(n)) ---------------------> Commenting this line avoids the linker issue
119         __check_object_size(ptr, n, to_user);
120 }
121 #else
122 static inline void check_object_size(const void *ptr, unsigned
long n,
123                                      bool to_user)
124 { }
125 #endif /* CONFIG_HARDENED_USERCOPY */

Commenting line 118 avoids the issue.

The required config, temporary object file, compilation logs are shared here.
https://wdc.box.com/s/m6be2vlnpp1pljr20o1bzrxl87xdp93p

Reproduction steps:

  1. Checkout the following branch
    https://github.com/atishp04/linux/tree/relocation_jal_issue
  2. Use the shared config from above directory
  3. Compile the kernel

Please let me know if you need anything else.

@jim-wilson

@jim-wilson
Copy link
Collaborator

I tried a build on my fedora rawhide box, with gcc-10.2 and binutils-2.35. I did not get a link error. I can see from your config file that you have gcc-9.3, and binutils-2.33. Checking ChangeLog entries, this could perhaps be
https://sourceware.org/bugzilla/show_bug.cgi?id=25181
fixed last November, which means it was fixed about a month and a half after the binutils-2.33 release.

@atishp04
Copy link
Author

atishp04 commented Oct 16, 2020

@jim-wilson Did you try the kernel tree I shared ? I am getting linker error with configs generated with defconfig as well with gcc-10.2 & binutils-2.35. Earlier, I used to see the error only with the config shared.

init/main.o: in function `kernel_init':
main.c:(.ref.text+0xec): relocation truncated to fit: R_RISCV_JAL against `kernel_init_freeable'
mm/page_alloc.o: in function `.L0 ':
page_alloc.c:(.ref.text+0x46): relocation truncated to fit: R_RISCV_JAL against symbol `memblock_alloc_try_nid' defined in .init.text section in mm/memblock.o
drivers/base/devtmpfs.o: in function `.L0 ':
devtmpfs.c:(.ref.text+0x3c): relocation truncated to fit: R_RISCV_JAL against symbol `init_mount' defined in .init.text section in fs/init.o
drivers/firmware/efi/earlycon.o: in function `.L0 ':
earlycon.c:(.ref.text+0x24): relocation truncated to fit: R_RISCV_JAL against symbol `early_memremap_prot' defined in .init.text section in mm/early_ioremap.o
make: *** [Makefile:1162: vmlinux] Error 1

Here is the part of the config generated from defconfig

CONFIG_CC_VERSION_TEXT="riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0"                                                                                                                                           
CONFIG_CC_IS_GCC=y                                                                                                                                                                                            
CONFIG_GCC_VERSION=100200                                                                                                                                                                                     
CONFIG_LD_VERSION=235000000                                                                                                                                                                                   
CONFIG_CLANG_VERSION=0         

@jim-wilson
Copy link
Collaborator

Yes, I tried your tree, but it didn't fail for me with gcc-10 and binutils-2.35. I was able to reproduce last night using gcc-9.3 and binutils-2.33.1 though. Adding the patch from 25181 didn't fix it, so I need to try to debug it.

@atishp04
Copy link
Author

atishp04 commented Oct 16, 2020

Huh..I can't reproduce the issue with the config where CONFIG_HARDENED_USERCOPY is enabled. But it fails with the config generated using defconfig. I guess the fix works for some cases but fails for others.

Here are the steps to reproduce the issue with gcc-10 & binutils-2.35

  1. Checkout the following branch
    https://github.com/atishp04/linux/tree/relocation_jal_issue

  2. Generate a config using defconfig

ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- make defconfig
  1. Compile Kernel

Here are the linker errors I see

init/main.o: in function `kernel_init':
main.c:(.ref.text+0xec): relocation truncated to fit: R_RISCV_JAL against `kernel_init_freeable'
mm/page_alloc.o: in function `.L0 ':
page_alloc.c:(.ref.text+0x46): relocation truncated to fit: R_RISCV_JAL against symbol `memblock_alloc_try_nid' defined in .init.text section in mm/memblock.o
drivers/base/devtmpfs.o: in function `.L0 ':
devtmpfs.c:(.ref.text+0x3c): relocation truncated to fit: R_RISCV_JAL against symbol `init_mount' defined in .init.text section in fs/init.o
drivers/firmware/efi/earlycon.o: in function `.L0 ':
earlycon.c:(.ref.text+0x24): relocation truncated to fit: R_RISCV_JAL against symbol `early_memremap_prot' defined in .init.text section in mm/early_ioremap.o
make: *** [Makefile:1162: vmlinux] Error 1

@jim-wilson
Copy link
Collaborator

This is an alignment padding problem. There is a call from .init.text to .text. .init.text immediately follows .text. The call is in range of a jal instruction when relaxed. Further relaxation causes the .text target address to decrease. An alignment directlve between .init.text and .text means that the .init.text starting address does not decrease during relaxation. Normally, the difference between two code addresses can only decrease during relaxation. But alignment directives means that offsets can increase, worst case, by as much as the specified alignment. In this case, the offset ends up increasing just enough to make it too large for a JAL and we get a relocation overflow error at the end.

The linker tries to take alignment directives into account, by adding section alignment to the offset before deciding if it will fit in a relaxed instruction. Normally alignments are small so this is OK. In this case you have a large alignment. But even worse is that the alignment is in between sections, and the RISC-V relaxation code isn't aware of it. This causes the relocation error as we aren't adjust for alignments properly. I don't know if we can handle alignment directives in between sections during relaxation time. The relaxation code may not have access to such linker script info. We do have access to section alignments though.

I can work around the problem by making the section alignments explicit in the linker script. With this change

46c46
<  . = ALIGN((1 << (12))); .init.text : AT(ADDR(.init.text) - 0xffffffe000000000
) { _sinittext = .; *(.init.text .init.text.*) *(.text.startup) *(.meminit.text*
) _einittext = .; }
---
>  . = ALIGN((1 << (12))); .init.text : AT(ADDR(.init.text) - 0xffffffe000000000
) ALIGN(1 << 21) { _sinittext = .; *(.init.text .init.text.*) *(.text.startup) *
(.meminit.text*) _einittext = .; }

In the executable .init.text is now specified to have 1<<21 alignment. it still has the same starting address as before. The link succeeds with this change. I get about a 6.6KB increase in the code size due to less relaxation, as the large section alignment will prevent a lot of cross section relaxation. For calls within a section, we use that section's alignment in the calculation. For calls across sections, e.g. from .init.text to .text, we use the max section alignment. We really should use the max section alignment of the sections in between the source and target sections, but it isn't obvious how to compute that, so we just use the max of all section alignments which is safe. This does mean that setting one section alignment to 1<<21 is going to affect all cross section relaxations though, and all relaxations inside that section. Relaxations within .text will still happen as before though, and I only see the .text size increase by 32 bytes. The .exit.text size increases by 100 bytes. And .init.text increases by 6.5K. Given that the kernel is about 8.9M a 6.5K increase should be OK.

@atishp04
Copy link
Author

Thanks @jim-wilson . That fixes the problem. I am not sure if that will be acceptable to upstream kernel though. I will propose this to the mailing list. Thanks a lot for the investigation. I have a question though. This may be a very stupid question as I don't have much experience in toolchain.

Why does the relaxation code doesn't have access to the alignment between sections while it have access to the section alignments ?

@jim-wilson
Copy link
Collaborator

I know that the linker goes through the linker script commands in order as it operates, repeating this until the result stablizes, and I don't know if the relaxation code has access to any of that info. But the relaxation code does have access to ELF stuff like section info, as that is all maintained in bfd not in the linker code. So the linker scripts are handled by the code in the ld dir, and input and output sections contents and flags are handled by the code in the bfd dir. The relaxation code is in the bfd dir also so it has access to all of the object file stuff, but maybe not the linker script. I'm more of a gcc expert than a binutils expert, so I don't kinow if there is some obscure way to get the info we need to fix this.

@atishp04
Copy link
Author

Thanks @jim-wilson . @palmer-dabbelt any thoughts ?

fengguang pushed a commit to 0day-ci/linux that referenced this issue Oct 26, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
atishp04 added a commit to atishp04/linux that referenced this issue Oct 31, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
atishp04 added a commit to atishp04/linux that referenced this issue Nov 3, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
atishp04 added a commit to atishp04/linux that referenced this issue Nov 4, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
fengguang pushed a commit to 0day-ci/linux that referenced this issue Nov 5, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
atishp04 added a commit to atishp04/linux that referenced this issue Nov 13, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
sudipm-mukherjee pushed a commit to sudipm-mukherjee/linux-next that referenced this issue Nov 27, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
atishp04 added a commit to atishp04/linux that referenced this issue Dec 3, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
atishp04 added a commit to atishp04/linux that referenced this issue Dec 19, 2020
In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
@lazyparser
Copy link
Collaborator

@atishp04 Hi, is this issue got solved?

@TommyMurphyTM1234
Copy link
Collaborator

No update/activity in over a year so presuming that there's no outstanding issue at this stage.

eclipse-oniro-oh-bot pushed a commit to eclipse-oniro-mirrors/kernel_linux_5.10 that referenced this issue Feb 10, 2024
mainline inclusion
from mainline-5.11
commit b6566dc1acca38ce6ed845ce8a270fb181ff6d41
category: feature
feature: native builds with llvm

Signed-off-by: Polyos Project <polyos@iscas.ac.cn>
---------------------------------------
[ Upstream commit ]

In order to improve kernel text protection, we need separate .init.text/
.init.data/.text in separate sections. However, RISC-V linker relaxation
code is not aware of any alignment between sections. As a result, it may
relax any RISCV_CALL relocations between sections to JAL without realizing
that an inter section alignment may move the address farther. That may
lead to a relocation truncated fit error. However, linker relaxation code
is aware of the individual section alignments.

The detailed discussion on this issue can be found here.
riscv-collab/riscv-gnu-toolchain#738

Keep the .init.text section aligned so that linker relaxation will take
that as a hint while relaxing inter section calls.
Here are the code size changes for each section because of this change.

section         change in size (in bytes)
  .head.text      +4
  .text           +40
  .init.text      +6530
  .exit.text      +84

The only significant increase in size happened for .init.text because
all intra relocations also use 2MB alignment.

Suggested-by: Jim Wilson <jimw@sifive.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
@dinyy
Copy link

dinyy commented Apr 8, 2024

I want to known if this problem has been solved, I occur this proble when I want to cross-compile LLVM.
Log shows blow:

/home/sole/work/qemu_rvv/llvm-project-main/clang/lib/CodeGen/CGBuiltin.cpp:21038:(.text+0x13606a): relocation truncated to fit: R_RISCV_JAL against `.L13090'
collect2: error: ld returned 1 exit status
[442/486] Linking CXX static library lib/libclangSerialization.a
ninja: build stopped: subcommand failed.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 8, 2024

I want to known if this problem has been solved, I occur this proble when I want to cross-compile LLVM. Log shows blow:

/home/sole/work/qemu_rvv/llvm-project-main/clang/lib/CodeGen/CGBuiltin.cpp:21038:(.text+0x13606a): relocation truncated to fit: R_RISCV_JAL against `.L13090' collect2: error: ld returned 1 exit status [442/486] Linking CXX static library lib/libclangSerialization.a ninja: build stopped: subcommand failed.

Please explain how exactly you are building LLVM - i.e. all commands/steps taken: git clone, configure, make etc.
And please capture and attach the build log.

@dinyy
Copy link

dinyy commented Apr 8, 2024

I want to known if this problem has been solved, I occur this proble when I want to cross-compile LLVM. Log shows blow:
/home/sole/work/qemu_rvv/llvm-project-main/clang/lib/CodeGen/CGBuiltin.cpp:21038:(.text+0x13606a): relocation truncated to fit: R_RISCV_JAL against `.L13090' collect2: error: ld returned 1 exit status [442/486] Linking CXX static library lib/libclangSerialization.a ninja: build stopped: subcommand failed.

Please explain how exactly you are building LLVM - i.e. all commands/steps taken: git clone, configure, make etc. And please capture and attach the build log.

first, I get the newest LLVM by Download ZIP from github
second, my cmake command is that:
image
and my ToolchainExample.cmake shows blew:
image
And the error log when I building is that:
FAILED: lib/libclang-cpp.so.19.0git : && /home/sole/opt/riscv/gcc/bin/riscv64-unknown-linux-gnu-g++ -fPIC -march=rv64gcv -mcmodel=medany - ... ..... /home/sole/work/qemu_rvv/llvm-project-main/clang/lib/CodeGen/CGBuiltin.cpp:21038:(.text+0x13606a): relocation truncated to fit: R_RISCV_JAL against .L13090' collect2: error: ld returned 1 exit status [442/486] Linking CXX static library lib/libclangSerialization.a ninja: build stopped: subcommand failed.

@dinyy
Copy link

dinyy commented Apr 8, 2024

-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/sole/opt/riscv/gcc/bin/riscv64-unknown-linux-gnu-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/sole/opt/riscv/gcc/bin/riscv64-unknown-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/sole/opt/riscv/gcc/bin/riscv64-unknown-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- bolt project is disabled
-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- cross-project-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- lld project is enabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- Found Python3: /usr/bin/python3 (found suitable version "3.11.6", minimum required is "3.6") found components: Interpreter
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for link.h
-- Looking for link.h - found
-- Looking for malloc/malloc.h
-- Looking for malloc/malloc.h - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for signal.h
-- Looking for signal.h - found
-- Looking for sys/ioctl.h
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/param.h
-- Looking for sys/param.h - found
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sysexits.h
-- Looking for sysexits.h - found
-- Looking for termios.h
-- Looking for termios.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for valgrind/valgrind.h
-- Looking for valgrind/valgrind.h - found
-- Looking for fenv.h
-- Looking for fenv.h - found
-- Looking for FE_ALL_EXCEPT
-- Looking for FE_ALL_EXCEPT - found
-- Looking for FE_INEXACT
-- Looking for FE_INEXACT - found
-- Performing Test HAVE_BUILTIN_THREAD_POINTER
-- Performing Test HAVE_BUILTIN_THREAD_POINTER - Success
-- Looking for mach/mach.h
-- Looking for mach/mach.h - not found
-- Looking for CrashReporterClient.h
-- Looking for CrashReporterClient.h - not found
-- Looking for linux/magic.h
-- Looking for linux/magic.h - found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Looking for pthread_rwlock_init in pthread
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found ZLIB: /home/sole/work/qemu_rvv/riscv-sysroot/usr/lib/riscv64-linux-gnu/libz.a (found version "1.2.13")
-- Looking for compress2
-- Looking for compress2 - found
-- Found LibXml2: /home/sole/work/qemu_rvv/riscv-sysroot/usr/lib/riscv64-linux-gnu/libxml2.so
-- Looking for xmlReadMemory
-- Looking for xmlReadMemory - not found
-- Performing Test Terminfo_LINKABLE
-- Performing Test Terminfo_LINKABLE - Success
-- Found Terminfo: /home/sole/work/qemu_rvv/riscv-sysroot/usr/lib/riscv64-linux-gnu/libtinfo.a
-- Looking for arc4random
-- Looking for arc4random - found
-- Looking for backtrace
-- Looking for backtrace - found
-- backtrace facility detected in default set of libraries
-- Found Backtrace: /home/sole/work/qemu_rvv/riscv-sysroot/usr/include
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Looking for __register_frame
-- Looking for __register_frame - found
-- Looking for __deregister_frame
-- Looking for __deregister_frame - found
-- Looking for __unw_add_dynamic_fde
-- Looking for __unw_add_dynamic_fde - not found
-- Looking for _Unwind_Backtrace
-- Looking for _Unwind_Backtrace - found
-- Looking for getpagesize
-- Looking for getpagesize - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Looking for getrusage
-- Looking for getrusage - found
-- Looking for setrlimit
-- Looking for setrlimit - found
-- Looking for isatty
-- Looking for isatty - found
-- Looking for futimens
-- Looking for futimens - found
-- Looking for futimes
-- Looking for futimes - found
-- Looking for sigaltstack
-- Looking for sigaltstack - found
-- Looking for mallctl
-- Looking for mallctl - not found
-- Looking for mallinfo
-- Looking for mallinfo - found
-- Looking for mallinfo2
-- Looking for mallinfo2 - found
-- Looking for malloc_zone_statistics
-- Looking for malloc_zone_statistics - not found
-- Looking for getrlimit
-- Looking for getrlimit - found
-- Looking for posix_spawn
-- Looking for posix_spawn - found
-- Looking for pread
-- Looking for pread - found
-- Looking for sbrk
-- Looking for sbrk - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for strerror_s
-- Looking for strerror_s - not found
-- Looking for setenv
-- Looking for setenv - found
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - Failed
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - Success
-- Looking for GLIBC
-- Looking for GLIBC - found
-- Looking for pthread_getname_np
-- Looking for pthread_getname_np - found
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Looking for dlopen
-- Looking for dlopen - found
-- Looking for dladdr
-- Looking for dladdr - found
-- Looking for proc_pid_rusage
-- Looking for proc_pid_rusage - not found
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS
-- Performing Test LLVM_HAS_ATOMICS - Success
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG - Success
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG - Failed
-- Performing Test HAS_MAYBE_UNINITIALIZED
-- Performing Test HAS_MAYBE_UNINITIALIZED - Success
-- Can't get errc messages in cross-compilation mode
-- LLVM host triple: riscv64-unknown-linux-gnu
-- Native target architecture is RISCV
-- Threads enabled.
-- Doxygen disabled.
-- Ninja version: 1.11.1
-- Found OCaml: /usr/bin/ocamlfind
-- OCaml bindings enabled.
-- Found Python module pygments
-- Found Python module pygments.lexers.c_cpp
-- Found Python module yaml
-- LLVM default target triple: riscv64-unknown-linux-gnu
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test C_SUPPORTS_CMAKE_CXX_FLAGS
-- Performing Test C_SUPPORTS_CMAKE_CXX_FLAGS - Success
-- Performing Test CXX_SUPPORTS_CMAKE_CXX_FLAGS
-- Performing Test CXX_SUPPORTS_CMAKE_CXX_FLAGS - Success
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Failed
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Success
-- Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG
-- Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG - Success
-- Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG
-- Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG - Success
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Failed
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Success
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL - Success
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Failed
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Failed
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Failed
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG - Success
-- Performing Test C_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG
-- Performing Test C_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG
-- Performing Test CXX_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG - Success
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS - Failed
-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found
-- Linker detection: GNU ld
-- Setting native build dir to /home/sole/work/qemu_rvv/llvm-project-main/build-riscv/NATIVE
-- Performing Test HAS_WERROR_GLOBAL_CTORS
-- Performing Test HAS_WERROR_GLOBAL_CTORS - Failed
-- Looking for x86_64
-- Looking for x86_64 - not found
-- Found Git: /usr/bin/git (found version "2.40.1")
-- Targeting RISCV
CMake Deprecation Warning at /home/sole/work/qemu_rvv/llvm-project-main/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
The OLD behavior for policy CMP0114 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
/home/sole/work/qemu_rvv/llvm-project-main/lld/CMakeLists.txt:6 (include)

-- LLD version: 19.0.0
CMake Deprecation Warning at /home/sole/work/qemu_rvv/llvm-project-main/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
The OLD behavior for policy CMP0114 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
/home/sole/work/qemu_rvv/llvm-project-main/clang/CMakeLists.txt:6 (include)

-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for dladdr
-- Looking for dladdr - found
-- Clang version: 19.0.0git
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Failed
-- Looking for include file sys/inotify.h
-- Looking for include file sys/inotify.h - found
-- Performing Test HAVE_LINKER_FLAG_LONG_PLT
-- Performing Test HAVE_LINKER_FLAG_LONG_PLT - Failed
-- Registering ExampleIRTransforms as a pass plugin (static build: OFF)
-- Registering Bye as a pass plugin (static build: OFF)
-- Google Benchmark version: v0.0.0, normalized to 0.0.0
-- Looking for shm_open in rt
-- Looking for shm_open in rt - found
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST - Success
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Failed
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Failed
-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Cross-compiling to test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Configuring done (19.9s)

@TommyMurphyTM1234
Copy link
Collaborator

What you've provided isn't sufficient for others to reproduce the issue. You need to ideally provide a small, self-contained, reproducible test case that will do this.

You also didn't clarify all relevant details - how you built your RISC-V GCC toolchain, what specific LLVM tarball you downloaded to use, why you didn't build LLVM using these instructions, etc:

That's why I asked for details of all of the commands that you used from start to finish to build GCC/LLVM/Clang etc.

And then a small, self-contained, reproducible test program that illustrates the error.

@kito-cheng
Copy link
Collaborator

@dinyy could you file new issue for that? also plz give text version for the cmake command and ToolchainExample.cmake if possible?

@dinyy
Copy link

dinyy commented Apr 8, 2024

@dinyy could you file new issue for that? also plz give text version for the cmake command and ToolchainExample.cmake if possible?

OK,I'm trying to upload all this.

@dinyy
Copy link

dinyy commented Apr 8, 2024

I file a new issue here:#1455 @TommyMurphyTM1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants