Unified · Split
| @@ -6962,6 +6962,8 @@ static void tcc_add_runtime(TCCState *s1) · 6961 unmodified lines | ||
| 6962 | 6962 | { |
| 6963 | 6963 | char buf[1024]; |
| 6964 | 6964 | unsigned long *ptr; |
| 6965 | + int i; | |
| 6966 | + Section *s; | |
| 6965 | 6967 | |
| 6966 | 6968 | snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "libtcc1.o"); |
| 6967 | 6969 | tcc_add_file(s1, buf); |
| @@ -6999,6 +7001,38 @@ static void tcc_add_runtime(TCCState *s1) · 31 unmodified lines | ||
| 6999 | 7001 | bss_section->data_offset, 0, |
| 7000 | 7002 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 7001 | 7003 | bss_section->sh_num, "_end"); |
| 7004 | + /* add start and stop symbols for sections whose name can be | |
| 7005 | + expressed in C */ | |
| 7006 | + for(i = 1; i < nb_sections; i++) { | |
| 7007 | + s = sections[i]; | |
| 7008 | + if (s->sh_type == SHT_PROGBITS && | |
| 7009 | + (s->sh_flags & SHF_ALLOC)) { | |
| 7010 | + const char *p; | |
| 7011 | + int ch; | |
| 7012 | + | |
| 7013 | + /* check if section name can be expressed in C */ | |
| 7014 | + p = s->name; | |
| 7015 | + for(;;) { | |
| 7016 | + ch = *p; | |
| 7017 | + if (!ch) | |
| 7018 | + break; | |
| 7019 | + if (!isid(ch) && !isnum(ch)) | |
| 7020 | + goto next_sec; | |
| 7021 | + p++; | |
| 7022 | + } | |
| 7023 | + snprintf(buf, sizeof(buf), "__start_%s", s->name); | |
| 7024 | + add_elf_sym(symtab_section, | |
| 7025 | + 0, 0, | |
| 7026 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), | |
| 7027 | + s->sh_num, buf); | |
| 7028 | + snprintf(buf, sizeof(buf), "__stop_%s", s->name); | |
| 7029 | + add_elf_sym(symtab_section, | |
| 7030 | + s->data_offset, 0, | |
| 7031 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), | |
| 7032 | + s->sh_num, buf); | |
| 7033 | + } | |
| 7034 | + next_sec: | |
| 7035 | + } | |
| 7002 | 7036 | } |
| 7003 | 7037 | |
| 7004 | 7038 | /* add dynamic sections so that the executable is dynamically linked */ |
| @@ -7115,13 +7149,11 @@ int tcc_output_file(TCCState *s1, const char *filename) · 110 unmodified lines | ||
| 7115 | 7149 | bss_section->data_offset = offset; |
| 7116 | 7150 | } |
| 7117 | 7151 | } else { |
| 7118 | − /* STT_NOTYPE or STB_WEAK undefined symbols | |
| 7119 | − are accepted */ | |
| 7120 | − /* XXX: STT_NOTYPE is only used to exclude the | |
| 7121 | − unreferenced '_fp_hw' symbol. need a better | |
| 7122 | − solution */ | |
| 7123 | − if (ELF32_ST_TYPE(sym->st_info) == STT_NOTYPE || | |
| 7124 | − ELF32_ST_BIND(sym->st_info) == STB_WEAK) { | |
| 7152 | + /* STB_WEAK undefined symbols are accepted */ | |
| 7153 | + /* XXX: _fp_hw seems to be part of the ABI, so we ignore | |
| 7154 | + it */ | |
| 7155 | + if (ELF32_ST_BIND(sym->st_info) == STB_WEAK || | |
| 7156 | + !strcmp(name, "_fp_hw")) { | |
| 7125 | 7157 | } else { |
| 7126 | 7158 | error("undefined symbol '%s'", name); |
| 7127 | 7159 | } |