tccpp_new/delete and other cleanups
[tinycc.git] / tccrun.c
blob6d31e2f44730dc3bca2972d4df23e3d574984ba8
1 /*
2 * TCC - Tiny C Compiler - Support for -run switch
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "tcc.h"
23 /* only native compiler supports -run */
24 #ifdef TCC_IS_NATIVE
26 #ifndef _WIN32
27 # include <sys/mman.h>
28 #endif
30 #ifdef CONFIG_TCC_BACKTRACE
31 # ifndef _WIN32
32 # include <signal.h>
33 # ifndef __OpenBSD__
34 # include <sys/ucontext.h>
35 # endif
36 # else
37 # define ucontext_t CONTEXT
38 # endif
39 ST_DATA int rt_num_callers = 6;
40 ST_DATA const char **rt_bound_error_msg;
41 ST_DATA void *rt_prog_main;
42 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level);
43 static void rt_error(ucontext_t *uc, const char *fmt, ...);
44 static void set_exception_handler(void);
45 #endif
47 static void set_pages_executable(void *ptr, unsigned long length);
48 static int tcc_relocate_ex(TCCState *s1, void *ptr);
50 #ifdef _WIN64
51 static void win64_add_function_table(TCCState *s1);
52 #endif
54 /* ------------------------------------------------------------- */
55 /* Do all relocations (needed before using tcc_get_symbol())
56 Returns -1 on error. */
58 LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
60 int ret;
62 if (TCC_RELOCATE_AUTO != ptr)
63 return tcc_relocate_ex(s1, ptr);
65 ret = tcc_relocate_ex(s1, NULL);
66 if (ret < 0)
67 return ret;
69 #ifdef HAVE_SELINUX
70 { /* Use mmap instead of malloc for Selinux. Ref:
71 http://www.gnu.org/s/libc/manual/html_node/File-Size.html */
73 char tmpfname[] = "/tmp/.tccrunXXXXXX";
74 int fd = mkstemp (tmpfname);
76 s1->mem_size = ret;
77 unlink (tmpfname);
78 ftruncate (fd, s1->mem_size);
80 s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE,
81 MAP_SHARED, fd, 0);
82 if (s1->write_mem == MAP_FAILED)
83 tcc_error("/tmp not writeable");
85 s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC,
86 MAP_SHARED, fd, 0);
87 if (s1->runtime_mem == MAP_FAILED)
88 tcc_error("/tmp not executable");
90 ret = tcc_relocate_ex(s1, s1->write_mem);
92 #else
93 s1->runtime_mem = tcc_malloc(ret);
94 ret = tcc_relocate_ex(s1, s1->runtime_mem);
95 #endif
96 return ret;
99 /* launch the compiled program with the given arguments */
100 LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
102 int (*prog_main)(int, char **);
104 if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
105 return -1;
106 prog_main = tcc_get_symbol_err(s1, s1->runtime_main);
108 #ifdef CONFIG_TCC_BACKTRACE
109 if (s1->do_debug) {
110 set_exception_handler();
111 rt_prog_main = prog_main;
113 #endif
115 errno = 0; /* clean errno value */
117 #ifdef CONFIG_TCC_BCHECK
118 if (s1->do_bounds_check) {
119 void (*bound_init)(void);
120 void (*bound_exit)(void);
121 void (*bound_new_region)(void *p, addr_t size);
122 int (*bound_delete_region)(void *p);
123 int i, ret;
125 /* set error function */
126 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
127 /* XXX: use .init section so that it also work in binary ? */
128 bound_init = tcc_get_symbol_err(s1, "__bound_init");
129 bound_exit = tcc_get_symbol_err(s1, "__bound_exit");
130 bound_new_region = tcc_get_symbol_err(s1, "__bound_new_region");
131 bound_delete_region = tcc_get_symbol_err(s1, "__bound_delete_region");
133 bound_init();
134 /* mark argv area as valid */
135 bound_new_region(argv, argc*sizeof(argv[0]));
136 for (i=0; i<argc; ++i)
137 bound_new_region(argv[i], strlen(argv[i]) + 1);
139 ret = (*prog_main)(argc, argv);
141 /* unmark argv area */
142 for (i=0; i<argc; ++i)
143 bound_delete_region(argv[i]);
144 bound_delete_region(argv);
145 bound_exit();
146 return ret;
148 #endif
149 return (*prog_main)(argc, argv);
152 /* relocate code. Return -1 on error, required size if ptr is NULL,
153 otherwise copy code into buffer passed by the caller */
154 static int tcc_relocate_ex(TCCState *s1, void *ptr)
156 Section *s;
157 unsigned long offset, length;
158 addr_t mem;
159 int i;
161 if (NULL == ptr) {
162 s1->nb_errors = 0;
163 #ifdef TCC_TARGET_PE
164 pe_output_file(s1, NULL);
165 #else
166 tcc_add_runtime(s1);
167 relocate_common_syms();
168 tcc_add_linker_symbols(s1);
169 build_got_entries(s1);
170 #endif
171 if (s1->nb_errors)
172 return -1;
175 offset = 0, mem = (addr_t)ptr;
176 for(i = 1; i < s1->nb_sections; i++) {
177 s = s1->sections[i];
178 if (0 == (s->sh_flags & SHF_ALLOC))
179 continue;
180 length = s->data_offset;
181 s->sh_addr = mem ? (mem + offset + 15) & ~15 : 0;
182 offset = (offset + length + 15) & ~15;
184 offset += 16;
186 /* relocate symbols */
187 relocate_syms(s1, 1);
188 if (s1->nb_errors)
189 return -1;
191 if (0 == mem)
192 return offset;
194 /* relocate each section */
195 for(i = 1; i < s1->nb_sections; i++) {
196 s = s1->sections[i];
197 if (s->reloc)
198 relocate_section(s1, s);
200 relocate_plt(s1);
202 for(i = 1; i < s1->nb_sections; i++) {
203 s = s1->sections[i];
204 if (0 == (s->sh_flags & SHF_ALLOC))
205 continue;
206 length = s->data_offset;
207 // printf("%-12s %08lx %04x\n", s->name, s->sh_addr, length);
208 ptr = (void*)s->sh_addr;
209 if (NULL == s->data || s->sh_type == SHT_NOBITS)
210 memset(ptr, 0, length);
211 else
212 memcpy(ptr, s->data, length);
213 /* mark executable sections as executable in memory */
214 if (s->sh_flags & SHF_EXECINSTR)
215 set_pages_executable(ptr, length);
218 #ifdef _WIN64
219 win64_add_function_table(s1);
220 #endif
221 return 0;
224 /* ------------------------------------------------------------- */
225 /* allow to run code in memory */
227 static void set_pages_executable(void *ptr, unsigned long length)
229 #ifdef _WIN32
230 unsigned long old_protect;
231 VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
232 #else
233 extern void __clear_cache(void *beginning, void *end);
234 #ifndef PAGESIZE
235 # define PAGESIZE 4096
236 #endif
237 addr_t start, end;
238 start = (addr_t)ptr & ~(PAGESIZE - 1);
239 end = (addr_t)ptr + length;
240 end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
241 mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
242 #ifndef __PCC__
243 __clear_cache(ptr, (char *)ptr + length);
244 #else
245 /* pcc 1.2.0.DEVEL 20141206 don't have such proc */
246 #endif
247 #endif
250 /* ------------------------------------------------------------- */
251 #ifdef CONFIG_TCC_BACKTRACE
253 ST_FUNC void tcc_set_num_callers(int n)
255 rt_num_callers = n;
258 /* print the position in the source file of PC value 'pc' by reading
259 the stabs debug information */
260 static addr_t rt_printline(addr_t wanted_pc, const char *msg)
262 char func_name[128], last_func_name[128];
263 addr_t func_addr, last_pc, pc;
264 const char *incl_files[INCLUDE_STACK_SIZE];
265 int incl_index, len, last_line_num, i;
266 const char *str, *p;
268 Stab_Sym *stab_sym = NULL, *stab_sym_end, *sym;
269 int stab_len = 0;
270 char *stab_str = NULL;
272 if (stab_section) {
273 stab_len = stab_section->data_offset;
274 stab_sym = (Stab_Sym *)stab_section->data;
275 stab_str = (char *) stabstr_section->data;
278 func_name[0] = '\0';
279 func_addr = 0;
280 incl_index = 0;
281 last_func_name[0] = '\0';
282 last_pc = (addr_t)-1;
283 last_line_num = 1;
285 if (!stab_sym)
286 goto no_stabs;
288 stab_sym_end = (Stab_Sym*)((char*)stab_sym + stab_len);
289 for (sym = stab_sym + 1; sym < stab_sym_end; ++sym) {
290 switch(sym->n_type) {
291 /* function start or end */
292 case N_FUN:
293 if (sym->n_strx == 0) {
294 /* we test if between last line and end of function */
295 pc = sym->n_value + func_addr;
296 if (wanted_pc >= last_pc && wanted_pc < pc)
297 goto found;
298 func_name[0] = '\0';
299 func_addr = 0;
300 } else {
301 str = stab_str + sym->n_strx;
302 p = strchr(str, ':');
303 if (!p) {
304 pstrcpy(func_name, sizeof(func_name), str);
305 } else {
306 len = p - str;
307 if (len > sizeof(func_name) - 1)
308 len = sizeof(func_name) - 1;
309 memcpy(func_name, str, len);
310 func_name[len] = '\0';
312 func_addr = sym->n_value;
314 break;
315 /* line number info */
316 case N_SLINE:
317 pc = sym->n_value + func_addr;
318 if (wanted_pc >= last_pc && wanted_pc < pc)
319 goto found;
320 last_pc = pc;
321 last_line_num = sym->n_desc;
322 /* XXX: slow! */
323 strcpy(last_func_name, func_name);
324 break;
325 /* include files */
326 case N_BINCL:
327 str = stab_str + sym->n_strx;
328 add_incl:
329 if (incl_index < INCLUDE_STACK_SIZE) {
330 incl_files[incl_index++] = str;
332 break;
333 case N_EINCL:
334 if (incl_index > 1)
335 incl_index--;
336 break;
337 case N_SO:
338 if (sym->n_strx == 0) {
339 incl_index = 0; /* end of translation unit */
340 } else {
341 str = stab_str + sym->n_strx;
342 /* do not add path */
343 len = strlen(str);
344 if (len > 0 && str[len - 1] != '/')
345 goto add_incl;
347 break;
351 no_stabs:
352 /* second pass: we try symtab symbols (no line number info) */
353 incl_index = 0;
354 if (symtab_section)
356 ElfW(Sym) *sym, *sym_end;
357 int type;
359 sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset);
360 for(sym = (ElfW(Sym) *)symtab_section->data + 1;
361 sym < sym_end;
362 sym++) {
363 type = ELFW(ST_TYPE)(sym->st_info);
364 if (type == STT_FUNC || type == STT_GNU_IFUNC) {
365 if (wanted_pc >= sym->st_value &&
366 wanted_pc < sym->st_value + sym->st_size) {
367 pstrcpy(last_func_name, sizeof(last_func_name),
368 (char *) strtab_section->data + sym->st_name);
369 func_addr = sym->st_value;
370 goto found;
375 /* did not find any info: */
376 fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc);
377 fflush(stderr);
378 return 0;
379 found:
380 i = incl_index;
381 if (i > 0)
382 fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num);
383 fprintf(stderr, "%s %p", msg, (void*)wanted_pc);
384 if (last_func_name[0] != '\0')
385 fprintf(stderr, " %s()", last_func_name);
386 if (--i >= 0) {
387 fprintf(stderr, " (included from ");
388 for (;;) {
389 fprintf(stderr, "%s", incl_files[i]);
390 if (--i < 0)
391 break;
392 fprintf(stderr, ", ");
394 fprintf(stderr, ")");
396 fprintf(stderr, "\n");
397 fflush(stderr);
398 return func_addr;
401 /* emit a run time error at position 'pc' */
402 static void rt_error(ucontext_t *uc, const char *fmt, ...)
404 va_list ap;
405 addr_t pc;
406 int i;
408 fprintf(stderr, "Runtime error: ");
409 va_start(ap, fmt);
410 vfprintf(stderr, fmt, ap);
411 va_end(ap);
412 fprintf(stderr, "\n");
414 for(i=0;i<rt_num_callers;i++) {
415 if (rt_get_caller_pc(&pc, uc, i) < 0)
416 break;
417 pc = rt_printline(pc, i ? "by" : "at");
418 if (pc == (addr_t)rt_prog_main && pc)
419 break;
423 /* ------------------------------------------------------------- */
424 #ifndef _WIN32
426 /* signal handler for fatal errors */
427 static void sig_error(int signum, siginfo_t *siginf, void *puc)
429 ucontext_t *uc = puc;
431 switch(signum) {
432 case SIGFPE:
433 switch(siginf->si_code) {
434 case FPE_INTDIV:
435 case FPE_FLTDIV:
436 rt_error(uc, "division by zero");
437 break;
438 default:
439 rt_error(uc, "floating point exception");
440 break;
442 break;
443 case SIGBUS:
444 case SIGSEGV:
445 if (rt_bound_error_msg && *rt_bound_error_msg)
446 rt_error(uc, *rt_bound_error_msg);
447 else
448 rt_error(uc, "dereferencing invalid pointer");
449 break;
450 case SIGILL:
451 rt_error(uc, "illegal instruction");
452 break;
453 case SIGABRT:
454 rt_error(uc, "abort() called");
455 break;
456 default:
457 rt_error(uc, "caught signal %d", signum);
458 break;
460 exit(255);
463 #ifndef SA_SIGINFO
464 # define SA_SIGINFO 0x00000004u
465 #endif
467 /* Generate a stack backtrace when a CPU exception occurs. */
468 static void set_exception_handler(void)
470 struct sigaction sigact;
471 /* install TCC signal handlers to print debug info on fatal
472 runtime errors */
473 sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
474 sigact.sa_sigaction = sig_error;
475 sigemptyset(&sigact.sa_mask);
476 sigaction(SIGFPE, &sigact, NULL);
477 sigaction(SIGILL, &sigact, NULL);
478 sigaction(SIGSEGV, &sigact, NULL);
479 sigaction(SIGBUS, &sigact, NULL);
480 sigaction(SIGABRT, &sigact, NULL);
483 /* ------------------------------------------------------------- */
484 #ifdef __i386__
486 /* fix for glibc 2.1 */
487 #ifndef REG_EIP
488 #define REG_EIP EIP
489 #define REG_EBP EBP
490 #endif
492 /* return the PC at frame level 'level'. Return negative if not found */
493 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
495 addr_t fp;
496 int i;
498 if (level == 0) {
499 #if defined(__APPLE__)
500 *paddr = uc->uc_mcontext->__ss.__eip;
501 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
502 *paddr = uc->uc_mcontext.mc_eip;
503 #elif defined(__dietlibc__)
504 *paddr = uc->uc_mcontext.eip;
505 #elif defined(__NetBSD__)
506 *paddr = uc->uc_mcontext.__gregs[_REG_EIP];
507 #elif defined(__OpenBSD__)
508 *paddr = uc->sc_eip;
509 #else
510 *paddr = uc->uc_mcontext.gregs[REG_EIP];
511 #endif
512 return 0;
513 } else {
514 #if defined(__APPLE__)
515 fp = uc->uc_mcontext->__ss.__ebp;
516 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
517 fp = uc->uc_mcontext.mc_ebp;
518 #elif defined(__dietlibc__)
519 fp = uc->uc_mcontext.ebp;
520 #elif defined(__NetBSD__)
521 fp = uc->uc_mcontext.__gregs[_REG_EBP];
522 #elif defined(__OpenBSD__)
523 *paddr = uc->sc_ebp;
524 #else
525 fp = uc->uc_mcontext.gregs[REG_EBP];
526 #endif
527 for(i=1;i<level;i++) {
528 /* XXX: check address validity with program info */
529 if (fp <= 0x1000 || fp >= 0xc0000000)
530 return -1;
531 fp = ((addr_t *)fp)[0];
533 *paddr = ((addr_t *)fp)[1];
534 return 0;
538 /* ------------------------------------------------------------- */
539 #elif defined(__x86_64__)
541 /* return the PC at frame level 'level'. Return negative if not found */
542 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
544 addr_t fp;
545 int i;
547 if (level == 0) {
548 /* XXX: only support linux */
549 #if defined(__APPLE__)
550 *paddr = uc->uc_mcontext->__ss.__rip;
551 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
552 *paddr = uc->uc_mcontext.mc_rip;
553 #elif defined(__NetBSD__)
554 *paddr = uc->uc_mcontext.__gregs[_REG_RIP];
555 #else
556 *paddr = uc->uc_mcontext.gregs[REG_RIP];
557 #endif
558 return 0;
559 } else {
560 #if defined(__APPLE__)
561 fp = uc->uc_mcontext->__ss.__rbp;
562 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
563 fp = uc->uc_mcontext.mc_rbp;
564 #elif defined(__NetBSD__)
565 fp = uc->uc_mcontext.__gregs[_REG_RBP];
566 #else
567 fp = uc->uc_mcontext.gregs[REG_RBP];
568 #endif
569 for(i=1;i<level;i++) {
570 /* XXX: check address validity with program info */
571 if (fp <= 0x1000)
572 return -1;
573 fp = ((addr_t *)fp)[0];
575 *paddr = ((addr_t *)fp)[1];
576 return 0;
580 /* ------------------------------------------------------------- */
581 #elif defined(__arm__)
583 /* return the PC at frame level 'level'. Return negative if not found */
584 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
586 addr_t fp, sp;
587 int i;
589 if (level == 0) {
590 /* XXX: only supports linux */
591 #if defined(__linux__)
592 *paddr = uc->uc_mcontext.arm_pc;
593 #else
594 return -1;
595 #endif
596 return 0;
597 } else {
598 #if defined(__linux__)
599 fp = uc->uc_mcontext.arm_fp;
600 sp = uc->uc_mcontext.arm_sp;
601 if (sp < 0x1000)
602 sp = 0x1000;
603 #else
604 return -1;
605 #endif
606 /* XXX: specific to tinycc stack frames */
607 if (fp < sp + 12 || fp & 3)
608 return -1;
609 for(i = 1; i < level; i++) {
610 sp = ((addr_t *)fp)[-2];
611 if (sp < fp || sp - fp > 16 || sp & 3)
612 return -1;
613 fp = ((addr_t *)fp)[-3];
614 if (fp <= sp || fp - sp < 12 || fp & 3)
615 return -1;
617 /* XXX: check address validity with program info */
618 *paddr = ((addr_t *)fp)[-1];
619 return 0;
623 /* ------------------------------------------------------------- */
624 #elif defined(__aarch64__)
626 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
628 if (level < 0)
629 return -1;
630 else if (level == 0) {
631 *paddr = uc->uc_mcontext.pc;
632 return 0;
634 else {
635 addr_t *fp = (addr_t *)uc->uc_mcontext.regs[29];
636 int i;
637 for (i = 1; i < level; i++)
638 fp = (addr_t *)fp[0];
639 *paddr = fp[1];
640 return 0;
644 /* ------------------------------------------------------------- */
645 #else
647 #warning add arch specific rt_get_caller_pc()
648 static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
650 return -1;
653 #endif /* !__i386__ */
655 /* ------------------------------------------------------------- */
656 #else /* WIN32 */
658 static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info)
660 EXCEPTION_RECORD *er = ex_info->ExceptionRecord;
661 CONTEXT *uc = ex_info->ContextRecord;
662 switch (er->ExceptionCode) {
663 case EXCEPTION_ACCESS_VIOLATION:
664 if (rt_bound_error_msg && *rt_bound_error_msg)
665 rt_error(uc, *rt_bound_error_msg);
666 else
667 rt_error(uc, "access violation");
668 break;
669 case EXCEPTION_STACK_OVERFLOW:
670 rt_error(uc, "stack overflow");
671 break;
672 case EXCEPTION_INT_DIVIDE_BY_ZERO:
673 rt_error(uc, "division by zero");
674 break;
675 default:
676 rt_error(uc, "exception caught");
677 break;
679 return EXCEPTION_EXECUTE_HANDLER;
682 /* Generate a stack backtrace when a CPU exception occurs. */
683 static void set_exception_handler(void)
685 SetUnhandledExceptionFilter(cpu_exception_handler);
688 #ifdef _WIN64
689 static void win64_add_function_table(TCCState *s1)
691 RtlAddFunctionTable(
692 (RUNTIME_FUNCTION*)s1->uw_pdata->sh_addr,
693 s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
694 text_section->sh_addr
697 #endif
699 /* return the PC at frame level 'level'. Return non zero if not found */
700 static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level)
702 addr_t fp, pc;
703 int i;
704 #ifdef _WIN64
705 pc = uc->Rip;
706 fp = uc->Rbp;
707 #else
708 pc = uc->Eip;
709 fp = uc->Ebp;
710 #endif
711 if (level > 0) {
712 for(i=1;i<level;i++) {
713 /* XXX: check address validity with program info */
714 if (fp <= 0x1000 || fp >= 0xc0000000)
715 return -1;
716 fp = ((addr_t*)fp)[0];
718 pc = ((addr_t*)fp)[1];
720 *paddr = pc;
721 return 0;
724 #endif /* _WIN32 */
725 #endif /* CONFIG_TCC_BACKTRACE */
726 /* ------------------------------------------------------------- */
727 #ifdef CONFIG_TCC_STATIC
729 /* dummy function for profiling */
730 ST_FUNC void *dlopen(const char *filename, int flag)
732 return NULL;
735 ST_FUNC void dlclose(void *p)
739 ST_FUNC const char *dlerror(void)
741 return "error";
744 typedef struct TCCSyms {
745 char *str;
746 void *ptr;
747 } TCCSyms;
750 /* add the symbol you want here if no dynamic linking is done */
751 static TCCSyms tcc_syms[] = {
752 #if !defined(CONFIG_TCCBOOT)
753 #define TCCSYM(a) { #a, &a, },
754 TCCSYM(printf)
755 TCCSYM(fprintf)
756 TCCSYM(fopen)
757 TCCSYM(fclose)
758 #undef TCCSYM
759 #endif
760 { NULL, NULL },
763 ST_FUNC void *dlsym(int flag, const char *symbol)
765 TCCSyms *p;
766 p = tcc_syms;
767 while (p->str != NULL) {
768 if (!strcmp(p->str, symbol))
769 return p->ptr;
770 p++;
772 return NULL;
775 #endif /* CONFIG_TCC_STATIC */
776 #endif /* TCC_IS_NATIVE */
777 /* ------------------------------------------------------------- */