Unified · Split
| @@ -460,7 +460,8 @@ struct TCCState { · 459 unmodified lines | ||
| 460 | 460 | |
| 461 | 461 | /* C language options */ |
| 462 | 462 | int char_is_unsigned; |
| 463 | − | |
| 463 | + int leading_underscore; | |
| 464 | + | |
| 464 | 465 | /* warning switches */ |
| 465 | 466 | int warn_write_strings; |
| 466 | 467 | int warn_unsupported; |
| @@ -1216,12 +1217,14 @@ Section *find_section(TCCState *s1, const char *name) · 749 unmodified lines | ||
| 1216 | 1217 | |
| 1217 | 1218 | /* update sym->c so that it points to an external symbol in section |
| 1218 | 1219 | 'section' with value 'value' */ |
| 1219 | −static void put_extern_sym(Sym *sym, Section *section, | |
| 1220 | − unsigned long value, unsigned long size) | |
| 1220 | +static void put_extern_sym2(Sym *sym, Section *section, | |
| 1221 | + unsigned long value, unsigned long size, | |
| 1222 | + int can_add_underscore) | |
| 1221 | 1223 | { |
| 1222 | 1224 | int sym_type, sym_bind, sh_num, info; |
| 1223 | 1225 | Elf32_Sym *esym; |
| 1224 | 1226 | const char *name; |
| 1227 | + char buf1[256]; | |
| 1225 | 1228 | |
| 1226 | 1229 | if (section == NULL) |
| 1227 | 1230 | sh_num = SHN_UNDEF; |
| @@ -1268,6 +1271,11 @@ static void put_extern_sym(Sym *sym, Section *section, · 40 unmodified lines | ||
| 1268 | 1271 | } |
| 1269 | 1272 | } |
| 1270 | 1273 | #endif |
| 1274 | + if (tcc_state->leading_underscore && can_add_underscore) { | |
| 1275 | + buf1[0] = '_'; | |
| 1276 | + pstrcpy(buf1 + 1, sizeof(buf1) - 1, name); | |
| 1277 | + name = buf1; | |
| 1278 | + } | |
| 1271 | 1279 | info = ELF32_ST_INFO(sym_bind, sym_type); |
| 1272 | 1280 | sym->c = add_elf_sym(symtab_section, value, size, info, 0, sh_num, name); |
| 1273 | 1281 | } else { |
| @@ -1278,6 +1286,12 @@ static void put_extern_sym(Sym *sym, Section *section, · 4 unmodified lines | ||
| 1278 | 1286 | } |
| 1279 | 1287 | } |
| 1280 | 1288 | |
| 1289 | +static void put_extern_sym(Sym *sym, Section *section, | |
| 1290 | + unsigned long value, unsigned long size) | |
| 1291 | +{ | |
| 1292 | + put_extern_sym2(sym, section, value, size, 1); | |
| 1293 | +} | |
| 1294 | + | |
| 1281 | 1295 | /* add a new relocation entry to symbol 'sym' in section 's' */ |
| 1282 | 1296 | static void greloc(Section *s, Sym *sym, unsigned long offset, int type) |
| 1283 | 1297 | { |
| @@ -3854,6 +3868,7 @@ static inline void next_nomacro1(void) · 2570 unmodified lines | ||
| 3854 | 3868 | case '?': |
| 3855 | 3869 | case '~': |
| 3856 | 3870 | case '$': /* only used in assembler */ |
| 3871 | + case '@': /* dito */ | |
| 3857 | 3872 | tok = c; |
| 3858 | 3873 | p++; |
| 3859 | 3874 | break; |
| @@ -9731,6 +9746,9 @@ TCCState *tcc_new(void) · 5871 unmodified lines | ||
| 9731 | 9746 | |
| 9732 | 9747 | #ifdef CHAR_IS_UNSIGNED |
| 9733 | 9748 | s->char_is_unsigned = 1; |
| 9749 | +#endif | |
| 9750 | +#ifdef TCC_TARGET_PE | |
| 9751 | + s->leading_underscore = 1; | |
| 9734 | 9752 | #endif |
| 9735 | 9753 | return s; |
| 9736 | 9754 | } |
| @@ -10109,6 +10127,7 @@ static const FlagDef flag_defs[] = { · 372 unmodified lines | ||
| 10109 | 10127 | { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, |
| 10110 | 10128 | { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, |
| 10111 | 10129 | { offsetof(TCCState, nocommon), FD_INVERT, "common" }, |
| 10130 | + { offsetof(TCCState, leading_underscore), 0, "leading-underscore" }, | |
| 10112 | 10131 | }; |
| 10113 | 10132 | |
| 10114 | 10133 | /* set/reset a flag */ |