0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Advance Toolchain for Linux on Powerを使ってx86PCを使って、Power用のアセンブラを解析(1)

Last updated at Posted at 2019-12-11

Advance Toolchain for Linux on Powerを使って、x86のPC上でPower用の実行ファイルを作成し、逆アセンブルして解析していきます。
以下のサイトを参考にしました。

Ubuntu 18.04.3 LTSを使いました。
適当なフォルダに移動し、以下のコマンドを実行します。

wget ftp://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu/dists/trusty/6976a827.gpg.key
sudo apt-key add 6976a827.gpg.key

/etc/apt/sources.listの最後の行に以下のコメントを追加してください。

deb ftp://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu trusty atX.X

atX.Xは、「APT supports package upgrades for new revision releases (i.e. 7.1-0 to 7.1-1). For new major releases (i.e. 7.1-1 to 8.0-0), please proceed as in a normal installation.」と書いてあるように、at7.1などと書き換えて使ってください。つまるところ、以下のようにやります。

deb ftp://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu trusty at7.1

そして

sudo apt-get update

を実行。

そして、以下も実行

sudo apt-get install advance-toolchain-atX.X-cross-ppc64

atX.Xは、at7.1などと書き換えてください。つまり、

sudo apt-get install advance-toolchain-at7.1-cross-ppc64

このように書き換わります。

/opt/at7.1/bin/  あたりに色々新しいファイルが作成されているので、それを指定して実行できます。

以下のファイルをコンパイルします。

# include <stdio.h>

int main(int argc, char *args[])
{
    printf("Hello, world!\n");
    return 0;
}
$ /opt/at7.1/bin/powerpc64le-linux-gnu-gcc helloworld.c 
$ ls
6976a827.gpg.key helloworld.c 
a.out (不必要なファイルは省略)
$ /opt/at7.1/bin/powerpc64le-linux-gnu-objdump -d a.out > dump.txt
$ ls
6976a827.gpg.key  
a.out             helloworld.c  
dump.txt 

これでPowerアーキテクチャの逆アセンブルがx86上で完了しました。

逆アセンブル結果

a.out:     file format elf64-powerpcle


Disassembly of section .init:

0000000010000370 <_init>:
    10000370:	02 10 40 3c 	lis     r2,4098
    10000374:	08 8b 42 38 	addi    r2,r2,-29944
    10000378:	a6 02 08 7c 	mflr    r0
    1000037c:	10 00 01 f8 	std     r0,16(r1)
    10000380:	a1 ff 21 f8 	stdu    r1,-96(r1)
    10000384:	00 00 00 60 	nop
    10000388:	08 80 02 e8 	ld      r0,-32760(r2)
    1000038c:	00 00 a0 2f 	cmpdi   cr7,r0,0
    10000390:	0c 00 fe 41 	beq+    cr7,1000039c <_init+0x2c>
    10000394:	6d fc ff 4b 	bl      10000000 <_init-0x370>
    10000398:	00 00 00 60 	nop
    1000039c:	4d 02 00 48 	bl      100005e8 <frame_dummy+0x8>
    100003a0:	00 00 00 60 	nop
    100003a4:	05 04 00 48 	bl      100007a8 <__do_global_ctors_aux+0x8>
    100003a8:	00 00 00 60 	nop
    100003ac:	60 00 21 38 	addi    r1,r1,96
    100003b0:	10 00 01 e8 	ld      r0,16(r1)
    100003b4:	a6 03 08 7c 	mtlr    r0
    100003b8:	20 00 80 4e 	blr

Disassembly of section .text:

00000000100003c0 <00000017.plt_call.puts@@GLIBC_2.17>:
    100003c0:	18 00 41 f8 	std     r2,24(r1)
    100003c4:	48 80 82 e9 	ld      r12,-32696(r2)
    100003c8:	a6 03 89 7d 	mtctr   r12
    100003cc:	20 04 80 4e 	bctr
(以下略)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?