2009. 1. 15. 10:38
[1] 64-bit/32-bit 빌드 실습
2009. 1. 15. 10:38 in 프로그래밍
[1] 64-bit/32-bit 빌드 실습
64-bit computing: Co-existing in a 32-bit world
Are 64-bit Binaries Really Slower than 32-bit Binaries? - OSNews.com
Ubuntu-7.04 Feisty 64-bit 버전에서,
아래와 같이 간단한 샘플을 하나 만들고 t.c 라고 저장한다.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("sizeof(short int) : %d\n", sizeof(short int));
printf("sizeof(int) : %d\n", sizeof(int));
printf("sizeof(long int) : %d\n", sizeof(long int));
printf("sizeof(long long int) : %d\n", sizeof(long long int));
printf("sizeof pointer : %d\n", sizeof(&i));
return 0;
}
우선 32-bit로 빌드하여 실행해본다.
$ gcc -m32 t.c -o a.out-32
$ ./a.out-32
sizeof(short int) : 2
sizeof(int) : 4
sizeof(long int) : 4
sizeof(long long int) : 8
sizeof pointer : 4
Integer와 Long integer와 Pointer가 모두 4byte(32bit)라서
ILP32라고 부른다는 것 같다.
이제 64-bit로 빌드하여 실행해본다.
$ gcc -m64 t.c -o a.out-64
$ ./a.out-64
sizeof(short int) : 2
sizeof(int) : 4
sizeof(long int) : 8
sizeof(long long int) : 8
sizeof pointer : 8
다른 것은 32-bit 때와 같은데, Long integer와 Pointer가 8byte(64bit)라서
LP64라고 부른다는 것 같다.
그냥 심심해서 적어봤다..
참, 처음에 32-bit로 빌드하려고 했을때 뭔가 오류가 발생했다.
아래의 패키지를 설치하고 나니 잘 되었다.
$ apt-get install glibc-dev-i386
덤으로 file utility를 이용해 위에서 빌드한 바이너리의 정보를 열람해보면..
$ gcc t.c
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
$ gcc -m64 t.c -o a.out-64
$ file a.out-64
a.out-64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
$ gcc -m32 t.c -o a.out-32
$ gcc -m32 -march=i686 t.c -o a.out-32
$ file a.out-32
a.out-32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
[2] Preprocessor derectives
-m32 : __i386__
-m64 : __x86_64__
아래 샘플을 -E 옵션으로 빌드해보면 확인할 수 있다.
test.c
---------------------
#ifdef __i386__
#warning "__i386__"
#endif
#ifdef __x86_64__
#warning "__x86_64__"
#endif
---------------------
64-bit computing: Co-existing in a 32-bit world
Are 64-bit Binaries Really Slower than 32-bit Binaries? - OSNews.com
Ubuntu-7.04 Feisty 64-bit 버전에서,
아래와 같이 간단한 샘플을 하나 만들고 t.c 라고 저장한다.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("sizeof(short int) : %d\n", sizeof(short int));
printf("sizeof(int) : %d\n", sizeof(int));
printf("sizeof(long int) : %d\n", sizeof(long int));
printf("sizeof(long long int) : %d\n", sizeof(long long int));
printf("sizeof pointer : %d\n", sizeof(&i));
return 0;
}
우선 32-bit로 빌드하여 실행해본다.
$ gcc -m32 t.c -o a.out-32
$ ./a.out-32
sizeof(short int) : 2
sizeof(int) : 4
sizeof(long int) : 4
sizeof(long long int) : 8
sizeof pointer : 4
Integer와 Long integer와 Pointer가 모두 4byte(32bit)라서
ILP32라고 부른다는 것 같다.
이제 64-bit로 빌드하여 실행해본다.
$ gcc -m64 t.c -o a.out-64
$ ./a.out-64
sizeof(short int) : 2
sizeof(int) : 4
sizeof(long int) : 8
sizeof(long long int) : 8
sizeof pointer : 8
다른 것은 32-bit 때와 같은데, Long integer와 Pointer가 8byte(64bit)라서
LP64라고 부른다는 것 같다.
그냥 심심해서 적어봤다..
참, 처음에 32-bit로 빌드하려고 했을때 뭔가 오류가 발생했다.
아래의 패키지를 설치하고 나니 잘 되었다.
$ apt-get install glibc-dev-i386
덤으로 file utility를 이용해 위에서 빌드한 바이너리의 정보를 열람해보면..
$ gcc t.c
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
$ gcc -m64 t.c -o a.out-64
$ file a.out-64
a.out-64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
$ gcc -m32 t.c -o a.out-32
$ gcc -m32 -march=i686 t.c -o a.out-32
$ file a.out-32
a.out-32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
[2] Preprocessor derectives
-m32 : __i386__
-m64 : __x86_64__
아래 샘플을 -E 옵션으로 빌드해보면 확인할 수 있다.
test.c
---------------------
#ifdef __i386__
#warning "__i386__"
#endif
#ifdef __x86_64__
#warning "__x86_64__"
#endif
---------------------
'프로그래밍' 카테고리의 다른 글
distcc: a fast, free distributed C/C++ compiler (0) | 2009.02.06 |
---|---|
디버깅의 도(5)-메모리 관련 문제들 (1) | 2008.10.28 |
디버깅의 도(4)-GDB (0) | 2008.10.28 |
디버깅의 도(3)-Assert (0) | 2008.10.28 |
디버깅의 도(2) (0) | 2008.10.28 |