shellの動きメモ

:/usr/pkgsrc/bootstrap $ var='* test'
:/usr/pkgsrc/bootstrap $ echo $var
CVS README README.AIX README.Cygwin README.FreeBSD README.HPUX README.Haiku README.IRIX README.IRIX5.3 README.Interix README.Linux README.MacOSX README.Minix3 README.MirBSD README.OSF1 README.OpenBSD README.Solaris bootstrap cleanup macpkg.pmproj.in testbootstrap test
:/usr/pkgsrc/bootstrap $ echo '$var'
$var
:/usr/pkgsrc/bootstrap $ echo "$var"

ELFとか

$ more hello.c
#include 
int main(){
        puts("Hellom World!");
        return 0;
}

$ hd hello.o
00000000  7f 45 4c 46  01 01 01 00  00 00 00 00  00 00 00 00 |.ELF............|
00000010  01 00 03 00  01 00 00 00  00 00 00 00  00 00 00 00 |................|
00000020  fc 00 00 00  00 00 00 00  34 00 00 00  00 00 28 00 |........4.....(.|
00000030  0b 00 08 00  00 00 00 00  00 00 00 00  00 00 00 00 |................|
00000040  55 89 e5 83  ec 08 83 c4  f4 68 00 00  00 00 e8 fc |U........h......|
00000050  ff ff ff 83  c4 10 31 c0  eb 06 8d b6  00 00 00 00 |......1.........|
00000060  c9 c3 00 00  08 00 00 00  00 00 00 00  01 00 00 00 |................|
00000070  30 31 2e 30  31 00 00 00  48 65 6c 6c  6f 6d 20 57 |01.01...Hellom W|
00000080  6f 72 6c 64  21 00 00 47  43 43 3a 20  28 47 4e 55 |orld!..GCC: (GNU|
00000090  29 20 32 2e  39 35 2e 33  20 32 30 30  31 30 33 31 |) 2.95.3 2001031|
000000a0  35 20 28 72  65 6c 65 61  73 65 29 00  00 2e 73 79 |5 (release)...sy|
000000b0  6d 74 61 62  00 2e 73 74  72 74 61 62  00 2e 73 68 |mtab..strtab..sh|
000000c0  73 74 72 74  61 62 00 2e  74 65 78 74  00 2e 72 65 |strtab..text..re|
000000d0  6c 2e 74 65  78 74 00 2e  64 61 74 61  00 2e 62 73 |l.text..data..bs|
000000e0  73 00 2e 6e  6f 74 65 00  2e 72 6f 64  61 74 61 00 |s..note..rodata.|
000000f0  2e 63 6f 6d  6d 65 6e 74  00 00 00 00  00 00 00 00 |.comment........|
00000100  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00 |................|

$ objdump -d hello.o

hello.o:     file format elf32-i386

Disassembly of section .text:

00000000 
: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 08 sub $0x8,%esp 6: 83 c4 f4 add $0xfffffff4,%esp 9: 68 00 00 00 00 push $0x0 e: e8 fc ff ff ff call f 13: 83 c4 10 add $0x10,%esp 16: 31 c0 xor %eax,%eax 18: eb 06 jmp 20 1a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 20: c9 leave 21: c3 ret $ objdump -j .rodata -s hello.o hello.o: file format elf32-i386 Contents of section .rodata: 0000 48656c6c 6f6d2057 6f726c64 2100 Hellom World!. $ objdump -h hello.o hello.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000022 00000000 00000000 00000040 2**4 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .data 00000000 00000000 00000000 00000064 2**2 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 00000064 2**2 ALLOC 3 .note 00000014 00000000 00000000 00000064 2**0 CONTENTS, READONLY 4 .rodata 0000000e 00000000 00000000 00000078 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .comment 00000026 00000000 00000000 00000086 2**0 CONTENTS, READONLY

readelfが無いから、objdump -hを使わんと...

知らなかったそんなの•••

http://slashdot.jp/story/02/08/27/1034257/NetBSD%E3%81%8C%E5%85%A8%E3%81%A6%E3%81%AEexecutable%E3%82%92dynamic-link%E3%81%AB
を読んで
>というか /sbin は system programs and adiministration utilities を おく場所ですよ? see hier(7)

HIER(7)                      BSD Reference Manual                      HIER(7)

NAME
     hier - layout of filesystems

DESCRIPTION
     A sketch of the filesystem hierarchy.

     /        root directory of the filesystem

     /boot    executable that loads /bsd; /boot is loaded by the block 0 boot-
              strap

     /bsd     pure kernel executable (the operating system loaded into memory
              at boot time by /boot)

...
HISTORY
     A hier manual page appeared in Version 7 AT&T UNIX.

BSDI BSD/OS                      June 5, 1993                                4

A hier manual page appeared in Version 7 AT&T UNIX.
ずいぶん古いな。昔の人もディレクトリの使用方法に悩んだのかしら?

gcc プリプロセッサ

gcc
E付でプリプロセッサが終わった状態で止めたやつと、
cpp0を指定して、プリプロセッサが終わった状態で止めたやつの
サイズの差が気になって調べていたら、
/usr/include/machine/types.hの

/*
 * Deal with 64-bit types, which are not defined by ANSI C.
 */
#if __GNUC__ >= 2
/* This ugly hack prevents warnings from -pedantic. */
typedef long                      int64_t __attribute__ ((__mode__(__DI__)));
typedef unsigned long           u_int64_t __attribute__ ((__mode__(__DI__)));
typedef long                      int64m_t __attribute__ ((__mode__(__DI__)));
typedef unsigned long           u_int64m_t __attribute__ ((__mode__(__DI__)));
#else
/* The following are probably correct for most other compilers */
typedef long long                 int64_t;
typedef unsigned long long      u_int64_t;
typedef long long                 int64m_t;
typedef unsigned long long      u_int64m_t;
#endif

に書いてあった。
gccドライバ経由だと、

 /usr/libexec/gcc-2.95.3/i386-unknown-bsdielf4.2/2.95.3/cpp0 -lang-c -v -D__GNUC__=2 
-D__GNUC_MINOR__=95 -Dunix -D__i386__ -Di386 -D__bsdi__ -Dbsdi -D__ELF__ 
-D__GAS__=2 -D__GAS_MINOR__=10 -D__unix__ -D__i386__ -D__i386__ -D__bsdi__ -D__bsdi__ -D__ELF__ 
-D__GAS__=2 -D__GAS_MINOR__=10 -D__unix -D__i386 -D__bsdi -Asystem(unix) -Asystem(bsd) 
-Acpu(i386) -Amachine(i386) -traditional -$ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -

で指定してあるからね。