I created the following test program in file backtrace.c
:
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
int main(int argc,char**argv){
void *stack[128];
int frameCount = backtrace(stack, sizeof stack);
char **symbols = backtrace_symbols(stack, frameCount);
printf("Backtrace: %d frames\n", frameCount);
for (int i = 0; i < frameCount; i ) {
printf("\t%s\n", symbols[i]);
}
free(symbols);
return 0;
}
Then I use the following script to test my program in i386,amd64,arm32v5,arm64v8 and s390x Debian Linux Docker containers:
for arch in i386 amd64 arm32v5 arm32v7 arm64v8 s390x; do
echo "=== $arch ==="
docker run -w /work -v $(pwd -P):/work $arch/debian /bin/bash -c "apt-get update && apt-get install -y gcc && gcc -funwind-tables -o backtrace backtrace.c && ./backtrace"
done
(Note -funwind-tables
is needed to get any frames on arm32v5. On other architectures, it isn't required but causes no harm.)
The host CPU architecture is amd64 (actually Docker Desktop for Mac 2.1.0.1) so the arm* and s390x containers are being executed by QEMU user emulation via binfmt_misc.
Anyway, I do the same thing on ppc64le, it segfaults:
arch=ppc64le
docker run -w /work -v $(pwd -P):/work $arch/debian /bin/bash -c "apt-get update && apt-get install -y gcc && gcc -funwind-tables -o backtrace backtrace.c && ./backtrace"
Why is it not working on ppc64le? Is it something about the gcc flags? (I tried with and without -funwind-tables
, either way it segfaults. Adding -fasynchronous-unwind-tables
makes no difference either.)
CodePudding user response:
Agree about this being a qemu bug.
It works as follows on bare metal:
danielgb@talos2:~$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
danielgb@talos2:~$ uname -a
Linux talos2 5.3.0-19-generic #20~18.04.2-Ubuntu SMP Tue Oct 22 18:08:01 UTC 2019 ppc64le ppc64le ppc64le GNU/Linux
danielgb@talos2:~$ gcc -funwind-tables -o backtrace backtrace.c
danielgb@talos2:~$ ./backtrace
Backtrace: 3 frames
./backtrace( 0x9c0) [0x84a0de609c0]
/lib/powerpc64le-linux-gnu/libc.so.6( 0x2441c) [0x7ed19cfa441c]
/lib/powerpc64le-linux-gnu/libc.so.6(__libc_start_main 0xb8) [0x7ed19cfa4618]