#10863 closed bug (invalid)

"hello world" produces illegal instruction error

Reported by: Ansible Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.2
Keywords: Cc: erikd
Operating System: Linux Architecture: arm
Type of failure: Runtime crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I saw there was a new debian experimental package for 7.10.2, so I installed it on my raspberry pi 2, an arm v7 computer running debian jessie. Someone on twitter had some success with the package, but it didn't work for me.

https://packages.debian.org/experimental/armhf/ghc/download

See the attached file for versions of things, and test results.

This is similar to another attempt where I installed the 7.10.2 binary available from the ghc website.

Attachments (8)

install_log (3.3 KB) - added by Ansible 22 months ago.
install and test of ghc 7.10.2
cpuinfo (1.2 KB) - added by Ansible 22 months ago.
/proc/cpuinfo
ghcinfo (2.2 KB) - added by Ansible 22 months ago.
ghc --info
gdb_output (2.1 KB) - added by Ansible 22 months ago.
gdb output
gcc_test (267 bytes) - added by Ansible 22 months ago.
test of gcc - hello world C prog
ghc-v (6.7 KB) - added by Ansible 22 months ago.
"ghc -v hello.hs -debug"
break_on_main (1.2 KB) - added by Ansible 22 months ago.
break on main in gdb.
ghc-v-fforce-recomp (5.9 KB) - added by Ansible 22 months ago.
output from: "ghc -v -fforce-recomp hello.hs"

Download all attachments as: .zip

Change History (32)

Changed 22 months ago by Ansible

Attachment: install_log added

install and test of ghc 7.10.2

Changed 22 months ago by Ansible

Attachment: cpuinfo added

/proc/cpuinfo

Changed 22 months ago by Ansible

Attachment: ghcinfo added

ghc --info

comment:1 Changed 22 months ago by rwbarton

Thanks for the report. Could you also try running the crashing executable under gdb and attach the output of bt, disas and info reg?

comment:2 Changed 22 months ago by Ansible

Ok here you go. I build it like so:

ghc hello.hs -debug

And the gdb output I'm attaching as a file.

Last edited 22 months ago by Ansible (previous) (diff)

Changed 22 months ago by Ansible

Attachment: gdb_output added

gdb output

comment:3 Changed 22 months ago by rwbarton

Ok so main is Thumb code (mixed 2- and 4-byte instructions) but it was called as ARM mode. The evidence is that the T bit (bit 5, 0x00000200) in the CPSR is not set, and we are in the middle of a Thumb instruction main+16, presumably by managing to stumble through four 32-bit ARM instructions.

I don't understand why main is Thumb code though. main is built from a C file with gcc when the executable is built. Could you attach the output of building your program with ghc -v? I assume gcc is not being invoked with -mthumb...

Maybe a dumb question, but can you compile and run a simple C hello world program? If you run it in gdb and break on main, is it ARM code or Thumb code?

Changed 22 months ago by Ansible

Attachment: gcc_test added

test of gcc - hello world C prog

Changed 22 months ago by Ansible

Attachment: ghc-v added

"ghc -v hello.hs -debug"

comment:4 Changed 22 months ago by Ansible

Ok I compiled a 'hello world' program in gdb and broke on main and did 'disas'. Whether these are ARM instructions or not I have no idea. Also added other attachments for ghc -v and 'hello world' output.

comment:5 Changed 22 months ago by rwbarton

Ok, so the C main is clearly Thumb code too. Can you check info reg? And also use -fforce-recomp for ghc. Thanks!

Changed 22 months ago by Ansible

Attachment: break_on_main added

break on main in gdb.

comment:6 Changed 22 months ago by Ansible

Ok appended the info_reg section onto the existing break_on_main file. I gave it a shot with "ghc -fforce-recomp hello.hs" but the resulting executable still crashes.

comment:7 Changed 22 months ago by rwbarton

Sorry, I meant ghc -v -fforce-recomp. Otherwise it doesn't really rebuild anything, and the -v output is not helpful.

comment:8 Changed 22 months ago by rwbarton

Ok so here CPSR is 0x60000030 which has the T bit set (0x20). So the CPU knows it is executing Thumb instructions.

I don't understand what is different about what we are doing though... I mean we are presumably linking against the same libc that contains the call to main.

Changed 22 months ago by Ansible

Attachment: ghc-v-fforce-recomp added

output from: "ghc -v -fforce-recomp hello.hs"

comment:9 Changed 22 months ago by erikd

Cc: erikd added

comment:10 Changed 22 months ago by rwbarton

Since I don't have any other good ideas, does your C program also work if you build it with -fuse-ld=gold?

comment:11 Changed 22 months ago by Ansible

yep, it does work with that option.

comment:12 Changed 22 months ago by erikd

I grabbed the same compiler from http://ftp.us.debian.org/debian/pool/main/g/ghc/ghc_7.10.2-2_armhf.deb and compiled up a "hello world" program. The compiler worked fine as did the resulting executable.

I inspected the file /usr/lib/ghc/settings and found:

 ("C compiler link flags", " -fuse-ld=gold -Wl,-z,noexecstack"),
 ("ld command", "/usr/bin/ld.gold"),
 ("LLVM llc command", "llc-3.5"),
 ("LLVM opt command", "opt-3.5")

which is exactly as I expected.

Here are the versions of llvm/binutils/gcc that I have on my machine:

llvm-3.5      1:3.5.2-1  armhf      Modular compiler and toolchain technologies
binutils      2.25.1-1   armhf      GNU assembler, linker and binary utilities
gcc           4:4.9.2-4  armhf      GNU C compiler

@Ansible, please check your versions of the above.

comment:13 Changed 22 months ago by Ansible

Ok here's some version info from my machine. Check your reddit pms, rwbarton.

 ("C compiler link flags", " -fuse-ld=gold -Wl,-z,noexecstack"),
 ("ld command", "/usr/bin/ld.gold"),
 ("LLVM llc command", "llc-3.5"),
 ("LLVM opt command", "opt-3.5")
ii  llvm-3.5                          1:3.5-10              armhf                 Modular compiler and toolchain technologies
ii  llvm-3.5-dev                      1:3.5-10              armhf                 Modular compiler and toolchain technologies, libraries and headers
ii  llvm-3.5-runtime                  1:3.5-10              armhf                 Modular compiler and toolchain technologies, IR interpreter


ii  gcc                               4:4.9.2-2             armhf                 GNU C compiler

ii  binutils                          2.25-5                armhf                 GNU assembler, linker and binary utilities

comment:14 Changed 22 months ago by erikd

I suspect binutils. Is it possible to upgrade just that, possibly to the version that is currently in debian testing?

comment:15 Changed 22 months ago by Ansible

I'll all for it, but I don't spend too much time on debian. Do you know the command sequence for installing just binutils from testing?

comment:16 Changed 22 months ago by erikd

Simple, go to https://www.debian.org/distrib/packages , scroll down to the section titled "Search package directories", enter the name "binutils" and choose the "testing" distribution which will give you a link to https://packages.debian.org/stretch/binutils , then go to the bottom of the page where it says "Download binutils", and click on "armhf" which leads you to https://packages.debian.org/stretch/armhf/binutils/download which gives a number of links to the binary package.

See, simple (not) when you know how :-).

comment:17 Changed 22 months ago by Ansible

Ok I installed the binutils, but no dice it seems...

