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