Broken executable when compiling IR/bitcode with llc
Good day
I am running into problems when I try to compile my llvm bitcode on Alpine. I was able to reproduce the problem with a simple C program which I quoted below. It happens on a Raspberry PI (32bit) (Alpine 3.11) as well as an Intel machine (32bit)(Alpine 3.7). Unfortunately I don't have any other Alpine machines to test on.
I am not getting the issue on the same Rasberry PI with Raspbian 10(buster) (32bit). My laptop (Unbuntu 18.04) and Desktop (OpenSuse Leap) also work correctly (64bit).
However, it works correctly on Alpine when I run it with 'lli main.ll'.
cat main.c
#include <stdio.h>
int main(int argc,char **argv)
{
puts("Hello world");
return 0;
}
clang -S -emit-llvm main.c
cat main.ll
cat main.ll
; ModuleID = 'main.c'
source_filename = "main.c"
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv6-alpine-linux-musleabihf"
@.str = private unnamed_addr constant [12 x i8] c"Hello world\00", align 1
; Function Attrs: noinline nounwind optnone sspstrong
define dso_local i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 4
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 4
%6 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0))
ret i32 0
}
declare i32 @puts(i8*) #1
attributes #0 = { noinline nounwind optnone sspstrong "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="arm1136jf-s" "target-features"="+armv6,+d32,+dsp,+fp64,+fpregs,+strict-align,+vfp2,+vfp2d16,+vfp2d16sp,+vfp2sp,-thumb-mode" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="arm1136jf-s" "target-features"="+armv6,+d32,+dsp,+fp64,+fpregs,+strict-align,+vfp2,+vfp2d16,+vfp2d16sp,+vfp2sp,-thumb-mode" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, !"min_enum_size", i32 4}
!2 = !{i32 7, !"PIC Level", i32 2}
!3 = !{i32 7, !"PIE Level", i32 2}
!4 = !{!"Alpine clang version 9.0.0 (https://git.alpinelinux.org/aports dd5c20fd574cd668a3f071fd43cb19e271c308d2) (based on LLVM 9.0.0)"}
llc --filetype=obj main.ll
gcc main.o -o main
./main
Segmentation fault
clang main.o -o main
./main
Segmentation fault
lli main.ll
Hello world