Similar documents
超初心者用

double float

program.dvi

Microsoft Word - C.....u.K...doc

r08.dvi

ohp08.dvi

Microsoft Word - Sample_CQS-Report_English_backslant.doc

ex12.dvi

‚æ4›ñ

char char 1 signed char unsigned char ( ; single-quote 0x27) ASCII Japan Advanced Institute of Science and Technology

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

r07.dvi

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

ohp07.dvi

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

大統一Debian勉強会 gdb+python拡張を使ったデバッグ手法

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

joho07-1.ppt

untitled


Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

ohp03.dvi

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

橡Pro PDF

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

解きながら学ぶC++入門編

tutorial_lc.dvi

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

main main Makefile Makefile C.5 Makefile Makefile Makefile A Mech (TA ) 1. Web ( iku

Informatics 2015

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

(Version: 2017/4/18) Intel CPU 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU do

/* sansu1.c */ #include <stdio.h> main() { int a, b, c; /* a, b, c */ a = 200; b = 1300; /* a 200 */ /* b 200 */ c = a + b; /* a b c */ }

I 2 tutimura/ I 2 p.1/??

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

pptx

bitvisor-ipc v12b.key

Informatics 2014

ex01.dvi

Networking Semester 802.3

untitled

joho09.ppt

2008 DS T050049

Condition DAQ condition condition 2 3 XML key value

para02-2.dvi

slide5.pptx

Nios® II HAL API を使用したソフトウェア・サンプル集 「Modular Scatter-Gather DMA Core」

Cプログラミング - 第8回 構造体と再帰

SML#³«È¯ºÇÁ°Àþ

第5回お試しアカウント付き並列プログラミング講習会

O(N) ( ) log 2 N

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

C言語によるアルゴリズムとデータ構造

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

r03.dvi

13 I/O

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

東京エリアDebian勉強会   Buffalo Linkstation向け Debian Installer - 第139回 2016年5月度

10

ex01.dvi

FreeBSD 1

1.ppt

8 / 0 1 i++ i 1 i-- i C !!! C 2

3 3.1 LAN ISDN (IP) 2 TCP/UDP IP IP IP IP (Ethernet) Ethernet LAN TCP/UDP LAN Ethernet LAN 2: Ethernet ATM, FDDI, LAN IP IP IP 3 IP 2 IP IP IP IP IP 3


18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

Intel Memory Protection Extensions(Intel MPX) x86, x CPU skylake 2015 Intel Software Development Emulator 本資料に登場する Intel は Intel Corp. の登録

MINI2440マニュアル

LAN Copyright c Daikoku Manabu This tutorial is licensed under a Creative Commons Attribution 2.1 Japan License

GNU/Linux on SuperH g,,,,, GNU/Linux on SuperH [1] SuperH (SH-3 SH-4) GNU/Linux g linux-kernel 1998 Linux (SH-3) g GD

2008 IIA (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) ( )

Informatics 2010.key

2 1. Ubuntu 1.1 OS OS OS ( OS ) OS ( OS ) VMware Player VMware Player jp/download/player/ URL VMware Plaeyr VMware

PowerPoint プレゼンテーション

(K&R 2.9) ~, &,, >>, << 2. (K&R 5.7) 3. (K&R 5.9) 4. (K&R 5.10) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, std

Taro-リストⅢ(公開版).jtd

アセンブラ入門(CASL II) 第3版

EDSF2006_ PDF


untitled


Baud Rate 9600 Parity NONE Number of Data Bits 8 Number of Stop Bits 1 Flow Control NONE 1 RS232C 200mm 2,000mm DIMM ( ) Telescope East/West LX200 * 1

プログラムローダを用いた 関数の置換により Stack-based Buffer Overflow攻撃を 緩和する手法の提案と実装


void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

untitled

:30 12:00 I. I VI II. III. IV. a d V. VI

C C UNIX C ( ) 4 1 HTML 1

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

Complex Lab – Operating Systems - Graphical Console

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

C

Transcription:

ARM gcc Kunihiko IMAI <bak d2.dion.ne.jp> 2009 1 11 ARM gcc 1 2 2 2 3 3 4 3 4.1................................. 3 4.2............................................ 4 4.3........................................ 5 5 6 5.1................................................... 6 5.2............................................ 7 5.3........................................ 7 6 char 8 6.1................................................... 8 6.2............................................ 9 6.3........................................ 9 7 soft fp hard fp 10 7.1............................................. 10 7.1.1 FPU................................... 10 7.1.2........................... 10 7.1.3............................................ 10 7.2 ARM........................................... 11

1. 2 7.2.1........................................ 11 7.2.2.............................................. 12 7.2.3........................................ 13 7.2.4.................................... 13 8 EABI legacy ABI 14 8.1 ABI............................................... 14 8.2 ABI.............................................. 14 8.2.1 legacy ABI.......................................... 14 8.2.2 ARM EABI.......................................... 14 8.3.................................................. 15 8.4.............................................. 15 8.5 Debian......................................... 16 8.6.............................................. 17 8.6.1................................ 17 8.6.2............................. 17 8.7........................................ 17 9 memcpy() 17 9.1.................................................. 17 9.2............................................ 18 9.3................................................. 19 9.4.................................................. 19 10 19 1 XScale ARM CPU gcc binutils 2

3. 3 3 x86 C ARM toolchain OS ARM Linux 4 RISC ARM x86 4.1 ARM ARM Linux ARM Linux /proc/cpu/alignment $ cat /proc/cpu/alignment User: 0 System: 0 Skipped: 0 Half: 0 Word: 0 Multi: 0 User faults: 0 (ignored) x86 #include <stdio.h> main ( void ) char *str = "\x01\x23\x45\x67\x89\xab\xcd\xef";

4. 4 unsigned *u = (unsigned *)(str + 1); printf ( "%08x\n", *u ); x86 89674523 ARM 01674523 /proc/cpu/alignment User $ cat /proc/cpu/alignment User: 1 System: 0 Skipped: 0 Half: 0 Word: 0 Multi: 0 User faults: 0 (ignored) +3 +2 +1 +0 67 45 23 01 str ef cd ab 89 +3 +2 +1 +0 02 01 00 x86 03 unsigned +3 +2 +1 +0 02 01 00 03 ARM 4.2

4. 5 x86 x86 x86 4.3 4.1 (ARM Linux ) /proc/cpu/alignment 2 # echo 2 >/proc/cpu/alignment # cat /proc/cpu/alignment User: 1 System: 0 Skipped: 0 Half: 0 Word: 0 Multi: 0 User faults: 2 (fixup) x86 x86 89674523 /proc/cpu/alignment bit OR 3 warn fixup 0 ignore 1 warn dmesg 2 fixup 4 signal core

5. 6 x86 aligned read x86 unaligned read read ARM unaligned(fixup) read aligned access read fixup 5 RISC 5.1 x86 x86 ARM #include <stdio.h> struct s0 ; unsigned char a, b, c; struct s1 char d; struct s0 e; ; main ( void ) struct s1 s;

5. 7 void *s_a = (void *)&s, *d_a = (void *)&s.d, *e_a = (void *)&s.e; printf ( "d = %d\n", d_a - s_a ); printf ( "e = %d\n", e_a - s_a ); x86 d = 0 e = 1 ARM d = 0 e = 4 5.2 5.3 gcc attribute ((packed)) #include <stdio.h> struct s0 char a, b, c; attribute ((packed)); struct s1 char d;

6. char 8 struct s0 e; attribute ((packed)); main ( void ) struct s1 s; void *s_a = (void *)&s, *d_a = (void *)&s.d, *e_a = (void *)&s.e; printf ( "d = %d\n", d_a - s_a ); printf ( "e = %d\n", e_a - s_a ); ARM d = 0 e = 1 x86 x86 x86 6 char ARM toolchain ARM gcc char unsinged char x86 gcc signed char char C C C char C 6.1

6. char 9 #include <stdio.h> main ( void ) char c1 = 0xff, c2 = 0x01; if ( c1 > c2 ) printf ( "c1 > c2\n" ); else printf ( "c1 <= c2\n" ); x86 signed char c1 = -1, c2 = 1 c1 <= c2 ARM unsigned char c1 = 255, c2 = 1 c1 > c2 6.2 char signed char C 6.3 ARM gcc -fsigned-char char signed char x86 $ gcc -fsigned-char char.c c1 <= c2

7. soft fp hard fp 10 7 soft fp hard fp fp 7.1 x86 FPU Floating Poing Unit; SoC 7.1.1 FPU CPU 7.1.2 gcc --msoft-float FPU FPU 7.1.3 FPU < < FPU

7. soft fp hard fp 11 7.2 ARM ARM 7.2.1 C /* foo.c */ int foo ( int a, int b ) return a + b; /* main.c */ #include <stdio.h> extern int foo ( int a, int b ); main ( void ) printf ( "%d\n", foo ( 1, 2 ) ); C $ gcc foo.c -msoft-float -c $ gcc main.c -c $ gcc foo.o main.o foo.c -msoft-float main.c x86 PowerPC a.out ARM toolchain $ gcc main.o foo.o /usr/bin/ld: ERROR: /usr/lib/gcc/arm-linux-gnu/4.0.4/libgcc_s.so uses hardware FP, whereas a.out uses software FP /usr/bin/ld: failed to merge target specific data of file /usr/lib/gcc/arm-linu x-gnu/4.0.4/libgcc_s.so /usr/bin/ld: ERROR: /lib/libc.so.6 uses hardware FP, whereas a.out uses softwar

7. soft fp hard fp 12 e FP ( collect2: ld returned 1 exit status 7.2.2 /usr/bin/ld: ERROR: /usr/lib/gcc/arm-linux-gnu/4.0.4/libgcc_s.so uses hardware FP, whereas a.out uses software FP hardware FP software FP google toolchain 1 readelf x86 $ readelf -h foo.o ELF : : 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 : ELF32 : 2 : 1 (current) OS/ABI: UNIX - System V ABI : 0 : REL ( ) : Intel 80386 : 0x1 : 0x0 : 0 ( ) : 192 ( ) : 0x0 : 52 ( ) : 0 ( ) : 0 : 40 ( ) Number of section headers: 9 Section header string table index: 6 x86 1

7. soft fp hard fp 13 $ readelf -h foo.o main.o : foo.o ELF : : 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 : main.o ELF : : 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 ARM $ readelf -h foo.o main.o : foo.o ELF : : 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 : 0x200, GNU EABI, software FP : main.o ELF : : 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 : 0x0 ELF soft FP hard FP 7.2.3 soft FP hard FP readelf soft FP hard FP 7.2.4 --no-warn-mismatch gcc --Wl,--no-warn-mismatch soft FP hard FP

8. EABI legacy ABI 14 $ gcc -Wl,--no-warn-mismatch foo.o main.o 8 EABI legacy ABI 8.1 ABI ABI (Application Binary Interface) C 8.2 ABI ARM Linux ABI 8.2.1 legacy ABI ARM gcc ABI gcc -mabi=apcs-gnu 8.2.2 ARM EABI ARM holdings 2 ABI gcc 4.1 -mabi=aapcs-linux 2 http://www.arm.com/products/devtools/abi.html

8. EABI legacy ABI 15 8.3 ABI Linux (linux-2.6.x/arch/arm/kconfig) Since there are major incompatibilities between the legacy ABI and EABI, especially with regard to structure member alignment, this option also changes the kernel syscall calling convention to disambiguate both ABIs and allow for backward compatibility support (selected with CONFIG OABI COMPAT). /* abitest.c */ #include <stdio.h> struct foo ; char a; main ( void ) printf ( "sizeof(struct foo) = %d\n", sizeof(struct foo)); lagacy ABI $ gcc -mabi=apcs-gnu abitest.c sizeof(struct foo) = 4 $ ARM EABI $ gcc -mabi=aapcs-linux abitest.c sizeof(struct foo) = 1 $ 8.4 ARM EABI legacy ABI readelf

8. EABI legacy ABI 16 $ gcc -mabi=aapcs-linux -c abitest.c # ARM EABI $ readelf -h abitest.o ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00...... Flags: 0x4000000, Version4 EABI...... $ gcc -mabi=apcs-gnu abitest.c # legacy ABI $ readelf -h abitest.o ELF Header: Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00...... Flags: 0x400, GNU EABI, VFP...... readelf Flags: legacy ABI GNU EABI ARM EABI Version4 EABI 8.5 Debian Debian lenny test EABI arm legacy ABI armel ARM EABI

9. memcpy() 17 8.6 ABI 8.6.1 ABI 8.6.2 ABI 8.7 Linux CONFIG AEABI CONFIG OABI COMPAT EABI EABI legacy ABI legacy ABI EABI apache ABI 9 memcpy() 9.1 #include <string.h> int foo ( char *to, char *from ) char buf[1024]; memcpy ( buf, "12345", 6 );

9. memcpy() 18 $ gcc -O0 -c foo.c $ nm foo.o 00000000 T foo $ memcpy() -O0 #include <string.h> int foo ( char *to, char *from, int len ) memcpy ( to, from, len ); $ gcc -O0 -c foo2.c $ nm foo2.o 00000000 T foo U memcpy memcpy() 9.2 gcc memcpy() x86 gcc info memcpy mempcpy memmove memset strcpy stpcpy strncpy strcat strncat

10. 19 9.3 gcc 32bit word align 9.4 gcc void *my_memcpy( void *dest, const void *src, size_t n ) char *s = (char *)src, *d = (char *)dest; while ( n-- ) *(d++) = *(f++); return dest; int foo ( char *to, char *from ) char buf[1024]; my_memcpy ( buf, "12345", 6 ); memcpy my memcpy() 10 RISC CPU RISC CPU char soft fp / hard fp ABI memcpy ARM gcc