FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

M1 Macでriscv-gnu-toolchainのビルド

M1 Mac上にRISC-Vのツールチェインを構築したくて色々試行錯誤している。

git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git -b 2022.05.15
cd riscv-gnu-toolchain
mkdir build
export RISCV=${インストールしたいディレクトリ}
../configure --prefix=${インストールしたいディレクトリ}
make -j10
Undefined symbols for architecture arm64:
  "_host_hooks", referenced from:
      c_common_no_more_pch() in c-pch.o
      toplev::main(int, char**) in libbackend.a(toplev.o)
      gt_pch_save(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_restore(__sFILE*) in libbackend.a(ggc-common.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ここを参考にした。

github.com

以下の変更を加えた。

diff --git a/gcc/config.host b/gcc/config.host
index 0a02c33cc80..fd071000eac 100644
--- a/gcc/config.host
+++ b/gcc/config.host
@@ -93,8 +93,8 @@ esac
 case ${host} in
   *-darwin*)
     # Generic darwin host support.
-    out_host_hook_obj=host-darwin.o
-    host_xmake_file="${host_xmake_file} x-darwin"
+    # out_host_hook_obj=host-darwin.o
+    # host_xmake_file="${host_xmake_file} x-darwin"
     ;;
 esac

次のエラーは、/Library/Developer/CommandLineTools/usr/bin/gm4: unrecognized option--gnu'だ。 m4をアップデートしてみよう。/usr/local/bin/m4`に最新版をインストールして、これを置き換えてみる。

sudo mv gm4 gm4.back
sudo ln -s /usr/local/bin/m4 gm4

次のエラーはyaccで出た。

plural.c:184:5: error: conflicting types for 'libintl_gettextparse'
int __gettextparse (void);
    ^

以下のスレッドを参考し、パッチを当ててリビルドしてみた。

lists.gnu.org

  • riscv-gnu-toolchain/riscv-gdb/intl
diff --git a/intl/plural.y b/intl/plural.y
index 3f75cf3dbb..673e73f174 100644
--- a/intl/plural.y
+++ b/intl/plural.y
@@ -43,6 +43,7 @@
 #define YYLEX_PARAM    &((struct parse_args *) arg)->cp
 #define YYPARSE_PARAM  arg
 %}
+%param {void *arg}
 %pure_parser
 %expect 7
 
@@ -67,7 +68,8 @@ static inline struct expression *new_exp_3 PARAMS ((enum operator op,
                                                   struct expression *tbranch,
                                                   struct expression *fbranch));
 static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
-static void yyerror PARAMS ((const char *str));
+static void yyerror PARAMS ((void *arg, const char *str));
+
 
 /* Allocation of expressions.  */
 
@@ -402,7 +404,8 @@ yylex (lval, pexp)
 
 
 static void
-yyerror (str)
+yyerror (arg, str)
+     void *arg;
      const char *str;
 {
   /* Do nothing.  We don't print error messages here.  */

とりあえずこれでビルド完了した!

 ./riscv64-unknown-elf-gcc --version
riscv64-unknown-elf-gcc (g5964b5cd727-dirty) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.