bburdette@jessie-rpi:~/code/ghcbug$ sudo dpkg -i binutils_2.25.1-1_armhf.deb 
[sudo] password for bburdette: 
(Reading database ... 38788 files and directories currently installed.)
Preparing to unpack binutils_2.25.1-1_armhf.deb ...
Unpacking binutils (2.25.1-1) over (2.25-5) ...
Setting up binutils (2.25.1-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for libc-bin (2.19-18) ...
bburdette@jessie-rpi:~/code/ghcbug$ ls
a.out                        core   hello     hello.hs  install_log
binutils_2.25.1-1_armhf.deb  frout  hello.hi  hello.o   main.cpp
bburdette@jessie-rpi:~/code/ghcbug$ ghc -fforce-recomp hello.hs
[1 of 1] Compiling Main             ( hello.hs, hello.o )
Linking hello ...
bburdette@jessie-rpi:~/code/ghcbug$ ./hello  
Illegal instruction
bburdette@jessie-rpi:~/code/ghcbug$ 

comment:18 Changed 22 months ago by erikd

Sorry, I mis-read the information you had provided. I thought it was the compiler that was crashing, not the compiled executable.

Since it is not the compiler and it *is* the executable, I am 100% certain that the version of the llvm tools you have contains a bug (discussed in ticket #9920). The fix for that LLVM bug is to install llvm-3.5.2 from debian testing.

You should list all the llvm-3.5 packages you have installed using dpkg -l | grep llvm-3.5 and then replace them with the relevant replacements here http://ftp.us.debian.org/debian/pool/main/l/llvm-toolchain-3.5/ whose package names match *3.5.2-2_armhf.deb.

comment:19 Changed 22 months ago by Ansible

Ok, running into dependency hell trying to install these packages manually. I'm going to try just changing over to debian testing and then see if it works. Will post back with results.

comment:20 Changed 22 months ago by erikd

Actually, I suspect that those packages alone will not trigger dependency hell, but Debian testing may be safer.

Last edited 22 months ago by erikd (previous) (diff)

comment:21 Changed 22 months ago by Ansible

Moved over to testing, but still getting the SIGILL, unfortunately. I did install ghc while it had the 3.5.2-1 llvm on there, but then upgraded to 3.5.2-2

bburdette@jessie-rpi:~/code/ghcbug$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.2
bburdette@jessie-rpi:~/code/ghcbug$ ghc hello.hs
bburdette@jessie-rpi:~/code/ghcbug$ ./hello 
Illegal instruction
bburdette@jessie-rpi:~/code/ghcbug$ ls
a.out                        hello.o
binutils_2.25.1-1_armhf.deb  install_log
core                         libllvm3.5v5_3.5.2-2_armhf.deb
download                     libstdc++6_5.2.1-16_armhf.deb
download.1                   libtinfo5_6.0+20150810-1_armhf.deb
frout                        llvm-3.5-dev_3.5.2-2_armhf.deb
hello                        llvm-3.5-runtime_3.5.2-2_armhf.deb
hello.hi                     llvm-3.5_3.5.2-2_armhf.deb
hello.hs                     main.cpp
bburdette@jessie-rpi:~/code/ghcbug$ rm hello
bburdette@jessie-rpi:~/code/ghcbug$ ghc hello.hs 
Linking hello ...
bburdette@jessie-rpi:~/code/ghcbug$ ./hello 
Illegal instruction
bburdette@jessie-rpi:~/code/ghcbug$ dpkg -l | grep llvm-3.5
ii  llvm-3.5                           1:3.5.2-2                       armhf        Modular compiler and toolchain technologies
ii  llvm-3.5-dev                       1:3.5.2-2                       armhf        Modular compiler and toolchain technologies, libraries and headers
ii  llvm-3.5-runtime                   1:3.5.2-2                       armhf        Modular compiler and toolchain technologies, IR interpreter
bburdette@jessie-rpi:~/code/ghcbug$ 

comment:22 Changed 22 months ago by erikd

This:

bburdette@jessie-rpi:~/code/ghcbug$ ghc hello.hs 
Linking hello ...

suggests that it the executable wasn't compiled, just linked (because the object file was already there).

Use ghc -fforce-recomp hello.hs -o hello.

comment:23 Changed 22 months ago by Ansible

that worked! thanks for the help.

seems like it would be worth noting that an exact version of llvm is required on the download page, which only mentions llvm 3.5 from jessie, which is 3.5-10 and not 3.5.2-2. Should that be filed as a bug?

https://www.haskell.org/ghc/download_ghc_7_10_2#linux_armv7

Last edited 22 months ago by Ansible (previous) (diff)

comment:24 Changed 22 months ago by erikd

Resolution: invalid
Status: newclosed

Great. Got this one figured out.

I'll close this but I'll also see if I can get that download page updated.

Note: See TracTickets for help on using tickets.