iOS目标的Ada交叉编译器

8

tl;dr
我如何将Ada源代码编译成适用于在运行iOS的iPad目标应用程序中链接的静态库文件?(GCC不是必需的。使用LLVM或其他解决方案也可以!)


我拥有一个大型可移植的Ada代码库,我想在iPad/iOS项目中使用它。我的主机操作系统是Mac OS X 10.9(安装了MacPorts中的GCC 4.8.1)。为此,我正在尝试构建带有Ada支持的GCC ARM交叉编译器。

我能够构建创建ARM可执行文件的工作GCC和GNAT,但似乎无法构建或安装Ada标准库,这是构建我的Ada代码所必需的。

我正在使用的源包:

gcc-4.8.1
binutils-2.24
libiconv-1.14
gmp-5.1.3
mpc-1.0.2
mpfr-3.1.2

GCC的构建配置:
$ bin/arm-none-eabi-gcc -v --version
Using built-in specs.
COLLECT_GCC=bin/arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/Users/ardnew/cross/libexec/gcc/arm-none-eabi/4.8.1/lto-wrapper
arm-none-eabi-gcc (GCC) 4.8.1
Copyright (C) 2013 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.


Target: arm-none-eabi
Configured with: /Users/ardnew/cross/src/gcc-4.8.1/configure --target=arm-none-eabi --prefix=/Users/ardnew/cross --with-cpu=cortex-a8 --enable-languages=c,ada --disable-multilib --enable-interwork --disable-threads --disable-shared --disable-nls --disable-lto --disable-libssp --disable-decimal-float --disable-libgomp --disable-libmudflap
Thread model: single
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '--version' '-mcpu=cortex-a8'
 /Users/ardnew/cross/libexec/gcc/arm-none-eabi/4.8.1/cc1 -quiet -v -D__USES_INITFINI__ help-dummy -quiet -dumpbase help-dummy -mcpu=cortex-a8 -auxbase help-dummy -version --version -o /var/folders/4c/y_sll7bj6b9bt15389wr66_80000gn/T//ccrSSKFx.s
GNU C (GCC) version 4.8.1 (arm-none-eabi)
  compiled by GNU C version 4.8.1, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '--version' '-mcpu=cortex-a8'
 /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/as -mcpu=cortex-a8 -meabi=5 --version -o /var/folders/4c/y_sll7bj6b9bt15389wr66_80000gn/T//ccZYvQLp.o /var/folders/4c/y_sll7bj6b9bt15389wr66_80000gn/T//ccrSSKFx.s
