micropythonのビルドができなかった話

micropython をローカルのPCでビルドしたら以下のエラーが出てしまった。

[1/1] Linking CXX executable source/microbit-micropython
FAILED: cmd.exe /C "cd . && C:\PROGRA~2\GNUTOO~1\82018-~1\bin\AR10B2~1.EXE   -fno-exceptions -fno-unwind-tables -Wl,--gc-sections -Wl,--sort-common -Wl,--sort-section=alignment -Wl,-wrap,main -mcpu=cortex-m0 -mthumb -T"C:/Users/***/Documents/GitHub/micropython/yotta_targets/bbc-microbit-classic-gcc-nosd/CMake/../ld/NRF51822.ld" -Wl,-Map,source/microbit-micropython.map -Wl,--start-group @CMakeFiles/microbit-micropython.rsp   -lstdc++ -lsupc++ -lm -lc -lgcc -lstdc++ -lsupc++ -lm -lc -lgcc -Wl,--end-group  --specs=nano.specs -o source/microbit-micropython && cmd.exe /C "cd /D C:/Users/***/Documents/GitHub/micropython/build/bbc-microbit-classic-gcc-nosd/source && arm-none-eabi-objcopy -O ihex microbit-micropython microbit-micropython.hex && srec_cat microbit-micropython.hex -intel -o microbit-micropython.hex -intel --line-length=44 && cd /D C:/Users/***/Documents/GitHub/micropython/build/bbc-microbit-classic-gcc-nosd/source && "C:/Program Files (x86)/GNU Tools Arm Embedded/8 2018-q4-major/bin/arm-none-eabi-objcopy.exe" -O binary microbit-micropython microbit-micropython.bin""
arm-none-eabi-objcopy: microbit-micropython.hex 64-bit address 0x4b4fa300000000 out of range for Intel Hex file
arm-none-eabi-objcopy:microbit-micropython.hex: bad value
ninja: build stopped: subcommand failed.
error: command ['ninja'] failed
make: *** [yotta] エラー 1

”64-bit address 0x4b4fa300000000 out of range for Intel Hex file”ってなによ、と思い調べてみました。

ソースを見る

bfd\ihex.c を見ると以下のコードがありました。

static bfd_boolean
ihex_write_object_contents (bfd *abfd)
{
  bfd_vma segbase;
  bfd_vma extbase;
  struct ihex_data_list *l;

  segbase = 0;
  extbase = 0;
  for (l = abfd->tdata.ihex_data->head; l != NULL; l = l->next)
    {
      bfd_vma where;
      bfd_byte *p;
      bfd_size_type count;
      const bfd_vma sign = (bfd_vma) 0xffffffff80000000ULL;
      const bfd_vma top = (bfd_vma) 0xffffffff00000000ULL;

      where = l->where;

      /* Check for unacceptable addresses sign extension.
	 See PR 23699 for more details.  */
      if ((where & sign) == top
	  || ((where & top) != 0 && (where & top) != top))
       {
         _bfd_error_handler
           /* xgettext:c-format */
           (_("%pB 64-bit address %#" PRIx64 " out of range for Intel Hex file"),
            abfd, (uint64_t) where);
         bfd_set_error (bfd_error_bad_value);
         return FALSE;
       }

このコードの

      /* Check for unacceptable addresses sign extension.
	 See PR 23699 for more details.  */
      if ((where & sign) == top
	  || ((where & top) != 0 && (where & top) != top))

この条件に入っているみたい。コメントに、詳細は「PR 23699をみてね」とある。

PR 23699の内容

PR 23699 の内容を見て初めて知ったのですが、ihex フォーマットって 32bit幅までのアドレスしかサポートしないのですね。
(今年入った修正みたい)

本当にPR 23699の修正の影響か?

ソースをビルドしてみる。
ソースはこちら からダウンロード。ビルド方法はダウンロードしたファイル(gcc-arm-none-eabi-8-2018-q4-major-src.tar.bz2)の中の
How-to-build-toolchain.pdf に書いてあります。

つづく。

この記事が気に入ったらサポートをしてみませんか?