Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv-toolsのビルドが失敗する #6

Closed
ohno418 opened this issue Jul 19, 2022 · 4 comments
Closed

riscv-toolsのビルドが失敗する #6

ohno418 opened this issue Jul 19, 2022 · 4 comments

Comments

@ohno418
Copy link

ohno418 commented Jul 19, 2022

タイトルの通り、riscv-toolsのビルドが失敗します。

riscv-toolsのGitHubリポジトリのissueにもビルドの失敗報告がいくつかあり、またそうしたissueに対してコメントされている通り、このリポジトリはすでにメンテナンスされてなさそうです。

再現環境はWSLでないLinux上なので、もしかしたらWSLではビルドできるのかも。
Spike, riscv-pkを個別にビルドしたら動いたので、もし同様にriscv-toolsがビルドできない人がいましたら同じようにすれば問題を回避できるかと思います。


一応ログを以下に。

$ export RISCV=${HOME}/riscv-tools-test/
$ ./build.sh
Starting RISC-V Toolchain build process

autoreconf: error: configure.ac: AC_INIT not found; not an autoconf script?
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:42: installing 'build-aux/ar-lib'
configure.ac:37: installing 'build-aux/compile'
configure.ac:28: installing 'build-aux/config.guess'
configure.ac:28: installing 'build-aux/config.sub'
configure.ac:30: installing 'build-aux/install-sh'
configure.ac:30: installing 'build-aux/missing'
Makefile.am: installing './INSTALL'
libjaylink/Makefile.am: installing 'build-aux/depcomp'
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
libtoolize: 'AC_PROG_RANLIB' is rendered obsolete by 'LT_INIT'
configure.ac:25: warning: The macro `AC_LANG_C' is obsolete.
configure.ac:25: You should run autoupdate.
./lib/autoconf/c.m4:72: AC_LANG_C is expanded from...
configure.ac:25: the top level
configure.ac:27: warning: The macro `AC_PROG_CC_C99' is obsolete.
configure.ac:27: You should run autoupdate.
./lib/autoconf/c.m4:1659: AC_PROG_CC_C99 is expanded from...
configure.ac:27: the top level
configure.ac:37: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.ac:37: You should run autoupdate.
aclocal.m4:122: AC_PROG_LIBTOOL is expanded from...
configure.ac:37: the top level
configure.ac:81: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:81: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:81: the top level
configure.ac:26: installing './compile'
configure.ac:37: installing './config.guess'
configure.ac:37: installing './config.sub'
configure.ac:16: installing './install-sh'
configure.ac:16: installing './missing'
Makefile.am:46: warning: wildcard $(srcdir: non-POSIX variable name
Makefile.am:46: (probably a GNU make extension)
Makefile.am: installing './INSTALL'
Makefile.am: installing './depcomp'
Makefile.am:23: installing './mdate-sh'
Makefile.am:23: installing './texinfo.tex'
@msyksphinz-self
Copy link
Owner

ご指摘ありがとうございます。出版前の確認が不足しており申し訳ありません。
正誤表に追加いたしました。

@hirooih
Copy link

hirooih commented Sep 4, 2022

closeされている issueですが、補足させていただきます。 (書き始めたら長くなってしまいました。新しい issue をopenしたほうがよければ、連絡ください。)

Summary:

riscv-toolsのGitHubリポジトリのissueにもビルドの失敗報告がいくつかあり、またそうしたissueに対して riscv-software-src/riscv-tools#351 (comment) 通り、このリポジトリはすでにメンテナンスされてなさそうです。

この通りの様ですが、Ubuntu 20.04.5 LTS では、README.md に従ってinstallすることで、(最新版のriscv-testsでも解決していない) 下記の一点を除いてbuildできました。

$ git clone https://github.com/riscv/riscv-gnu-toolchain
$ cd riscv-gnu-toolchain
$ ./configure --prefix=/opt/riscv
$ make

$ git clone https://github.com/riscv-software-src/riscv-tools.git
$ cd riscv-tools
$ git submodule update --init --recursive
$ export RISCV=/opt/riscv
$ ./build.sh

P.71では git submodule ... の変わりに git clone commandに --recurse-submodules optonを使用しています。 git submodule commandでいくつかのfileが更新されたので、この差が要因かと思われます。

一点問題があったのは riscv-software-src/riscv-tests#286 で報告されている件です。
以下のように riscv-tests/isa/Makefile に-fcommon optionの追加が必要です。

diff --git a/isa/Makefile b/isa/Makefile
index 4e1ba20..ee89ede 100644
--- a/isa/Makefile
+++ b/isa/Makefile
@@ -33,7 +33,7 @@ default: all
 
 RISCV_PREFIX ?= riscv$(XLEN)-unknown-elf-
 RISCV_GCC ?= $(RISCV_PREFIX)gcc
-RISCV_GCC_OPTS ?= -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles
+RISCV_GCC_OPTS ?= -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -fcommon
 RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.text.init --section=.data
 RISCV_SIM ?= spike

Andrew Watermanが

Recent versions of GCC default to -fno-common, causing these multiple-definition errors. ... This is now fixed on master.

と答えています。 "This is now fixed on master." とありますが、最新版の Makefile にも -fcommon は追加されていないので、 現在の riscv-gnu-toolchain の gcc よりも新しい gcc でdefaultが -fcommon に戻っているという意味だと思われます。


もう一点、私が躓いたのは P.318 のPICの例の実行で -shared not supported というerrorとなることです。
riscv-gnu-toolchain が古いためかと思い、今回 git pullしてbuildし直しました。ただerrorはなくなりませんでした。
よくよく読むと、これまでの例が riscv64-unkown-elf-gcc を使用しているのに対して、ここでは riscv64-unkown-linux-gnu-gcc を使用しています。

P.70の手順では、riscv64-unkown-linux-gnu-gcc はinstallされません。P.70の riscv-gnu-toolchain のinstallで make でnewlib版のbuildを行ったあと、 make linux でLinux libc版のbuildも行う必要があります。
https://github.com/riscv-collab/riscv-gnu-toolchain の README.md の説明も少し分かりづらく、両方必要だと理解するのに少し時間がかかりました。

Installation (Newlib/Linux multilib)
...
And then either make, make linux or make musl for the Newlib, Linux glibc-based or Linux musl libc-based cross-compiler, respectively.

私はconfigure に --enable-multilib を加えれば、いずれかで良いと解釈してしまいました。

P.70 and/or P.318に一言補足があると良いと思います。

以上。
素晴らしい書籍をありがとうございます。

@msyksphinz-self
Copy link
Owner

補足ありがとうございます。P.318のほうは確認が不足しており申し訳ありません。
そうでした、riscv64-unknown-linux-gnu-gccを使えばLinux等が使うPLTを手っ取り早く出せるというわけで無意識にそちらを使っていました。正誤表に追加します。

@hirooih
Copy link

hirooih commented Sep 11, 2022

@msyksphinz-self
正誤表の更新ありがとうございました。
おかげさまで、
https://github.com/riscv-collab/riscv-gnu-toolchain でbuild済みのものがdownloadできることを知ることができました。
これからをこれを使うことにします。

現在の riscv-gnu-toolchain の gcc よりも新しい gcc でdefaultが -fcommon に戻っているという意味だと思われます。

これは誤りだったので訂正します。 -common, -no-commonの意味を確認しました。

https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85678

同じ名前でstatic, externなどが指定されず、かつ初期値が指定されていない変数が複数のfileで定義されていなかった場合、言語仕様ではerrorとなるべきなのに、gccでは昔から defaultではerrorとしていなかった。 -fno-commonを指定するとerrorとなるという仕様となっていた。
比較的最近になって gcc も LLVM も -fno-common をdefaultとしたそうです。

2重定義になっているところを修正したと考えるのが、正しそうです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants