Bug 191630 - emulators/dosbox inline assembly requires more registers with clang
Summary: emulators/dosbox inline assembly requires more registers with clang
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: i386 Any
: --- Affects Many People
Assignee: Rodrigo Osorio
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-05 14:01 UTC by mikhail.rokhin
Modified: 2014-12-31 14:54 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mikhail.rokhin 2014-07-05 14:01:53 UTC
uname -a
FreeBSD localhost 11.0-CURRENT FreeBSD 11.0-CURRENT #5 r268088: Tue Jul  1 23:31:59 MSK 2014     root@localhost:/usr/obj/usr/src/sys/GENERIC  i386

FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: i386-unknown-freebsd11.0
Thread model: posix


--- core_dyn_x86.o ---
In file included from core_dyn_x86.cpp:185:
./core_dyn_x86/risc_x86.h:134:3: error: inline assembly requires more registers than available
                "pushl %%ebp                                            \n"
                ^
4 warnings and 1 error generated.
*** [core_dyn_x86.o] Error code 1

make[6]: stopped in /usr/ports/emulators/dosbox/work/dosbox-0.74/src/cpu
1 error

---
gcc47 -v
Using built-in specs.
COLLECT_GCC=gcc47
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc47/gcc/i386-portbld-freebsd11.0/4.7.3/lto-wrapper
Target: i386-portbld-freebsd11.0
Configured with: ./../gcc-4.7.3/configure --disable-bootstrap --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc47 --libexecdir=/usr/local/libexec/gcc47 --program-suffix=47 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc47/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc47 --build=i386-portbld-freebsd11.0
Thread model: posix
gcc version 4.7.3 (FreeBSD Ports Collection) 

build fine.

It's well-known registers problem of clang.
Comment 1 mikhail.rokhin 2014-07-05 18:19:24 UTC
Other clangs from ports work fine:

clang32 -v
clang version 3.2 (tags/RELEASE_32/final)
Target: i386-portbld-freebsd11.0
Thread model: posix


clang33 -v
clang version 3.3 (tags/RELEASE_33/final)
Target: i386-portbld-freebsd11.0
Thread model: posix

but failing
clang34 -v
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd11.0
Thread model: posix
Selected GCC installation:
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2014-07-05 23:27:07 UTC
Notify maintainer.
Comment 3 Tom Carrick 2014-07-06 08:51:14 UTC
Hello, maintainer here.

I'm aware of the issue and have been working with the devs for a fix. I have a potential patch. It builds, but so far I've been unable to test that it doesn't break something. I'll see if I can test it today.
Comment 4 John Marino freebsd_committer freebsd_triage 2014-07-26 07:41:33 UTC
Tom, do you have an update yet?
Comment 5 Tom Carrick 2014-08-02 17:57:35 UTC
Sorry for the delay, have some major issues with my machine, so I can't make a patch. I can give instructions, however:

src/cpu/core_dyn_x86/risc_x86.h

Change line 141 from:
:"r" (tempflags),"r" (code)

to:
:"a" (tempflags),"a" (code)


This should at least fix compilation, but I'm unable to test if it breaks anything. If someone could make this into a patch and more importantly test that it runs and test a few games with it, that would be great.
Comment 6 Rodrigo Osorio freebsd_committer freebsd_triage 2014-12-11 10:42:15 UTC
cherry picking
Comment 7 Alexey Dokuchaev freebsd_committer freebsd_triage 2014-12-16 03:24:14 UTC
(In reply to Tom Carrick from comment #5)
> Sorry for the delay, have some major issues with my machine, so I can't make
> a patch. I can give instructions, however: [...]

This patch helps the build on 11-CURRENT to succeed, but resulting package apparently has some problem.  For example, when trying to run Borland C++ 3.1 suite (both IDE, bc.exe, or just the compiler, bcc.exe) results in DOSBox crash with the following message:

  DOSBox switched to max cycles, because of the setting: cycles=auto.
  If the game runs too fast try a fixed cycles amount in DOSBox's options.
  Trace/BPT trap(core dumped)

The build is broken with USE_GCC as well.  Thus, it looks like DOSBox is severely broken on -CURRENT right now.

Building it on 8.4-STABLE works flawlessly and I am able to run Borland C++ 3.1 just fine.
Comment 8 Rodrigo Osorio freebsd_committer freebsd_triage 2014-12-16 08:59:49 UTC
It's time for a deep investigation. But sorry if I have to delay it for a few days.
Comment 9 Willem Jan Palenstijn 2014-12-17 22:58:50 UTC
There appears to have been some communication error. The correct line is

:"a" (tempflags),"r" (code)

I'm not a FreeBSD user, but I've quickly tested this in one of the available FreeBSD 32-bit VM images with clang 3.4.1, and it appears to fix the compilation error.
Comment 10 Alexey Dokuchaev freebsd_committer freebsd_triage 2014-12-18 08:07:01 UTC
(In reply to Willem Jan Palenstijn from comment #9)
> There appears to have been some communication error. The correct line is
> 
> :"a" (tempflags),"r" (code)

I confirm that with this change, I can build DOSBox with Clang on FreeBSD/i386 11-CURRENT and successfully run Borland C++ 3.1 IDE, thanks!

However, it still does not build with USE_GCC (for an unrelated reason though).
Comment 11 Rodrigo Osorio freebsd_committer freebsd_triage 2014-12-31 13:03:25 UTC
USE_GCC problem aside, we ca
Comment 12 Rodrigo Osorio freebsd_committer freebsd_triage 2014-12-31 13:06:36 UTC
If it works with Borland, USE_GCC problem aside, I think we can commit the fix and close the PR.
Comment 13 commit-hook freebsd_committer freebsd_triage 2014-12-31 14:37:14 UTC
A commit references this bug:

Author: rodrigo
Date: Wed Dec 31 14:36:58 UTC 2014
New revision: 375888
URL: https://svnweb.freebsd.org/changeset/ports/375888

Log:
  Fix build and running issues with clang on 11 and beyond
  Bump portrevision

  PR:		191630
  Submitted by:	knyght@gmail.com

Changes:
  head/emulators/dosbox/Makefile
  head/emulators/dosbox/files/patch-src_cpu_core_dyn_x86_risc_x86.h
Comment 14 Rodrigo Osorio freebsd_committer freebsd_triage 2014-12-31 14:54:29 UTC
committed, thanks