$ nm -A libjpeg.a
libjpeg.a:jcapimin.o:00000330 T jpeg_CreateCompress
libjpeg.a:jcapimin.o: U jpeg_abort
libjpeg.a:jcapistd.o: U jinit_compress_master
libjpeg.a:jcapistd.o:000001b0 T jpeg_start_compress
libjpeg.a:jctrans.o:000000c0 t compress_output
libjpeg.a:jctrans.o: U jinit_c_master_control
libjpeg.a:jcparam.o:000008a0 t add_huff_table
libjpeg.a:jcparam.o:000000e2 r bits_ac_chrominance.3846
... 파일별로 반복
'
U,T,r 등은 symbol type 이라고 하며,
위의 U는 Undefined 을, T는 Text section(code) 을 의미한다.
$ nm --help
Usage: nm [option(s)] [file(s)]
List symbols in [file(s)] (a.out by default).
The options are:
-a, --debug-syms Display debugger-only symbols
-A, --print-file-name Print name of the input file before every symbol
-B Same as --format=bsd
-C, --demangle[=STYLE] Decode low-level symbol names into user-level names
The STYLE, if specified, can be `auto' (the default),
`gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'
or `gnat'
--no-demangle Do not demangle low-level symbol names
-D, --dynamic Display dynamic symbols instead of normal symbols
--defined-only Display only defined symbols
-e (ignored)
-f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',
`sysv' or `posix'. The default is `bsd'
-g, --extern-only Display only external symbols
-l, --line-numbers Use debugging information to find a filename and
line number for each symbol
-n, --numeric-sort Sort symbols numerically by address
-o Same as -A
-p, --no-sort Do not sort the symbols
-P, --portability Same as --format=posix
-r, --reverse-sort Reverse the sense of the sort
-S, --print-size Print size of defined symbols
-s, --print-armap Include index for symbols from archive members
--size-sort Sort symbols by size
--special-syms Include special symbols in the output
--synthetic Display synthetic symbols as well
-t, --radix=RADIX Use RADIX for printing symbol values
--target=BFDNAME Specify the target object format as BFDNAME
-u, --undefined-only Display only undefined symbols
-X 32_64 (ignored)
@FILE Read options from FILE
-h, --help Display this information
-V, --version Display this program's version number
DESCRIPTION
GNU nm lists the symbols from object files objfile.... If no object files are listed as argu-
ments, nm assumes the file a.out.
For each symbol, nm shows:
o The symbol value, in the radix selected by options (see below), or hexadecimal by default.
o The symbol type. At least the following types are used; others are, as well, depending on
the object file format. If lowercase, the symbol is local; if uppercase, the symbol is
global (external).
"A" The symbol's value is absolute, and will not be changed by further linking.
"B"
"b" The symbol is in the uninitialized data section (known as BSS).
"C" The symbol is common. Common symbols are uninitialized data. When linking, multiple
common symbols may appear with the same name. If the symbol is defined anywhere, the
common symbols are treated as undefined references.
"D"
"d" The symbol is in the initialized data section.
"G"
"g" The symbol is in an initialized data section for small objects. Some object file formats
permit more efficient access to small data objects, such as a global int variable as
opposed to a large global array.
"I" The symbol is an indirect reference to another symbol. This is a GNU extension to the
a.out object file format which is rarely used.
"i" The symbol is in a section specific to the implementation of DLLs.
"N" The symbol is a debugging symbol.
"p" The symbols is in a stack unwind section.
"R"
"r" The symbol is in a read only data section.
"S"
"s" The symbol is in an uninitialized data section for small objects.
"T"
"t" The symbol is in the text (code) section.
"U" The symbol is undefined.
"V"
"v" The symbol is a weak object. When a weak defined symbol is linked with a normal defined
symbol, the normal defined symbol is used with no error. When a weak undefined symbol is
linked and the symbol is not defined, the value of the weak symbol becomes zero with no
error. On some systems, uppercase indicates that a default value has been specified.
"W"
"w" The symbol is a weak symbol that has not been specifically tagged as a weak object sym-
bol. When a weak defined symbol is linked with a normal defined symbol, the normal
defined symbol is used with no error. When a weak undefined symbol is linked and the
symbol is not defined, the value of the symbol is determined in a system-specific manner
without error. On some systems, uppercase indicates that a default value has been speci-
fied.
"-" The symbol is a stabs symbol in an a.out object file. In this case, the next values
printed are the stabs other field, the stabs desc field, and the stab type. Stabs sym-
bols are used to hold debugging information.
"?" The symbol type is unknown, or object file format specific.
$ ar -t libjpeg.a
jcapimin.o
jcapistd.o
jctrans.o
jcparam.o
jdatadst.o
...
$ ar --help
Usage: ar [emulation options] [-]{dmpqrstx}[abcfilNoPsSuvV] [member-name] [count] archive-file file...
ar -M [<mri-script]
commands:
d - delete file(s) from the archive
m[ab] - move file(s) in the archive
p - print file(s) found in the archive
q[f] - quick append file(s) to the archive
r[ab][f][u] - replace existing or insert new file(s) into the archive t - display contents of archive
x[o] - extract file(s) from the archive
command specific modifiers:
[a] - put file(s) after [member-name]
[b] - put file(s) before [member-name] (same as [i])
[N] - use instance [count] of name
[f] - truncate inserted file names
[P] - use full path names when matching
[o] - preserve original dates
[u] - only replace files that are newer than current archive contents
generic modifiers:
[c] - do not warn if the library had to be created
[s] - create an archive index (cf. ranlib)
[S] - do not build a symbol table
[T] - make a thin archive
[v] - be verbose
[V] - display the version number
@<file> - read options from <file>
emulation options:
No emulation specific options
ar: supported targets: elf32-i386 a.out-i386-linux efi-app-ia32
efi-bsdrv-ia32 efi-rtdrv-ia32 elf32-little elf32-big elf64-x86-64
efi-app-x86_64 efi-bsdrv-x86_64 efi-rtdrv-x86_64 elf64-little elf64-big
srec symbolsrec tekhex binary ihex trad-core
Report bugs to <http://www.sourceware.org/bugzilla/>
Sections:
SYMBOL TABLE:
RELOCATION RECORDS FOR [.text]:
... 파일별로 반복
$ objdump --help
Usage: objdump <option(s)> <file(s)>
Display information from object <file(s)>.
At least one of the following switches must be given:
-a, --archive-headers Display archive header information
-f, --file-headers Display the contents of the overall file header
-p, --private-headers Display object format specific file header contents
-h, --[section-]headers Display the contents of the section headers -x, --all-headers Display the contents of all headers
-d, --disassemble Display assembler contents of executable sections
-D, --disassemble-all Display assembler contents of all sections
-S, --source Intermix source code with disassembly
-s, --full-contents Display the full contents of all sections requested
-g, --debugging Display debug information in object file
-e, --debugging-tags Display debug information using ctags style
-G, --stabs Display (in raw form) any STABS info in the file
-W, --dwarf Display DWARF info in the file
-t, --syms Display the contents of the symbol table(s)
-T, --dynamic-syms Display the contents of the dynamic symbol table
-r, --reloc Display the relocation entries in the file
-R, --dynamic-reloc Display the dynamic relocation entries in the file
@<file> Read options from <file>
-v, --version Display this program's version number
-i, --info List object formats and architectures supported
-H, --help Display this information
The following switches are optional:
-b, --target=BFDNAME Specify the target object format as BFDNAME
-m, --architecture=MACHINE Specify the target architecture as MACHINE
-j, --section=NAME Only display information for section NAME
-M, --disassembler-options=OPT Pass text OPT on to the disassembler
-EB --endian=big Assume big endian format when disassembling
-EL --endian=little Assume little endian format when disassembling
--file-start-context Include context from start of file (with -S)
-I, --include=DIR Add DIR to search list for source files
-l, --line-numbers Include line numbers and filenames in output
-F, --file-offsets Include file offsets when displaying information
-C, --demangle[=STYLE] Decode mangled/processed symbol names
The STYLE, if specified, can be `auto', `gnu',
`lucid', `arm', `hp', `edg', `gnu-v3', `java'
or `gnat'
-w, --wide Format output for more than 80 columns
-z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling
--start-address=ADDR Only process data whose address is >= ADDR
--stop-address=ADDR Only process data whose address is <= ADDR
--prefix-addresses Print complete address alongside disassembly
--[no-]show-raw-insn Display hex alongside symbolic disassembly
--adjust-vma=OFFSET Add OFFSET to all displayed section addresses
--special-syms Include special symbols in symbol dumps
The following i386/x86-64 specific disassembler options are supported for use
with the -M switch (multiple options should be separated by commas):
x86-64 Disassemble in 64bit mode
i386 Disassemble in 32bit mode
i8086 Disassemble in 16bit mode
att Display instruction in AT&T syntax
intel Display instruction in Intel syntax
att-mnemonic
Display instruction in AT&T mnemonic
intel-mnemonic
Display instruction in Intel mnemonic
addr64 Assume 64bit address size
addr32 Assume 32bit address size
addr16 Assume 16bit address size
data32 Assume 32bit data size
data16 Assume 16bit data size
suffix Always display instruction suffix in AT&T syntax
Report bugs to <http://www.sourceware.org/bugzilla/>.
mangling은 컴파일러에서 이름이 중복되지 않도록 독특한 이름을 지어주는 것으로
C++에서 overloading을 지원하기 하는데 사용되기도 한다고 한다. [링크 : http://rubyeye.kr/]
int _cdecl f (int x) { return 0; } // _f
int _stdcall g (int y) { return 0; } // _g@4
int _fastcall h (int z) { return 0; } // @h@4
$ c++filt --help
Usage: c++filt [options] [mangled names]
Options are:
[-_|--strip-underscore] Ignore first leading underscore
[-n|--no-strip-underscore] Do not ignore a leading underscore (default)
[-p|--no-params] Do not display function arguments
[-i|--no-verbose] Do not show implementation details (if any)
[-t|--types] Also attempt to demangle type encodings
[-s|--format {none,auto,gnu,lucid,arm,hp,edg,gnu-v3,java,gnat}]
[@<file>] Read extra options from <file>
[-h|--help] Display this information
[-v|--version] Show the version information
Demangled names are displayed to stdout.
If a name cannot be demangled it is just echoed to stdout.
If no names are provided on the command line, stdin is read.
Report bugs to <http://www.sourceware.org/bugzilla/>.
간단하게 설명을 하자면,
for문을 돌릴때 어느 시점에서 증가가 이루어지고, ++연산자가 적용되는 시점, 그리고 연산자 우선순위 대한 문제이다.
(개인적으로 이런 문제 싫어 한다. 가독성 지랄 같이 하면 다른 사람이 어떻게 수정하라고 ㄱ-)
아무튼 for문의 ([초기화];[조건];[증가]) 에서 증가문은 마지막 닫히는 } 부분에서 증가가 이루어 지고,
이로 인해서 더해지는 값이 달라지는 현상이 발생이 되게 된다.
65짜리는 2에서 11 까지 더하게 되고
55짜리는 1에서 10 까지 더하게 된다.
같은 i < 11 조건이지만,
증가되고 더해지고, 더해지고 증가됨의 차이가 있기 때문에 결과는 55와 65로 벌어지게 된다.
원본 코드 - 결과 65 짜리
sum = 0 ;
i = 1 ;
for( ; i<11 ;)
sum += ++i ;
변형된 코드 1 - for문에 초기화 넣어줌
for(sum = 0,i=1;i<11;)
sum += ++i;
변형된 코드 2 - while문으로 변형
sum = 0 ;
i=1;
while(i<11)
{
sum += ++i;
}
변형된 코드 3 - goto문으로 변형
sum = 0 ;
i = 1;
while_loop:
{
if(i<11) ;
else break;
++i;
sum += i;
}
goto while_loop:
원본 코드 - 결과 값 55 짜리
sum = 0 ;
i = 1 ;
for( ; i<11 ; ++i)
sum += 1 ;
변형된 코드 1 - for문에 초기화 넣어줌
for(sum = 0,i=1;i<11;++i)
sum += 1;
변형된 코드 2 - for문에 초기화 넣어줌
sum = 0 ;
i=1;
while(i<11)
{
sum += 1;
++i;
}
변형된 코드 3 - goto문으로 변형
sum = 0 ;
i =1;
while_loop:
{
if(i<11) ;
else break;
sum += 1;
++i;
}
goto while_loop:
main 함수의 기본 프로토타입은 int main(int argc, char *argv[]) 이다.
물론 귀찮아서 void main()으로 주로 쓰긴 하지만, 인자를 받기 위해서는 저 프로토타입을 써야 한다.
아무튼 막상 인자로 받다가 그 인자를 만들어 내려니 자꾸만 안되서 머리를 데굴데굴 굴려봤다.
Besides, unix way is to be ascetic and elegant, avoiding putting messy and slow algorithms under the hood, and filecopy is definitely slow ( you want syscall with fast filecopy - great, here's hardlink for you ).
생각해보니.. UNIX의 설계 철학중 simple is beautiful이 근간이 되어 있다는게 생각이 났다.
cp() 가 빈번하게 사용될지라도, 느린 함수이고(최소한 fopen/fread/fwrite/fclose 4개의 함수를 사용한다)
이러한 복잡한 함수는 단순함의 철학에 위배가 되기에 많이 사용함에도 불구하고
cp() 라는 함수가 존재하지 않는것 같다.
그래도...
rename() remove() 이런건 있으면서 cp()가 없다는 건 웬지 억울한 느낌?
int cp(char *dest, char *sour)
{
FILE *dst;
FILE *src;
int readlen;
unsigned char buf[1024];