crash-utility / crash

Linux kernel crash utility
https://crash-utility.github.io
819 stars 271 forks source link

Compilation error when doing cross compilation for arm64 #162

Closed fmartinsons closed 10 months ago

fmartinsons commented 10 months ago

Hello , I try to build the latest crash tag 8.0.4 in a cross compiled environnement in order to analyze vmcore for an arm64 target.

I used yocto (kirkstone) framework for building an os for my arm target and I use cross canadian flavor to embed crash on an sdk (x86 host). The gcc version used is 11.4

Finally I have strange compilation error that I didn't manage to understand:

| In file included from ./../gdb/nat/aarch64-sve-linux-ptrace.h:29,
|                  from linux-aarch64-low.cc:45:
| ./../gdb/nat/aarch64-sve-linux-sigcontext.h:25:29: error: field 'head' has incomplete type '_aarch64_ctx'
|    25 |         struct _aarch64_ctx head;
|       |                             ^~~~
| ./../gdb/nat/aarch64-sve-linux-sigcontext.h:25:16: note: forward declaration of 'struct _aarch64_ctx'
|    25 |         struct _aarch64_ctx head;
|       |                ^~~~~~~~~~~~
| linux-aarch64-low.cc: In function 'void aarch64_fill_gregset(regcache*, void*)':
| linux-aarch64-low.cc:202:63: error: invalid use of incomplete type 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   202 |     collect_register (regcache, AARCH64_X0_REGNUM + i, &regset->regs[i]);
|       |                                                               ^~
| linux-aarch64-low.cc:198:10: note: forward declaration of 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   198 |   struct user_pt_regs *regset = (struct user_pt_regs *) buf;
|       |          ^~~~~~~~~~~~
| linux-aarch64-low.cc:203:57: error: invalid use of incomplete type 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   203 |   collect_register (regcache, AARCH64_SP_REGNUM, &regset->sp);
|       |                                                         ^~
| linux-aarch64-low.cc:198:10: note: forward declaration of 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   198 |   struct user_pt_regs *regset = (struct user_pt_regs *) buf;
|       |          ^~~~~~~~~~~~
| linux-aarch64-low.cc:204:57: error: invalid use of incomplete type 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   204 |   collect_register (regcache, AARCH64_PC_REGNUM, &regset->pc);
|       |                                                         ^~
| linux-aarch64-low.cc:198:10: note: forward declaration of 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   198 |   struct user_pt_regs *regset = (struct user_pt_regs *) buf;
|       |          ^~~~~~~~~~~~
| linux-aarch64-low.cc:205:59: error: invalid use of incomplete type 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   205 |   collect_register (regcache, AARCH64_CPSR_REGNUM, &regset->pstate);
|       |                                                           ^~
| linux-aarch64-low.cc:198:10: note: forward declaration of 'struct aarch64_fill_gregset(regcache*, void*)::user_pt_regs'
|   198 |   struct user_pt_regs *regset = (struct user_pt_regs *) buf;
|       |          ^~~~~~~~~~~~

I'm pretty sure that there is a misconfiguration on my side but I try to look where the "struct _aarch64_ctx" is defined and found that it is defined in linux header there but I don't see any include of this in the crash/gdb code so I'm puzzled.

Can somebody help me to know where to look for ? Thanks

fmartinsons commented 10 months ago

Hello, I finally found what was the error and it was indeed a configuration error. By looking at configure part of gdb inside crash, I saw:

checking build system type... x86_64-pc-linux-gnu
checking host system type... aarch64-tapos-linux-gnu
checking target system type... aarch64-tapos-linux-gnu

The host system was wrong and should be the crosstool for my sdk.

It was a mistake and I was not using GDB_TARGET GDB_HOST and --target correctly during make call.

Sorry for the noise. Closing the issue.

HeBea commented 7 months ago

Hi, Martinsons. I met the same inssur when I built gdb-server for my arm device. My compile commands are:

./configure --build=x86_64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
make all-gdbserver

As the commands showing, I try to build arm program on my PC and aarch64-linux-gnu is cross-tool. What do you mean 'The host system was wrong' ? Should I change --host and target?

fmartinsons commented 7 months ago

You don't have the same configuration as I had, my use case was to build an SDK, so my build toolchain (the toolchain install on my host) is different that the host one (which is the SDK build chain, in my case, another x86 flavor) and different to the target one (arm64 in my case) My initial issue was that the host was equal to the target which doesn't fit.

It seems you want a normal cross compilation (not cross canadian) so host=target, I don't know why you experienced this error, maybe your toolchain is misconfigured ?

HeBea commented 7 months ago

Thank you so much for your reply. In your case, you do a cross Canadian compilation, so --host should be x86_64-pc-linux-gnu(which is another system) not arm64, is it right?

According to my understanding of this issue, if build system is equal to host system, everything is ok,. But if build system(x86) ≠ host system(arm64), build system does not have those .h files(which define _aarch64_ctx).

fmartinsons commented 7 months ago

Yes, like you said, in my case, the correct configuration for building crash in a x86 sdk to analyze aarm64 bin is (tapos is my distribution code name):

checking build system type... x86_64-tapossdk-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... aarch64-tapos-linux-gnu

I'm sorry I cannot help you more like that, you may want to try to look at the compile/configure log and the different toolchain configuration.

For info, for a cross compile crash (not canadian), I have these in the log of compilation:

checking build system type... x86_64-pc-linux-gnu
checking host system type... aarch64-tapos-linux-gnu
checking target system type... aarch64-tapos-linux-gnu
HeBea commented 7 months ago

Thank you again. I think I find the key of this issue. The structure _aarch64_ctx is defined at 'path/to/gcc/aarch64-none-linux-gnu/libc/usr/include/asm/sigcontext.h'.

Gdb build script do not include this path and my cross compiler default search path(use 'echo 'main(){}' | aarch64-none-linux-gnu-gcc -E -v -' to see the path) is: ` ...

include "..." search starts here:

include <...> search starts here:

path/to/gcc/bin/../lib/gcc/aarch64-none-linux-gnu/10.3.1/include path/to/gcc/bin/../lib/gcc/aarch64-none-linux-gnu/10.3.1/include-fixed path/to/gcc/bin/../lib/gcc/aarch64-none-linux-gnu/10.3.1/../../../../aarch64-none-linux-gnu/include path/to/gcc/bin/../aarch64-none-linux-gnu/libc/usr/include ... `

Before building the gdb-server, I run this command to add the path and this error does not occur again. export CPLUS_INCLUDE_PATH=path/to/gcc/aarch64-none-linux-gnu/libc/usr/include/asm

fmartinsons commented 7 months ago

Glad you manage to sort this out, but It seems a little strange for you to have to do that. path/to/gcc/aarch64-none-linux-gnu/libc/usr/include/asm should be part of the arm toolchain config, you should not have to explicitely set it. Again, I'm suggest you to look for you different toolchain configuration and env variables, maybe the compiler option --sysroot is at the wrong place.

Anyway, in the end, if it does work for you, fine (I'm no expert in gdb/crash cross compilation, by the way, just giving my feelings here).

Have a nice day