added -f[no-]leading-underscore - '@' symbol for asm

This commit is contained in:
bellard 2005-06-15 22:32:29 +00:00
parent 0c7f0ed312
commit f6db2edc40

23
tcc.c
View File

@ -460,6 +460,7 @@ struct TCCState {
/* C language options */ /* C language options */
int char_is_unsigned; int char_is_unsigned;
int leading_underscore;
/* warning switches */ /* warning switches */
int warn_write_strings; int warn_write_strings;
@ -1216,12 +1217,14 @@ Section *find_section(TCCState *s1, const char *name)
/* update sym->c so that it points to an external symbol in section /* update sym->c so that it points to an external symbol in section
'section' with value 'value' */ 'section' with value 'value' */
static void put_extern_sym(Sym *sym, Section *section, static void put_extern_sym2(Sym *sym, Section *section,
unsigned long value, unsigned long size) unsigned long value, unsigned long size,
int can_add_underscore)
{ {
int sym_type, sym_bind, sh_num, info; int sym_type, sym_bind, sh_num, info;
Elf32_Sym *esym; Elf32_Sym *esym;
const char *name; const char *name;
char buf1[256];
if (section == NULL) if (section == NULL)
sh_num = SHN_UNDEF; sh_num = SHN_UNDEF;
@ -1268,6 +1271,11 @@ static void put_extern_sym(Sym *sym, Section *section,
} }
} }
#endif #endif
if (tcc_state->leading_underscore && can_add_underscore) {
buf1[0] = '_';
pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
name = buf1;
}
info = ELF32_ST_INFO(sym_bind, sym_type); info = ELF32_ST_INFO(sym_bind, sym_type);
sym->c = add_elf_sym(symtab_section, value, size, info, 0, sh_num, name); sym->c = add_elf_sym(symtab_section, value, size, info, 0, sh_num, name);
} else { } else {
@ -1278,6 +1286,12 @@ static void put_extern_sym(Sym *sym, Section *section,
} }
} }
static void put_extern_sym(Sym *sym, Section *section,
unsigned long value, unsigned long size)
{
put_extern_sym2(sym, section, value, size, 1);
}
/* add a new relocation entry to symbol 'sym' in section 's' */ /* add a new relocation entry to symbol 'sym' in section 's' */
static void greloc(Section *s, Sym *sym, unsigned long offset, int type) static void greloc(Section *s, Sym *sym, unsigned long offset, int type)
{ {
@ -3854,6 +3868,7 @@ static inline void next_nomacro1(void)
case '?': case '?':
case '~': case '~':
case '$': /* only used in assembler */ case '$': /* only used in assembler */
case '@': /* dito */
tok = c; tok = c;
p++; p++;
break; break;
@ -9731,6 +9746,9 @@ TCCState *tcc_new(void)
#ifdef CHAR_IS_UNSIGNED #ifdef CHAR_IS_UNSIGNED
s->char_is_unsigned = 1; s->char_is_unsigned = 1;
#endif
#ifdef TCC_TARGET_PE
s->leading_underscore = 1;
#endif #endif
return s; return s;
} }
@ -10109,6 +10127,7 @@ static const FlagDef flag_defs[] = {
{ offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" },
{ offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" },
{ offsetof(TCCState, nocommon), FD_INVERT, "common" }, { offsetof(TCCState, nocommon), FD_INVERT, "common" },
{ offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
}; };
/* set/reset a flag */ /* set/reset a flag */