PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ghc-7.0.4/rts/Linker.c

http://picorec.googlecode.com/
C | 1526 lines | 1199 code | 117 blank | 210 comment | 94 complexity | a6888914a5d23ce40b8b99dfcf181f56 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. /* -----------------------------------------------------------------------------
  2. *
  3. * (c) The GHC Team, 2000-2004
  4. *
  5. * RTS Object Linker
  6. *
  7. * ---------------------------------------------------------------------------*/
  8. #if 0
  9. #include "PosixSource.h"
  10. #endif
  11. /* Linux needs _GNU_SOURCE to get RTLD_DEFAULT from <dlfcn.h> and
  12. MREMAP_MAYMOVE from <sys/mman.h>.
  13. */
  14. #ifdef __linux__
  15. #define _GNU_SOURCE
  16. #endif
  17. #include "Rts.h"
  18. #include "HsFFI.h"
  19. #include "sm/Storage.h"
  20. #include "Stats.h"
  21. #include "Hash.h"
  22. #include "LinkerInternals.h"
  23. #include "RtsUtils.h"
  24. #include "Trace.h"
  25. #include "StgPrimFloat.h" // for __int_encodeFloat etc.
  26. #include "Stable.h"
  27. #if !defined(mingw32_HOST_OS)
  28. #include "posix/Signals.h"
  29. #endif
  30. // get protos for is*()
  31. #include <ctype.h>
  32. #ifdef HAVE_SYS_TYPES_H
  33. #include <sys/types.h>
  34. #endif
  35. #include <inttypes.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <assert.h>
  40. #ifdef HAVE_SYS_STAT_H
  41. #include <sys/stat.h>
  42. #endif
  43. #if defined(HAVE_DLFCN_H)
  44. #include <dlfcn.h>
  45. #endif
  46. #if defined(cygwin32_HOST_OS)
  47. #ifdef HAVE_DIRENT_H
  48. #include <dirent.h>
  49. #endif
  50. #ifdef HAVE_SYS_TIME_H
  51. #include <sys/time.h>
  52. #endif
  53. #include <regex.h>
  54. #include <sys/fcntl.h>
  55. #include <sys/termios.h>
  56. #include <sys/utime.h>
  57. #include <sys/utsname.h>
  58. #include <sys/wait.h>
  59. #endif
  60. #if defined(linux_HOST_OS ) || defined(freebsd_HOST_OS) || \
  61. defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
  62. defined(openbsd_HOST_OS ) || \
  63. ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) )
  64. /* Don't use mmap on powerpc-apple-darwin as mmap doesn't support
  65. * reallocating but we need to allocate jump islands just after each
  66. * object images. Otherwise relative branches to jump islands can fail
  67. * due to 24-bits displacement overflow.
  68. */
  69. #define USE_MMAP
  70. #include <fcntl.h>
  71. #include <sys/mman.h>
  72. #ifdef HAVE_UNISTD_H
  73. #include <unistd.h>
  74. #endif
  75. #endif
  76. #if defined(linux_HOST_OS) || defined(solaris2_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
  77. # define OBJFORMAT_ELF
  78. # include <regex.h> // regex is already used by dlopen() so this is OK
  79. // to use here without requiring an additional lib
  80. #elif defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS)
  81. # define OBJFORMAT_PEi386
  82. # include <windows.h>
  83. # include <math.h>
  84. #elif defined(darwin_HOST_OS)
  85. # define OBJFORMAT_MACHO
  86. # include <regex.h>
  87. # include <mach-o/loader.h>
  88. # include <mach-o/nlist.h>
  89. # include <mach-o/reloc.h>
  90. #if !defined(HAVE_DLFCN_H)
  91. # include <mach-o/dyld.h>
  92. #endif
  93. #if defined(powerpc_HOST_ARCH)
  94. # include <mach-o/ppc/reloc.h>
  95. #endif
  96. #if defined(x86_64_HOST_ARCH)
  97. # include <mach-o/x86_64/reloc.h>
  98. #endif
  99. #endif
  100. #if defined(x86_64_HOST_ARCH) && defined(darwin_HOST_OS)
  101. #define ALWAYS_PIC
  102. #endif
  103. /* Hash table mapping symbol names to Symbol */
  104. static /*Str*/HashTable *symhash;
  105. /* Hash table mapping symbol names to StgStablePtr */
  106. static /*Str*/HashTable *stablehash;
  107. /* List of currently loaded objects */
  108. ObjectCode *objects = NULL; /* initially empty */
  109. static HsInt loadOc( ObjectCode* oc );
  110. static ObjectCode* mkOc( char *path, char *image, int imageSize,
  111. char *archiveMemberName
  112. #ifndef USE_MMAP
  113. #ifdef darwin_HOST_OS
  114. , int misalignment
  115. #endif
  116. #endif
  117. );
  118. #if defined(OBJFORMAT_ELF)
  119. static int ocVerifyImage_ELF ( ObjectCode* oc );
  120. static int ocGetNames_ELF ( ObjectCode* oc );
  121. static int ocResolve_ELF ( ObjectCode* oc );
  122. #if defined(powerpc_HOST_ARCH) || defined(x86_64_HOST_ARCH)
  123. static int ocAllocateSymbolExtras_ELF ( ObjectCode* oc );
  124. #endif
  125. #elif defined(OBJFORMAT_PEi386)
  126. static int ocVerifyImage_PEi386 ( ObjectCode* oc );
  127. static int ocGetNames_PEi386 ( ObjectCode* oc );
  128. static int ocResolve_PEi386 ( ObjectCode* oc );
  129. static void *lookupSymbolInDLLs ( unsigned char *lbl );
  130. static void zapTrailingAtSign ( unsigned char *sym );
  131. #elif defined(OBJFORMAT_MACHO)
  132. static int ocVerifyImage_MachO ( ObjectCode* oc );
  133. static int ocGetNames_MachO ( ObjectCode* oc );
  134. static int ocResolve_MachO ( ObjectCode* oc );
  135. #ifndef USE_MMAP
  136. static int machoGetMisalignment( FILE * );
  137. #endif
  138. #if defined(powerpc_HOST_ARCH) || defined(x86_64_HOST_ARCH)
  139. static int ocAllocateSymbolExtras_MachO ( ObjectCode* oc );
  140. #endif
  141. #ifdef powerpc_HOST_ARCH
  142. static void machoInitSymbolsWithoutUnderscore( void );
  143. #endif
  144. #endif
  145. /* on x86_64 we have a problem with relocating symbol references in
  146. * code that was compiled without -fPIC. By default, the small memory
  147. * model is used, which assumes that symbol references can fit in a
  148. * 32-bit slot. The system dynamic linker makes this work for
  149. * references to shared libraries by either (a) allocating a jump
  150. * table slot for code references, or (b) moving the symbol at load
  151. * time (and copying its contents, if necessary) for data references.
  152. *
  153. * We unfortunately can't tell whether symbol references are to code
  154. * or data. So for now we assume they are code (the vast majority
  155. * are), and allocate jump-table slots. Unfortunately this will
  156. * SILENTLY generate crashing code for data references. This hack is
  157. * enabled by X86_64_ELF_NONPIC_HACK.
  158. *
  159. * One workaround is to use shared Haskell libraries. This is
  160. * coming. Another workaround is to keep the static libraries but
  161. * compile them with -fPIC, because that will generate PIC references
  162. * to data which can be relocated. The PIC code is still too green to
  163. * do this systematically, though.
  164. *
  165. * See bug #781
  166. * See thread http://www.haskell.org/pipermail/cvs-ghc/2007-September/038458.html
  167. *
  168. * Naming Scheme for Symbol Macros
  169. *
  170. * SymI_*: symbol is internal to the RTS. It resides in an object
  171. * file/library that is statically.
  172. * SymE_*: symbol is external to the RTS library. It might be linked
  173. * dynamically.
  174. *
  175. * Sym*_HasProto : the symbol prototype is imported in an include file
  176. * or defined explicitly
  177. * Sym*_NeedsProto: the symbol is undefined and we add a dummy
  178. * default proto extern void sym(void);
  179. */
  180. #define X86_64_ELF_NONPIC_HACK 1
  181. /* Link objects into the lower 2Gb on x86_64. GHC assumes the
  182. * small memory model on this architecture (see gcc docs,
  183. * -mcmodel=small).
  184. *
  185. * MAP_32BIT not available on OpenBSD/amd64
  186. */
  187. #if defined(x86_64_HOST_ARCH) && defined(MAP_32BIT)
  188. #define TRY_MAP_32BIT MAP_32BIT
  189. #else
  190. #define TRY_MAP_32BIT 0
  191. #endif
  192. /*
  193. * Due to the small memory model (see above), on x86_64 we have to map
  194. * all our non-PIC object files into the low 2Gb of the address space
  195. * (why 2Gb and not 4Gb? Because all addresses must be reachable
  196. * using a 32-bit signed PC-relative offset). On Linux we can do this
  197. * using the MAP_32BIT flag to mmap(), however on other OSs
  198. * (e.g. *BSD, see #2063, and also on Linux inside Xen, see #2512), we
  199. * can't do this. So on these systems, we have to pick a base address
  200. * in the low 2Gb of the address space and try to allocate memory from
  201. * there.
  202. *
  203. * We pick a default address based on the OS, but also make this
  204. * configurable via an RTS flag (+RTS -xm)
  205. */
  206. #if !defined(ALWAYS_PIC) && defined(x86_64_HOST_ARCH)
  207. #if defined(MAP_32BIT)
  208. // Try to use MAP_32BIT
  209. #define MMAP_32BIT_BASE_DEFAULT 0
  210. #else
  211. // A guess: 1Gb.
  212. #define MMAP_32BIT_BASE_DEFAULT 0x40000000
  213. #endif
  214. static void *mmap_32bit_base = (void *)MMAP_32BIT_BASE_DEFAULT;
  215. #endif
  216. /* MAP_ANONYMOUS is MAP_ANON on some systems, e.g. OpenBSD */
  217. #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
  218. #define MAP_ANONYMOUS MAP_ANON
  219. #endif
  220. /* -----------------------------------------------------------------------------
  221. * Built-in symbols from the RTS
  222. */
  223. typedef struct _RtsSymbolVal {
  224. char *lbl;
  225. void *addr;
  226. } RtsSymbolVal;
  227. #define Maybe_Stable_Names SymI_HasProto(stg_mkWeakzh) \
  228. SymI_HasProto(stg_mkWeakForeignEnvzh) \
  229. SymI_HasProto(stg_makeStableNamezh) \
  230. SymI_HasProto(stg_finalizzeWeakzh)
  231. #if !defined (mingw32_HOST_OS)
  232. #define RTS_POSIX_ONLY_SYMBOLS \
  233. SymI_HasProto(__hscore_get_saved_termios) \
  234. SymI_HasProto(__hscore_set_saved_termios) \
  235. SymI_HasProto(shutdownHaskellAndSignal) \
  236. SymI_HasProto(lockFile) \
  237. SymI_HasProto(unlockFile) \
  238. SymI_HasProto(signal_handlers) \
  239. SymI_HasProto(stg_sig_install) \
  240. SymI_HasProto(rtsTimerSignal) \
  241. SymI_NeedsProto(nocldstop)
  242. #endif
  243. #if defined (cygwin32_HOST_OS)
  244. #define RTS_MINGW_ONLY_SYMBOLS /**/
  245. /* Don't have the ability to read import libs / archives, so
  246. * we have to stupidly list a lot of what libcygwin.a
  247. * exports; sigh.
  248. */
  249. #define RTS_CYGWIN_ONLY_SYMBOLS \
  250. SymI_HasProto(regfree) \
  251. SymI_HasProto(regexec) \
  252. SymI_HasProto(regerror) \
  253. SymI_HasProto(regcomp) \
  254. SymI_HasProto(__errno) \
  255. SymI_HasProto(access) \
  256. SymI_HasProto(chmod) \
  257. SymI_HasProto(chdir) \
  258. SymI_HasProto(close) \
  259. SymI_HasProto(creat) \
  260. SymI_HasProto(dup) \
  261. SymI_HasProto(dup2) \
  262. SymI_HasProto(fstat) \
  263. SymI_HasProto(fcntl) \
  264. SymI_HasProto(getcwd) \
  265. SymI_HasProto(getenv) \
  266. SymI_HasProto(lseek) \
  267. SymI_HasProto(open) \
  268. SymI_HasProto(fpathconf) \
  269. SymI_HasProto(pathconf) \
  270. SymI_HasProto(stat) \
  271. SymI_HasProto(pow) \
  272. SymI_HasProto(tanh) \
  273. SymI_HasProto(cosh) \
  274. SymI_HasProto(sinh) \
  275. SymI_HasProto(atan) \
  276. SymI_HasProto(acos) \
  277. SymI_HasProto(asin) \
  278. SymI_HasProto(tan) \
  279. SymI_HasProto(cos) \
  280. SymI_HasProto(sin) \
  281. SymI_HasProto(exp) \
  282. SymI_HasProto(log) \
  283. SymI_HasProto(sqrt) \
  284. SymI_HasProto(localtime_r) \
  285. SymI_HasProto(gmtime_r) \
  286. SymI_HasProto(mktime) \
  287. SymI_NeedsProto(_imp___tzname) \
  288. SymI_HasProto(gettimeofday) \
  289. SymI_HasProto(timezone) \
  290. SymI_HasProto(tcgetattr) \
  291. SymI_HasProto(tcsetattr) \
  292. SymI_HasProto(memcpy) \
  293. SymI_HasProto(memmove) \
  294. SymI_HasProto(realloc) \
  295. SymI_HasProto(malloc) \
  296. SymI_HasProto(free) \
  297. SymI_HasProto(fork) \
  298. SymI_HasProto(lstat) \
  299. SymI_HasProto(isatty) \
  300. SymI_HasProto(mkdir) \
  301. SymI_HasProto(opendir) \
  302. SymI_HasProto(readdir) \
  303. SymI_HasProto(rewinddir) \
  304. SymI_HasProto(closedir) \
  305. SymI_HasProto(link) \
  306. SymI_HasProto(mkfifo) \
  307. SymI_HasProto(pipe) \
  308. SymI_HasProto(read) \
  309. SymI_HasProto(rename) \
  310. SymI_HasProto(rmdir) \
  311. SymI_HasProto(select) \
  312. SymI_HasProto(system) \
  313. SymI_HasProto(write) \
  314. SymI_HasProto(strcmp) \
  315. SymI_HasProto(strcpy) \
  316. SymI_HasProto(strncpy) \
  317. SymI_HasProto(strerror) \
  318. SymI_HasProto(sigaddset) \
  319. SymI_HasProto(sigemptyset) \
  320. SymI_HasProto(sigprocmask) \
  321. SymI_HasProto(umask) \
  322. SymI_HasProto(uname) \
  323. SymI_HasProto(unlink) \
  324. SymI_HasProto(utime) \
  325. SymI_HasProto(waitpid)
  326. #elif !defined(mingw32_HOST_OS)
  327. #define RTS_MINGW_ONLY_SYMBOLS /**/
  328. #define RTS_CYGWIN_ONLY_SYMBOLS /**/
  329. #else /* defined(mingw32_HOST_OS) */
  330. #define RTS_POSIX_ONLY_SYMBOLS /**/
  331. #define RTS_CYGWIN_ONLY_SYMBOLS /**/
  332. #if HAVE_GETTIMEOFDAY
  333. #define RTS_MINGW_GETTIMEOFDAY_SYM SymI_NeedsProto(gettimeofday)
  334. #else
  335. #define RTS_MINGW_GETTIMEOFDAY_SYM /**/
  336. #endif
  337. #if HAVE___MINGW_VFPRINTF
  338. #define RTS___MINGW_VFPRINTF_SYM SymI_HasProto(__mingw_vfprintf)
  339. #else
  340. #define RTS___MINGW_VFPRINTF_SYM /**/
  341. #endif
  342. /* These are statically linked from the mingw libraries into the ghc
  343. executable, so we have to employ this hack. */
  344. #define RTS_MINGW_ONLY_SYMBOLS \
  345. SymI_HasProto(stg_asyncReadzh) \
  346. SymI_HasProto(stg_asyncWritezh) \
  347. SymI_HasProto(stg_asyncDoProczh) \
  348. SymI_HasProto(memset) \
  349. SymI_HasProto(inet_ntoa) \
  350. SymI_HasProto(inet_addr) \
  351. SymI_HasProto(htonl) \
  352. SymI_HasProto(recvfrom) \
  353. SymI_HasProto(listen) \
  354. SymI_HasProto(bind) \
  355. SymI_HasProto(shutdown) \
  356. SymI_HasProto(connect) \
  357. SymI_HasProto(htons) \
  358. SymI_HasProto(ntohs) \
  359. SymI_HasProto(getservbyname) \
  360. SymI_HasProto(getservbyport) \
  361. SymI_HasProto(getprotobynumber) \
  362. SymI_HasProto(getprotobyname) \
  363. SymI_HasProto(gethostbyname) \
  364. SymI_HasProto(gethostbyaddr) \
  365. SymI_HasProto(gethostname) \
  366. SymI_HasProto(strcpy) \
  367. SymI_HasProto(strncpy) \
  368. SymI_HasProto(abort) \
  369. SymI_NeedsProto(_alloca) \
  370. SymI_HasProto(isxdigit) \
  371. SymI_HasProto(isupper) \
  372. SymI_HasProto(ispunct) \
  373. SymI_HasProto(islower) \
  374. SymI_HasProto(isspace) \
  375. SymI_HasProto(isprint) \
  376. SymI_HasProto(isdigit) \
  377. SymI_HasProto(iscntrl) \
  378. SymI_HasProto(isalpha) \
  379. SymI_HasProto(isalnum) \
  380. SymI_HasProto(isascii) \
  381. RTS___MINGW_VFPRINTF_SYM \
  382. SymI_HasProto(strcmp) \
  383. SymI_HasProto(memmove) \
  384. SymI_HasProto(realloc) \
  385. SymI_HasProto(malloc) \
  386. SymI_HasProto(pow) \
  387. SymI_HasProto(tanh) \
  388. SymI_HasProto(cosh) \
  389. SymI_HasProto(sinh) \
  390. SymI_HasProto(atan) \
  391. SymI_HasProto(acos) \
  392. SymI_HasProto(asin) \
  393. SymI_HasProto(tan) \
  394. SymI_HasProto(cos) \
  395. SymI_HasProto(sin) \
  396. SymI_HasProto(exp) \
  397. SymI_HasProto(log) \
  398. SymI_HasProto(sqrt) \
  399. SymI_HasProto(powf) \
  400. SymI_HasProto(tanhf) \
  401. SymI_HasProto(coshf) \
  402. SymI_HasProto(sinhf) \
  403. SymI_HasProto(atanf) \
  404. SymI_HasProto(acosf) \
  405. SymI_HasProto(asinf) \
  406. SymI_HasProto(tanf) \
  407. SymI_HasProto(cosf) \
  408. SymI_HasProto(sinf) \
  409. SymI_HasProto(expf) \
  410. SymI_HasProto(logf) \
  411. SymI_HasProto(sqrtf) \
  412. SymI_HasProto(erf) \
  413. SymI_HasProto(erfc) \
  414. SymI_HasProto(erff) \
  415. SymI_HasProto(erfcf) \
  416. SymI_HasProto(memcpy) \
  417. SymI_HasProto(rts_InstallConsoleEvent) \
  418. SymI_HasProto(rts_ConsoleHandlerDone) \
  419. SymI_NeedsProto(mktime) \
  420. SymI_NeedsProto(_imp___timezone) \
  421. SymI_NeedsProto(_imp___tzname) \
  422. SymI_NeedsProto(_imp__tzname) \
  423. SymI_NeedsProto(_imp___iob) \
  424. SymI_NeedsProto(_imp___osver) \
  425. SymI_NeedsProto(localtime) \
  426. SymI_NeedsProto(gmtime) \
  427. SymI_NeedsProto(opendir) \
  428. SymI_NeedsProto(readdir) \
  429. SymI_NeedsProto(rewinddir) \
  430. SymI_NeedsProto(_imp____mb_cur_max) \
  431. SymI_NeedsProto(_imp___pctype) \
  432. SymI_NeedsProto(__chkstk) \
  433. RTS_MINGW_GETTIMEOFDAY_SYM \
  434. SymI_NeedsProto(closedir)
  435. #endif
  436. #if defined(darwin_HOST_OS) && HAVE_PRINTF_LDBLSTUB
  437. #define RTS_DARWIN_ONLY_SYMBOLS \
  438. SymI_NeedsProto(asprintf$LDBLStub) \
  439. SymI_NeedsProto(err$LDBLStub) \
  440. SymI_NeedsProto(errc$LDBLStub) \
  441. SymI_NeedsProto(errx$LDBLStub) \
  442. SymI_NeedsProto(fprintf$LDBLStub) \
  443. SymI_NeedsProto(fscanf$LDBLStub) \
  444. SymI_NeedsProto(fwprintf$LDBLStub) \
  445. SymI_NeedsProto(fwscanf$LDBLStub) \
  446. SymI_NeedsProto(printf$LDBLStub) \
  447. SymI_NeedsProto(scanf$LDBLStub) \
  448. SymI_NeedsProto(snprintf$LDBLStub) \
  449. SymI_NeedsProto(sprintf$LDBLStub) \
  450. SymI_NeedsProto(sscanf$LDBLStub) \
  451. SymI_NeedsProto(strtold$LDBLStub) \
  452. SymI_NeedsProto(swprintf$LDBLStub) \
  453. SymI_NeedsProto(swscanf$LDBLStub) \
  454. SymI_NeedsProto(syslog$LDBLStub) \
  455. SymI_NeedsProto(vasprintf$LDBLStub) \
  456. SymI_NeedsProto(verr$LDBLStub) \
  457. SymI_NeedsProto(verrc$LDBLStub) \
  458. SymI_NeedsProto(verrx$LDBLStub) \
  459. SymI_NeedsProto(vfprintf$LDBLStub) \
  460. SymI_NeedsProto(vfscanf$LDBLStub) \
  461. SymI_NeedsProto(vfwprintf$LDBLStub) \
  462. SymI_NeedsProto(vfwscanf$LDBLStub) \
  463. SymI_NeedsProto(vprintf$LDBLStub) \
  464. SymI_NeedsProto(vscanf$LDBLStub) \
  465. SymI_NeedsProto(vsnprintf$LDBLStub) \
  466. SymI_NeedsProto(vsprintf$LDBLStub) \
  467. SymI_NeedsProto(vsscanf$LDBLStub) \
  468. SymI_NeedsProto(vswprintf$LDBLStub) \
  469. SymI_NeedsProto(vswscanf$LDBLStub) \
  470. SymI_NeedsProto(vsyslog$LDBLStub) \
  471. SymI_NeedsProto(vwarn$LDBLStub) \
  472. SymI_NeedsProto(vwarnc$LDBLStub) \
  473. SymI_NeedsProto(vwarnx$LDBLStub) \
  474. SymI_NeedsProto(vwprintf$LDBLStub) \
  475. SymI_NeedsProto(vwscanf$LDBLStub) \
  476. SymI_NeedsProto(warn$LDBLStub) \
  477. SymI_NeedsProto(warnc$LDBLStub) \
  478. SymI_NeedsProto(warnx$LDBLStub) \
  479. SymI_NeedsProto(wcstold$LDBLStub) \
  480. SymI_NeedsProto(wprintf$LDBLStub) \
  481. SymI_NeedsProto(wscanf$LDBLStub)
  482. #else
  483. #define RTS_DARWIN_ONLY_SYMBOLS
  484. #endif
  485. #ifndef SMP
  486. # define MAIN_CAP_SYM SymI_HasProto(MainCapability)
  487. #else
  488. # define MAIN_CAP_SYM
  489. #endif
  490. #if !defined(mingw32_HOST_OS)
  491. #define RTS_USER_SIGNALS_SYMBOLS \
  492. SymI_HasProto(setIOManagerControlFd) \
  493. SymI_HasProto(setIOManagerWakeupFd) \
  494. SymI_HasProto(ioManagerWakeup) \
  495. SymI_HasProto(blockUserSignals) \
  496. SymI_HasProto(unblockUserSignals)
  497. #else
  498. #define RTS_USER_SIGNALS_SYMBOLS \
  499. SymI_HasProto(ioManagerWakeup) \
  500. SymI_HasProto(sendIOManagerEvent) \
  501. SymI_HasProto(readIOManagerEvent) \
  502. SymI_HasProto(getIOManagerEvent) \
  503. SymI_HasProto(console_handler)
  504. #endif
  505. #define RTS_LIBFFI_SYMBOLS \
  506. SymE_NeedsProto(ffi_prep_cif) \
  507. SymE_NeedsProto(ffi_call) \
  508. SymE_NeedsProto(ffi_type_void) \
  509. SymE_NeedsProto(ffi_type_float) \
  510. SymE_NeedsProto(ffi_type_double) \
  511. SymE_NeedsProto(ffi_type_sint64) \
  512. SymE_NeedsProto(ffi_type_uint64) \
  513. SymE_NeedsProto(ffi_type_sint32) \
  514. SymE_NeedsProto(ffi_type_uint32) \
  515. SymE_NeedsProto(ffi_type_sint16) \
  516. SymE_NeedsProto(ffi_type_uint16) \
  517. SymE_NeedsProto(ffi_type_sint8) \
  518. SymE_NeedsProto(ffi_type_uint8) \
  519. SymE_NeedsProto(ffi_type_pointer)
  520. #ifdef TABLES_NEXT_TO_CODE
  521. #define RTS_RET_SYMBOLS /* nothing */
  522. #else
  523. #define RTS_RET_SYMBOLS \
  524. SymI_HasProto(stg_enter_ret) \
  525. SymI_HasProto(stg_gc_fun_ret) \
  526. SymI_HasProto(stg_ap_v_ret) \
  527. SymI_HasProto(stg_ap_f_ret) \
  528. SymI_HasProto(stg_ap_d_ret) \
  529. SymI_HasProto(stg_ap_l_ret) \
  530. SymI_HasProto(stg_ap_n_ret) \
  531. SymI_HasProto(stg_ap_p_ret) \
  532. SymI_HasProto(stg_ap_pv_ret) \
  533. SymI_HasProto(stg_ap_pp_ret) \
  534. SymI_HasProto(stg_ap_ppv_ret) \
  535. SymI_HasProto(stg_ap_ppp_ret) \
  536. SymI_HasProto(stg_ap_pppv_ret) \
  537. SymI_HasProto(stg_ap_pppp_ret) \
  538. SymI_HasProto(stg_ap_ppppp_ret) \
  539. SymI_HasProto(stg_ap_pppppp_ret)
  540. #endif
  541. /* Modules compiled with -ticky may mention ticky counters */
  542. /* This list should marry up with the one in $(TOP)/includes/stg/Ticky.h */
  543. #define RTS_TICKY_SYMBOLS \
  544. SymI_NeedsProto(ticky_entry_ctrs) \
  545. SymI_NeedsProto(top_ct) \
  546. \
  547. SymI_HasProto(ENT_VIA_NODE_ctr) \
  548. SymI_HasProto(ENT_STATIC_THK_ctr) \
  549. SymI_HasProto(ENT_DYN_THK_ctr) \
  550. SymI_HasProto(ENT_STATIC_FUN_DIRECT_ctr) \
  551. SymI_HasProto(ENT_DYN_FUN_DIRECT_ctr) \
  552. SymI_HasProto(ENT_STATIC_CON_ctr) \
  553. SymI_HasProto(ENT_DYN_CON_ctr) \
  554. SymI_HasProto(ENT_STATIC_IND_ctr) \
  555. SymI_HasProto(ENT_DYN_IND_ctr) \
  556. SymI_HasProto(ENT_PERM_IND_ctr) \
  557. SymI_HasProto(ENT_PAP_ctr) \
  558. SymI_HasProto(ENT_AP_ctr) \
  559. SymI_HasProto(ENT_AP_STACK_ctr) \
  560. SymI_HasProto(ENT_BH_ctr) \
  561. SymI_HasProto(UNKNOWN_CALL_ctr) \
  562. SymI_HasProto(SLOW_CALL_v_ctr) \
  563. SymI_HasProto(SLOW_CALL_f_ctr) \
  564. SymI_HasProto(SLOW_CALL_d_ctr) \
  565. SymI_HasProto(SLOW_CALL_l_ctr) \
  566. SymI_HasProto(SLOW_CALL_n_ctr) \
  567. SymI_HasProto(SLOW_CALL_p_ctr) \
  568. SymI_HasProto(SLOW_CALL_pv_ctr) \
  569. SymI_HasProto(SLOW_CALL_pp_ctr) \
  570. SymI_HasProto(SLOW_CALL_ppv_ctr) \
  571. SymI_HasProto(SLOW_CALL_ppp_ctr) \
  572. SymI_HasProto(SLOW_CALL_pppv_ctr) \
  573. SymI_HasProto(SLOW_CALL_pppp_ctr) \
  574. SymI_HasProto(SLOW_CALL_ppppp_ctr) \
  575. SymI_HasProto(SLOW_CALL_pppppp_ctr) \
  576. SymI_HasProto(SLOW_CALL_OTHER_ctr) \
  577. SymI_HasProto(ticky_slow_call_unevald) \
  578. SymI_HasProto(SLOW_CALL_ctr) \
  579. SymI_HasProto(MULTI_CHUNK_SLOW_CALL_ctr) \
  580. SymI_HasProto(MULTI_CHUNK_SLOW_CALL_CHUNKS_ctr) \
  581. SymI_HasProto(KNOWN_CALL_ctr) \
  582. SymI_HasProto(KNOWN_CALL_TOO_FEW_ARGS_ctr) \
  583. SymI_HasProto(KNOWN_CALL_EXTRA_ARGS_ctr) \
  584. SymI_HasProto(SLOW_CALL_FUN_TOO_FEW_ctr) \
  585. SymI_HasProto(SLOW_CALL_FUN_CORRECT_ctr) \
  586. SymI_HasProto(SLOW_CALL_FUN_TOO_MANY_ctr) \
  587. SymI_HasProto(SLOW_CALL_PAP_TOO_FEW_ctr) \
  588. SymI_HasProto(SLOW_CALL_PAP_CORRECT_ctr) \
  589. SymI_HasProto(SLOW_CALL_PAP_TOO_MANY_ctr) \
  590. SymI_HasProto(SLOW_CALL_UNEVALD_ctr) \
  591. SymI_HasProto(UPDF_OMITTED_ctr) \
  592. SymI_HasProto(UPDF_PUSHED_ctr) \
  593. SymI_HasProto(CATCHF_PUSHED_ctr) \
  594. SymI_HasProto(UPDF_RCC_PUSHED_ctr) \
  595. SymI_HasProto(UPDF_RCC_OMITTED_ctr) \
  596. SymI_HasProto(UPD_SQUEEZED_ctr) \
  597. SymI_HasProto(UPD_CON_IN_NEW_ctr) \
  598. SymI_HasProto(UPD_CON_IN_PLACE_ctr) \
  599. SymI_HasProto(UPD_PAP_IN_NEW_ctr) \
  600. SymI_HasProto(UPD_PAP_IN_PLACE_ctr) \
  601. SymI_HasProto(ALLOC_HEAP_ctr) \
  602. SymI_HasProto(ALLOC_HEAP_tot) \
  603. SymI_HasProto(ALLOC_FUN_ctr) \
  604. SymI_HasProto(ALLOC_FUN_adm) \
  605. SymI_HasProto(ALLOC_FUN_gds) \
  606. SymI_HasProto(ALLOC_FUN_slp) \
  607. SymI_HasProto(UPD_NEW_IND_ctr) \
  608. SymI_HasProto(UPD_NEW_PERM_IND_ctr) \
  609. SymI_HasProto(UPD_OLD_IND_ctr) \
  610. SymI_HasProto(UPD_OLD_PERM_IND_ctr) \
  611. SymI_HasProto(UPD_BH_UPDATABLE_ctr) \
  612. SymI_HasProto(UPD_BH_SINGLE_ENTRY_ctr) \
  613. SymI_HasProto(UPD_CAF_BH_UPDATABLE_ctr) \
  614. SymI_HasProto(UPD_CAF_BH_SINGLE_ENTRY_ctr) \
  615. SymI_HasProto(GC_SEL_ABANDONED_ctr) \
  616. SymI_HasProto(GC_SEL_MINOR_ctr) \
  617. SymI_HasProto(GC_SEL_MAJOR_ctr) \
  618. SymI_HasProto(GC_FAILED_PROMOTION_ctr) \
  619. SymI_HasProto(ALLOC_UP_THK_ctr) \
  620. SymI_HasProto(ALLOC_SE_THK_ctr) \
  621. SymI_HasProto(ALLOC_THK_adm) \
  622. SymI_HasProto(ALLOC_THK_gds) \
  623. SymI_HasProto(ALLOC_THK_slp) \
  624. SymI_HasProto(ALLOC_CON_ctr) \
  625. SymI_HasProto(ALLOC_CON_adm) \
  626. SymI_HasProto(ALLOC_CON_gds) \
  627. SymI_HasProto(ALLOC_CON_slp) \
  628. SymI_HasProto(ALLOC_TUP_ctr) \
  629. SymI_HasProto(ALLOC_TUP_adm) \
  630. SymI_HasProto(ALLOC_TUP_gds) \
  631. SymI_HasProto(ALLOC_TUP_slp) \
  632. SymI_HasProto(ALLOC_BH_ctr) \
  633. SymI_HasProto(ALLOC_BH_adm) \
  634. SymI_HasProto(ALLOC_BH_gds) \
  635. SymI_HasProto(ALLOC_BH_slp) \
  636. SymI_HasProto(ALLOC_PRIM_ctr) \
  637. SymI_HasProto(ALLOC_PRIM_adm) \
  638. SymI_HasProto(ALLOC_PRIM_gds) \
  639. SymI_HasProto(ALLOC_PRIM_slp) \
  640. SymI_HasProto(ALLOC_PAP_ctr) \
  641. SymI_HasProto(ALLOC_PAP_adm) \
  642. SymI_HasProto(ALLOC_PAP_gds) \
  643. SymI_HasProto(ALLOC_PAP_slp) \
  644. SymI_HasProto(ALLOC_TSO_ctr) \
  645. SymI_HasProto(ALLOC_TSO_adm) \
  646. SymI_HasProto(ALLOC_TSO_gds) \
  647. SymI_HasProto(ALLOC_TSO_slp) \
  648. SymI_HasProto(RET_NEW_ctr) \
  649. SymI_HasProto(RET_OLD_ctr) \
  650. SymI_HasProto(RET_UNBOXED_TUP_ctr) \
  651. SymI_HasProto(RET_SEMI_loads_avoided)
  652. // On most platforms, the garbage collector rewrites references
  653. // to small integer and char objects to a set of common, shared ones.
  654. //
  655. // We don't do this when compiling to Windows DLLs at the moment because
  656. // it doesn't support cross package data references well.
  657. //
  658. #if defined(__PIC__) && defined(mingw32_HOST_OS)
  659. #define RTS_INTCHAR_SYMBOLS
  660. #else
  661. #define RTS_INTCHAR_SYMBOLS \
  662. SymI_HasProto(stg_CHARLIKE_closure) \
  663. SymI_HasProto(stg_INTLIKE_closure)
  664. #endif
  665. #define RTS_SYMBOLS \
  666. Maybe_Stable_Names \
  667. RTS_TICKY_SYMBOLS \
  668. SymI_HasProto(StgReturn) \
  669. SymI_HasProto(stg_enter_info) \
  670. SymI_HasProto(stg_gc_void_info) \
  671. SymI_HasProto(__stg_gc_enter_1) \
  672. SymI_HasProto(stg_gc_noregs) \
  673. SymI_HasProto(stg_gc_unpt_r1_info) \
  674. SymI_HasProto(stg_gc_unpt_r1) \
  675. SymI_HasProto(stg_gc_unbx_r1_info) \
  676. SymI_HasProto(stg_gc_unbx_r1) \
  677. SymI_HasProto(stg_gc_f1_info) \
  678. SymI_HasProto(stg_gc_f1) \
  679. SymI_HasProto(stg_gc_d1_info) \
  680. SymI_HasProto(stg_gc_d1) \
  681. SymI_HasProto(stg_gc_l1_info) \
  682. SymI_HasProto(stg_gc_l1) \
  683. SymI_HasProto(__stg_gc_fun) \
  684. SymI_HasProto(stg_gc_fun_info) \
  685. SymI_HasProto(stg_gc_gen) \
  686. SymI_HasProto(stg_gc_gen_info) \
  687. SymI_HasProto(stg_gc_gen_hp) \
  688. SymI_HasProto(stg_gc_ut) \
  689. SymI_HasProto(stg_gen_yield) \
  690. SymI_HasProto(stg_yield_noregs) \
  691. SymI_HasProto(stg_yield_to_interpreter) \
  692. SymI_HasProto(stg_gen_block) \
  693. SymI_HasProto(stg_block_noregs) \
  694. SymI_HasProto(stg_block_1) \
  695. SymI_HasProto(stg_block_takemvar) \
  696. SymI_HasProto(stg_block_putmvar) \
  697. MAIN_CAP_SYM \
  698. SymI_HasProto(MallocFailHook) \
  699. SymI_HasProto(OnExitHook) \
  700. SymI_HasProto(OutOfHeapHook) \
  701. SymI_HasProto(StackOverflowHook) \
  702. SymI_HasProto(addDLL) \
  703. SymI_HasProto(__int_encodeDouble) \
  704. SymI_HasProto(__word_encodeDouble) \
  705. SymI_HasProto(__2Int_encodeDouble) \
  706. SymI_HasProto(__int_encodeFloat) \
  707. SymI_HasProto(__word_encodeFloat) \
  708. SymI_HasProto(stg_atomicallyzh) \
  709. SymI_HasProto(barf) \
  710. SymI_HasProto(debugBelch) \
  711. SymI_HasProto(errorBelch) \
  712. SymI_HasProto(sysErrorBelch) \
  713. SymI_HasProto(stg_getMaskingStatezh) \
  714. SymI_HasProto(stg_maskAsyncExceptionszh) \
  715. SymI_HasProto(stg_maskUninterruptiblezh) \
  716. SymI_HasProto(stg_catchzh) \
  717. SymI_HasProto(stg_catchRetryzh) \
  718. SymI_HasProto(stg_catchSTMzh) \
  719. SymI_HasProto(stg_checkzh) \
  720. SymI_HasProto(closure_flags) \
  721. SymI_HasProto(cmp_thread) \
  722. SymI_HasProto(createAdjustor) \
  723. SymI_HasProto(stg_decodeDoublezu2Intzh) \
  724. SymI_HasProto(stg_decodeFloatzuIntzh) \
  725. SymI_HasProto(defaultsHook) \
  726. SymI_HasProto(stg_delayzh) \
  727. SymI_HasProto(stg_deRefWeakzh) \
  728. SymI_HasProto(stg_deRefStablePtrzh) \
  729. SymI_HasProto(dirty_MUT_VAR) \
  730. SymI_HasProto(stg_forkzh) \
  731. SymI_HasProto(stg_forkOnzh) \
  732. SymI_HasProto(forkProcess) \
  733. SymI_HasProto(forkOS_createThread) \
  734. SymI_HasProto(freeHaskellFunctionPtr) \
  735. SymI_HasProto(getOrSetTypeableStore) \
  736. SymI_HasProto(getOrSetGHCConcSignalSignalHandlerStore) \
  737. SymI_HasProto(getOrSetGHCConcWindowsPendingDelaysStore) \
  738. SymI_HasProto(getOrSetGHCConcWindowsIOManagerThreadStore) \
  739. SymI_HasProto(getOrSetGHCConcWindowsProddingStore) \
  740. SymI_HasProto(getOrSetSystemEventThreadEventManagerStore) \
  741. SymI_HasProto(getOrSetSystemEventThreadIOManagerThreadStore) \
  742. SymI_HasProto(genSymZh) \
  743. SymI_HasProto(genericRaise) \
  744. SymI_HasProto(getProgArgv) \
  745. SymI_HasProto(getFullProgArgv) \
  746. SymI_HasProto(getStablePtr) \
  747. SymI_HasProto(hs_init) \
  748. SymI_HasProto(hs_exit) \
  749. SymI_HasProto(hs_set_argv) \
  750. SymI_HasProto(hs_add_root) \
  751. SymI_HasProto(hs_perform_gc) \
  752. SymI_HasProto(hs_free_stable_ptr) \
  753. SymI_HasProto(hs_free_fun_ptr) \
  754. SymI_HasProto(hs_hpc_rootModule) \
  755. SymI_HasProto(hs_hpc_module) \
  756. SymI_HasProto(initLinker) \
  757. SymI_HasProto(stg_unpackClosurezh) \
  758. SymI_HasProto(stg_getApStackValzh) \
  759. SymI_HasProto(stg_getSparkzh) \
  760. SymI_HasProto(stg_numSparkszh) \
  761. SymI_HasProto(stg_isCurrentThreadBoundzh) \
  762. SymI_HasProto(stg_isEmptyMVarzh) \
  763. SymI_HasProto(stg_killThreadzh) \
  764. SymI_HasProto(loadArchive) \
  765. SymI_HasProto(loadObj) \
  766. SymI_HasProto(insertStableSymbol) \
  767. SymI_HasProto(insertSymbol) \
  768. SymI_HasProto(lookupSymbol) \
  769. SymI_HasProto(stg_makeStablePtrzh) \
  770. SymI_HasProto(stg_mkApUpd0zh) \
  771. SymI_HasProto(stg_myThreadIdzh) \
  772. SymI_HasProto(stg_labelThreadzh) \
  773. SymI_HasProto(stg_newArrayzh) \
  774. SymI_HasProto(stg_newBCOzh) \
  775. SymI_HasProto(stg_newByteArrayzh) \
  776. SymI_HasProto_redirect(newCAF, newDynCAF) \
  777. SymI_HasProto(stg_newMVarzh) \
  778. SymI_HasProto(stg_newMutVarzh) \
  779. SymI_HasProto(stg_newTVarzh) \
  780. SymI_HasProto(stg_noDuplicatezh) \
  781. SymI_HasProto(stg_atomicModifyMutVarzh) \
  782. SymI_HasProto(stg_newPinnedByteArrayzh) \
  783. SymI_HasProto(stg_newAlignedPinnedByteArrayzh) \
  784. SymI_HasProto(newSpark) \
  785. SymI_HasProto(performGC) \
  786. SymI_HasProto(performMajorGC) \
  787. SymI_HasProto(prog_argc) \
  788. SymI_HasProto(prog_argv) \
  789. SymI_HasProto(stg_putMVarzh) \
  790. SymI_HasProto(stg_raisezh) \
  791. SymI_HasProto(stg_raiseIOzh) \
  792. SymI_HasProto(stg_readTVarzh) \
  793. SymI_HasProto(stg_readTVarIOzh) \
  794. SymI_HasProto(resumeThread) \
  795. SymI_HasProto(resolveObjs) \
  796. SymI_HasProto(stg_retryzh) \
  797. SymI_HasProto(rts_apply) \
  798. SymI_HasProto(rts_checkSchedStatus) \
  799. SymI_HasProto(rts_eval) \
  800. SymI_HasProto(rts_evalIO) \
  801. SymI_HasProto(rts_evalLazyIO) \
  802. SymI_HasProto(rts_evalStableIO) \
  803. SymI_HasProto(rts_eval_) \
  804. SymI_HasProto(rts_getBool) \
  805. SymI_HasProto(rts_getChar) \
  806. SymI_HasProto(rts_getDouble) \
  807. SymI_HasProto(rts_getFloat) \
  808. SymI_HasProto(rts_getInt) \
  809. SymI_HasProto(rts_getInt8) \
  810. SymI_HasProto(rts_getInt16) \
  811. SymI_HasProto(rts_getInt32) \
  812. SymI_HasProto(rts_getInt64) \
  813. SymI_HasProto(rts_getPtr) \
  814. SymI_HasProto(rts_getFunPtr) \
  815. SymI_HasProto(rts_getStablePtr) \
  816. SymI_HasProto(rts_getThreadId) \
  817. SymI_HasProto(rts_getWord) \
  818. SymI_HasProto(rts_getWord8) \
  819. SymI_HasProto(rts_getWord16) \
  820. SymI_HasProto(rts_getWord32) \
  821. SymI_HasProto(rts_getWord64) \
  822. SymI_HasProto(rts_lock) \
  823. SymI_HasProto(rts_mkBool) \
  824. SymI_HasProto(rts_mkChar) \
  825. SymI_HasProto(rts_mkDouble) \
  826. SymI_HasProto(rts_mkFloat) \
  827. SymI_HasProto(rts_mkInt) \
  828. SymI_HasProto(rts_mkInt8) \
  829. SymI_HasProto(rts_mkInt16) \
  830. SymI_HasProto(rts_mkInt32) \
  831. SymI_HasProto(rts_mkInt64) \
  832. SymI_HasProto(rts_mkPtr) \
  833. SymI_HasProto(rts_mkFunPtr) \
  834. SymI_HasProto(rts_mkStablePtr) \
  835. SymI_HasProto(rts_mkString) \
  836. SymI_HasProto(rts_mkWord) \
  837. SymI_HasProto(rts_mkWord8) \
  838. SymI_HasProto(rts_mkWord16) \
  839. SymI_HasProto(rts_mkWord32) \
  840. SymI_HasProto(rts_mkWord64) \
  841. SymI_HasProto(rts_unlock) \
  842. SymI_HasProto(rts_unsafeGetMyCapability) \
  843. SymI_HasProto(rtsSupportsBoundThreads) \
  844. SymI_HasProto(rts_isProfiled) \
  845. SymI_HasProto(setProgArgv) \
  846. SymI_HasProto(startupHaskell) \
  847. SymI_HasProto(shutdownHaskell) \
  848. SymI_HasProto(shutdownHaskellAndExit) \
  849. SymI_HasProto(stable_ptr_table) \
  850. SymI_HasProto(stackOverflow) \
  851. SymI_HasProto(stg_CAF_BLACKHOLE_info) \
  852. SymI_HasProto(stg_BLACKHOLE_info) \
  853. SymI_HasProto(__stg_EAGER_BLACKHOLE_info) \
  854. SymI_HasProto(stg_BLOCKING_QUEUE_CLEAN_info) \
  855. SymI_HasProto(stg_BLOCKING_QUEUE_DIRTY_info) \
  856. SymI_HasProto(startTimer) \
  857. SymI_HasProto(stg_MVAR_CLEAN_info) \
  858. SymI_HasProto(stg_MVAR_DIRTY_info) \
  859. SymI_HasProto(stg_IND_STATIC_info) \
  860. SymI_HasProto(stg_ARR_WORDS_info) \
  861. SymI_HasProto(stg_MUT_ARR_PTRS_DIRTY_info) \
  862. SymI_HasProto(stg_MUT_ARR_PTRS_FROZEN_info) \
  863. SymI_HasProto(stg_MUT_ARR_PTRS_FROZEN0_info) \
  864. SymI_HasProto(stg_WEAK_info) \
  865. SymI_HasProto(stg_ap_v_info) \
  866. SymI_HasProto(stg_ap_f_info) \
  867. SymI_HasProto(stg_ap_d_info) \
  868. SymI_HasProto(stg_ap_l_info) \
  869. SymI_HasProto(stg_ap_n_info) \
  870. SymI_HasProto(stg_ap_p_info) \
  871. SymI_HasProto(stg_ap_pv_info) \
  872. SymI_HasProto(stg_ap_pp_info) \
  873. SymI_HasProto(stg_ap_ppv_info) \
  874. SymI_HasProto(stg_ap_ppp_info) \
  875. SymI_HasProto(stg_ap_pppv_info) \
  876. SymI_HasProto(stg_ap_pppp_info) \
  877. SymI_HasProto(stg_ap_ppppp_info) \
  878. SymI_HasProto(stg_ap_pppppp_info) \
  879. SymI_HasProto(stg_ap_0_fast) \
  880. SymI_HasProto(stg_ap_v_fast) \
  881. SymI_HasProto(stg_ap_f_fast) \
  882. SymI_HasProto(stg_ap_d_fast) \
  883. SymI_HasProto(stg_ap_l_fast) \
  884. SymI_HasProto(stg_ap_n_fast) \
  885. SymI_HasProto(stg_ap_p_fast) \
  886. SymI_HasProto(stg_ap_pv_fast) \
  887. SymI_HasProto(stg_ap_pp_fast) \
  888. SymI_HasProto(stg_ap_ppv_fast) \
  889. SymI_HasProto(stg_ap_ppp_fast) \
  890. SymI_HasProto(stg_ap_pppv_fast) \
  891. SymI_HasProto(stg_ap_pppp_fast) \
  892. SymI_HasProto(stg_ap_ppppp_fast) \
  893. SymI_HasProto(stg_ap_pppppp_fast) \
  894. SymI_HasProto(stg_ap_1_upd_info) \
  895. SymI_HasProto(stg_ap_2_upd_info) \
  896. SymI_HasProto(stg_ap_3_upd_info) \
  897. SymI_HasProto(stg_ap_4_upd_info) \
  898. SymI_HasProto(stg_ap_5_upd_info) \
  899. SymI_HasProto(stg_ap_6_upd_info) \
  900. SymI_HasProto(stg_ap_7_upd_info) \
  901. SymI_HasProto(stg_exit) \
  902. SymI_HasProto(stg_sel_0_upd_info) \
  903. SymI_HasProto(stg_sel_10_upd_info) \
  904. SymI_HasProto(stg_sel_11_upd_info) \
  905. SymI_HasProto(stg_sel_12_upd_info) \
  906. SymI_HasProto(stg_sel_13_upd_info) \
  907. SymI_HasProto(stg_sel_14_upd_info) \
  908. SymI_HasProto(stg_sel_15_upd_info) \
  909. SymI_HasProto(stg_sel_1_upd_info) \
  910. SymI_HasProto(stg_sel_2_upd_info) \
  911. SymI_HasProto(stg_sel_3_upd_info) \
  912. SymI_HasProto(stg_sel_4_upd_info) \
  913. SymI_HasProto(stg_sel_5_upd_info) \
  914. SymI_HasProto(stg_sel_6_upd_info) \
  915. SymI_HasProto(stg_sel_7_upd_info) \
  916. SymI_HasProto(stg_sel_8_upd_info) \
  917. SymI_HasProto(stg_sel_9_upd_info) \
  918. SymI_HasProto(stg_upd_frame_info) \
  919. SymI_HasProto(stg_bh_upd_frame_info) \
  920. SymI_HasProto(suspendThread) \
  921. SymI_HasProto(stg_takeMVarzh) \
  922. SymI_HasProto(stg_threadStatuszh) \
  923. SymI_HasProto(stg_tryPutMVarzh) \
  924. SymI_HasProto(stg_tryTakeMVarzh) \
  925. SymI_HasProto(stg_unmaskAsyncExceptionszh) \
  926. SymI_HasProto(unloadObj) \
  927. SymI_HasProto(stg_unsafeThawArrayzh) \
  928. SymI_HasProto(stg_waitReadzh) \
  929. SymI_HasProto(stg_waitWritezh) \
  930. SymI_HasProto(stg_writeTVarzh) \
  931. SymI_HasProto(stg_yieldzh) \
  932. SymI_NeedsProto(stg_interp_constr_entry) \
  933. SymI_HasProto(stg_arg_bitmaps) \
  934. SymI_HasProto(alloc_blocks_lim) \
  935. SymI_HasProto(g0) \
  936. SymI_HasProto(allocate) \
  937. SymI_HasProto(allocateExec) \
  938. SymI_HasProto(freeExec) \
  939. SymI_HasProto(getAllocations) \
  940. SymI_HasProto(revertCAFs) \
  941. SymI_HasProto(RtsFlags) \
  942. SymI_NeedsProto(rts_breakpoint_io_action) \
  943. SymI_NeedsProto(rts_stop_next_breakpoint) \
  944. SymI_NeedsProto(rts_stop_on_exception) \
  945. SymI_HasProto(stopTimer) \
  946. SymI_HasProto(n_capabilities) \
  947. SymI_HasProto(stg_traceCcszh) \
  948. SymI_HasProto(stg_traceEventzh) \
  949. RTS_USER_SIGNALS_SYMBOLS \
  950. RTS_INTCHAR_SYMBOLS
  951. // 64-bit support functions in libgcc.a
  952. #if defined(__GNUC__) && SIZEOF_VOID_P <= 4
  953. #define RTS_LIBGCC_SYMBOLS \
  954. SymI_NeedsProto(__divdi3) \
  955. SymI_NeedsProto(__udivdi3) \
  956. SymI_NeedsProto(__moddi3) \
  957. SymI_NeedsProto(__umoddi3) \
  958. SymI_NeedsProto(__muldi3) \
  959. SymI_NeedsProto(__ashldi3) \
  960. SymI_NeedsProto(__ashrdi3) \
  961. SymI_NeedsProto(__lshrdi3)
  962. #else
  963. #define RTS_LIBGCC_SYMBOLS
  964. #endif
  965. #if defined(darwin_HOST_OS) && defined(powerpc_HOST_ARCH)
  966. // Symbols that don't have a leading underscore
  967. // on Mac OS X. They have to receive special treatment,
  968. // see machoInitSymbolsWithoutUnderscore()
  969. #define RTS_MACHO_NOUNDERLINE_SYMBOLS \
  970. SymI_NeedsProto(saveFP) \
  971. SymI_NeedsProto(restFP)
  972. #endif
  973. /* entirely bogus claims about types of these symbols */
  974. #define SymI_NeedsProto(vvv) extern void vvv(void);
  975. #if defined(__PIC__) && defined(mingw32_HOST_OS)
  976. #define SymE_HasProto(vvv) SymE_HasProto(vvv);
  977. #define SymE_NeedsProto(vvv) extern void _imp__ ## vvv (void);
  978. #else
  979. #define SymE_NeedsProto(vvv) SymI_NeedsProto(vvv);
  980. #define SymE_HasProto(vvv) SymI_HasProto(vvv)
  981. #endif
  982. #define SymI_HasProto(vvv) /**/
  983. #define SymI_HasProto_redirect(vvv,xxx) /**/
  984. RTS_SYMBOLS
  985. RTS_RET_SYMBOLS
  986. RTS_POSIX_ONLY_SYMBOLS
  987. RTS_MINGW_ONLY_SYMBOLS
  988. RTS_CYGWIN_ONLY_SYMBOLS
  989. RTS_DARWIN_ONLY_SYMBOLS
  990. RTS_LIBGCC_SYMBOLS
  991. RTS_LIBFFI_SYMBOLS
  992. #undef SymI_NeedsProto
  993. #undef SymI_HasProto
  994. #undef SymI_HasProto_redirect
  995. #undef SymE_HasProto
  996. #undef SymE_NeedsProto
  997. #ifdef LEADING_UNDERSCORE
  998. #define MAYBE_LEADING_UNDERSCORE_STR(s) ("_" s)
  999. #else
  1000. #define MAYBE_LEADING_UNDERSCORE_STR(s) (s)
  1001. #endif
  1002. #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
  1003. (void*)(&(vvv)) },
  1004. #define SymE_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
  1005. (void*)DLL_IMPORT_DATA_REF(vvv) },
  1006. #define SymI_NeedsProto(vvv) SymI_HasProto(vvv)
  1007. #define SymE_NeedsProto(vvv) SymE_HasProto(vvv)
  1008. // SymI_HasProto_redirect allows us to redirect references to one symbol to
  1009. // another symbol. See newCAF/newDynCAF for an example.
  1010. #define SymI_HasProto_redirect(vvv,xxx) \
  1011. { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
  1012. (void*)(&(xxx)) },
  1013. static RtsSymbolVal rtsSyms[] = {
  1014. RTS_SYMBOLS
  1015. RTS_RET_SYMBOLS
  1016. RTS_POSIX_ONLY_SYMBOLS
  1017. RTS_MINGW_ONLY_SYMBOLS
  1018. RTS_CYGWIN_ONLY_SYMBOLS
  1019. RTS_DARWIN_ONLY_SYMBOLS
  1020. RTS_LIBGCC_SYMBOLS
  1021. RTS_LIBFFI_SYMBOLS
  1022. #if defined(darwin_HOST_OS) && defined(i386_HOST_ARCH)
  1023. // dyld stub code contains references to this,
  1024. // but it should never be called because we treat
  1025. // lazy pointers as nonlazy.
  1026. { "dyld_stub_binding_helper", (void*)0xDEADBEEF },
  1027. #endif
  1028. { 0, 0 } /* sentinel */
  1029. };
  1030. /* -----------------------------------------------------------------------------
  1031. * Insert symbols into hash tables, checking for duplicates.
  1032. */
  1033. static void ghciInsertStrHashTable ( char* obj_name,
  1034. HashTable *table,
  1035. char* key,
  1036. void *data
  1037. )
  1038. {
  1039. if (lookupHashTable(table, (StgWord)key) == NULL)
  1040. {
  1041. insertStrHashTable(table, (StgWord)key, data);
  1042. return;
  1043. }
  1044. debugBelch(
  1045. "\n\n"
  1046. "GHCi runtime linker: fatal error: I found a duplicate definition for symbol\n"
  1047. " %s\n"
  1048. "whilst processing object file\n"
  1049. " %s\n"
  1050. "This could be caused by:\n"
  1051. " * Loading two different object files which export the same symbol\n"
  1052. " * Specifying the same object file twice on the GHCi command line\n"
  1053. " * An incorrect `package.conf' entry, causing some object to be\n"
  1054. " loaded twice.\n"
  1055. "GHCi cannot safely continue in this situation. Exiting now. Sorry.\n"
  1056. "\n",
  1057. (char*)key,
  1058. obj_name
  1059. );
  1060. stg_exit(1);
  1061. }
  1062. /* -----------------------------------------------------------------------------
  1063. * initialize the object linker
  1064. */
  1065. static int linker_init_done = 0 ;
  1066. #if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1067. static void *dl_prog_handle;
  1068. static regex_t re_invalid;
  1069. static regex_t re_realso;
  1070. #ifdef THREADED_RTS
  1071. static Mutex dl_mutex; // mutex to protect dlopen/dlerror critical section
  1072. #endif
  1073. #endif
  1074. void
  1075. initLinker( void )
  1076. {
  1077. RtsSymbolVal *sym;
  1078. #if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1079. int compileResult;
  1080. #endif
  1081. IF_DEBUG(linker, debugBelch("initLinker: start\n"));
  1082. /* Make initLinker idempotent, so we can call it
  1083. before evey relevant operation; that means we
  1084. don't need to initialise the linker separately */
  1085. if (linker_init_done == 1) {
  1086. IF_DEBUG(linker, debugBelch("initLinker: idempotent return\n"));
  1087. return;
  1088. } else {
  1089. linker_init_done = 1;
  1090. }
  1091. #if defined(THREADED_RTS) && (defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO))
  1092. initMutex(&dl_mutex);
  1093. #endif
  1094. stablehash = allocStrHashTable();
  1095. symhash = allocStrHashTable();
  1096. /* populate the symbol table with stuff from the RTS */
  1097. for (sym = rtsSyms; sym->lbl != NULL; sym++) {
  1098. ghciInsertStrHashTable("(GHCi built-in symbols)",
  1099. symhash, sym->lbl, sym->addr);
  1100. IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
  1101. }
  1102. # if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH)
  1103. machoInitSymbolsWithoutUnderscore();
  1104. # endif
  1105. # if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1106. # if defined(RTLD_DEFAULT)
  1107. dl_prog_handle = RTLD_DEFAULT;
  1108. # else
  1109. dl_prog_handle = dlopen(NULL, RTLD_LAZY);
  1110. # endif /* RTLD_DEFAULT */
  1111. compileResult = regcomp(&re_invalid,
  1112. "(([^ \t()])+\\.so([^ \t:()])*):([ \t])*invalid ELF header",
  1113. REG_EXTENDED);
  1114. ASSERT( compileResult == 0 );
  1115. compileResult = regcomp(&re_realso,
  1116. "GROUP *\\( *(([^ )])+)",
  1117. REG_EXTENDED);
  1118. ASSERT( compileResult == 0 );
  1119. # endif
  1120. #if !defined(ALWAYS_PIC) && defined(x86_64_HOST_ARCH)
  1121. if (RtsFlags.MiscFlags.linkerMemBase != 0) {
  1122. // User-override for mmap_32bit_base
  1123. mmap_32bit_base = (void*)RtsFlags.MiscFlags.linkerMemBase;
  1124. }
  1125. #endif
  1126. #if defined(mingw32_HOST_OS)
  1127. /*
  1128. * These two libraries cause problems when added to the static link,
  1129. * but are necessary for resolving symbols in GHCi, hence we load
  1130. * them manually here.
  1131. */
  1132. addDLL("msvcrt");
  1133. addDLL("kernel32");
  1134. #endif
  1135. IF_DEBUG(linker, debugBelch("initLinker: done\n"));
  1136. return;
  1137. }
  1138. void
  1139. exitLinker( void ) {
  1140. #if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1141. if (linker_init_done == 1) {
  1142. regfree(&re_invalid);
  1143. regfree(&re_realso);
  1144. #ifdef THREADED_RTS
  1145. closeMutex(&dl_mutex);
  1146. #endif
  1147. }
  1148. #endif
  1149. }
  1150. /* -----------------------------------------------------------------------------
  1151. * Loading DLL or .so dynamic libraries
  1152. * -----------------------------------------------------------------------------
  1153. *
  1154. * Add a DLL from which symbols may be found. In the ELF case, just
  1155. * do RTLD_GLOBAL-style add, so no further messing around needs to
  1156. * happen in order that symbols in the loaded .so are findable --
  1157. * lookupSymbol() will subsequently see them by dlsym on the program's
  1158. * dl-handle. Returns NULL if success, otherwise ptr to an err msg.
  1159. *
  1160. * In the PEi386 case, open the DLLs and put handles to them in a
  1161. * linked list. When looking for a symbol, try all handles in the
  1162. * list. This means that we need to load even DLLs that are guaranteed
  1163. * to be in the ghc.exe image already, just so we can get a handle
  1164. * to give to loadSymbol, so that we can find the symbols. For such
  1165. * libraries, the LoadLibrary call should be a no-op except for returning
  1166. * the handle.
  1167. *
  1168. */
  1169. #if defined(OBJFORMAT_PEi386)
  1170. /* A record for storing handles into DLLs. */
  1171. typedef
  1172. struct _OpenedDLL {
  1173. char* name;
  1174. struct _OpenedDLL* next;
  1175. HINSTANCE instance;
  1176. }
  1177. OpenedDLL;
  1178. /* A list thereof. */
  1179. static OpenedDLL* opened_dlls = NULL;
  1180. #endif
  1181. # if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1182. static const char *
  1183. internal_dlopen(const char *dll_name)
  1184. {
  1185. void *hdl;
  1186. const char *errmsg;
  1187. char *errmsg_copy;
  1188. // omitted: RTLD_NOW
  1189. // see http://www.haskell.org/pipermail/cvs-ghc/2007-September/038570.html
  1190. IF_DEBUG(linker,
  1191. debugBelch("internal_dlopen: dll_name = '%s'\n", dll_name));
  1192. //-------------- Begin critical section ------------------
  1193. // This critical section is necessary because dlerror() is not
  1194. // required to be reentrant (see POSIX -- IEEE Std 1003.1-2008)
  1195. // Also, the error message returned must be copied to preserve it
  1196. // (see POSIX also)
  1197. ACQUIRE_LOCK(&dl_mutex);
  1198. hdl = dlopen(dll_name, RTLD_LAZY | RTLD_GLOBAL);
  1199. errmsg = NULL;
  1200. if (hdl == NULL) {
  1201. /* dlopen failed; return a ptr to the error msg. */
  1202. errmsg = dlerror();
  1203. if (errmsg == NULL) errmsg = "addDLL: unknown error";
  1204. errmsg_copy = stgMallocBytes(strlen(errmsg)+1, "addDLL");
  1205. strcpy(errmsg_copy, errmsg);
  1206. errmsg = errmsg_copy;
  1207. }
  1208. RELEASE_LOCK(&dl_mutex);
  1209. //--------------- End critical section -------------------
  1210. return errmsg;
  1211. }
  1212. # endif
  1213. const char *
  1214. addDLL( char *dll_name )
  1215. {
  1216. # if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
  1217. /* ------------------- ELF DLL loader ------------------- */
  1218. #define NMATCH 5
  1219. regmatch_t match[NMATCH];
  1220. const char *errmsg;
  1221. FILE* fp;
  1222. size_t match_length;
  1223. #define MAXLINE 1000
  1224. char line[MAXLINE];
  1225. int result;
  1226. initLinker();
  1227. IF_DEBUG(linker, debugBelch("addDLL: dll_name = '%s'\n", dll_name));
  1228. errmsg = internal_dlopen(dll_name);
  1229. if (errmsg == NULL) {
  1230. return NULL;
  1231. }
  1232. // GHC Trac ticket #2615
  1233. // On some systems (e.g., Gentoo Linux) dynamic files (e.g. libc.so)
  1234. // contain linker scripts rather than ELF-format object code. This
  1235. // code handles the situation by recognizing the real object code
  1236. // file name given in the linker script.
  1237. //
  1238. // If an "invalid ELF header" error occurs, it is assumed that the
  1239. // .so file contains a linker script instead of ELF object code.
  1240. // In this case, the code looks for the GROUP ( ... ) linker
  1241. // directive. If one is found, the first file name inside the
  1242. // parentheses is treated as the name of a dynamic library and the
  1243. // code attempts to dlopen that file. If this is also unsuccessful,
  1244. // an error message is returned.
  1245. // see if the error message is due to an invalid ELF header
  1246. IF_DEBUG(linker, debugBelch("errmsg = '%s'\n", errmsg));
  1247. result = regexec(&re_invalid, errmsg, (size_t) NMATCH, match, 0);
  1248. IF_DEBUG(linker, debugBelch("result = %i\n", result));
  1249. if (result == 0) {
  1250. // success -- try to read the named file as a linker script
  1251. match_length = (size_t) stg_min((match[1].rm_eo - match[1].rm_so),
  1252. MAXLINE-1);
  1253. strncpy(line, (errmsg+(match[1].rm_so)),match_length);
  1254. line[match_length] = '\0'; // make sure string is null-terminated
  1255. IF_DEBUG(linker, debugBelch ("file name = '%s'\n", line));
  1256. if ((fp = fopen(line, "r")) == NULL) {
  1257. return errmsg; // return original error if open fails
  1258. }
  1259. // try to find a GROUP ( ... ) command
  1260. while (fgets(line, MAXLINE, fp) != NULL) {
  1261. IF_DEBUG(linker, debugBelch("input line = %s", line));
  1262. if (regexec(&re_realso, line, (size_t) NMATCH, match, 0) == 0) {
  1263. // success -- try to dlopen the first named file
  1264. IF_DEBUG(linker, debugBelch("match%s\n",""));
  1265. line[match[1].rm_eo] = '\0';
  1266. errmsg = internal_dlopen(line+match[1].rm_so);
  1267. break;
  1268. }
  1269. // if control reaches here, no GROUP ( ... ) directive was found
  1270. // and the original error message is returned to the caller
  1271. }
  1272. fclose(fp);
  1273. }
  1274. return errmsg;
  1275. # elif defined(OBJFORMAT_PEi386)
  1276. /* ------------------- Win32 DLL loader ------------------- */
  1277. char* buf;
  1278. OpenedDLL* o_dll;
  1279. HINSTANCE instance;
  1280. initLinker();
  1281. /* debugBelch("\naddDLL; dll_name = `%s'\n", dll_name); */
  1282. /* See if we've already got it, and ignore if so. */
  1283. for (o_dll = opened_dlls; o_dll != NULL; o_dll = o_dll->next) {
  1284. if (0 == strcmp(o_dll->name, dll_name))
  1285. return NULL;
  1286. }
  1287. /* The file name has no suffix (yet) so that we can try
  1288. both foo.dll and foo.drv
  1289. The documentation for LoadLibrary says:
  1290. If no file name extension is specified in the lpFileName
  1291. parameter, the default library extension .dll is
  1292. appended. However, the file name string can include a trailing
  1293. point character (.) to indicate that the module name has no
  1294. extension. */
  1295. buf = stgMallocBytes(strlen(dll_name) + 10, "addDLL");
  1296. sprintf(buf, "%s.DLL", dll_name);
  1297. instance = LoadLibrary(buf);
  1298. if (instance == NULL) {
  1299. if (GetLastError() != ERROR_MOD_NOT_FOUND) goto error;
  1300. // KAA: allow loading of drivers (like winspool.drv)
  1301. sprintf(buf, "%s.DRV", dll_name);
  1302. instance = LoadLibrary(buf);
  1303. if (instance == NULL) {
  1304. if (GetLastError() != ERROR_MOD_NOT_FOUND) goto error;
  1305. // #1883: allow loading of unix-style libfoo.dll DLLs
  1306. sprintf(buf, "lib%s.DLL", dll_name);
  1307. instance = LoadLibrary(buf);
  1308. if (instance == NULL) {
  1309. goto error;
  1310. }
  1311. }
  1312. }
  1313. stgFree(buf);
  1314. /* Add this DLL to the list of DLLs in which to search for symbols. */
  1315. o_dll = stgMallocBytes( sizeof(OpenedDLL), "addDLL" );
  1316. o_dll->name = stgMallocBytes(1+strlen(dll_name), "addDLL");
  1317. strcpy(o_dll->name, dll_name);
  1318. o_dll->instance = instance;
  1319. o_dll->next = opened_dlls;
  1320. opened_dlls = o_dll;
  1321. return NULL;
  1322. error:
  1323. stgFree(buf);
  1324. sysErrorBelch(dll_name);
  1325. /* LoadLibrary failed; return a ptr to the error msg. */
  1326. return "addDLL: could not load DLL";
  1327. # else
  1328. barf("addDLL: not implemented on this platform");
  1329. # endif
  1330. }
  1331. /* -----------------------------------------------------------------------------
  1332. * insert a stable symbol in the hash table
  1333. */
  1334. void
  1335. insertStableSymbol(char* obj_name, char* key, StgPtr p)
  1336. {
  1337. ghciInsertStrHashTable(obj_name, stablehash, key, getStablePtr(p));
  1338. }
  1339. /* -----------------------------------------------------------------------------
  1340. * insert a symbol in the hash table
  1341. */
  1342. void
  1343. insertSymbol(char* obj_name, char* key, void* data)
  1344. {
  1345. ghciInsertStrHashTable(obj_name, symhash, key, data);
  1346. }
  1347. /* -----------------------------------------------------------------------------
  1348. * lookup a symbol in the hash table
  1349. */
  1350. void *
  1351. lookupSymbol( char *lbl )
  1352. {
  1353. void *val;
  1354. IF_DEBUG(linker, debugBelch("lookupSymbol: looking up %s\n", lbl));
  1355. initLinker() ;
  1356. ASSERT(symhash != NULL);
  1357. val = lookupStrHashTable(symhash, lbl);
  1358. if (val == NULL) {
  1359. IF_DEBUG(linker, debugBelch("lookupSymbol: symbol not found\n"));
  1360. # if defined(OBJFORMAT_ELF)
  1361. return dlsym(dl_prog_handle, lbl);
  1362. # elif defined(OBJFORMAT_MACHO)
  1363. # if HAVE_DLFCN_H
  1364. /* On OS X 10.3 and later, we use dlsym instead of the old legacy
  1365. interface.
  1366. HACK: On OS X, global symbols are prefixed with an underscore.
  1367. However, dlsym wants us to omit the leading underscore from the
  1368. symbol name. For now, we simply strip it off here (and ONLY
  1369. here).
  1370. */
  1371. IF_DEBUG(linker, debugBelch("lookupSymbol: looking up %s with dlsym\n", lbl));
  1372. ASSERT(lbl[0] == '_');
  1373. return dlsym(dl_prog_handle, lbl+1);
  1374. # else
  1375. if(NSIsSymbolNameDefined(lbl)) {
  1376. NSSymbol symbol = NSLookupAndBindSymbol(lbl);
  1377. return NSAddressOfSymbol(symbol);
  1378. } else {
  1379. return NULL;
  1380. }
  1381. # endif /* HAVE_DLFCN_H */
  1382. # elif defined(OBJFORMAT_PEi386)
  1383. void* sym;
  1384. sym = lookupSymbolInDLLs((unsigned char*)lbl);
  1385. if (sym != NULL) { return sym; };
  1386. // Also try looking up the symbol without the @N suffix. Some
  1387. // DLLs have the suffixes on their symbols, some don't.
  1388. zapTrailingAtSign ( (unsigned char*)lbl );
  1389. sym = lookupSymbolInDLLs((unsigned char*)lbl);
  1390. if (sym != NULL) { return sym; };
  1391. return NULL;
  1392. # else
  1393. ASSERT(2+2 == 5);
  1394. return NULL;
  1395. # endif
  1396. } else {
  1397. IF_DEBUG(linker, debugBelch("lookupSymbol: value of %s is %p\n", lbl, val));
  1398. return val;
  1399. }
  1400. }
  1401. /* -----------------------------------------------------------------------------
  1402. * Debugging aid: look in GHCi's object symbol tables for symbols
  1403. * within DELTA bytes of the specified address, and show their names.
  1404. */
  1405. #ifdef DEBUG
  1406. void ghci_enquire ( char* addr );
  1407. void