FPGA開発日記

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

ベンチマークをシミュレータで動作させてみる(sbrkでメモリが足りない?)

msyksphinz.hatenablog.com

うーん、sbrkで、確保しているメモリが足りない気がしている。 そこで、リンカスクリプトで、ヒープの領域をさらに大きめに確保してみた。

diff --git a/coremark-pro_1.1.2446/mith/mips/mips.simple.ld b/coremark-pro_1.1.2446/mith/mips/mips.simple.ld
index 35d7e38..de42d51 100644
--- a/coremark-pro_1.1.2446/mith/mips/mips.simple.ld
+++ b/coremark-pro_1.1.2446/mith/mips/mips.simple.ld
@@ -1,15 +1,21 @@
 SECTIONS
 {
-       .data   0x7F000000 : { *(.data) }
+       .data   0x7F000000 : {
+        *(.data)
+        *(.sdata)
+    }
     .ctors : { *(.ctors) }
     .dtors : { *(.dtors) }
     .jcr   : { *(.jcr) }
     _gp = ALIGN(16);
     heap_low = .; /* for _sbrk */
-    . = . + 0x4000; /* 64kB of stack memory */
+    . = . + 0x10000; /* 64kB of stack memory */
     heap_top = .; /* for _sbrk */
        _sp = ALIGN(16) + 0xFFFF8;
-    .bss    :            { *(.bss)  }
+    .bss : {
+         *(.sbss)
+         *(.bss)
+    }
     stack_top = .; /* for startup.s */

     .text   0x80000000 : {

しかし、何故かエラーが出る。

/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/bin/ld: small-data section exceeds 64KB; lower small-data size limit (see option -G)
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-freer.o): In function `_free_r':
(.text+0x368): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_top_pad'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x3a4): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_top_pad'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x4b8): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_max_sbrked_mem'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x4cc): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_max_sbrked_mem'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x4d0): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_max_total_mem'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x4e8): relocation truncated to fit: R_MIPS_GPREL16 against `__malloc_max_total_mem'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
(.text+0x18): relocation truncated to fit: R_MIPS_GPREL16 against `errno'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
(.text+0x38): relocation truncated to fit: R_MIPS_GPREL16 against `errno'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-writer.o): In function `_write_r':
(.text+0x24): relocation truncated to fit: R_MIPS_GPREL16 against `errno'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-writer.o): In function `_write_r':
(.text+0x44): relocation truncated to fit: R_MIPS_GPREL16 against `errno'
/usr/local/lib/gcc/mipsel-unknown-elf/5.1.0/../../../../mipsel-unknown-elf/lib/libc.a(lib_a-closer.o): In function `_close_r':
(.text+0x18): additional relocation overflows omitted from the output

うーん?small-dataのセクションを拡充させてみたが、結果は変わらなかった。

diff --git a/coremark-pro_1.1.2446/util/make/gcc-mips.mak b/coremark-pro_1.1.2446/util/make/gcc-mips.mak
index af25a76..4f4ef1b 100644
--- a/coremark-pro_1.1.2446/util/make/gcc-mips.mak
+++ b/coremark-pro_1.1.2446/util/make/gcc-mips.mak
@@ -81,7 +81,7 @@ INCLUDE = $(TOOLS)/include
 # -O0                   Do not optimize
 # -O2                   Optimize for speed

-COMPILER_TARGET = -mips32r5 -msoft-float
+COMPILER_TARGET = -mips32r5 -msoft-float -mlong-calls -G0
 COMPILER_FLAGS = -O2 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1 -std=gnu99
 COMPILER_NOOPT = -g -O0 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1
 COMPILER_DEBUG = -O0 -g $(CDEFN)HOST_EXAMPLE_CODE=1 -DBMDEBUG=1 -DTHDEBUG=1
@@ -137,6 +137,7 @@ ASSEMBLER_INCLUDES  =
 # -lm is optional. Some linkers (linux gcc) do not include math library by default.

 LINKER_LAST =
+LINKER_FLAGS = -G0 -mlong-calls

よく分からないなあ。