Mercurial > hg > tinycc
changeset 553:4533aa54ffcf
More simplification and attacking warnings.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 21 Jan 2008 00:29:43 -0600 |
parents | 40ec0942b7f4 |
children | 8c020de0af57 |
files | i386/asm.c libtinycc.h tcc.c tcc.h tccasm.c tccelf.c |
diffstat | 6 files changed, 148 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/i386/asm.c Sun Jan 20 15:33:50 2008 -0600 +++ b/i386/asm.c Mon Jan 21 00:29:43 2008 -0600 @@ -96,7 +96,7 @@ ExprValue e; } Operand; -static const uint8_t reg_to_size[5] = { +static uint8_t reg_to_size[5] = { [OP_REG8] = 0, [OP_REG16] = 1, [OP_REG32] = 2, @@ -106,7 +106,7 @@ #define NB_TEST_OPCODES 30 -static const uint8_t test_bits[NB_TEST_OPCODES] = { +static uint8_t test_bits[NB_TEST_OPCODES] = { 0x00, /* o */ 0x01, /* no */ 0x02, /* b */ @@ -139,7 +139,7 @@ 0x0f, /* g */ }; -static const uint8_t segment_prefixes[] = { +static uint8_t segment_prefixes[] = { 0x26, /* es */ 0x2e, /* cs */ 0x36, /* ss */ @@ -148,7 +148,7 @@ 0x65 /* gs */ }; -static const ASMInstr asm_instrs[] = { +static ASMInstr asm_instrs[] = { #define ALT(x) x #define DEF_ASM_OP0(name, opcode) #define DEF_ASM_OP0L(name, opcode, group, instr_type) { TOK_ASM_ ## name, opcode, (instr_type | group << OPC_GROUP_SHIFT), 0 }, @@ -161,7 +161,7 @@ { 0, }, }; -static const uint16_t op0_codes[] = { +static uint16_t op0_codes[] = { #define ALT(x) #define DEF_ASM_OP0(x, opcode) opcode, #define DEF_ASM_OP0L(name, opcode, group, instr_type) @@ -218,7 +218,7 @@ { ExprValue e; int reg, indir; - const char *p; + char *p; indir = 0; if (tok == '*') { @@ -408,7 +408,7 @@ static void asm_opcode(TCCState *s1, int opcode) { - const ASMInstr *pa; + ASMInstr *pa; int i, modrm_index, reg, v, op1, is_short_jmp, has_seg_prefix; int nb_ops, s, ss; Operand ops[MAX_OPERANDS], *pop, seg_prefix; @@ -720,7 +720,7 @@ /* return the constraint priority (we allocate first the lowest numbered constraints) */ -static inline int constraint_priority(const char *str) +static inline int constraint_priority(char *str) { int priority, c, pr; @@ -767,7 +767,7 @@ return priority; } -static const char *skip_constraint_modifiers(const char *p) +static char *skip_constraint_modifiers(char *p) { while (*p == '=' || *p == '&' || *p == '+' || *p == '%') p++; @@ -781,13 +781,13 @@ static void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, - const uint8_t *clobber_regs, + uint8_t *clobber_regs, int *pout_reg) { ASMOperand *op; int sorted_op[MAX_ASM_OPERANDS]; int i, j, k, p1, p2, tmp, reg, c, reg_mask; - const char *str; + char *str; uint8_t regs_allocated[NB_ASM_REGS]; /* init fields */ @@ -1176,7 +1176,7 @@ } } -static void asm_clobber(uint8_t *clobber_regs, const char *str) +static void asm_clobber(uint8_t *clobber_regs, char *str) { int reg; TokenSym *ts;
--- a/libtinycc.h Sun Jan 20 15:33:50 2008 -0600 +++ b/libtinycc.h Mon Jan 21 00:29:43 2008 -0600 @@ -20,7 +20,7 @@ /* set error/warning display callback */ void tcc_set_error_func(TCCState *s, void *error_opaque, - void (*error_func)(void *opaque, const char *msg)); + void (*error_func)(void *opaque, char *msg)); /* set/reset a warning */ int tcc_set_warning(TCCState *s, char *warning_name, int value); @@ -29,27 +29,27 @@ /* preprocessor */ /* add include path */ -int tcc_add_include_path(TCCState *s, const char *pathname); +int tcc_add_include_path(TCCState *s, char *pathname); /* add in system include path */ -int tcc_add_sysinclude_path(TCCState *s, const char *pathname); +int tcc_add_sysinclude_path(TCCState *s, char *pathname); /* define preprocessor symbol 'sym'. Can put optional value */ -void tcc_define_symbol(TCCState *s, const char *sym, const char *value); +void tcc_define_symbol(TCCState *s, char *sym, char *value); /* undefine preprocess symbol 'sym' */ -void tcc_undefine_symbol(TCCState *s, const char *sym); +void tcc_undefine_symbol(TCCState *s, char *sym); /*****************************/ /* compiling */ /* add a file (either a C file, dll, an object, a library or an ld script). Return -1 if error. */ -int tcc_add_file(TCCState *s, const char *filename); +int tcc_add_file(TCCState *s, char *filename); /* compile a string containing a C source. Return non zero if error. */ -int tcc_compile_string(TCCState *s, const char *buf); +int tcc_compile_string(TCCState *s, char *buf); /*****************************/ /* linking commands */ @@ -68,17 +68,17 @@ #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */ /* equivalent to -Lpath option */ -int tcc_add_library_path(TCCState *s, const char *pathname); +int tcc_add_library_path(TCCState *s, char *pathname); /* the library name is the same as the argument of the '-l' option */ -int tcc_add_library(TCCState *s, const char *libraryname); +int tcc_add_library(TCCState *s, char *libraryname); /* add a symbol to the compiled program */ -int tcc_add_symbol(TCCState *s, const char *name, unsigned long val); +int tcc_add_symbol(TCCState *s, char *name, unsigned long val); /* output an executable, library or object file. DO NOT call tcc_relocate() before. */ -int tcc_output_file(TCCState *s, const char *filename); +int tcc_output_file(TCCState *s, char *filename); /* link and run main() function and return its value. DO NOT call tcc_relocate() before. */ @@ -89,7 +89,7 @@ int tcc_relocate(TCCState *s); /* return symbol value. return 0 if OK, -1 if symbol not found */ -int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name); +int tcc_get_symbol(TCCState *s, unsigned long *pval, char *name); #ifdef __cplusplus }
--- a/tcc.c Sun Jan 20 15:33:50 2008 -0600 +++ b/tcc.c Mon Jan 21 00:29:43 2008 -0600 @@ -109,13 +109,13 @@ /* max number of callers shown if error */ static int num_callers = 6; -static const char **rt_bound_error_msg; +static char **rt_bound_error_msg; /* XXX: get rid of this ASAP */ static struct TCCState *tcc_state; /* give the path of the compiler's libraries */ -const char *tinycc_path; +char *tinycc_path; /********************************************************/ @@ -130,7 +130,7 @@ } /* copy a string and truncate it. */ -char *pstrcpy(char *buf, int buf_size, const char *s) +char *pstrcpy(char *buf, int buf_size, char *s) { char *q, *q_end; int c; @@ -149,7 +149,7 @@ } /* strcat and truncate. */ -static char *pstrcat(char *buf, int buf_size, const char *s) +static char *pstrcat(char *buf, int buf_size, char *s) { int len; len = strlen(buf); @@ -160,7 +160,7 @@ // If str starts with val, return 1 and move ptr right after val in str. // Otherwise return 0 -int strstart(const char *str, const char *val, const char **ptr) +int strstart(char *str, char *val, char **ptr) { while (*val) { if (*str != *val) return 0; @@ -192,7 +192,7 @@ return ptr1; } -static char *xstrdup(const char *str) +static char *xstrdup(char *str) { char *ptr = xmalloc(strlen(str) + 1); strcpy(ptr, str); @@ -258,7 +258,7 @@ sym_free_first = sym; } -Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) +Section *new_section(TCCState *s1, char *name, int sh_type, int sh_flags) { Section *sec; @@ -329,7 +329,7 @@ /* return a reference to a section, and create it if it does not exists */ -Section *find_section(TCCState *s1, const char *name) +Section *find_section(TCCState *s1, char *name) { Section *sec; int i; @@ -352,24 +352,19 @@ { int sym_type, sym_bind, sh_num, info; Elf32_Sym *esym; - const char *name; + char *name; char buf1[256]; - if (section == NULL) - sh_num = SHN_UNDEF; - else if (section == SECTION_ABS) - sh_num = SHN_ABS; - else - sh_num = section->sh_num; + if (!section) sh_num = SHN_UNDEF; + else if (section == SECTION_ABS) sh_num = SHN_ABS; + else sh_num = section->sh_num; + if (!sym->c) { - if ((sym->type.t & VT_BTYPE) == VT_FUNC) - sym_type = STT_FUNC; - else - sym_type = STT_OBJECT; - if (sym->type.t & VT_STATIC) - sym_bind = STB_LOCAL; - else - sym_bind = STB_GLOBAL; + if ((sym->type.t & VT_BTYPE) == VT_FUNC) sym_type = STT_FUNC; + else sym_type = STT_OBJECT; + + if (sym->type.t & VT_STATIC) sym_bind = STB_LOCAL; + else sym_bind = STB_GLOBAL; name = get_tok_str(sym->token, NULL); #ifdef CONFIG_TCC_BCHECK @@ -444,14 +439,14 @@ return c; } -static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap) +static void strcat_vprintf(char *buf, int buf_size, char *fmt, va_list ap) { int len; len = strlen(buf); vsnprintf(buf + len, buf_size - len, fmt, ap); } -static void strcat_printf(char *buf, int buf_size, const char *fmt, ...) +static void strcat_printf(char *buf, int buf_size, char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -459,7 +454,7 @@ va_end(ap); } -void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap) +void error1(TCCState *s1, int is_warning, char *fmt, va_list ap) { char buf[2048]; BufferedFile **f; @@ -496,7 +491,7 @@ #ifdef LIBTCC void tcc_set_error_func(TCCState *s, void *error_opaque, - void (*error_func)(void *opaque, const char *msg)) + void (*error_func)(void *opaque, char *msg)) { s->error_opaque = error_opaque; s->error_func = error_func; @@ -504,7 +499,7 @@ #endif /* error without aborting current compilation */ -void error_noabort(const char *fmt, ...) +void error_noabort(char *fmt, ...) { TCCState *s1 = tcc_state; va_list ap; @@ -514,7 +509,7 @@ va_end(ap); } -void error(const char *fmt, ...) +void error(char *fmt, ...) { TCCState *s1 = tcc_state; va_list ap; @@ -531,12 +526,12 @@ } } -void expect(const char *msg) +void expect(char *msg) { error("%s expected", msg); } -void warning(const char *fmt, ...) +void warning(char *fmt, ...) { TCCState *s1 = tcc_state; va_list ap; @@ -563,7 +558,7 @@ } /* allocate a new token */ -static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) +static TokenSym *tok_alloc_new(TokenSym **pts, char *str, int len) { TokenSym *ts, **ptable; int i; @@ -597,7 +592,7 @@ #define TOK_HASH_FUNC(h, c) ((h) * 263 + (c)) /* find a token and add it if not found */ -static TokenSym *tok_alloc(const char *str, int len) +static TokenSym *tok_alloc(char *str, int len) { TokenSym *ts, **pts; int i; @@ -649,7 +644,7 @@ cstr->size = size; } -static void cstr_cat(CString *cstr, const char *str) +static void cstr_cat(CString *cstr, char *str) { int c; for(;;) { @@ -927,7 +922,7 @@ /* I/O layer */ -BufferedFile *tcc_open(TCCState *s1, const char *filename) +BufferedFile *tcc_open(TCCState *s1, char *filename) { int fd; BufferedFile *bf; @@ -1791,14 +1786,14 @@ define_push(v, t, str.str, first); } -static inline int hash_cached_include(int type, const char *filename) -{ - const unsigned char *s; +static inline int hash_cached_include(int type, char *filename) +{ + uint8_t *s; unsigned int h; h = TOK_HASH_INIT; h = TOK_HASH_FUNC(h, type); - s = filename; + s = (uint8_t *)filename; while (*s) { h = TOK_HASH_FUNC(h, *s); s++; @@ -1809,7 +1804,7 @@ /* XXX: use a token or a hash table to accelerate matching ? */ static CachedInclude *search_cached_include(TCCState *s1, - int type, const char *filename) + int type, char *filename) { CachedInclude *e; int i, h; @@ -1827,7 +1822,7 @@ } static inline void add_cached_include(TCCState *s1, int type, - const char *filename, int ifndef_macro) + char *filename, int ifndef_macro) { CachedInclude *e; int h; @@ -2013,7 +2008,7 @@ /* now search in all the include paths */ n = s1->include_paths.len + s1->sysinclude_paths.len; for(i = 0; i < n; i++) { - const char *path; + char *path; int verbose = s1->verbose; verbose -= (s1->include_stack_ptr != s1->include_stack); @@ -2177,10 +2172,10 @@ } /* evaluate escape codes in a string. */ -static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long) +static void parse_escape_string(CString *outstr, uint8_t *buf, int is_long) { int c, n, i; - const uint8_t *p; + uint8_t *p; p = buf; for(;;) { @@ -2297,7 +2292,7 @@ /* parse number in null terminated string 'p' and return it in the current token */ -void parse_number(const char *p) +void parse_number(char *p) { int b, t, shift, frac_bits, s, exp_val, ch; char *q; @@ -3111,7 +3106,7 @@ return str.str; } -static char const ab_month_name[12][4] = +static char ab_month_name[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" @@ -3272,12 +3267,12 @@ /* handle the '##' operator. Return NULL if no '##' seen. Otherwise return the resulting string (which must be freed). */ -static inline int *macro_twosharps(const int *macro_str) +static inline int *macro_twosharps(int *macro_str) { TokenSym *ts; - const int *macro_ptr1, *start_macro_ptr, *ptr, *saved_macro_ptr; + int *macro_ptr1, *start_macro_ptr, *ptr, *saved_macro_ptr; int t, tf; - const char *p1, *p2; + char *p1, *p2; CValue cval; TokenString macro_str1; CString cstr; @@ -3341,7 +3336,7 @@ /* if identifier, we must do a test to validate we have a correct identifier */ if (t == TOK_PPNUM) { - const char *p; + char *p; int c; p = p2; @@ -3358,8 +3353,8 @@ tok = ts->tok; /* modify current token */ } } else { - const char *str = cstr.data; - const unsigned char *q; + char *str = cstr.data; + unsigned char *q; /* we look for a valid token */ /* XXX: do more extensive checks */ @@ -3413,11 +3408,11 @@ (tok_str,tok_len). 'nested_list' is the list of all macros we got inside to avoid recursing. */ static void macro_subst(TokenString *tok_str, Sym **nested_list, - const int *macro_str, struct macro_level ** can_read_stream) + int *macro_str, struct macro_level ** can_read_stream) { Sym *s; int *macro_str1; - const int *ptr; + int *ptr; int t, tf, ret; CValue cval; struct macro_level ml; @@ -5209,12 +5204,12 @@ /* XXX: union */ /* XXX: add array and function pointers */ void type_to_str(char *buf, int buf_size, - CType *type, const char *varstr) + CType *type, char *varstr) { int bt, token, t; Sym *s, *sa; char buf1[256]; - const char *tstr; + char *tstr; t = type->t & VT_TYPE; bt = t & VT_BTYPE; @@ -8569,7 +8564,7 @@ } #ifdef LIBTCC -int tcc_compile_string(TCCState *s, const char *str) +int tcc_compile_string(TCCState *s, char *str) { BufferedFile bf1, *bf = &bf1; int ret, len; @@ -8598,7 +8593,7 @@ #endif /* define a preprocessor symbol. A value can also be provided with the '=' operator */ -void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) +void tcc_define_symbol(TCCState *s1, char *sym, char *value) { BufferedFile bf1, *bf = &bf1; @@ -8628,7 +8623,7 @@ } /* undefine a preprocessor symbol */ -void tcc_undefine_symbol(TCCState *s1, const char *sym) +void tcc_undefine_symbol(TCCState *s1, char *sym) { TokenSym *ts; Sym *s; @@ -8762,9 +8757,9 @@ return (*prog_main)(argc, argv); } -void add_dynarray_path(TCCState *s, const char *pathname, struct dynarray *dd) -{ - const char *c = pathname; +void add_dynarray_path(TCCState *s, char *pathname, struct dynarray *dd) +{ + char *c = pathname; for (;;) { if (!*c || *c==LIB_PATH_SEPCHAR) { @@ -8784,7 +8779,7 @@ TCCState *tcc_new(void) { - const char *p, *r; + char *p, *r; TCCState *s; TokenSym *ts; int i, c; @@ -8937,9 +8932,9 @@ free(s1); } -int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) -{ - const char *ext, *filename1; +int tcc_add_file_internal(TCCState *s1, char *filename, int flags) +{ + char *ext, *filename1; Elf32_Ehdr ehdr; int fd, ret; BufferedFile *saved_file; @@ -9054,14 +9049,14 @@ goto the_end; } -int tcc_add_file(TCCState *s, const char *filename) +int tcc_add_file(TCCState *s, char *filename) { return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR); } /* find and load a dll. Return non zero if not found */ /* XXX: add '-rpath' option support ? */ -static int tcc_add_dll(TCCState *s, const char *filename, int flags) +static int tcc_add_dll(TCCState *s, char *filename, int flags) { char buf[1024]; int i; @@ -9076,7 +9071,7 @@ } /* the library name is the same as the argument of the '-l' option */ -int tcc_add_library(TCCState *s, const char *libraryname) +int tcc_add_library(TCCState *s, char *libraryname) { char buf[1024]; int i; @@ -9102,7 +9097,7 @@ return -1; } -int tcc_add_symbol(TCCState *s, const char *name, unsigned long val) +int tcc_add_symbol(TCCState *s, char *name, unsigned long val) { add_elf_sym(symtab_section, val, 0, ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
--- a/tcc.h Sun Jan 20 15:33:50 2008 -0600 +++ b/tcc.h Mon Jan 21 00:29:43 2008 -0600 @@ -390,7 +390,7 @@ /* error handling */ void *error_opaque; - void (*error_func)(void *opaque, const char *msg); + void (*error_func)(void *opaque, char *msg); int error_set_jmp_enabled; jmp_buf error_jmp_buf; int nb_errors; @@ -619,7 +619,7 @@ #undef DEF }; -static const char tcc_keywords[] = +static char tcc_keywords[] = #define DEF(id, str) str "\0" #include "tcctok.h" #undef DEF @@ -662,8 +662,8 @@ extern long double strtold (const char *__nptr, char **__endptr); #endif -char *pstrcpy(char *buf, int buf_size, const char *s); -static char *pstrcat(char *buf, int buf_size, const char *s); +char *pstrcpy(char *buf, int buf_size, char *s); +static char *pstrcat(char *buf, int buf_size, char *s); static char *tcc_basename(char *name); static void next(void); @@ -699,7 +699,7 @@ }; static void macro_subst(TokenString *tok_str, Sym **nested_list, - const int *macro_str, struct macro_level **can_read_stream); + int *macro_str, struct macro_level **can_read_stream); void gen_op(int op); void force_charshort_cast(int t); static void gen_cast(CType *type); @@ -718,7 +718,7 @@ static void expr_const1(void); int ieee_finite(double d); -void error(const char *fmt, ...); +void error(char *fmt, ...); void vpushi(int v); void vrott(int n); void vnrott(int n); @@ -726,7 +726,7 @@ static void vpush_global_sym(CType *type, int v); void vset(CType *type, int r, int v); void type_to_str(char *buf, int buf_size, - CType *type, const char *varstr); + CType *type, char *varstr); char *get_tok_str(int v, CValue *cv); static Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size); @@ -738,36 +738,36 @@ static void put_extern_sym(Sym *sym, Section *section, unsigned long value, unsigned long size); static void greloc(Section *s, Sym *sym, unsigned long addr, int type); -static int put_elf_str(Section *s, const char *sym); +static int put_elf_str(Section *s, char *sym); static int put_elf_sym(Section *s, unsigned long value, unsigned long size, - int info, int other, int shndx, const char *name); + int info, int other, int shndx, char *name); static int add_elf_sym(Section *s, unsigned long value, unsigned long size, - int info, int other, int sh_num, const char *name); + int info, int other, int sh_num, char *name); static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol); -static void put_stabs(const char *str, int type, int other, int desc, +static void put_stabs(char *str, int type, int other, int desc, unsigned long value); -static void put_stabs_r(const char *str, int type, int other, int desc, +static void put_stabs_r(char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index); static void put_stabn(int type, int other, int desc, int value); static void put_stabd(int type, int other, int desc); -static int tcc_add_dll(TCCState *s, const char *filename, int flags); +static int tcc_add_dll(TCCState *s, char *filename, int flags); #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */ #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ #define AFF_PREPROCESS 0x0004 /* preprocess file */ -int tcc_add_file_internal(TCCState *s, const char *filename, int flags); +int tcc_add_file_internal(TCCState *s, char *filename, int flags); /* tcccoff.c */ int tcc_output_coff(TCCState *s1, FILE *f); /* tccpe.c */ -static void *resolve_sym(TCCState *s1, const char *sym, int type); +static void *resolve_sym(TCCState *s1, char *sym, int type); int pe_load_def_file(struct TCCState *s1, FILE *fp); -void pe_setup_paths(struct TCCState *s1, int *p_output_type, const char **p_outfile, char *first_file); +void pe_setup_paths(struct TCCState *s1, int *p_output_type, char **p_outfile, char *first_file); unsigned long pe_add_runtime(struct TCCState *s1); -int tcc_output_pe(struct TCCState *s1, const char *filename); +int tcc_output_pe(struct TCCState *s1, char *filename); /* tccasm.c */ @@ -797,7 +797,7 @@ static void asm_expr(TCCState *s1, ExprValue *pe); static int asm_int_expr(TCCState *s1); static int find_constraint(ASMOperand *operands, int nb_operands, - const char *name, const char **pp); + char *name, char **pp); static int tcc_assemble(TCCState *s1, int do_preprocess); @@ -847,7 +847,7 @@ { NULL, NULL }, }; -static void *resolve_sym(TCCState *s1, const char *symbol, int type) +static void *resolve_sym(TCCState *s1, char *symbol, int type) { TCCSyms *p; p = tcc_syms; @@ -860,12 +860,12 @@ } /* dummy function for profiling */ -void *dlopen(const char *filename, int flag) +void *dlopen(char *filename, int flag) { return NULL; } -const char *dlerror(void) +char *dlerror(void) { return "error"; } @@ -874,7 +874,7 @@ #include <dlfcn.h> -static inline void *resolve_sym(TCCState *s1, const char *sym, int type) +static inline void *resolve_sym(TCCState *s1, char *sym, int type) { return dlsym(RTLD_DEFAULT, sym); }
--- a/tccasm.c Sun Jan 20 15:33:50 2008 -0600 +++ b/tccasm.c Mon Jan 21 00:29:43 2008 -0600 @@ -25,7 +25,7 @@ { Sym *sym; int op, n, label; - const char *p; + char *p; switch(tok) { case TOK_PPNUM: @@ -278,14 +278,12 @@ Sym *s, *s1; Section *sec; - for(s = st->asm_labels; s != NULL; s = s1) { + for(s = st->asm_labels; s; s = s1) { s1 = s->prev; /* define symbol value in object file */ if (s->r) { - if (s->r == SHN_ABS) - sec = SECTION_ABS; - else - sec = st->sections[s->r]; + if (s->r == SHN_ABS) sec = SECTION_ABS; + else sec = st->sections[s->r]; put_extern_sym2(s, sec, (long)s->next, 0, 0); } /* remove label */ @@ -302,7 +300,7 @@ ind = cur_text_section->data_offset; } -static void use_section(TCCState *s1, const char *name) +static void use_section(TCCState *s1, char *name) { Section *sec; sec = find_section(s1, name); @@ -353,7 +351,7 @@ next(); for(;;) { uint64_t vl; - const char *p; + char *p; p = tokc.cstr->data; if (tok != TOK_PPNUM) { @@ -484,7 +482,7 @@ case TOK_ASM_ascii: case TOK_ASM_asciz: { - const uint8_t *p; + uint8_t *p; int i, size, t; t = tok; @@ -574,7 +572,7 @@ #if 0 /* print stats about opcodes */ { - const ASMInstr *pa; + ASMInstr *pa; int freq[4]; int op_vals[500]; int nb_op_vals, i, j; @@ -623,7 +621,7 @@ } else if (tok == '.') { asm_parse_directive(s1); } else if (tok == TOK_PPNUM) { - const char *p; + char *p; int n; p = tokc.cstr->data; n = strtoul(p, (char **)&p, 10); @@ -727,11 +725,11 @@ syntax). return -1 if not found. Return in *pp in char after the constraint */ static int find_constraint(ASMOperand *operands, int nb_operands, - const char *name, const char **pp) + char *name, char **pp) { int index; TokenSym *ts; - const char *p; + char *p; if (isnum(*name)) { index = 0; @@ -769,7 +767,7 @@ CString *out_str, CString *in_str) { int c, index, modifier; - const char *str; + char *str; ASMOperand *op; SValue sv;
--- a/tccelf.c Sun Jan 20 15:33:50 2008 -0600 +++ b/tccelf.c Mon Jan 21 00:29:43 2008 -0600 @@ -8,7 +8,7 @@ #include <limits.h> -static int put_elf_str(Section *s, const char *sym) +static int put_elf_str(Section *s, char *sym) { int offset, len; char *ptr; @@ -21,7 +21,7 @@ } /* elf symbol hashing function */ -static unsigned long elf_hash(const unsigned char *name) +static unsigned long elf_hash(unsigned char *name) { unsigned long h = 0, g; @@ -72,7 +72,7 @@ /* return the symbol number */ static int put_elf_sym(Section *s, unsigned long value, unsigned long size, - int info, int other, int shndx, const char *name) + int info, int other, int shndx, char *name) { int name_offset, sym_index; int nbuckets, h; @@ -120,12 +120,12 @@ /* find global ELF symbol 'name' and return its index. Return 0 if not found. */ -static int find_elf_sym(Section *s, const char *name) +static int find_elf_sym(Section *s, char *name) { Elf32_Sym *sym; Section *hs; int nbuckets, sym_index, h; - const char *name1; + char *name1; hs = s->hash; if (!hs) @@ -144,7 +144,7 @@ } /* return elf symbol value or error */ -int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name) +int tcc_get_symbol(TCCState *s, unsigned long *pval, char *name) { int sym_index; Elf32_Sym *sym; @@ -157,7 +157,7 @@ return 0; } -void *tcc_get_symbol_err(TCCState *s, const char *name) +void *tcc_get_symbol_err(TCCState *s, char *name) { unsigned long val; if (tcc_get_symbol(s, &val, name) < 0) @@ -168,7 +168,7 @@ /* add an elf symbol : check if it is already defined and patch it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, - int info, int other, int sh_num, const char *name) + int info, int other, int sh_num, char *name) { Elf32_Sym *esym; int sym_bind, sym_index, sym_type, esym_bind; @@ -270,7 +270,7 @@ unsigned long n_value; /* value of symbol */ } Stab_Sym; -static void put_stabs(const char *str, int type, int other, int desc, +static void put_stabs(char *str, int type, int other, int desc, unsigned long value) { Stab_Sym *sym; @@ -287,7 +287,7 @@ sym->n_value = value; } -static void put_stabs_r(const char *str, int type, int other, int desc, +static void put_stabs_r(char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index) { put_stabs(str, type, other, desc, value); @@ -399,7 +399,7 @@ { Elf32_Sym *sym, *esym, *sym_end; int sym_bind, sh_num, sym_index; - const char *name; + char *name; unsigned long addr; sym_end = (Elf32_Sym *)(symtab_section->data + symtab_section->data_offset); @@ -713,7 +713,7 @@ int sym_index) { int index; - const char *name; + char *name; Elf32_Sym *sym; unsigned long offset; int *ptr; @@ -908,9 +908,9 @@ } static Section *new_symtab(TCCState *s1, - const char *symtab_name, int sh_type, int sh_flags, - const char *strtab_name, - const char *hash_name, int hash_sh_flags) + char *symtab_name, int sh_type, int sh_flags, + char *strtab_name, + char *hash_name, int hash_sh_flags) { Section *symtab, *strtab, *hash; int *ptr, nb_buckets; @@ -945,7 +945,7 @@ dyn->d_un.d_val = val; } -static void add_init_array_defines(TCCState *s1, const char *section_name) +static void add_init_array_defines(TCCState *s1, char *section_name) { Section *s; long end_offset; @@ -1050,7 +1050,7 @@ s = s1->sections[i]; if (s->sh_type == SHT_PROGBITS && (s->sh_flags & SHF_ALLOC)) { - const char *p; + char *p; int ch; /* check if section name can be expressed in C */ @@ -1090,7 +1090,7 @@ #endif static void tcc_output_binary(TCCState *s1, FILE *f, - const int *section_order) + int *section_order) { Section *s; int i, offset, size; @@ -1113,7 +1113,7 @@ /* output an ELF file */ /* XXX: suppress unneeded sections */ -int tcc_output_file(TCCState *s1, const char *filename) +int tcc_output_file(TCCState *s1, char *filename) { Elf32_Ehdr ehdr; FILE *f; @@ -1150,7 +1150,7 @@ tcc_add_linker_symbols(s1); if (!s1->static_link) { - const char *name; + char *name; int sym_index, index; Elf32_Sym *esym, *sym_end; @@ -2019,7 +2019,7 @@ char ar_fmag[2]; /* should contain ARFMAG */ } ArchiveHeader; -static int get_be32(const uint8_t *b) +static int get_be32(uint8_t *b) { return b[3] | (b[2] << 8) | (b[1] << 16) | (b[0] << 24); } @@ -2029,8 +2029,8 @@ { int i, bound, nsyms, sym_index, off, ret; uint8_t *data; - const char *ar_names, *p; - const uint8_t *ar_index; + char *ar_names, *p; + uint8_t *ar_index; Elf32_Sym *sym; data = xmalloc(size); @@ -2123,7 +2123,7 @@ /* load a DLL and all referenced DLLs. 'level = 0' means that the DLL is referenced by the user (so it should be added as DT_NEEDED in the generated ELF file) */ -static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) +static int tcc_load_dll(TCCState *s1, int fd, char *filename, int level) { Elf32_Ehdr ehdr; Elf32_Shdr *shdr, *sh, *sh1; @@ -2131,7 +2131,7 @@ Elf32_Sym *sym, *dynsym; Elf32_Dyn *dt, *dynamic; unsigned char *dynstr; - const char *name, *soname, *p; + char *name, *soname, *p; DLLReference *dllref; read(fd, &ehdr, sizeof(ehdr));