tcc_relocate: return error and remove unused code

This commit is contained in:
grischka
2009-04-18 13:14:07 +02:00
parent d36fea34e3
commit 73ba078d2f

23
tcc.c
View File

@ -10315,9 +10315,9 @@ int tcc_relocate(TCCState *s1, void *ptr)
unsigned long offset, length, mem; unsigned long offset, length, mem;
int i; int i;
s1->nb_errors = 0;
if (0 == s1->runtime_added) { if (0 == s1->runtime_added) {
s1->runtime_added = 1;
s1->nb_errors = 0;
#ifdef TCC_TARGET_PE #ifdef TCC_TARGET_PE
pe_add_runtime(s1); pe_add_runtime(s1);
relocate_common_syms(); relocate_common_syms();
@ -10328,28 +10328,15 @@ int tcc_relocate(TCCState *s1, void *ptr)
tcc_add_linker_symbols(s1); tcc_add_linker_symbols(s1);
build_got_entries(s1); build_got_entries(s1);
#endif #endif
s1->runtime_added = 1;
} }
offset = 0; offset = 0, mem = (unsigned long)ptr;
mem = (unsigned long)ptr;
for(i = 1; i < s1->nb_sections; i++) { for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i]; s = s1->sections[i];
if (0 == (s->sh_flags & SHF_ALLOC)) if (0 == (s->sh_flags & SHF_ALLOC))
continue; continue;
length = s->data_offset; length = s->data_offset;
if (0 == mem) { s->sh_addr = mem ? (mem + offset + 15) & ~15 : 0;
s->sh_addr = 0;
} else if (1 == mem) {
/* section are relocated in place.
We also alloc the bss space */
if (s->sh_type == SHT_NOBITS)
s->data = tcc_malloc(length);
s->sh_addr = (unsigned long)s->data;
} else {
/* sections are relocated to new memory */
s->sh_addr = (mem + offset + 15) & ~15;
}
offset = (offset + length + 15) & ~15; offset = (offset + length + 15) & ~15;
} }
@ -10385,7 +10372,7 @@ int tcc_relocate(TCCState *s1, void *ptr)
ptr = (void*)s->sh_addr; ptr = (void*)s->sh_addr;
if (NULL == s->data || s->sh_type == SHT_NOBITS) if (NULL == s->data || s->sh_type == SHT_NOBITS)
memset(ptr, 0, length); memset(ptr, 0, length);
else if (ptr != s->data) else
memcpy(ptr, s->data, length); memcpy(ptr, s->data, length);
/* mark executable sections as executable in memory */ /* mark executable sections as executable in memory */
if (s->sh_flags & SHF_EXECINSTR) if (s->sh_flags & SHF_EXECINSTR)