0

我正在使用需要 g77 3.2.x 才能成功编译和运行的遗留 + 学术 + 数字 fortran-77 代码......我在 Red Hat Linux 9 for i386 上使用该编译器

其中一个 fortran-77 文件定义了一个子例程,其中包含许多实数、整数和双精度数组作为局部变量……如果我使用以下方法编译它:

$ g77 -c thefile.F -o thefile.o

它会生成一个大小约为 10kB 的目标文件......但如下:

$ g77 -finit-local-zero -c thefile.F -o thefile.o

生成大小为 14MB 的目标文件

我尝试strip了目标文件,但大小没有太大变化

代码中有几十个这样的文件,可执行二进制文件最终大小为 200MB

知道发生了什么吗?更重要的是,我能做些什么来恢复更健全的对象/二进制大小?

PS:当我将 200MB 二进制文件压缩到 tar.gz 中时,tarball 小于 1 MB ......这意味着 200MB 可能充满了 0 或其他东西(我可以在十六进制编辑器中打开它,但我觉得太懒了现在)

PS:编译器细节如下(使用g77的-v标志)

$ g77 -v -finit-local-zero -c thefile.F -o thefile.o
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/tradcpp0 -lang-fortran -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ thefile.F /tmp/ccXXvzMA.f
GNU traditional CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/f771 /tmp/ccXXvzMA.f -quiet -dumpbase thefile.F -version -finit-local-zero -o /tmp/cck0Blw1.s
GNU F77 version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (i386-redhat-linux)
    compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
 as -V -Qy -o thefile.o /tmp/cck0Blw1.s
GNU assembler version 2.13.90.0.18 (i386-redhat-linux) using BFD version 2.13.90.0.18 20030206

编辑:较新的 g77/gfortran 版本没有这个问题(目标文件大小与 -finit-local-zero 几乎保持相同)但我不能使用它们(使用最新的编译器版本使代码产生正确的结果将是项目本身)......我需要 -finit-local-zero 标志(没有它的代码挂起)

编辑 2:我进行了十六进制转储,果然 99% 的文件由零组成!

4

1 回答 1

2

从在线文档:

http://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html

-finit-local-zero
-finit-integer=n
-finit-real=<zero|inf|-inf|nan|snan>
-finit-logical=<true|false>
-finit-character=n
    The -finit-local-zero option instructs the compiler to initialize local INTEGER,
    REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER 
    variables to a string of null bytes. Finer-grained initialization options are
    provided by the -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which 
    also initializes the real and imaginary parts of local COMPLEX variables), 
    -finit-logical=<true|false>, and -finit-character=n (where n is an ASCII 
    character value) options. These options do not initialize

    * allocatable arrays
    * components of derived type variables
    * variables that appear in an EQUIVALENCE statement. 

    (These limitations may be removed in future releases). 

问:知道发生了什么吗?我该怎么做才能恢复到更健全的对象/二进制大小?

意味着可能 200MB 充满了 0 或什么?

答:是的。听起来您已经回答了自己的问题:)

于 2012-01-20T23:13:24.063 回答