mips gccインタプリタ用にコンパイルする方法は?

mips gccインタプリタ用にコンパイルする方法は?

下に太字で示された理由のため、もはや関係がないので、ここにあった古い質問を捨てました。問題自体はまだ存在します。私は、クロスコンパイルしたいシステムがもう存在しないということです。前の質問が次の場所にコピーされました。貼り付けボックス

F@ST 2704Nのファームウェアをフラッシュできることがわかりました。OpenWRT.org。私はluciのWebインターフェイスへのリンクを使っていましたが、私のルータにOpenWRTがあります。私のルーター用のプログラムをクロスコンパイルする方法を学びたいので、この質問はまだ有効ですが、組み込みファームウェアで作業しようとしないので、これは簡単になります。

OpenWRTを実行しているMips32バージョン1プロセッサで実行するように私のプログラムをどのようにコンパイルしますか?

通訳を直接使用してください。

root@OpenWrt:~# /lib/ld-musl-mips-sf.so.1 hello
/lib/ld-musl-mips-sf.so.1: hello: Not a valid dynamic program

root@OpenWrt:~# ./hello
Segmentation fault

CPU情報:

root@OpenWrt:~# cat /proc/cpuinfo
system type     : bcm63xx/F@ST2704N (0x6318/0xB0)
machine         : Sagem F@ST2704N
processor       : 0
cpu model       : Broadcom BMIPS3300 V3.3
BogoMIPS        : 332.54
wait instruction    : yes
microsecond timers  : yes
tlb_entries     : 32
extra interrupt vector  : yes
hardware watchpoint : no
isa         : mips1 mips2 mips32r1
ASEs implemented    :
shadow register sets    : 1
kscratch registers  : 0
package         : 0
core            : 0
VCED exceptions     : not available
VCEI exceptions     : not available

Linuxバージョン:

root@OpenWrt:~# cat /proc/version
Linux version 4.1.4 (thepeople@viasatpilot) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r46566) ) #1 Fri Aug 7 05:54:20 CEST 2015

オンボードバイナリ:

Alexs-MacBook-Air:hello-world senor$ file ls
ls: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, stripped

Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h ls
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x403990
  Start of program headers:          52 (bytes into file)
  Start of section headers:          427656 (bytes into file)
  Flags:                             0x50001005, noreorder, cpic, o32, mips32
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         29
  Section header string table index: 28

私のバイナリ:

Alexs-MacBook-Air:hello-world senor$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped

Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0xa0020004
  Start of program headers:          52 (bytes into file)
  Start of section headers:          200884 (bytes into file)
  Flags:                             0x50001001, noreorder, o32, mips32
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         2
  Size of section headers:           40 (bytes)
  Number of section headers:         29
  Section header string table index: 28

こんにちはバイナリソースコード:

#include <stdio.h>
int main() {
  printf("Hello MIPS! \n");
  return 0;
}

hello バイナリのコンパイルに使用したコマンドは/opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello.

コマンドを使用してプログラムをコンパイルしようとしましたが、/opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -dynamic-linker=/lib/ld-musl-mips-sf.so.1 -static hello.c -o hello-inter新しいリンカーオプションを追加しなかったかのように、多くのファイルが生成され、同じバイナリが生成されました。ソースからバイナリを接続する必要があると思いますが、間違っている可能性があります。

ベストアンサー1

私が見つけたOpenWRT.orgのこのガイドこれはビルドツールのインストール方法を学ぶのに役立ち、私のOpenWRTバージョンに合わせて指示を修正しました。

git commitを確認してみる70255e3d624cd393612069aae0a859d1acbbeeae(タグ: v18.06.1)私は設定を指定しました:

system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"

path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/binまた、コマンドを使用して実行するようにPATH環境変数を設定しましたmips-openwrt-linux-gcc hello.c -o hello

OSXでコンパイルしたので、gnu-getoptとgnu-timeをインストールする必要があることに言及したいと思います。

また、追加ボーナスとしてBusyBoxなどの既存のプログラムに対してコンパイルをテストしたときLDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-"

編集する:

ELFファイルにインタプリタが必要な理由に興味がある人のために、インタプリタはプログラムがロードされる前に環境を設定します。ブログ投稿から引用クリスチャンアイジンガーの考え「カーネルからプログラムをロードする」セクションで。

静的にリンクされたバイナリにはインタプリタが必要ない場合があります。 linux.soが必要です。」

私のプログラムを静的に接続していても、もともとSagemcomファームウェアで「Kill​​ed」と表示され続けるのは、おそらくルータが不正アクセスの実行を防ぐためにプログラムを実行したいユーザーを混乱させるように設計されているからです。私はuClibcをコンパイルし、元のファームウェアとは別のSagemcomデバイス(この質問で質問したデバイスとは無関係)で動作するようにする方法を見つけました。

おすすめ記事