Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wangbj@localhost ~/test $ ghci -v
- GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
- Glasgow Haskell Compiler, Version 7.4.1, stage 2 booted by GHC version 7.4.1
- Using binary package database: /usr/lib64/ghc-7.4.1/package.conf.d/package.cache
- hiding package time-1.4 to avoid conflict with later version time-1.4.0.1
- wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-c2ff696e5b8ec4d4b2bc2e42085fe471
- wired-in package integer-gmp mapped to integer-gmp-0.4.0.0-3cccac07aef8e27023f605c1f45bdf74
- wired-in package base mapped to base-4.5.0.0-40b99d05fae6a4eea95ea69e6e0c9702
- wired-in package rts mapped to builtin_rts
- wired-in package template-haskell mapped to template-haskell-2.7.0.0-8c8cd20e21666657195efabced685fe1
- wired-in package dph-seq not found.
- wired-in package dph-par not found.
- Hsc static flags: -static
- Loading package ghc-prim ... linking ... done.
- *** gcc:
- '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'
- Loading package integer-gmp ... linking ... done.
- 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'
- *** Deleting temp files:
- Deleting:
- *** Deleting temp dirs:
- Deleting:
- ghc: unable to load package `base'
- wangbj@localhost ~/test $
- I create a simple program for testing ``stat'':
- $ cat ex98.c
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdio.h>
- int main(int argc, char* argv[])
- {
- struct stat st;
- stat (argv[0], &st);
- return 0;
- }
- $ readelf -s ex98 | grep stat
- 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __xstat@GLIBC_2.2.5 (2)
- 39: 0000000000400670 16 FUNC GLOBAL HIDDEN 13 __stat
- 40: 0000000000400670 16 FUNC WEAK HIDDEN 13 stat
- 43: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __xstat@@GLIBC_2.2.5
- GLIBC (2.15) don't have symbol for function ``stat'' (or __stat):
- wangbj@localhost ~/test $ readelf -s /lib64/libc.so.6 | grep 'stat\>'
- 65: 0000000000077730 16 FUNC GLOBAL DEFAULT 12 _IO_file_stat@@GLIBC_2.2.5
- 452: 00000000000dc8d0 69 FUNC GLOBAL DEFAULT 12 __lxstat@@GLIBC_2.2.5
- 1466: 00000000000dc880 69 FUNC GLOBAL DEFAULT 12 __fxstat@@GLIBC_2.2.5
- 1513: 00000000000ea300 69 FUNC GLOBAL DEFAULT 12 ustat@@GLIBC_2.2.5
- 1929: 00000000000dc830 69 FUNC GLOBAL DEFAULT 12 __xstat@@GLIBC_2.2.5
- If I objdump ex98:
- 0000000000400594 <main>:
- 400594: 55 push %rbp
- 400595: 48 89 e5 mov %rsp,%rbp
- 400598: 48 81 ec a0 00 00 00 sub $0xa0,%rsp
- 40059f: 89 bd 6c ff ff ff mov %edi,-0x94(%rbp)
- 4005a5: 48 89 b5 60 ff ff ff mov %rsi,-0xa0(%rbp)
- 4005ac: 48 8b 85 60 ff ff ff mov -0xa0(%rbp),%rax
- 4005b3: 48 8b 00 mov (%rax),%rax
- 4005b6: 48 8d 95 70 ff ff ff lea -0x90(%rbp),%rdx
- 4005bd: 48 89 d6 mov %rdx,%rsi
- 4005c0: 48 89 c7 mov %rax,%rdi
- 4005c3: e8 a8 00 00 00 callq 400670 <__stat>
- 4005c8: b8 00 00 00 00 mov $0x0,%eax
- 4005cd: c9 leaveq
- 4005ce: c3 retq
- 4005cf: 90 nop
- ...
- 0000000000400670 <__stat>:
- 400670: 48 89 f2 mov %rsi,%rdx
- 400673: 48 89 fe mov %rdi,%rsi
- 400676: bf 01 00 00 00 mov $0x1,%edi
- 40067b: e9 20 fe ff ff jmpq 4004a0 <__xstat@plt>
- 400680: 55 push %rbp
- 400681: 48 89 e5 mov %rsp,%rbp
- 400684: 53 push %rbx
- 400685: 48 83 ec 08 sub $0x8,%rsp
- 400689: 48 8b 05 58 07 20 00 mov 0x200758(%rip),%rax # 600de8 <__init_array_end+0x4>
- 400690: 48 83 f8 ff cmp $0xffffffffffffffff,%rax
- 400694: 74 19 je 4006af <__stat+0x3f>
- 400696: bb e8 0d 60 00 mov $0x600de8,%ebx
- 40069b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
- 4006a0: 48 83 eb 08 sub $0x8,%rbx
- 4006a4: ff d0 callq *%rax
- 4006a6: 48 8b 03 mov (%rbx),%rax
- 4006a9: 48 83 f8 ff cmp $0xffffffffffffffff,%rax
- 4006ad: 75 f1 jne 4006a0 <__stat+0x30>
- 4006af: 48 83 c4 08 add $0x8,%rsp
- 4006b3: 5b pop %rbx
- 4006b4: c9 leaveq
- 4006b5: c3 retq
- 4006b6: 90 nop
- 4006b7: 90 nop
- So it seems GCC will create its own stat, and will call __xstat@plt from glibc, not the plain ``stat''.
- in /usr/include/sys/stat.h:
- #if defined __GNUC__ && __GNUC__ >= 2 && defined __USE_EXTERN_INLINES
- /* Inlined versions of the real stat and mknod functions. */
- __extern_inline int
- __NTH (stat (__const char *__path, struct stat *__statbuf))
- {
- return __xstat (_STAT_VER, __path, __statbuf);
- }
- So it should be an error that HSbase.o linked agaist ``stat'' directly?
Advertisement
Add Comment
Please, Sign In to add comment