GNU assembler (GNU Binutils) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `arm-none-eabi'.
COMPILER_PATH=/Users/ardnew/cross/libexec/gcc/arm-none-eabi/4.8.1/:/Users/ardnew/cross/libexec/gcc/arm-none-eabi/4.8.1/:/Users/ardnew/cross/libexec/gcc/arm-none-eabi/:/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/:/Users/ardnew/cross/lib/gcc/arm-none-eabi/:/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/
LIBRARY_PATH=/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/:/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/
COLLECT_GCC_OPTIONS='-v' '--version' '-mcpu=cortex-a8'
 /Users/ardnew/cross/libexec/gcc/arm-none-eabi/4.8.1/collect2 -X --version /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crti.o /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtbegin.o crt0.o -L/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1 -L/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib /var/folders/4c/y_sll7bj6b9bt15389wr66_80000gn/T//ccZYvQLp.o --start-group -lgcc -lc --end-group /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtend.o /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtn.o
collect2 version 4.8.1
/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/ld -X --version /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crti.o /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtbegin.o crt0.o -L/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1 -L/Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib /var/folders/4c/y_sll7bj6b9bt15389wr66_80000gn/T//ccZYvQLp.o --start-group -lgcc -lc --end-group /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtend.o /Users/ardnew/cross/lib/gcc/arm-none-eabi/4.8.1/crtn.o
GNU ld (GNU Binutils) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

测试程序以确保构建ARM二进制文件:

$ cat told_unit1.adb told_unit1.ads

--
-- FILE: told_unit1.adb
--
with Ada.Text_IO;
use Ada.Text_IO;

package body told_unit1 is

  procedure hello is
  begin
    put_line("hello, world");
  end hello;

  function double(x : in float) return float is
  begin
    return x + x;
  end double;

end told_unit1;


--
-- FILE: told_unit1.ads
--
package told_unit1 is

  procedure hello;
  pragma Export
  (
    convention     =>  C,
    entity         =>  hello,
    external_name  =>  "ada_hello"
  );

  function double(x : in float) return float;
  pragma Export
  (
    convention     =>  C,
    entity         =>  double,
    external_name  =>  "ada_double"
  );

end told_unit1;

然后编译Ada代码并使用file检查它:

$ arm-none-eabi-gcc -c told_unit1.adb

$ file told_unit1.o
told_unit1.o: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped

然后当我尝试绑定库对象文件时,它会出错:

$ arm-none-eabi-gnatbind -aO$ADA_OBJECT_PATH -Ltold told_unit1
error: "a-textio.ali" not found, "a-textio.adb" must be compiled

回顾我的GCC构建日志,我发现libada(我相信它是GNAT的一部分)从未被构建。当我尝试从GCC构建目录运行make all-target-libada时,它最终告诉我:
Configuring in arm-none-eabi/libada
configure: loading cache ./config.cache
checking build system type... x86_64-apple-darwin13.1.0
checking host system type... arm-none-eabi
checking target system type... arm-none-eabi
checking for arm-none-eabi-gcc...  /Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/xgcc -B/Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/ -B/Users/ardnew/cross/arm-none-eabi/bin/ -B/Users/ardnew/cross/arm-none-eabi/lib/ -isystem /Users/ardnew/cross/arm-none-eabi/include -isystem /Users/ardnew/cross/arm-none-eabi/sys-include
checking for C compiler default output file name...
configure: error: in `/Users/ardnew/cross/src/gcc-4.8.1-obj/arm-none-eabi/libada':
configure: error: C compiler cannot create executables
See `config.log' for more details.
make: *** [configure-target-libada] Error 1

于是我检查了它所提到的config.log,发现如下内容:

configure:2351: $? = 0
configure:2340:  /Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/xgcc -B/Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/ -B/Users/ardnew/cross/arm-none-eabi/bin/ -B/Users/ardnew/cross/arm-none-eabi/lib/ -isystem /Users/ardnew/cross/arm-none-eabi/include -isystem /Users/ardnew/cross/arm-none-eabi/sys-include    -v >&5
COLLECT_LTO_WRAPPER=/Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/lto-wrapper
Target: arm-none-eabi
Configured with: /Users/ardnew/cross/src/gcc-4.8.1/configure --target=arm-none-eabi --prefix=/Users/ardnew/cross --with-cpu=cortex-a8 --enable-languages=c,ada --disable-multilib --enable-interwork --disable-threads --disable-shared --disable-nls --disable-lto --disable-libssp --disable-decimal-float --disable-libgomp --disable-libmudflap
configure:2351: $? = 0
xgcc: error: unrecognized command line option '-qversion'
xgcc: fatal error: no input files
compilation terminated.
configure:2351: $? = 1
configure:2371: checking for C compiler default output file name
configure:2393:  /Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/xgcc -B/Users/ardnew/cross/src/gcc-4.8.1-obj/./gcc/ -B/Users/ardnew/cross/arm-none-eabi/bin/ -B/Users/ardnew/cross/arm-none-eabi/lib/ -isystem /Users/ardnew/cross/arm-none-eabi/include -isystem /Users/ardnew/cross/arm-none-eabi/sys-include    -g -O2   conftest.c  >&5
/Users/ardnew/cross/arm-none-eabi/bin/ld: cannot find crt0.o: No such file or directory
/Users/ardnew/cross/arm-none-eabi/bin/ld: cannot find -lg
/Users/ardnew/cross/arm-none-eabi/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
configure:2397: $? = 1
configure:2434: result:
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:2440: error: in `/Users/ardnew/cross/src/gcc-4.8.1-obj/arm-none-eabi/libada':
configure:2444: error: C compiler cannot create executables
See `config.log' for more details.

现在我已经超出了自己的能力范围,不太确定接下来该怎么办。看起来我可能缺少ARM平台的C运行时库?

如果有任何帮助配置GNAT/libada用于ARM目标的方法,那就太好了。

或者,是否有更简单的方法从Xcode iOS项目中链接到Ada库?


你应该检查一下你的 arm-none-eabi 交叉编译器是否生成 ELF 或 Macho 二进制文件 - 后者在 MacOSX 上都是必需的,但我强烈怀疑配置会生成 ELF,而你无法使用。这不是一个很大的问题,但你可能需要自己构建一个带有 Mach-o 支持的交叉编译 GCC 和 bin-utils。 - marko
@marko,“arm-none-eabi-gcc”生成ELF二进制文件(抱歉,这段文字有点长,请查看我从顶部粘贴的第4个代码块),你是说真实的iPad目标iOS期望Mach-O格式而不是ELF?如果我改变格式,我相信我的当前问题仍然存在。 - ardnew
2
是的。在MacOSX或iOS上,ELF目标文件对您没有用处,因为它们只使用Mach-o目标文件和共享库。ARM ABI也略有不同。我预计针对iOS上的ARM的gcc将具有arm arm-apple-darwin-前缀或类似的内容。您的错误很可能与可执行文件格式不匹配有关。 - marko
1
有一些 Ada 到 C 的翻译器,另一个则是构建路径。 - Gene
@marko,我看到的错误甚至在iOS设备出现之前就发生了。我无法为与主机不同的任何架构构建libada。让生成的可执行文件在iPad上实际运行还不是问题。明天我会拿回我的Macbook(交叉编译器主机)并尝试演示Mach-O二进制文件的问题。 - ardnew
@Gene谢谢你的评论。我们过去已经为专业源代码翻译(Mapusoft的Ada到C转换器)付费,并且在翻译的类型定义和异常处理方面遇到了严重问题,需要大量手动清理。此外,这是一个非常庞大的代码库,还需要安全认证。将项目分叉成两个代码库需要两倍于所需认证的数量。对于这个项目来说,源代码翻译是不可行的 :( - ardnew
1个回答

1
很遗憾,目前还没有自动化工具可以完成这个任务。您可以在翻译后使用工具进行验证,但您想要的还不可用。
我曾经也面临过同样的问题。如果有不同的答案,我的一个项目预算就会发生巨大变化。或许将来会有解决方案。
尽管我承认,最终可能存在足够多的不兼容性,需要对源代码进行大幅修改,这会降低您所期望实现的价值。最终,新的投资虽然令人沮丧,但如果您能承担得起,将会产生更好的源代码。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接