SHOW:
|
|
- or go back to the newest paste.
1 | wangbj@localhost ~/test $ ghci -v | |
2 | GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help | |
3 | Glasgow Haskell Compiler, Version 7.4.1, stage 2 booted by GHC version 7.4.1 | |
4 | Using binary package database: /usr/lib64/ghc-7.4.1/package.conf.d/package.cache | |
5 | hiding package time-1.4 to avoid conflict with later version time-1.4.0.1 | |
6 | wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-c2ff696e5b8ec4d4b2bc2e42085fe471 | |
7 | wired-in package integer-gmp mapped to integer-gmp-0.4.0.0-3cccac07aef8e27023f605c1f45bdf74 | |
8 | wired-in package base mapped to base-4.5.0.0-40b99d05fae6a4eea95ea69e6e0c9702 | |
9 | wired-in package rts mapped to builtin_rts | |
10 | wired-in package template-haskell mapped to template-haskell-2.7.0.0-8c8cd20e21666657195efabced685fe1 | |
11 | wired-in package dph-seq not found. | |
12 | wired-in package dph-par not found. | |
13 | Hsc static flags: -static | |
14 | Loading package ghc-prim ... linking ... done. | |
15 | *** gcc: | |
16 | 'gcc' '-fno-stack-protector' '-Wl,--hash-size=31' '-Wl,--reduce-memory-overheads' '-L/usr/lib64/ghc-7.4.1/integer-gmp-0.4.0.0' '--print-file-name' 'libgmp.so' | |
17 | Loading package integer-gmp ... linking ... done. | |
18 | Loading package base ... linking ... ghc: /usr/lib64/ghc-7.4.1/base-4.5.0.0/HSbase-4.5.0.0.o: unknown symbol `stat' | |
19 | *** Deleting temp files: | |
20 | Deleting: | |
21 | *** Deleting temp dirs: | |
22 | Deleting: | |
23 | ghc: unable to load package `base' | |
24 | wangbj@localhost ~/test $ | |
25 | ||
26 | ||
27 | ||
28 | I create a simple program for testing ``stat'': | |
29 | ||
30 | $ cat ex98.c | |
31 | #include <sys/types.h> | |
32 | #include <sys/stat.h> | |
33 | ||
34 | #include <stdio.h> | |
35 | ||
36 | int main(int argc, char* argv[]) | |
37 | { | |
38 | struct stat st; | |
39 | ||
40 | stat (argv[0], &st); | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
45 | ||
46 | $ readelf -s ex98 | grep stat | |
47 | 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __xstat@GLIBC_2.2.5 (2) | |
48 | 39: 0000000000400670 16 FUNC GLOBAL HIDDEN 13 __stat | |
49 | 40: 0000000000400670 16 FUNC WEAK HIDDEN 13 stat | |
50 | 43: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __xstat@@GLIBC_2.2.5 | |
51 | ||
52 | GLIBC (2.15) don't have symbol for function ``stat'' (or __stat): | |
53 | ||
54 | wangbj@localhost ~/test $ readelf -s /lib64/libc.so.6 | grep 'stat\>' | |
55 | 65: 0000000000077730 16 FUNC GLOBAL DEFAULT 12 _IO_file_stat@@GLIBC_2.2.5 | |
56 | 452: 00000000000dc8d0 69 FUNC GLOBAL DEFAULT 12 __lxstat@@GLIBC_2.2.5 | |
57 | 1466: 00000000000dc880 69 FUNC GLOBAL DEFAULT 12 __fxstat@@GLIBC_2.2.5 | |
58 | 1513: 00000000000ea300 69 FUNC GLOBAL DEFAULT 12 ustat@@GLIBC_2.2.5 | |
59 | 1929: 00000000000dc830 69 FUNC GLOBAL DEFAULT 12 __xstat@@GLIBC_2.2.5 | |
60 | ||
61 | If I objdump ex98: | |
62 | ||
63 | 0000000000400594 <main>: | |
64 | 400594: 55 push %rbp | |
65 | 400595: 48 89 e5 mov %rsp,%rbp | |
66 | 400598: 48 81 ec a0 00 00 00 sub $0xa0,%rsp | |
67 | 40059f: 89 bd 6c ff ff ff mov %edi,-0x94(%rbp) | |
68 | 4005a5: 48 89 b5 60 ff ff ff mov %rsi,-0xa0(%rbp) | |
69 | 4005ac: 48 8b 85 60 ff ff ff mov -0xa0(%rbp),%rax | |
70 | 4005b3: 48 8b 00 mov (%rax),%rax | |
71 | 4005b6: 48 8d 95 70 ff ff ff lea -0x90(%rbp),%rdx | |
72 | 4005bd: 48 89 d6 mov %rdx,%rsi | |
73 | 4005c0: 48 89 c7 mov %rax,%rdi | |
74 | 4005c3: e8 a8 00 00 00 callq 400670 <__stat> | |
75 | 4005c8: b8 00 00 00 00 mov $0x0,%eax | |
76 | 4005cd: c9 leaveq | |
77 | 4005ce: c3 retq | |
78 | 4005cf: 90 nop | |
79 | ||
80 | ... | |
81 | ||
82 | ||
83 | 0000000000400670 <__stat>: | |
84 | 400670: 48 89 f2 mov %rsi,%rdx | |
85 | 400673: 48 89 fe mov %rdi,%rsi | |
86 | 400676: bf 01 00 00 00 mov $0x1,%edi | |
87 | 40067b: e9 20 fe ff ff jmpq 4004a0 <__xstat@plt> | |
88 | 400680: 55 push %rbp | |
89 | 400681: 48 89 e5 mov %rsp,%rbp | |
90 | 400684: 53 push %rbx | |
91 | 400685: 48 83 ec 08 sub $0x8,%rsp | |
92 | 400689: 48 8b 05 58 07 20 00 mov 0x200758(%rip),%rax # 600de8 <__init_array_end+0x4> | |
93 | 400690: 48 83 f8 ff cmp $0xffffffffffffffff,%rax | |
94 | 400694: 74 19 je 4006af <__stat+0x3f> | |
95 | 400696: bb e8 0d 60 00 mov $0x600de8,%ebx | |
96 | 40069b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) | |
97 | 4006a0: 48 83 eb 08 sub $0x8,%rbx | |
98 | 4006a4: ff d0 callq *%rax | |
99 | 4006a6: 48 8b 03 mov (%rbx),%rax | |
100 | 4006a9: 48 83 f8 ff cmp $0xffffffffffffffff,%rax | |
101 | 4006ad: 75 f1 jne 4006a0 <__stat+0x30> | |
102 | 4006af: 48 83 c4 08 add $0x8,%rsp | |
103 | 4006b3: 5b pop %rbx | |
104 | 4006b4: c9 leaveq | |
105 | 4006b5: c3 retq | |
106 | 4006b6: 90 nop | |
107 | 4006b7: 90 nop | |
108 | ||
109 | ||
110 | - | So it seems GCC will create its own stat, and will call __xstat@plt from glibc, not the plain ``stat''. |
110 | + | So it seems GCC will create its own stat, and will call __xstat@plt from glibc, not the plain ``stat''. |
111 | ||
112 | in /usr/include/sys/stat.h: | |
113 | ||
114 | #if defined __GNUC__ && __GNUC__ >= 2 && defined __USE_EXTERN_INLINES | |
115 | /* Inlined versions of the real stat and mknod functions. */ | |
116 | ||
117 | __extern_inline int | |
118 | __NTH (stat (__const char *__path, struct stat *__statbuf)) | |
119 | { | |
120 | return __xstat (_STAT_VER, __path, __statbuf); | |
121 | } | |
122 | ||
123 | So it should be an error that HSbase.o linked agaist ``stat'' directly? |