我正在使用 crosstool-ng 1.24.0 构建 gccgo。编译非常简单的 main.go 时出现链接器错误。知道如何解决这个问题吗?任何指向成功构建 gogcc 的指针,即使对于可以轻松验证的不同流行目标也是如此?
主机是 ubuntu 18.04 和 gcc 7.3.0。crosstool-ng 目标是 x86_64-ubuntu16.04-linux-gnu,它应该使用 glibc 2.23 创建 gcc 8.3.0。
以下是缺少的符号:
undefined reference to `__morestack_block_signals'
undefined reference to `__generic_morestack'
undefined reference to `__morestack_unblock_signals'
undefined reference to `__morestack_block_signals'
undefined reference to `__generic_releasestack'
undefined reference to `__generic_findstack'
undefined reference to `__generic_morestack_set_initial_sp'
undefined reference to `__morestack_load_mmap'
构建步骤的更多细节:
[1] 查看 crosstool-ng。它的主人现在在 1.24.0 上。
[2] 运行这些命令来构建一个普通的 c 和 c++ 工具链:
./bootstrap
./configure --enable-local
make
./ct-ng show-x86_64-ubuntu16.04-linux-gnu
./ct-ng x86_64-ubuntu16.04-linux-gnu
./ct-ng build
[3] 通过编译一个 hello-world 程序并运行来验证 gcc 是否工作。
[4] 编辑脚本以启用 go。补丁看起来像:
diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh
@@ -597,7 +597,7 @@ do_gcc_core_backend() {
- --enable-languages="${lang_list}" \
+ --enable-languages="${lang_list},go" \
@@ -903,7 +903,7 @@ do_gcc_backend() {
- extra_config+=("--enable-languages=${lang_list}")
+ extra_config+=("--enable-languages=${lang_list},go")
[5]./ct-ng build
再次运行。
[6] 编译一个非常简单的main.go:
// main.go
package main
import "fmt"
func main() {
fmt.Printf("Ok, ok, this is exactly perfect!\n")
}
使用命令:
PATH=${HOME}/x-tools/x86_64-ubuntu16.04-linux-gnu/bin/:${PATH}
export PATH
x86_64-ubuntu16.04-linux-gnu-gccgo -o main main.go
得到这些错误:
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/x-tools/x86_64-ubuntu16.04-linux-gnu/lib/gcc/x86_64-ubuntu16.04-linux-gnu/8.3.0/libgcc.a(morestack.o):
in function `__morestack':
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:504:
undefined reference to `__morestack_block_signals'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:512:
undefined reference to `__generic_morestack'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:531:
undefined reference to `__morestack_unblock_signals'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:556:
undefined reference to `__morestack_block_signals'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:562:
undefined reference to `__generic_releasestack'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:588:
undefined reference to `__morestack_unblock_signals'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:609:
undefined reference to `__generic_findstack'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/x-tools/x86_64-ubuntu16.04-linux-gnu/lib/gcc/x86_64-ubuntu16.04-linux-gnu/8.3.0/libgcc.a(morestack.o):
in function `__stack_split_initialize':
~/crosstool-ng/.build/x86_64-ubuntu16.04-linux-gnu/src/gcc/libgcc/config/i386/morestack.S:758:
undefined reference to `__generic_morestack_set_initial_sp'
~/x-tools/x86_64-ubuntu16.04-linux-gnu/lib/gcc/x86_64-ubuntu16.04-linux-gnu/8.3.0/../../../../x86_64-ubuntu16.04-linux-gnu/bin/ld:
~/x-tools/x86_64-ubuntu16.04-linux-gnu/lib/gcc/x86_64-ubuntu16.04-linux-gnu/8.3.0/libgcc.a(morestack.o):
(.ctors.65535+0x8):
undefined reference to `__morestack_load_mmap'
collect2: error: ld returned 1 exit status